From 2aae874781ed3dec3d64a57a278c3212c62a333c Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 1 Sep 2024 18:42:53 +0100 Subject: [PATCH] Remove a few bytes --- source/index.js | 3 ++- source/pipe.js | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/source/index.js b/source/index.js index ddb0536..296790f 100644 --- a/source/index.js +++ b/source/index.js @@ -12,11 +12,12 @@ export default function nanoSpawn(file, second, third, previous) { const nodeChildProcess = spawnSubprocess(file, commandArguments, spawnOptions, context); let subprocess = getResult(nodeChildProcess, spawnOptions, context); Object.assign(subprocess, {nodeChildProcess}); - subprocess = previous ? handlePipe(previous, subprocess) : subprocess; + subprocess = previous ? handlePipe([previous, subprocess]) : subprocess; const stdout = lineIterator(subprocess, context, 'stdout'); const stderr = lineIterator(subprocess, context, 'stderr'); return Object.assign(subprocess, { + nodeChildProcess, stdout, stderr, [Symbol.asyncIterator]: () => combineAsyncIterators(stdout, stderr), diff --git a/source/pipe.js b/source/pipe.js index fa477e4..82310c6 100644 --- a/source/pipe.js +++ b/source/pipe.js @@ -1,8 +1,6 @@ import {pipeline} from 'node:stream/promises'; -export const handlePipe = (previous, subprocess) => Object.assign(runProcesses([previous, subprocess]), subprocess); - -const runProcesses = async subprocesses => { +export const handlePipe = async subprocesses => { // Ensure both subprocesses have exited before resolving, and that we handle errors from both const [[from, to]] = await Promise.all([Promise.allSettled(subprocesses), pipeStreams(subprocesses)]);