Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a few bytes #74

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 1 addition & 3 deletions source/pipe.js
Original file line number Diff line number Diff line change
@@ -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)]);

Expand Down