Skip to content

Conversation

@JamesPatrickGill
Copy link
Member

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:

  • Root package.json has "@types/node": "npm:@types/web@^0.0.148" (aliased)
  • A nested dependency (apache-arrow) depends on the real "@types/node": "^20.13.0"
  • The lockfile has both: node_modules/@types/node (actually @types/web) and node_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/node to be incorrectly filtered out during ancestry matching (because it expected @types/web in the ancestry). This resulted in a false OutOfSyncError.

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-alias covers this specific edge case where:

  1. A top-level dependency is aliased (@types/node@types/web)
  2. A transitive dependency requires the real package (@types/node@^20.13.0)
  3. Both exist in the lockfile at different paths

More information

Screenshots

N/A - internal parsing logic change

@JamesPatrickGill JamesPatrickGill requested review from a team as code owners November 27, 2025 11:13
@JamesPatrickGill JamesPatrickGill force-pushed the fix/nodejs-transitive-with-a-top-level-alias-but-transitive-is-not branch from e446b31 to 9e53a97 Compare November 27, 2025 11:15
@JamesPatrickGill JamesPatrickGill merged commit 2a56305 into main Nov 27, 2025
5 checks passed
@JamesPatrickGill JamesPatrickGill deleted the fix/nodejs-transitive-with-a-top-level-alias-but-transitive-is-not branch November 27, 2025 16:44
@snyksec
Copy link

snyksec commented Nov 27, 2025

🎉 This PR is included in version 2.4.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants