fix(arborist): repair wrong-but-existing symlink target in linked strategy#9628
Merged
owlstronaut merged 1 commit intoJun 24, 2026
Merged
Conversation
a5f9815 to
d3fa3d2
Compare
d3fa3d2 to
23f3ac6
Compare
owlstronaut
approved these changes
Jun 24, 2026
Contributor
|
🎉 Backport to |
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.
In continuation of our exploration of using
install-strategy=linkedin the Gutenberg monorepo, which powers the WordPress Block Editor.Under
install-strategy=linked, if a top-levelnode_modules/<dep>symlink points to a store key that exists on disk but is the wrong version, re-runningnpm installdoes not repair it. npm reports success and leaves the dependency resolving to the wrong version. This is the state an interrupted update leaves behind: the new store key is extracted but the symlink has not yet been repointed.A symlink pointing at a non-existent target is already repaired on reinstall; only a wrong-but-existing target slips through, because cleanup validates the link name, not its target.
Why
For linked installs,
#buildLinkedActualForDiffsynthesizes the "actual" tree the diff compares against from the ideal children, never reading the real on-disk symlink target. So a link whose on-disk target is a valid-but-wrong store key looks identical to the ideal node, the diff reports no change, and the symlink is left untouched. The hoisted strategy is unaffected because it self-heals the analogous corruption.How
In
#buildLinkedActualForDiff, when an existing link's resolved on-disk target differs from its ideal target, skip creating a synthetic actual entry for it. With no actual entry to match, the diff treats the link as anADD, and#reifyNoderemoves the old symlink and recreates it pointing at the correct store key. A new#linkTargetMismatchhelper compares the two resolved targets; it runs only after the existingexistsSyncguards, so both paths are known to exist.This repairs both the top-level symlink and wrong transitive/sibling links inside the store, and leaves already-correct trees untouched (no spurious relinking on an idempotent reinstall).
References
Fixes #9611