Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(info): adding more functionality to info package #833

Closed
wants to merge 54 commits into from

Conversation

pranshuchittora
Copy link
Member

@pranshuchittora pranshuchittora commented Apr 17, 2019

Today, while working on this PR, I observed that many CLI packages have very fewer downloads.

info package downloads npm

As a developer, I have expected the info package to give some information about config or something related to webpack. Strangely it outputs some environment information.

So the idea is to revamp the current info package by adding a few features.

  • Information about webpack config. By specifying the path of the webpack config, it will provide some information about plugins, entry point, output point...

Screenshot from 2019-04-18 02-53-53
Expected behaviour

Solution: By using the power of AST we can parse the config file & get the required details.

  • Extending the current environment information.
    The current env info looks good, but someone might want some other env info, so the idea is to add more env info & access them dynamically by flags.

Screenshot from 2019-04-18 02-54-46

Screenshot from 2019-04-18 02-55-24
Multiple flags supported, in order to get multiple env info

Solution: By reading the process arguments (flags)

What kind of change does this PR introduce?
Feature
Did you add tests for your changes?
Yes
If relevant, did you update the documentation?
Yes

I am working on this, so pls suggest any improvements. 🙏
Let's discuss 🔥

a small step towards improving the current info package
for faster and precise execution, a list of supported flags is added
@ematipico
Copy link
Contributor

Now that you're proposing some new flags, which are Great, we should also provide an help command/flag so we show how to use the info

Copy link
Member

@anshumanv anshumanv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also include your .lock file? That should fix the tests. 👍

updates the lock file of packages/info
Copy link
Member

@rishabh3112 rishabh3112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a good idea to me :) left a change for you.
Also, add [WIP] in the PR title as work is not completed here IMO

packages/info/index.ts Outdated Show resolved Hide resolved
@pranshuchittora
Copy link
Member Author

@ematipico check this out.

  • Help flag

Screenshot from 2019-04-18 18-05-32

Output formats

  • JSON

Screenshot from 2019-04-18 18-11-43

  • Markdown

Screenshot from 2019-04-18 18-12-31
Markdown format would make issues to look more cleaner.

Default

Screenshot from 2019-04-18 18-14-40

Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna take this for a spin on a corp project, so chilling this for a bit

@pranshuchittora pranshuchittora changed the title feat(info): adding more functionality to info package [WIP] feat(info): adding more functionality to info package Apr 19, 2019
@anikethsaha
Copy link
Member

This one is really great . You can give the command name like describe configfilename much like in kubernetes does to output the state and configuration of the file.

@pranshuchittora
Copy link
Member Author

pranshuchittora commented Apr 19, 2019

@evenstensberg I am thinking of going with ASTs to extract the required information from the config file. Is there any other way around 😎

Screenshot from 2019-04-20 00-41-27

@ematipico
Copy link
Contributor

@evenstensberg why did you chill a PR that is still WIP?

Copy link
Contributor

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion

packages/info/index.ts Outdated Show resolved Hide resolved
adds more options and command types
fixed the linting error
packages/info/README.md Outdated Show resolved Hide resolved
@@ -0,0 +1,13 @@
export const AVAILABLE_COMMANDS: string[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use these constants inside your commands.ts, so you can keep your code DRY.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not getting it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You should create an enum for your available commands.
  2. Later you will use AVAILABLE_COMMANDS.BINARIES inside commands.ts

Basically it's not convenient to have the same string repeated in different places. Create ONE constant and it in those places

}
export default async function info(CustomArgv: object): Promise<void> {
const CUSTOM_AGRUMENTS: boolean = typeof CustomArgv === "object";
const args: ArgvI = CUSTOM_AGRUMENTS ? CustomArgv : argv;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You define the options using yargs, so could you please use yargs to parse the arguments too? It will keep consistency. Sorry to be annoying but I don't see any reason to not do that

Copy link
Member

@rishabh3112 rishabh3112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more suggestions

packages/info/README.md Outdated Show resolved Hide resolved
packages/info/package.json Outdated Show resolved Hide resolved
packages/info/renderTable.ts Outdated Show resolved Hide resolved
packages/info/renderTable.ts Outdated Show resolved Hide resolved
packages/info/README.md Show resolved Hide resolved
@webpack-bot
Copy link

@pranshuchittora Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@rishabh3112 Please review the new changes.

yarn add @webpack-cli/info -D

#npx
npx webpack info [options]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an installation command, it should be under usage :)

now plugin name can be retrived from the constructor call
@webpack-bot
Copy link

@pranshuchittora Please review the following output log for errors:

