-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(ls): correctly show deduped dependencies #8217
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
base: latest
Are you sure you want to change the base?
Conversation
fb7ba8e
to
1ff339c
Compare
lib/commands/ls.js
Outdated
// the `tree` obj) that was just visited in the `visit` method below | ||
// `nodeResult` is going to be the returned `item` from `visit` | ||
const result = exploreDependencyGraph({ | ||
node: tree, | ||
getChildren (node, nodeResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing in function like this and visit
can be pretty confusing when trying to understand the code later. It's also easy to introduce unintended mistakes cause state can get pretty noodly.
Let's call these beforehand and pass the results as new params.
@@ -58,6 +58,7 @@ class LS extends ArboristWorkspaceCmd { | |||
const unicode = this.npm.config.get('unicode') | |||
const packageLockOnly = this.npm.config.get('package-lock-only') | |||
const workspacesEnabled = this.npm.flatOptions.workspacesEnabled | |||
const includeWorkspaceRoot = this.npm.flatOptions.includeWorkspaceRoot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason workspacesEnabled is pulling from flatoptions is because it's derived from workspaces
config. includeWorkspaceRoot has no such distinction so we should pull it from config like the rest of this command does.
We know this is less than ideal, but fixing this disparity is a future concern.
Attempt to fix
npm ls
outputProblem:
npm ls dep-name
ifdep-name
is a child of some deduped parent then whole tree would be shown till that parent but logicallydep-name
is still the child/grand-child of that.dep1
is ancestor ofdep2
which again depends ondep1
creating a cycle when explored, also the algorithm used is BFS so it's hard to detect cycle.Solution:
Progress:
Test output
`npm ls child` - before and after
fixes: #7917