Skip to content

fix(arborist): avoid full reinstall on subsequent linked strategy runs#9031

Open
manzoorwanijk wants to merge 1 commit intonpm:latestfrom
manzoorwanijk:fix/linked-strategy-subsequent-install
Open

fix(arborist): avoid full reinstall on subsequent linked strategy runs#9031
manzoorwanijk wants to merge 1 commit intonpm:latestfrom
manzoorwanijk:fix/linked-strategy-subsequent-install

Conversation

@manzoorwanijk
Copy link
Contributor

In continuation of our exploration of using install-strategy=linked in the Gutenberg monorepo, which powers the WordPress Block Editor, this is a follow-up of the fixes from #8996.

Running npm install --install-strategy=linked a second time (with nothing changed) performs a full reinstall instead of recognizing everything is up-to-date. This is because the flat proxy tree built by _createIsolatedTree() doesn't match the nested actual tree from loadActual(), so the diff marks every package as needing work.

There are a few things going wrong:

  1. Proxy link objects created in processDeps() were missing version, so the diff always saw a version mismatch (undefined !== "4.1.2") and marked every top-level link as CHANGE.

  2. Proxy links used the registry tarball URL for resolved, but actual links loaded from disk have file:.store/... URLs. Even with version fixed, the resolved mismatch triggered CHANGE.

  3. The proxy tree is flat — all store entries and links are direct children of root. But loadActual() produces a nested tree where store entries are deep link targets, not visible to allChildren(actual). So every store entry looked like an ADD.

  4. binPaths were computed one directory level too deep (join(from.realpath, 'node_modules', '.bin', bn) instead of join(nmFolder, '.bin', bn)), so the bin existence check always failed for store entries with bins.

The fix:

  • Set version and correct resolved on proxy link objects in isolated-reifier.js
  • Fix binPaths to point at the right directory level
  • Add #buildLinkedActualForDiff() in reify.js that wraps the actual tree with synthetic entries for store nodes and store links that already exist on disk, so the diff can match them

On a project with 20 direct deps (457 total nodes), a second npm install --install-strategy=linked now reports "up to date" in ~0.2s instead of reinstalling everything in ~1.5s.

References

Fixes #6100

@manzoorwanijk manzoorwanijk requested a review from a team as a code owner February 26, 2026 07:27
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] Subsequent runs of npm install --install-strategy=linked are slow

1 participant