Skip to content
Myr

setup.js

This file

Path

lib/pipe/setup.js

72 lines · 2.2 KiB · JavaScript

Last changed by

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

History of this file

Take it

The walk stopped after 200 commits: lines older than 8ee5985 point at it.

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

line 1why, one step back
1import isPlainObject from 'is-plain-obj';

Rename files (#977)ehmickybefore adoption4b2e316

line 2why, one step back
2import {normalizePipeArguments} from './pipe-arguments.js';

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 3–8why, one step back
3import {handlePipeArgumentsError} from './throw.js';
4import {waitForBothSubprocesses} from './sequence.js';5import {pipeSubprocessStream} from './streaming.js';6import {unpipeOnAbort} from './abort.js';78// Pipe a subprocess' `stdout`/`stderr`/`stdio` into another subprocess' `stdin`

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 9–10why, one step back
9export const pipeToSubprocess = (sourceInfo, ...pipeArguments) => {
10 if (isPlainObject(pipeArguments[0])) {

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 11–12why, one step back
11 return pipeToSubprocess.bind(undefined, {
12 ...sourceInfo,

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 13why, one step back
13 boundOptions: {...sourceInfo.boundOptions, ...pipeArguments[0]},

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 14–16why, one step back
14 });
15 }16

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 17why, one step back
17 const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...pipeArguments);

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

line 18why, one step back
18 const promise = handlePipePromise({...normalizedInfo, destination});

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 19–24why, one step back
19 promise.pipe = pipeToSubprocess.bind(undefined, {
20 ...sourceInfo,21 source: destination,22 sourcePromise: promise,23 boundOptions: {},24 });

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 25–27why, one step back
25 return promise;
26};27

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 28why, one step back
28// Asynchronous logic when piping subprocesses

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 29–37why, one step back
29const handlePipePromise = async ({
30 sourcePromise,31 sourceStream,32 sourceOptions,33 sourceError,34 destination,35 destinationStream,36 destinationError,37 unpipeSignal,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 38why, one step back
38 fileDescriptors,

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 39–46why, one step back
39 startTime,
40}) => {41 const subprocessPromises = getSubprocessPromises(sourcePromise, destination);42 handlePipeArgumentsError({43 sourceStream,44 sourceError,45 destinationStream,46 destinationError,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 47why, one step back
47 fileDescriptors,

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 48–55why, one step back
48 sourceOptions,
49 startTime,50 });51 const maxListenersController = new AbortController();52 try {53 const mergedStream = pipeSubprocessStream(sourceStream, destinationStream, maxListenersController);54 return await Promise.race([55 waitForBothSubprocesses(subprocessPromises),

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 56–62why, one step back
56 ...unpipeOnAbort(unpipeSignal, {
57 sourceStream,58 mergedStream,59 sourceOptions,60 fileDescriptors,61 startTime,62 }),

Fix Markdown typos in documentation (#907)ehmickybefore adoption8ee5985

lines 63–72why, one step back
63 ]);
64 } finally {65 maxListenersController.abort();66 }67};6869// `.pipe()` awaits the subprocess promises.70// When invalid arguments are passed to `.pipe()`, we throw an error, which prevents awaiting them.71// We need to ensure this does not create unhandled rejections.72const getSubprocessPromises = (sourcePromise, destination) => Promise.allSettled([sourcePromise, destination]);