Worker information [...]
Build system information [...]
docker stop/waiting [...]
resolvconf stop/waiting [...]


Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions

Setting environment variables from repository settings
$ export nproc=4

Setting environment variables from .travis.yml
$ export JOB_PART=integration


Setting up build cache [...]
$ node --version
v8.16.0
$ npm --version
6.4.1
$ nvm --version
0.34.0

$ npm run travis:lint

> webpack-cli@3.3.5 travis:lint /home/travis/build/webpack/webpack-cli
> npm run build && npm run lint


> webpack-cli@3.3.5 build /home/travis/build/webpack/webpack-cli
> tsc


> webpack-cli@3.3.5 lint /home/travis/build/webpack/webpack-cli
> eslint "./bin/*.js" "./bin/**/*.js" "./test/**/*.js" "packages/**/!(node_modules)/*.ts"  "packages/**/!(node_modules)/**/*.ts"


/home/travis/build/webpack/webpack-cli/packages/info/configParser.ts
  34:26  error    Delete `⏎↹↹`                                   prettier/prettier
  36:3   error    Delete `↹`                                     prettier/prettier
  37:1   error    Delete `↹`                                     prettier/prettier
  37:5   error    'modifyConfig' was used before it was defined  @typescript-eslint/no-use-before-define
  38:1   error    Delete `↹`                                     prettier/prettier
  39:3   error    Delete `↹`                                     prettier/prettier
  40:1   error    Delete `↹`                                     prettier/prettier
  41:1   error    Delete `↹`                                     prettier/prettier
  42:2   error    Replace `↹}⏎↹` with `}`                        prettier/prettier
  48:1   warning  Missing return type on function                @typescript-eslint/explicit-function-return-type
  51:24  warning  Missing return type on function                @typescript-eslint/explicit-function-return-type

/home/travis/build/webpack/webpack-cli/packages/info/index.ts
  63:29  warning  Missing return type on function  @typescript-eslint/explicit-function-return-type

/home/travis/build/webpack/webpack-cli/packages/info/renderTable.ts
   8:11  error  Delete `⏎↹↹`             prettier/prettier
  10:3   error  Delete `↹`               prettier/prettier
  11:2   error  Replace `↹}⏎↹` with `}`  prettier/prettier

/home/travis/build/webpack/webpack-cli/packages/utils/modify-config-helper.ts
  46:4  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

/home/travis/build/webpack/webpack-cli/packages/webpack-scaffold/index.ts
   51:8   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
   57:13  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
   90:8   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
   95:13  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  108:8   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  114:13  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  127:8   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  132:13  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

✖ 24 problems (12 errors, 12 warnings)
  11 errors and 0 warnings potentially fixable with the `--fix` option.



The command "npm run travis:lint" exited with 1.

$ npm run test:ci

> webpack-cli@3.3.5 test:ci /home/travis/build/webpack/webpack-cli
> nyc jest --maxWorkers=$(nproc) --reporters=default --reporters=jest-junit

 PASS  test/test-utils.test.js
 PASS  packages/webpack-scaffold/__tests__/index.test.ts (7.071s)
 PASS  packages/utils/__tests__/ast-utils.test.ts (9.258s)
 PASS  packages/utils/__tests__/package-manager.test.ts
 PASS  packages/utils/__tests__/resolve-packages.test.ts
 PASS  packages/utils/__tests__/validate-identifier.test.ts
 PASS  packages/info/__tests__/index.test.ts
 PASS  packages/utils/__tests__/recursive-parser.test.ts
 PASS  packages/migrate/commonsChunkPlugin/__tests__/commonsChunkPlugin.test.ts
 PASS  packages/migrate/__tests__/migrate.test.ts
 PASS  test/binCases/help/help-output/help-output.test.js
 PASS  packages/utils/__tests__/npm-packages-exists.test.ts
 PASS  test/binCases/output/output-library-many/output-library-many.test.js
 PASS  test/binCases/env/complex/comple.test.js
 PASS  test/binCases/entry/named-entry/named-entry.test.js
 PASS  test/binCases/output/output-library-single/output-library-single.test.js
 PASS  test/binCases/module/module-bind/module-bind.test.js
 PASS  packages/utils/__tests__/is-local-path.test.ts
 PASS  test/binCases/entry/non-hyphenated-args/non-hyphenated-args.test.js
 PASS  test/binCases/stats/single-config/single-config.test.js
 PASS  test/binCases/entry/multi-file/multi-file.test.js
 PASS  test/binCases/config-name/found-many/found-many.test.js
 PASS  test/binCases/configFile/plugins-precedence/plugins-precedence.test.js
 PASS  test/binCases/config-type/array/array.test.js
 PASS  test/binCases/env/string/string.test.js
 PASS  test/binCases/entry/cli-override/cli-override.test.js
 PASS  test/binCases/errors/info-verbosity/info-verbosity.test.js
 PASS  packages/migrate/loaders/__tests__/loaders.test.ts
 PASS  packages/generators/__tests__/add-generator.test.ts
 PASS  test/binCases/config-name/found-one/found-one.test.js

