fix: nodejs transitive with a top level alias but transitive it not #293
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this does
Fixes a bug in npm lockfile v2 parsing where dependencies could not be resolved when a top-level alias shadows a nested real package.
Example scenario:
package.jsonhas"@types/node": "npm:@types/web@^0.0.148"(aliased)apache-arrow) depends on the real"@types/node": "^20.13.0"node_modules/@types/node(actually@types/web) andnode_modules/apache-arrow/node_modules/@types/node(real@types/node)Previously, the code resolved the package name from the first candidate globally, causing the nested real
@types/nodeto be incorrectly filtered out during ancestry matching (because it expected@types/webin the ancestry). This resulted in a falseOutOfSyncError.The fix moves the name resolution inside the candidate filter loop so each candidate resolves its own real package name for ancestry matching.
Notes for the reviewer
To reproduce the original issue:
npx jest test/jest/dep-graph-builders/npm-lock-v2.test.tsThe new test fixture
nested-non-alias-with-top-level-aliascovers this specific edge case where:@types/node→@types/web)@types/node@^20.13.0)More information
Screenshots
N/A - internal parsing logic change