Skip to content

fix(ls): show absolute paths for global links - #10201

Open
ShryukGrandhi wants to merge 1 commit into
npm:latestfrom
ShryukGrandhi:fix/issue-3752-bug-npm-7-shows-links-as-non-absolute-pa
Open

ShryukGrandhi wants to merge 1 commit into
npm:latestfrom
ShryukGrandhi:fix/issue-3752-bug-npm-7-shows-links-as-non-absolute-pa

Conversation

@ShryukGrandhi

Copy link
Copy Markdown

Summary

npm ls -g prints linked packages with a path relative to the global lib directory, prefixed with ./, e.g. my-pkg@1.0.0 -> ./../../../home/me/my-pkg.
That path is awkward to read and isn't usable from wherever the user runs the command.
npm 6 printed the absolute target path here.

Fixes #3752

Changes

  • In lib/commands/ls.js, the human-readable output now prints the link's absolute realpath when --global is set.
    Local (non-global) output keeps the existing ./relative form, so project trees and their snapshots don't change.

Testing

  • Added a linked package to the existing ls global test.
    Before the fix the snapshot showed linked@1.0.0 -> ./../../prefix; after the fix it shows linked@1.0.0 -> {CWD}/prefix.
  • npx tap test/lib/commands/ls.js passes with 100% coverage of lib/commands/ls.js.
  • npx eslint lib/commands/ls.js test/lib/commands/ls.js is clean.

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
@ShryukGrandhi
ShryukGrandhi requested a review from a team as a code owner November 2, 2026 04:35
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.

[BUG] npm 7 shows links as non-absolute paths

1 participant