fix(arborist): clean up orphaned .store/ entries on linked install#9033
Draft
manzoorwanijk wants to merge 2 commits intonpm:latestfrom
Draft
fix(arborist): clean up orphaned .store/ entries on linked install#9033manzoorwanijk wants to merge 2 commits intonpm:latestfrom
manzoorwanijk wants to merge 2 commits intonpm:latestfrom
Conversation
550d12a to
00ae7b0
Compare
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.
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=linkedin 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 byname@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_removeTrashcompletes for linked installs:node_modules/.store/directory entries from diskisInStorechildren.store/entry not in the valid setThe 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