Repository navigation
Conversation
cmd.exe looks up a command that already has an extension by that exact name before it tries PATHEXT. For a bin like `npm.windows-bin-issue` that finds the extensionless sh shim in node_modules/.bin, and Windows opens it with whatever program is registered for the "extension" instead of running it, so `npx` prints nothing. When the bin name has a dot and a .cmd shim for it exists in binPaths or in a node_modules/.bin above runPath, run the .cmd shim directly. Fixes npm#8518 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What / Why
On Windows,
npx/npm execcan't run a bin whose name has a.in it (for examplenpx npm.windows-bin-issue, or the only bin of a package like@org/namespace.foo). Nothing runs: Windows opens the file with whatever program is registered for the "extension" instead.cmd.exe looks up a command that already has an extension by that exact name before it tries PATHEXT, so it finds the extensionless sh shim in
node_modules/.bininstead of the.cmdnext to it. npm/exec#17 already described the fix: run the.cmdshim directly instead of letting the shell resolve the extension.libnpmexec'srun-script.jsnow does that on Windows. If the bin name has an extension and a<bin>.cmdexists inbinPathsor in anode_modules/.binaboverunPath, it runs<bin>.cmd. Names without a dot, and commands without a.cmdshim, are unchanged.Testing
A new case in
workspaces/libnpmexec/test/run-script.jscovers a shim inbinPaths, a shim in anode_modules/.binaboverunPath, and a dotted name with no shim. The first two fail without the change (dot.bininstead ofdot.bin.cmd). The libnpmexec suite passes on Windows 11 with 100% coverage, andtest/lib/commands/exec.jspasses.On Windows 11, with a package whose bin is
dot.bin,node . exec dot.bin hello worldnow prints the script's output, both for a locally installed package and through the npx cache (--package=<dir>). With npm 11.12.1 the same command printed nothing.References
Fixes #8518
I used Claude Code to write this change.