node/test/fixtures/sea-exec-argv-extension-env.js
Joyee Cheung 6722642e3d
sea: implement execArgvExtension
This implements the execArgvExtension configuration field for SEA,
which takes one of three string values to specify whether and how
execution arguments can be extended for the SEA at run time:

* `"none"`: No extension is allowed. Only the arguments specified
  in `execArgv` will be used,
  and the `NODE_OPTIONS` environment variable will be ignored.
* `"env"`: _(Default)_ The `NODE_OPTIONS` environment variable can
  extend the execution arguments.
  This is the default behavior to maintain backward compatibility.
* `"cli"`: The executable can be launched with
  `--node-options="--flag1 --flag2"`, and those flags
  will be parsed as execution arguments for Node.js instead of being
  passed to the user script. This allows using arguments that are
  not supported by the `NODE_OPTIONS` environment variable.

PR-URL: https://github.com/nodejs/node/pull/59560
Fixes: https://github.com/nodejs/node/issues/55573
Fixes: https://github.com/nodejs/single-executable/issues/100
Refs: https://github.com/nodejs/node/issues/51688
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2025-08-25 11:35:56 +00:00

19 lines
687 B
JavaScript

const assert = require('assert');
process.emitWarning('This warning should not be shown in the output', 'TestWarning');
console.log('process.argv:', JSON.stringify(process.argv));
console.log('process.execArgv:', JSON.stringify(process.execArgv));
// Should have execArgv from SEA config.
// Note that flags from NODE_OPTIONS are not included in process.execArgv no matter it's
// an SEA or not, but we can test whether it works by checking that the warning emitted
// above was silenced.
assert.deepStrictEqual(process.execArgv, ['--no-warnings']);
assert.deepStrictEqual(process.argv.slice(2), [
'user-arg1',
'user-arg2'
]);
console.log('execArgvExtension env test passed');