Skip to content

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

Draft
wants to merge 7 commits into
base: latest
Choose a base branch
from

Conversation

milaninfy
Copy link
Contributor

@milaninfy milaninfy commented Apr 9, 2025

Attempt to fix npm ls output

Problem:

  • deduped nodes are cloned when encountered using previously seen nodes set but they are not explored further when we are requesting npm ls dep-name if dep-name is a child of some deduped parent then whole tree would be shown till that parent but logically dep-name is still the child/grand-child of that.
  • When deduped nodes are explored further it results in cycle when dep1 is ancestor of dep2 which again depends on dep1 creating a cycle when explored, also the algorithm used is BFS so it's hard to detect cycle.

Solution:

  • This solution attempts to explore cloned nodes of deduped nodes so that it fixes the output
  • Attempts to detect cycle through naive approach of tracking how the current node is discovered thorough tracking pkgid+path of it's parent and so on creating a kind of ancestor chain and checking if current node is in that chain and marking it as a cycle to indicate not to explore further.

Progress:

  • still some cases which might result in Infinite loop and need to discovered those.
  • very slow and uses very large memory during run when ran on big repo, need to find out optimizations or better approach
  • Fix/add the test cases
  • Refactor

Test output

`npm ls child` - before and after

Before

~/workarea/rep/repro $ npm ls child
[email protected] /Users/milaninfy/workarea/rep/repro
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └── [email protected]

After

~/workarea/rep/repro $ lnpm ls child
[email protected] /Users/milaninfy/workarea/rep/repro
├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected] deduped
│     └─┬ [email protected] deduped
│       └── [email protected] deduped
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └── [email protected]

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.

1 participant