Skip to content

Commit

Permalink
Make arguments array optional (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Aug 21, 2024
1 parent 102d1c1 commit 883c682
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {spawn} from 'node:child_process';
import {lineIterator, combineAsyncIterables} from './utilities.js';

export default function nanoSpawn(command, arguments_ = [], {signal, timeout, nativeOptions} = {}) {
const subprocess = spawn(command, arguments_, {...nativeOptions, signal, timeout});
export default function nanoSpawn(command, rawArguments = [], rawOptions = {}) {
const [commandArguments, {signal, timeout, nativeOptions}] = Array.isArray(rawArguments)
? [rawArguments, rawOptions]
: [[], rawArguments];

const subprocess = spawn(command, commandArguments, {...nativeOptions, signal, timeout});

// eslint-disable-next-line no-async-promise-executor
const promise = new Promise(async (resolve, reject) => {
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import test from 'ava';
import nanoSpawn from './index.js';

test('can pass options object without any arguments', async t => {
const {exitCode} = await nanoSpawn('node', {timeout: 1});
t.is(exitCode, null);
});

test('can be awaited', async t => {
const result = await nanoSpawn('echo', ['🦄']);
// TODO
Expand Down

0 comments on commit 883c682

Please sign in to comment.