Repository: sindresorhus/execa
Pull request #299 (2019-06-19 10:30:07)

Rename `nodeArguments` to `nodeOptions`
I think the name `nodeArguments` makes it unclear it's about Node CLI flags, as opposed to the arguments passed to `node scriptPath.js ...`. 

Also this makes it more consistent with the way Node.js calls it [in the documentation](https://nodejs.org/api/cli.html).

@GMartigny 	


Patch:
diff --git a/index.d.ts b/index.d.ts
index 6a7e21e..526593f 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -203,11 +203,11 @@ declare namespace execa {
 		readonly nodePath?: string;
 
 		/**
-		List of string arguments passed to the Node.js executable.
+		List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.
 
 		@default process.execArgv
 		*/
-		readonly nodeArguments?: string[];
+		readonly nodeOptions?: string[];
 	}
 
 	interface ExecaReturnBase<StdoutStderrType> {
diff --git a/index.js b/index.js
index 3d78cf7..a7230cb 100644
--- a/index.js
+++ b/index.js
@@ -531,12 +531,12 @@ module.exports.node = (scriptPath, args, options = {}) => {
 
 	const stdioOption = stdio.node(options);
 
-	const {nodePath = process.execPath, nodeArguments = process.execArgv} = options;
+	const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
 
 	return execa(
 		nodePath,
 		[
-			...nodeArguments,
+			...nodeOptions,
 			scriptPath,
 			...(Array.isArray(args) ? args : [])
 		],
diff --git a/lib/stdio.js b/lib/stdio.js
index fcc3a15..310d5b4 100644
--- a/lib/stdio.js
+++ b/lib/stdio.js
@@ -32,20 +32,21 @@ const stdio = opts => {
 
 module.exports = stdio;
 
+// `ipc` is pushed unless it is already present
 module.exports.node = opts => {
-	const defaultOption = 'pipe';
+	const stdioOption = stdio(opts);
 
-	let stdioOption = stdio(opts || {stdio: defaultOption});
+	if (stdioOption === 'ipc') {
+		return 'ipc';
+	}
 
-	if (typeof stdioOption === 'string') {
-		stdioOption = [...new Array(3)].fill(stdioOption);
-	} else if (Array.isArray(stdioOption)) {
-		stdioOption = stdioOption.map((channel = defaultOption) => channel);
+	if (stdioOption === undefined || typeof stdioOption === 'string') {
+		return [stdioOption, stdioOption, stdioOption, 'ipc'];
 	}
 
-	if (!stdioOption.includes('ipc')) {
-		stdioOption.push('ipc');
+	if (stdioOption.includes('ipc')) {
+		return stdioOption;
 	}
 
-	return stdioOption;
+	return [...stdioOption, 'ipc'];
 };
diff --git a/readme.md b/readme.md
index 100cd36..1416c2f 100644
--- a/readme.md
+++ b/readme.md
@@ -189,7 +189,7 @@ Returns or throws a [`childProcessResult`](#childProcessResult).
 Execute a Node.js script as a child process.
 
 Same as `execa('node', [scriptPath, ...arguments], options)` except (like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)):
-  - the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeArguments`](#nodearguments-for-node-only) options.
+  - the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeOptions`](#nodeoptions-for-node-only) options.
   - the [`shell`](#shell) option cannot be used
   - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio)
 
@@ -454,12 +454,12 @@ Default: [`process.execPath`](https://nodejs.org/api/process.html#process_proces
 
 Node.js executable used to create the child process.
 
-#### nodeArguments *(for `.node()` only)*
+#### nodeOptions *(for `.node()` only)*
 
 Type: `string[]`<br>
 Default: [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv)
 
-List of string arguments passed to the Node.js executable.
+List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.
 
 ## Tips
 


Test patch:
diff --git a/test/node.js b/test/node.js
index c6ff30d..0be9494 100644
--- a/test/node.js
+++ b/test/node.js
@@ -22,16 +22,16 @@ test('node correctly use nodePath', async t => {
 	const {stdout} = await execa.node(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', {
 		stdout: 'pipe',
 		nodePath: process.platform === 'win32' ? 'cmd.exe' : 'bash',
-		nodeArguments: process.platform === 'win32' ? ['/c'] : []
+		nodeOptions: process.platform === 'win32' ? ['/c'] : []
 	});
 
 	t.is(stdout, 'Hello World');
 });
 
-test('node pass on nodeArguments', async t => {
+test('node pass on nodeOptions', async t => {
 	const {stdout} = await execa.node('console.log("foo")', {
 		stdout: 'pipe',
-		nodeArguments: ['-e']
+		nodeOptions: ['-e']
 	});
 
 	t.is(stdout, 'foo');
diff --git a/test/stdio.js b/test/stdio.js
index 3aa5d37..153ca61 100644
--- a/test/stdio.js
+++ b/test/stdio.js
@@ -50,14 +50,17 @@ test(stdioMacro, {stdin: 0, stdio: 'pipe'}, new Error('It\'s not possible to pro
 const forkMacro = (...args) => macro(...args, stdio.node);
 forkMacro.title = macroTitle('execa.fork()');
 
-test(forkMacro, undefined, ['pipe', 'pipe', 'pipe', 'ipc']);
+test(forkMacro, undefined, [undefined, undefined, undefined, 'ipc']);
 test(forkMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore', 'ipc']);
+test(forkMacro, {stdio: 'ipc'}, 'ipc');
 test(forkMacro, {stdio: [0, 1, 2]}, [0, 1, 2, 'ipc']);
 test(forkMacro, {stdio: [0, 1, 2, 3]}, [0, 1, 2, 3, 'ipc']);
 test(forkMacro, {stdio: [0, 1, 2, 'ipc']}, [0, 1, 2, 'ipc']);
 
-test(forkMacro, {stdout: 'ignore'}, ['pipe', 'ignore', 'pipe', 'ipc']);
-test(forkMacro, {stdout: 'ignore', stderr: 'ignore'}, ['pipe', 'ignore', 'ignore', 'ipc']);
+test(forkMacro, {stdio: [0, 1, undefined]}, [0, 1, undefined, 'ipc']);
+test(forkMacro, {stdio: [0, 1, 2, undefined]}, [0, 1, 2, undefined, 'ipc']);
+test(forkMacro, {stdout: 'ignore'}, [undefined, 'ignore', undefined, 'ipc']);
+test(forkMacro, {stdout: 'ignore', stderr: 'ignore'}, [undefined, 'ignore', 'ignore', 'ipc']);
 
 test(forkMacro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));
 test(forkMacro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));