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:
azadgupta1
2025-11-23 11:16:19 +05:30
committed by Renegade334
parent 67527c427e
commit 060deae99b
2 changed files with 47 additions and 80 deletions

View File

@@ -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);
}