You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Arborist lockfile handling when the project root is a filesystem symlink.
For example:
/shortcuts/project -> /repo/project
Arborist keeps /shortcuts/project as the configured path, while the project files and installed dependencies use /repo/project. Shrinkwrap previously mixed these paths, so the same node could be saved or looked up under different lockfile locations.
Why add an abstraction?
The first fixes translated paths at individual call sites. Further testing showed that serialization, virtual loading, validation, hidden lockfiles, and Yarn integration were all making the same path decision independently.
Continuing to patch each case would be fragile. The underlying rule is simple:
Lockfiles use portable paths relative to the configured project root. Filesystem operations use canonical paths.
This PR puts that rule in one immutable PathCoordinates object shared by every consumer. It converts between lockfile locations, filesystem paths, and local file specifications.
Shrinkwrap owns the coordinate context and updates it when the live root target changes. Non-symlink projects use the same object with identical configured and canonical roots, so their behavior does not change.
Bugs fixed
These issues are present on the base branch.
Non-portable package-lock locations
Committing a tree loaded through a symlinked root could write canonical directory traversal into package-lock.json.
Instead of portable entries such as node_modules/foo, the lockfile could contain machine-specific locations such as ../actual/node_modules/foo.
Package entries now remain relative to the configured project root.
Incorrect root metadata
Shrinkwrap could track the root Link instead of its live target.
Root metadata could therefore come from the link rather than the project package.
When the canonical directory name differed from the package name, legacy lockfile generation could incorrectly write the root version as an npm: alias.
Shrinkwrap now tracks the live target while preserving logical lockfile locations.
Unstable local tarball resolutions
A portable dependency such as file:tarballs/dep.tgz could be serialized using a path derived from the canonical project location.
This made the lockfile depend on the machine’s symlink layout.
Local tarball resolutions now remain stable and relative to the configured project root.
Incorrect linked-project locations
Links and their targets could be written relative to the canonical root.
This produced incorrect locations for entries such as node_modules/workspace and packages/workspace.
Both the link and its target now use portable lockfile coordinates.
Inconsistent metadata operations
The same node could map to different metadata depending on whether a caller used a relative lockfile location, an absolute configured path, or an absolute canonical path.
This affected get(), add(), and delete().
Metadata added using a canonical path might not be returned by a relative lookup, and deleting by canonical path might leave the lockfile entry intact.
All supported path forms now resolve to the same metadata location.
Stale root targets
During tree transplantation, metadata can be attached while the root Link temporarily has no target.
When the target was restored or replaced, Shrinkwrap could continue tracking the detached or stale node.
Shrinkwrap now updates its metadata tree and canonical root whenever the live target changes.
Scope
This PR does not change how Arborist reconciles ideal and virtual inventory identities.
A dependency-free npm ci invocation through a symlinked prefix still exposes a separate mismatch between ideal and virtual synthetic-root inventory keys. That behavior reproduces on the base commit and occurs after lockfile coordinate hydration.
Testing
Regression coverage verifies:
portable package-lock keys
root metadata from the live target
stable local tarball resolutions
correct link and target locations
equivalent relative, configured-absolute, and canonical-absolute lookups
consistent get(), add(), and delete() behavior
targetless root restoration and target replacement
virtual loading and save/reload round trips
external dependencies
hidden lockfiles
Yarn metadata
local directory and tarball validation
Validation:
npm test --ignore-scripts --workspace @npmcli/arborist
npm run lint --ignore-scripts --workspace @npmcli/arborist
The reason will be displayed to describe this comment to others. Learn more.
Verified 810ec4b on Linux/Node 24.22.3: the complete 59-file Arborist suite passes with 100% coverage, plus ESLint and the template check. Actual CLI installs through a sibling symlink now write node_modules/foo rather than ../../real/app/node_modules/foo; registry, alias, local-tarball and internal/external file: dependencies remain loadable after installation.
One remaining round-trip case may be useful for a follow-up test. Even a dependency-free project installed through the symlink still fails npm ci through that same path:
I checked this against both the parent d538936 and this head: both fail the symlinked ci case, while both direct-path install/ci controls pass. The head correctly saves the root's name/version, so this is a remaining end-to-end limitation rather than a regression introduced by this change. The serialization correction itself is reproduced and verified; I have not tested the independent fixtures on Windows.
Yeah, that’s an interesting finding, but I think it’s outside the scope of this PR because addressing it requires a broader decision about how Arborist compares or normalizes the ideal and virtual tree inventories. This PR is a localized fix to how Shrinkwrap serializes and looks up lockfile paths for symlinked roots. The npm ci failure also reproduces on the base commit and happens later, when the ideal and virtual trees represent the synthetic root link under different location keys.
The reason will be displayed to describe this comment to others. Learn more.
Agreed on scope. The dependency-free ci case fails on both d538936 and 810ec4b, so it does not block this serialization fix. The full Arborist suite and the independent install cases I reported pass at this unchanged head.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Symlink-root path handling leaves linked dependencies missing and tarball edges invalid after reload, while target replacement can cause stale metadata to be serialized.
This PR updates Arborist’s Shrinkwrap handling for symlinked project roots, keeping lockfile locations relative to the configured logical path while using the canonical target for metadata.
Changes:
Centralizes path translation across metadata lookups, mutations, and serialization.
Adjusts root metadata, linked targets, local tarball resolutions, and legacy version handling.
Adds symlink-root regression coverage and updates lockfile snapshots.
File
Description
workspaces/arborist/test/shrinkwrap.js
Adds filesystem-symlink and targetless-root metadata regressions.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved symlink-root path inconsistencies can corrupt hydrated dependency graphs, invalidate local dependencies, and produce incorrect or unusable lockfiles.
For a symlinked root with a file:. dependency, nodes.get('') is the root Link, not its canonical target. Passing that Link into #loadLink() gives the dependency the logical root path and corrupts the hydrated graph. Pass target.target (ordinary nodes return themselves) and cover this root-backlink reload case.
Translate symlink targets when validating hidden lockfiles
workspaces/arborist/lib/shrinkwrap.js:1022
For a symlinked root with an absolute dependency-link target, the new hidden-lockfile key is packages/workspace, but assertNoNewer() checks the target as ../actual/packages/workspace. A fresh .package-lock.json is therefore rejected and loadActual() falls back to a full filesystem walk. Translate symlink targets during validation and add a hidden-lockfile save/reload regression covering relative and absolute targets.
a3cfe1f also resolves root backlinks against the canonical target and translates symlink targets during hidden-lockfile validation, with regressions for both relative and absolute link targets.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
File and link paths still resolve against logical rather than canonical roots in symlinked projects, selecting incorrect tarballs and link targets and causing dependency validation failures and rejection of freshly saved hidden lockfiles.
With /shortcuts/project -> /repo/project, an absolute directory request such as file:/shortcuts/project/packages/ws keeps its logical fetchSpec, while this loader attaches a link targeting /repo/project/packages/ws. linkValid() compares those paths directly, so the reloaded dependency is invalid. Normalize directory requests with the root-coordinate translator in dep-valid.js:154, as tarball validation now does.
The summary-only directory validation finding is also fixed in 65758f0: absolute logical directory requests and canonical link targets now normalize through the same coordinate context before comparison. 36f9fbc restores the suite’s required 100% coverage, and CI is green.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical defects remain: symlink-root migration can produce invalid tarball paths, while incomplete external-node adoption can lose dependency edges and drop lockfile entries.
Keep lockfile metadata in configured-root coordinates while resolving filesystem operations from the canonical root. Preserve virtual tree shape and external dependency topology across symlink roots.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ec52121e7f84203af4415cf8082eae1
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
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.
Summary
Fix Arborist lockfile handling when the project root is a filesystem symlink.
For example:
Arborist keeps
/shortcuts/projectas the configured path, while the project files and installed dependencies use/repo/project. Shrinkwrap previously mixed these paths, so the same node could be saved or looked up under different lockfile locations.Why add an abstraction?
The first fixes translated paths at individual call sites. Further testing showed that serialization, virtual loading, validation, hidden lockfiles, and Yarn integration were all making the same path decision independently.
Continuing to patch each case would be fragile. The underlying rule is simple:
This PR puts that rule in one immutable
PathCoordinatesobject shared by every consumer. It converts between lockfile locations, filesystem paths, and local file specifications.Shrinkwrap owns the coordinate context and updates it when the live root target changes. Non-symlink projects use the same object with identical configured and canonical roots, so their behavior does not change.
Bugs fixed
These issues are present on the base branch.
Non-portable package-lock locations
package-lock.json.node_modules/foo, the lockfile could contain machine-specific locations such as../actual/node_modules/foo.Incorrect root metadata
Linkinstead of its live target.npm:alias.Unstable local tarball resolutions
file:tarballs/dep.tgzcould be serialized using a path derived from the canonical project location.Incorrect linked-project locations
node_modules/workspaceandpackages/workspace.Inconsistent metadata operations
get(),add(), anddelete().Stale root targets
Linktemporarily has no target.Scope
This PR does not change how Arborist reconciles ideal and virtual inventory identities.
A dependency-free
npm ciinvocation through a symlinked prefix still exposes a separate mismatch between ideal and virtual synthetic-root inventory keys. That behavior reproduces on the base commit and occurs after lockfile coordinate hydration.Testing
Regression coverage verifies:
get(),add(), anddelete()behaviorValidation:
npm test --ignore-scripts --workspace @npmcli/arboristnpm run lint --ignore-scripts --workspace @npmcli/arborist