Skip to content

fix(arborist): remove stale .bin shims after uninstall under linked#9632

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-dangling-bin-shim
Jun 24, 2026
Merged

fix(arborist): remove stale .bin shims after uninstall under linked#9632
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-dangling-bin-shim

Conversation

@manzoorwanijk

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, 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

@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 24, 2026 14:39
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 24, 2026 14:39
@owlstronaut owlstronaut merged commit 981e249 into npm:latest Jun 24, 2026
24 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9643

@manzoorwanijk manzoorwanijk deleted the fix/linked-dangling-bin-shim branch June 24, 2026 18:18
owlstronaut pushed a commit that referenced this pull request Jun 24, 2026
…9643)

Backport of #9632 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: .bin shim left dangling after npm uninstall

2 participants