npm transitive alias support - #1865
Open
dterrybd wants to merge 4 commits into
Open
Conversation
dterrybd
requested review from
bd-samratmuk,
bd-spratikbharti,
shantyk and
zahidblackduck
September 3, 2026 14:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
There were two things going on here. 1) Aliases to the same package were not properly handled in the map and 2) aliases were only handled at the root project level. If components used aliases in their own package.json files, Detect would not appropriately discover that.
Problem 1 — Lockfile detector: aliases to the same package conflated into one BOM entry
When a project declares multiple aliases to the same underlying package (e.g. "react-is-18": "npm:react-is@18.3.1" and "react-is-19": "npm:react-is@19.2.7"), the lockfile detector reported only one of them in the BOM.
Root cause: NpmDependencyConverter was storing actual package name (react-is) rather than their alias key. Both entries then had NpmDependency.name = "react-is", so when the graph transformer looked
up each declared dependency by name the code returned the same object for both, conflating two distinct versions into a single BOM entry.
Fix: NpmDependencyConverter.convertLockPackagesToNpmDependencies now stores the lockfile map key (the alias, e.g.
react-is-18) as NpmDependency.name. Each alias resolves to a unique NpmDependency so both versions reach
the BOM. As a consequence, the alias-mapping in GraphTransformer became redundant and was removed. Lookups now work directly against the alias key.
Problem 2 — Both detectors: transitive aliases invisible in the BOM
When an intermediate dependency declares alias dependencies in its own subtree, neither
detector reported them.
Fix: Covered by the same change above. Because alias keys are now the native lookup name in every NpmDependency, transitive aliases are found the same way as normal dependencies.
CLI detector root cause: npm ls --json outputs only the alias key and version (e.g. "react-is-18": {"version": "18.3.1"}). The alias map was built exclusively from the root package.json, so transitive aliases were invisible to it.
Fix: NpmCliExtractor.extract() now scans node_modules and crates a map of alias to real packages. npm itself writes node_modules folder so we have to go there to get the information missing from the CLI command. This supplemental map is then merged with the package.json derived map before processing, covering both root and transitive aliases.