Repository navigation
fix: keep npx command flags after negated switches like --no - #10155
Open
mkantautas wants to merge 1 commit into
Open
mkantautas wants to merge 1 commit into
mkantautas wants to merge 1 commit into
Conversation
npx treated --no (expanded to --no-yes) and other negated switches such as --no-color as options that take a value, so the command name was consumed as that value and the command's own flags were parsed by npm. A negated switch now takes the next argument only when npm's parser reads it as the switch's value.
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.
npx --no <command> <args>hands the command's own flags to npm.--noexpands to--no-yes, andbin/npx-cli.jsonly knows the non-negated switch names, so it reads the command name as the value of--no-yesand never puts--in front of the command. The same happens after--no-color,--local(--no-global) and other negated switches.With npm 12.2.1 and a locally installed
hellobin:npx --no hello --edit xfails withEUNKNOWNCONFIGnpx --no hello --versionprints npm's versionnpx --no hello -c xfails withEUSAGEnpx --local hello --jsonrunshellowithout--jsonnpm 11 dropped these flags silently, for example
--edit xwas read as npm's--editor x.A negated switch now takes the next argument only when nopt reads it as that switch's value, so
--no=true,--no-color alwaysand--no-workspaces nullwork as before. Plain switches are unchanged.Testing
New cases in
test/bin/npx-cli.js: bare negations put--before the command (these fail without the change), and values that nopt reads after a negation stay before--. Also checked end to end against a local registry fixture. The full test suite passes on Linux with Node 22.22.2, 24.15.0 and 26.8.2.References
Related to #8021