Please remove deprecated plugins manually. 
See https://webpack.js.org/guides/migrating/ for more information.
Please remove deprecated plugins manually. 
See https://webpack.js.org/guides/migrating/ for more information.
Please remove deprecated plugins manually. 
See https://webpack.js.org/guides/migrating/ for more information. PASS  packages/migrate/removeDeprecatedPlugins/__tests__/removeDeprecatedPlugins.test.ts
 PASS  test/binCases/errors/parse/parse.test.js
 PASS  test/binCases/errors/clean-webpack-options/clean-webpack-options.test.js
 PASS  test/binCases/config-location/set-explicitly/set-explicitly.test.js
 PASS  test/binCases/config-type/invalid-array/invalid-array.test.js
 PASS  test/binCases/config-type/invalid-type/invalid-type.test.js
 PASS  packages/generators/__tests__/loader-generator.test.ts
 PASS  test/binCases/config-location/webpackfile-config/packages/foo/webpackfile-config.test.js
 PASS  test/binCases/stats/custom-preset/custom-preset.test.js
 PASS  test/binCases/config-type/function-promise/function-promise.test.js
 PASS  test/binCases/output/output-argument/output-argument.test.js
 PASS  test/binCases/config-type/function/function.test.js
 PASS  test/binCases/config-type/promise/promise.test.js
 PASS  packages/migrate/uglifyJsPlugin/__tests__/uglifyJsPlugin.test.ts
 PASS  test/binCases/config-type/object/object.test.js
 PASS  test/binCases/mode/none/none.test.js
 PASS  test/binCases/config-location/find-recursively/packages/foo/find-recursively.test.js
 PASS  packages/migrate/loaderOptionsPlugin/__tests__/loaderOptionsPlugin.test.ts
 PASS  packages/utils/__tests__/npm-exists.test.ts
 PASS  test/binCases/config-location/set-implicitly/set-implicitly.test.js
 PASS  test/binCases/no-options/production/production.test.js
 PASS  test/binCases/stats/build-delimiter/build-delimiter.test.js
 PASS  test/binCases/config-name/not-found/not-found.test.js
 PASS  packages/migrate/removeJsonLoader/__tests__/removeJsonLoader.test.ts
 PASS  test/binCases/config-location/not-found/not-found.test.js
 PASS  packages/migrate/moduleConcatenationPlugin/__tests__/moduleConcatenationPlugin.test.ts
 PASS  test/binCases/no-options/none/none.test.js
 PASS  test/binCases/errors/issue-5576/issue-5576.test.js
 PASS  packages/migrate/noEmitOnErrorsPlugin/__tests__/noEmitOnErrorsPlugin.test.ts
 PASS  packages/migrate/namedModulesPlugin/__tests__/namedModulesPlugin.test.ts
 PASS  test/binCases/configFile/profile/profile.test.js
 PASS  test/binCases/entry/display-entrypoints/display-entrypoints.test.js
 PASS  test/binCases/stats/multi-config/multi-config.test.js
 PASS  test/binCases/silent/silent-output/silent.test.js
 PASS  packages/migrate/bannerPlugin/__tests__/bannerPlugin.test.ts
 PASS  packages/migrate/outputPath/__tests__/outputPath.test.ts
 PASS  test/binCases/stats/none/none.test.js
 PASS  packages/migrate/extractTextPlugin/__tests__/extractTextPlugin.test.ts
 PASS  packages/migrate/resolve/__tests__/resolve.test.ts
 PASS  test/binCases/config-location/webpack-babel-config/webpack-babel-config.test.js (19.837s)
�[999D�[K
Test Suites: 8 skipped, 70 passed, 70 of 78 total
Tests:       8 skipped, 197 passed, 205 total
Snapshots:   95 passed, 95 total
Time:        87.169s
Ran all test suites.
The command "npm run test:ci" exited with 0.

store build cache [...]

Done. Your build exited with 1.

See complete report here.

@evenstensberg
Copy link
Member

Could you rebase this against the next branch?

@ematipico ematipico changed the base branch from master to next July 23, 2019 07:14
@pranshuchittora
Copy link
Member Author

Refer #1007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants