Skip to content

Commit 32a2b37

Browse files
committed
util: fix parseArgs skipping first positional arg with --eval= and --print=
1 parent 6c306b6 commit 32a2b37

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/internal/util/parse_args/parse_args.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,22 @@ const {
5656

5757

5858
function getMainArgs() {
59-
// Work out where to slice process.argv for user supplied arguments.
60-
61-
// Check node options for scenarios where user CLI args follow executable.
6259
const execArgv = process.execArgv;
63-
if (ArrayPrototypeIncludes(execArgv, '-e') ||
64-
ArrayPrototypeIncludes(execArgv, '--eval') ||
65-
ArrayPrototypeIncludes(execArgv, '-p') ||
66-
ArrayPrototypeIncludes(execArgv, '--print')) {
60+
61+
const hasEvalOrPrint = execArgv.some(arg =>
62+
arg === '-e' || arg === '--eval' ||
63+
arg === '-p' || arg === '--print' ||
64+
arg.startsWith('--eval=') || arg.startsWith('--print=')
65+
);
66+
67+
if (hasEvalOrPrint) {
6768
return ArrayPrototypeSlice(process.argv, 1);
6869
}
6970

70-
// Normally first two arguments are executable and script, then CLI arguments
7171
return ArrayPrototypeSlice(process.argv, 2);
7272
}
7373

74+
7475
/**
7576
* In strict mode, throw for possible usage errors like --foo --bar
7677
* @param {object} token - from tokens as available from parseArgs

0 commit comments

Comments
 (0)