Skip to content

fix(arborist): clean up orphaned .store/ entries on linked install#9033

Draft
manzoorwanijk wants to merge 2 commits intonpm:latestfrom
manzoorwanijk:fix/linked-strategy-orphaned-store-cleanup
Draft

fix(arborist): clean up orphaned .store/ entries on linked install#9033
manzoorwanijk wants to merge 2 commits intonpm:latestfrom
manzoorwanijk:fix/linked-strategy-orphaned-store-cleanup

Conversation

@manzoorwanijk
Copy link
Contributor

A follow-up to #9031. I initially thought to make this change in that PR, but then decided to split it out to keep the scope of the original change focused. This PR adds a new cleanup step to remove orphaned store entries after a linked install.

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

When using --install-strategy=linked, updating or removing a dependency leaves the old .store/ directory behind. Each install creates a new store entry keyed by name@version-<treeHash>, but the previous entry is never cleaned up. Over time, node_modules/.store/ accumulates orphaned directories that waste disk space.

This is particularly wasteful because each store entry includes the package and all of its transitive dependencies as nested directories.

The root cause is that the reify diff only sees nodes present in the ideal tree, so stale store entries from previous installs are invisible to the cleanup path (_retireShallowNodes_removeTrash).

Approach

Added a post-reify sweep (#cleanOrphanedStoreEntries) that runs after _removeTrash completes for linked installs:

  1. Reads node_modules/.store/ directory entries from disk
  2. Collects the set of valid store keys from the isolated ideal tree's isInStore children
  3. Removes any .store/ entry not in the valid set

The cleanup runs while the isolated ideal tree is still set as this.idealTree (before the swap-back to the original tree for lockfile preservation), so it has access to all valid store keys.

References

Fixes #9032

@manzoorwanijk manzoorwanijk requested a review from a team as a code owner February 26, 2026 08:30
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-strategy-orphaned-store-cleanup branch from 550d12a to 00ae7b0 Compare February 26, 2026 09:00
@manzoorwanijk manzoorwanijk marked this pull request as draft February 27, 2026 16:57
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] --install-strategy=linked leaves orphaned .store/ entries when dependencies change

1 participant