Skip to content

Commit

Permalink
Simplify passing options
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 18, 2024
1 parent b354022 commit beffce6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit beffce6

Please sign in to comment.