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

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

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 errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 3why, one step back
3import {handlePipeArgumentsError} from './throw.js';

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 4–5why, one step back
4import {waitForBothSubprocesses} from './sequence.js';
5import {pipeSubprocessStream} from './streaming.js';

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 6–7why, one step back
6import {unpipeOnAbort} from './abort.js';
7

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 8why, one step back
8// 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])) {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 11why, one step back
11 return pipeToSubprocess.bind(undefined, {

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 12why, one step back
12 ...sourceInfo,

Upgrade xo (#980)ehmickybefore adoptionccfa412

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

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

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 errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

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 });

Improve piping processes (#834)ehmickybefore adoption1a47ea2

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 errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

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

Rename `signal` option to `unpipeSignal` (#852)ehmickybefore adoption9dc1141

line 37why, one step back
37 unpipeSignal,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 38why, one step back
38 fileDescriptors,

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 39why, one step back
39 startTime,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 40why, one step back
40}) => {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 41why, one step back
41 const subprocessPromises = getSubprocessPromises(sourcePromise, destination);

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 42–46why, one step back
42 handlePipeArgumentsError({
43 sourceStream,44 sourceError,45 destinationStream,46 destinationError,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 47why, one step back
47 fileDescriptors,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 48why, one step back
48 sourceOptions,

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 49why, one step back
49 startTime,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 50why, one step back
50 });

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 51–52why, one step back
51 const maxListenersController = new AbortController();
52 try {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 53why, one step back
53 const mergedStream = pipeSubprocessStream(sourceStream, destinationStream, maxListenersController);

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 54why, one step back
54 return await Promise.race([

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 55why, one step back
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 }),

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 63–66why, one step back
63 ]);
64 } finally {65 maxListenersController.abort();66 }

Improve spawning errors (#847)ehmickybefore adoption381dee2

line 67why, one step back
67};

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 68why, one step back
68

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 69why, one step back
69// `.pipe()` awaits the subprocess promises.

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

lines 70–71why, one step back
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.

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 72why, one step back
72const getSubprocessPromises = (sourcePromise, destination) => Promise.allSettled([sourcePromise, destination]);