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

Add 'npm explain' command #1776

Closed
wants to merge 2 commits into from
Closed

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Sep 7, 2020

Took the code used to explain ERESOLVE errors, and just made it a top-level command that will explain a given set of nodes.

This is surprisingly handy! Like, if you noticed that react is in the node_modules tree, you could do this:

$ npm explain node_modules/react
react@16.13.1 dev
node_modules/react
  react@"^16.12.0" from tap@14.10.8
  node_modules/tap
    dev tap@"^14.10.8" from the root project
  peer react@">=16.8.0" from ink@2.7.1
  node_modules/tap/node_modules/ink
    ink@"^2.6.0" from tap@14.10.8
    node_modules/tap
      dev tap@"^14.10.8" from the root project
    ink@"^2.6.0" from treport@1.0.2
    node_modules/tap/node_modules/treport
      treport@"^1.0.2" from tap@14.10.8
      node_modules/tap
        dev tap@"^14.10.8" from the root project
  peer react@"^16.0.0" from react-reconciler@0.24.0
  node_modules/tap/node_modules/react-reconciler
    react-reconciler@"^0.24.0" from ink@2.7.1
    node_modules/tap/node_modules/ink
      ink@"^2.6.0" from tap@14.10.8
      node_modules/tap
        dev tap@"^14.10.8" from the root project
      ink@"^2.6.0" from treport@1.0.2
      node_modules/tap/node_modules/treport
        treport@"^1.0.2" from tap@14.10.8
        node_modules/tap
          dev tap@"^14.10.8" from the root project
  peer react@"^16.8.6" from treport@1.0.2
  node_modules/tap/node_modules/treport
    treport@"^1.0.2" from tap@14.10.8
    node_modules/tap
      dev tap@"^14.10.8" from the root project

Or if you want to know why mkdirp is being duplicated, you could run:

$ npm explain mkdirp
mkdirp@1.0.4
node_modules/mkdirp
  mkdirp@"^1.0.4" from the root project

mkdirp@0.5.5
node_modules/node-gyp/node_modules/mkdirp
  mkdirp@"^0.5.1" from node-gyp@6.1.0
  node_modules/node-gyp
    node-gyp@"^6.1.0" from @npmcli/run-script@1.5.0
    node_modules/@npmcli/run-script
      @npmcli/run-script@"^1.5.0" from the root project
  mkdirp@"^0.5.0" from tar@4.4.13
  node_modules/node-gyp/node_modules/tar
    tar@"^4.4.12" from node-gyp@6.1.0
    node_modules/node-gyp
      node-gyp@"^6.1.0" from @npmcli/run-script@1.5.0
      node_modules/@npmcli/run-script
        @npmcli/run-script@"^1.5.0" from the root project

Definitely some overlap in use-cases with npm ls, but coming at the data in the other direction, starting with the dependency as the top of the "tree" and then showing each dependent tracking back to the root project, which makes it a better fit for the "why is this here??" questions.

cc: @ljharb I think I promised you this when we were discussing removing the _-prefixed fields from package.json files in node_modules.

Reduce visual noise, make the more important information more obvious.
@isaacs isaacs requested a review from a team as a code owner September 7, 2020 21:57
@ljharb
Copy link
Contributor

ljharb commented Sep 7, 2020

Could there be colors added for supporting terminals? it might help the readability of what is otherwise a large block of text

@ljharb
Copy link
Contributor

ljharb commented Sep 7, 2020

also is there a way it could be a table instead, with the react@"^16.12.0" from tap@14.10.8 on one column and the node_modules/tap on another? (since the only time the actual path will matter is if there's more than one instance of that package in the tree)

@isaacs
Copy link
Contributor Author

isaacs commented Sep 7, 2020

Could there be colors added for supporting terminals?

Yes, there are colors.

Screen Shot 2020-09-07 at 15 05 33

also is there a way it could be a table instead, with the react@"^16.12.0" from tap@14.10.8 on one column and the node_modules/tap on another?

The challenge there is that the indentation can get pretty deep, and so putting too much horizontally can be a problem, especially when these node explanations appear in error logs for ERESOLVE failures.

@isaacs
Copy link
Contributor Author

isaacs commented Sep 8, 2020

Oops forgot to push the rebase to remove all those debug commits. Should have this ready to land shortly.

@isaacs isaacs force-pushed the isaacs/npm-explain branch 2 times, most recently from e41fe4f to ffe16b0 Compare September 8, 2020 16:47
Pass a specifier or folder path, and it'll explain what that dependency
is doing there.
@isaacs
Copy link
Contributor Author

isaacs commented Sep 8, 2020

Ok, this is now ready for review.

@isaacs isaacs closed this Sep 8, 2020
isaacs added a commit that referenced this pull request Sep 8, 2020
Pass a specifier or folder path, and it'll explain what that dependency
is doing there.

PR-URL: #1776
Credit: @isaacs
Close: #1776
Reviewed-by: @ruyadorno
@isaacs
Copy link
Contributor Author

isaacs commented Sep 8, 2020

Landed 5e49bda

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

Successfully merging this pull request may close these issues.

4 participants