From beffce685fd0e36908e2c6cd77edd6ba0fa47cd8 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 18 Aug 2024 14:08:24 +0100 Subject: [PATCH] Simplify passing options --- index.js | 10 +++++----- test.js | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 6171a92..87d3e84 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,12 @@ import {spawn} from 'node:child_process'; import {once} from 'node:events'; import {lineIterator, combineAsyncIterators} from './utilities.js'; -export default function nanoSpawn(command, rawArguments = [], rawOptions = {}) { - const [commandArguments, {signal, timeout, nativeOptions}] = Array.isArray(rawArguments) - ? [rawArguments, rawOptions] - : [[], rawArguments]; +export default function nanoSpawn(command, commandArguments = [], options = {}) { + [commandArguments, options] = Array.isArray(commandArguments) + ? [commandArguments, options] + : [[], commandArguments]; - const subprocess = spawn(command, commandArguments, {...nativeOptions, signal, timeout}); + const subprocess = spawn(command, commandArguments, options); const promise = getResult(subprocess); diff --git a/test.js b/test.js index cbbc5b1..15f983f 100644 --- a/test.js +++ b/test.js @@ -11,6 +11,13 @@ const arrayFromAsync = async asyncIterable => { return chunks; }; +const testString = 'test'; + +test('can pass options.argv0', async t => { + const {stdout} = await nanoSpawn('node', ['-p', 'process.argv0'], {argv0: testString}); + t.is(stdout, testString); +}); + test('can pass options object without any arguments', async t => { const {exitCode} = await nanoSpawn('node', {timeout: 1}); t.is(exitCode, null);