Try to catch "npm run" arguments without "--" #3470
Labels
cli
stage: proposal 💡
No work has been done of this issue
stale
no activity on this issue for a long period
Sometimes our users forget that NPM run script needs command line arguments to the tool separated from the NPM's own arguments with
--
. For example, see #3467We have a warning in our docs about it, and should put the warning in more places cypress-io/cypress-documentation#1418 but I think we can help users even in the current situation.
Here is how. Imagine we have
index.js
that just prints command line argumentsand we have NPM script in
package.json
Here is what happens when running script directly vs through
npm run test
Calling directly with arguments
Calling via NPM script
npm test
So we are losing "run" command.
But
If we prince
process.env
we can find the original command line arguments in NPM variablenpm_config_argv
passed as a stringIdea
In our Cypress CLI module, whenever we get an unknown command (because instead of
open
orrun
we see something like--record
), we take a look atnpm_config_argv original
list of arguments, load user'spackage.json
, if the first argument matches the script name like "test" we know the user forgot to add--
, and in that case we can take the rest of thenpm_config_argv original
arguments as the real CLI arguments the user meant to use.The text was updated successfully, but these errors were encountered: