fix(arborist): remove stale .bin shims after uninstall under linked#9643
Merged
Conversation
…9632) In continuation of our exploration of using `install-strategy=linked` in the [Gutenberg monorepo](WordPress/gutenberg#75814), which powers the WordPress Block Editor. Under `install-strategy=linked`, `npm uninstall <pkg>` removed the package's top-level symlink and its `.store` entry but left its shim in `node_modules/.bin` behind as a dangling link. The leftover shim can break tools that enumerate `node_modules/.bin`, shadow a later-installed binary of the same name, and is not healed by a subsequent `npm install`. ## Why A linked reify builds the actual tree for the diff from the ideal tree (`#buildLinkedActualForDiff`), so a removed dependency is never compared against what is on disk and the diff emits no action to drop its bin shim. The top-level symlink and store entry are already cleaned by the post-reify sweep, but bin shims were not covered by it. ## How `reify.js` `#cleanOrphanedStoreEntries` now also builds `binsByDir`: while collecting the valid top-level links per `node_modules` directory, it records the bin names each still-linked package provides from `child.package.bin`. The new `#cleanStaleBinLinks` then removes any `.bin` entry whose base name (after stripping a `.cmd`/`.ps1` suffix) is not provided by a surviving package, or which is a dangling symlink. Matching by name keeps the check cross-platform across POSIX symlink shims and Windows `.cmd`/`.ps1` shim files, and reuses data already in the ideal tree without adding a dependency. Shims for packages that survive the uninstall are preserved. ## References Fixes #9613 (cherry picked from commit 981e249)
owlstronaut
approved these changes
Jun 24, 2026
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.
Backport of #9632 to
release/v11.