From d9cf13265315bfcbd9280dd93b97e9456b0f82b8 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 27 Sep 2023 21:43:14 -0700 Subject: [PATCH] process: `argv1` property to preserve original `argv[1]` --- doc/api/process.md | 26 +++++++ lib/internal/main/run_main_module.js | 17 ++--- lib/internal/modules/run_main.js | 21 +++--- lib/internal/process/pre_execution.js | 67 +++++++++++++------ test/fixtures/process-argv1.js | 2 + ...rocess-argv-0.js => test-process-argv0.js} | 0 test/parallel/test-process-argv1.mjs | 20 ++++++ 7 files changed, 115 insertions(+), 38 deletions(-) create mode 100644 test/fixtures/process-argv1.js rename test/parallel/{test-process-argv-0.js => test-process-argv0.js} (100%) create mode 100644 test/parallel/test-process-argv1.mjs diff --git a/doc/api/process.md b/doc/api/process.md index 5718c83e4fbcf4d..3a770b779bae15a 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -958,6 +958,32 @@ $ bash -c 'exec -a customArgv0 ./node' 'customArgv0' ``` +## `process.argv1` + + + +* {string | undefined} + +The `process.argv1` property stores a read-only copy of the original value of +`argv[1]` passed when Node.js starts. + +```js +// test.js +console.log('argv1 ', process.argv1); +console.log('argv[1]', process.argv[1]); +``` + +```shell +$ node ./test.js +argv1 ./test.js +argv[1] /Users/geoffrey/Sites/node/test.js +``` + +`process.argv1` is `undefined` for cases where Node.js is run without a main +entry point, such as `node --eval`. + ## `process.channel`