Skip to content

fix(arborist): repair wrong-but-existing symlink target in linked strategy#9628

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-repair-wrong-symlink-target
Jun 24, 2026
Merged

fix(arborist): repair wrong-but-existing symlink target in linked strategy#9628
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-repair-wrong-symlink-target

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

In continuation of our exploration of using install-strategy=linked in the Gutenberg monorepo, which powers the WordPress Block Editor.

Under install-strategy=linked, if a top-level node_modules/<dep> symlink points to a store key that exists on disk but is the wrong version, re-running npm install does 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, #buildLinkedActualForDiff synthesizes 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 an ADD, and #reifyNode removes the old symlink and recreates it pointing at the correct store key. A new #linkTargetMismatch helper compares the two resolved targets; it runs only after the existing existsSync guards, 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

@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 24, 2026 14:26
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 24, 2026 14:26
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-repair-wrong-symlink-target branch from a5f9815 to d3fa3d2 Compare June 24, 2026 14:36
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-repair-wrong-symlink-target branch from d3fa3d2 to 23f3ac6 Compare June 24, 2026 14:44
@owlstronaut owlstronaut merged commit 0ffce98 into npm:latest Jun 24, 2026
24 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9644

@manzoorwanijk manzoorwanijk deleted the fix/linked-repair-wrong-symlink-target branch June 24, 2026 18:34
owlstronaut pushed a commit that referenced this pull request Jun 24, 2026
…ategy (#9644)

Backport of #9628 to `release/v11`.

Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] install-strategy=linked: install does not repair a wrong-but-existing symlink target (silently keeps the wrong version)

2 participants