Improve the documentation of the `node`/`nodePath`/`nodeOptions` options (#1011)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 42bea7f · Browse files · 3 files·+14 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+14 added−4 removed
- other:+14 added−4 removed
Provenance
- Commit
4878db5- Tree
8544fad- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
42bea7f
3 files changed+14 added−4 removed
modified:docs/api.md+3 added-1 removed
635 unmodified lines636 _Default:_ `true` with [`execaNode()`](#execanodescriptpath-arguments-options), `false` otherwise637 638 If `true`, runs with Node.js. The first argument must be a Node.js file.639 640+The subprocess inherits the current Node.js [CLI flags](https://nodejs.org/api/cli.html#options) and version. This can be overridden using the [`nodeOptions`](#optionsnodeoptions) and [`nodePath`](#optionsnodepath) options.641+642 [More info.](node.md)643 644 ### options.nodeOptions645 646 _Type:_ `string[]`\645-_Default:_ [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)647+_Default:_ [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI flags)648 649 List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the [Node.js executable](#optionsnodepath).650 651 Requires the [`node`](#optionsnode) option to be `true`.394 unmodified linesmodified:docs/node.md+8 added-2 removed
16 unmodified lines17181920212122232425262724282930313233343536373811 unmodified lines16 unmodified lines// Or:await execa`node file.js argument`;```
## Node.js [CLI flags](https://nodejs.org/api/cli.html#options)## Node.js CLI flags
When using the [`node`](api.md#optionsnode) option or [`execaNode()`](api.md#execanodescriptpath-arguments-options), the current Node.js [CLI flags](https://nodejs.org/api/cli.html#options) are inherited. For example, the subprocess will use [`--allow-fs-read`](https://nodejs.org/api/cli.html#--allow-fs-read) if the current process does.
The [`nodeOptions`](api.md#optionsnodeoptions) option can be used to set different CLI flags.
```jsawait execaNode({nodeOptions: ['--no-warnings']})`file.js argument`;await execaNode({nodeOptions: ['--allow-fs-write']})`file.js argument`;```
## Node.js version
The same applies to the Node.js version, which is inherited too.
[`get-node`](https://github.com/ehmicky/get-node) and the [`nodePath`](api.md#optionsnodepath) option can be used to run a specific Node.js version. Alternatively, [`nvexeca`](https://github.com/ehmicky/nvexeca) or [`nve`](https://github.com/ehmicky/nve) can be used.
```jsimport {execaNode} from 'execa';11 unmodified linesmodified:types/arguments/options.d.ts+3 added-1 removed
20 unmodified lines21 22 /**23 If `true`, runs with Node.js. The first argument must be a Node.js file.24 25+ The subprocess inherits the current Node.js [CLI flags](https://nodejs.org/api/cli.html#options) and version. This can be overridden using the `nodeOptions` and `nodePath` options.26+27 @default `true` with `execaNode()`, `false` otherwise28 */29 readonly node?: boolean;30 1 unmodified line32 List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.33 34 Requires the `node` option to be `true`.35 34- @default [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI options)36+ @default [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI flags)37 */38 readonly nodeOptions?: readonly string[];39 40 /**330 unmodified lines