fix(libnpmexec): correctly resolve workspace dependency binaries from graph#9650
fix(libnpmexec): correctly resolve workspace dependency binaries from graph#9650arjun-vegeta wants to merge 3 commits into
Conversation
owlstronaut
left a comment
There was a problem hiding this comment.
Thanks for digging into this, but I ran your exact repro on the branch and it still prints A bin / A bin under workspace hoisting only one shared-bin link gets created (→tool-a), so the binPaths change doesn't actually fix #9640
Fixes npm#9640 by preventing fallback to hoisted .bin directories for workspace packages.
Thanks for testing it out. The old I just pushed a complete rewrite. I dropped the The repro now outputs |
Description:
Fixes #9640
Bug:
When running
npm execwith a workspace-scoped dependency that shares a binary name with a root-hoisted dependency from another workspace, the root-hoisted binary is incorrectly executed instead of the locally specified dependency.Root Cause:
Under workspace hoisting, multiple workspaces might use tools that expose identically-named binaries (e.g.
shared-bin). Because npm links hoisted dependencies tonode_modules/.binat the root, the root.bindirectory will only contain a single symlink forshared-bin(pointing to whichever package got hoisted).libnpmexecwas previously falling back to searching.bindirectories vialocalFileExists(), meaning it would always incorrectly execute the hoisted root symlink, completely ignoring the specific dependency version declared by the active workspace.Fix:
npm execis invoked from within a workspace (opts.pkgPath !== path).arboristgraph and directly traverse theedgesOutof the specific workspace node to find the correctly scoped dependency'sbinpath natively..binfallback search entirely when inside a workspace context, effectively isolating executions from root-hoisted symlink collisions.Testing:
test/local.jsthat exactly mimics theshared-binhoist collision from the bug report.