fix(outdated): report aliased global packages against the aliased registry name#9707
Open
Sanjays2402 wants to merge 1 commit into
Open
fix(outdated): report aliased global packages against the aliased registry name#9707Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
…istry name Closes npm#9706 When a package is installed globally via an alias spec (`npm install -g cat@npm:dog@1.0.1`), the outdated command iterated the global root's children as Nodes rather than Edges, so `edge.spec` was undefined and the existing alias detection path was skipped. The lookup then fell through to the wrapper directory name, which either resolved against the wrong packument or produced no row at all. Detect this case by checking that the wrapper directory name (`node.name`) differs from the actual package name (`node.packageName`), synthesize an `npm:<pkg>@<version>` spec, and reuse the existing alias code path so Wanted / Latest resolve against the aliased package's packument. The row name now reads `<wrapper>@npm:<pkg>@<version>` so users can tell which on-disk package is being reported on.
Contributor
|
Thank you so much for resolving my issue! |
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.
Description
npm outdated -greports the wrong package and the wrong target version for globally installed alias packages.When you install a global alias such as
npm install -g cat@npm:dog@1.0.1, the directory on disk iscat/butpackage.jsoninside is{ "name": "dog", "version": "1.0.1" }.outdatediterates the global root asnode.children.values()(Nodes, not Edges), soedge.specisundefined, and the existing alias-detection path (safeNpa(edge.spec)?.subSpec) is skipped. The packument fetch then falls through to the wrapper directory name (cat) instead of the aliased package (dog), and the row that prints to the user is essentially nonsense: theCurrentcolumn shows the aliased package's installed version whileWanted/Latestcome from the wrong packument.This is the exact scenario in #9706, where the user installs
cowsay@npm:typescript@5.0.0and sees:6.0.2is typescript's installed version and1.6.0is cowsay's latest, so the row is mixing two different packages.Fix
In
#getOutdatedInfo, whenedge.specis missing (the global-Node case) and the wrapper directory name differs from the package's own name (node.name !== node.packageName), synthesize annpm:<packageName>@<version>spec and feed it through the existing alias code path. The packument now comes from the aliased package,Wanted/Latestresolve correctly, and the row label becomes<wrapper>@npm:<pkg>@<version>so the user can tell which on-disk package is being reported on.The pre-existing local-alias path (
edge.spec.replace('npm', edge.name)producing rows likecat:dog@^1.0.0) is untouched so existing snapshots and behavior are unchanged.References
Fixes #9706
Test Coverage
Added a regression test
global alias packages report alias spec, not aliased package versionintest/lib/commands/outdated.jsthat:node_modules/cat/package.jsonis actually{ name: 'dog', version: '1.0.1' }(the on-disk shape ofnpm install -g cat@npm:dog@1.0.1).outdated.exec([])withconfig: { global: true }.cat@npm:dog@1.0.1, the Current column reflects the alias, and the Latest column resolves to dog's latest (2.0.0) rather than cat's.Verified the test fails on the base commit (all three assertions fail; no row is even produced) and passes with this fix. Full
test/lib/commands/outdated.jssuite (12 subtests) passes; no existing snapshots were touched. Lint clean.AI disclosure
This change was written with the assistance of Claude. I have reviewed the diff and the test and take responsibility for the code.