mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
util: fix parseArgs skipping positional arg with --eval and --print
PR-URL: https://github.com/nodejs/node/pull/60814 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
const {
|
||||
ArrayPrototypeForEach,
|
||||
ArrayPrototypeIncludes,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypePushApply,
|
||||
@@ -54,20 +53,16 @@ const {
|
||||
kEmptyObject,
|
||||
} = require('internal/util');
|
||||
|
||||
const { getOptionValue } = require('internal/options');
|
||||
|
||||
function getMainArgs() {
|
||||
// Work out where to slice process.argv for user supplied arguments.
|
||||
// -p / --print internally sets --eval, so this works for all cases
|
||||
const evalValue = getOptionValue('--eval');
|
||||
|
||||
// Check node options for scenarios where user CLI args follow executable.
|
||||
const execArgv = process.execArgv;
|
||||
if (ArrayPrototypeIncludes(execArgv, '-e') ||
|
||||
ArrayPrototypeIncludes(execArgv, '--eval') ||
|
||||
ArrayPrototypeIncludes(execArgv, '-p') ||
|
||||
ArrayPrototypeIncludes(execArgv, '--print')) {
|
||||
if (evalValue.length !== 0) {
|
||||
return ArrayPrototypeSlice(process.argv, 1);
|
||||
}
|
||||
|
||||
// Normally first two arguments are executable and script, then CLI arguments
|
||||
return ArrayPrototypeSlice(process.argv, 2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user