fix(exec): prevent shared binPaths pollution across workspace runs#9692
Merged
Conversation
…9650) **Description:** related: #9640 **Bug:** When running `npm exec` across multiple workspaces, the binary from the first workspace would accidentally bleed into the second one if they shared the same name. **Root Cause:** In `libnpmexec`, the `binPaths` array was scoped at the module level instead of inside the `exec()` function. Since `execWorkspaces` runs everything in a single process, `binPaths` just kept accumulating paths. When the second workspace ran, the first workspace's `.bin` path was still sitting at the front of `PATH`, so it hijacked the execution. **Fix:** Moved `binPaths` inside `exec()` so it gets a fresh array on every call. I left the `manifests` map at the module level (keyed by `spec.raw`) because we still want to cache registry specs across calls, and absolute paths won't collide anyway. **Testing:** - Added a regression test in `test/local.js` with two workspaces using the exact same local bin name (`shared-bin`). - Gave each test call its own `args` array to stop `@npmcli/run-script` from mutating it and hanging the tests. - Fails correctly without the fix. With the fix, all tests pass 100%. (cherry picked from commit 18b930f)
owlstronaut
approved these changes
Jun 29, 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 #9650 to
release/v11.