Skip to content
Myr

setup.js

This file

Path

lib/pipe/setup.js

60 lines · 2.0 KiB · JavaScript

Last changed by

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

History of this file

Take it

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

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

Improve piping processes (#834)ehmickybefore adoption1a47ea2

line 2why, one step back
2import {normalizePipeArguments} from './validate.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

lines 8–9why, one step back
8// Pipe a subprocess' `stdout`/`stderr`/`stdio` into another subprocess' `stdin`
9export const pipeToSubprocess = (sourceInfo, ...args) => {

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

line 10why, one step back
10 if (isPlainObject(args[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,

Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2

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

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

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

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

lines 17–18why, one step back
17 const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...args);
18 const promise = handlePipePromise({...normalizedInfo, destination});

Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2

line 19why, one step back
19 promise.pipe = pipeToSubprocess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise, boundOptions: {}});

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 20–22why, one step back
20 return promise;
21};22

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

lines 23–30why, one step back
23const handlePipePromise = async ({
24 sourcePromise,25 sourceStream,26 sourceOptions,27 sourceError,28 destination,29 destinationStream,30 destinationError,

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

line 31why, one step back
31 unpipeSignal,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 32why, one step back
32 fileDescriptors,

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

line 33why, one step back
33 startTime,

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

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

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

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

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

lines 36–40why, one step back
36 handlePipeArgumentsError({
37 sourceStream,38 sourceError,39 destinationStream,40 destinationError,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 41why, one step back
41 fileDescriptors,

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

line 42why, one step back
42 sourceOptions,

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

line 43why, one step back
43 startTime,

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

line 44why, one step back
44 });

Improve piping processes (#834)ehmickybefore adoption1a47ea2

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

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

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

Improve piping processes (#834)ehmickybefore adoption1a47ea2

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

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

line 49why, one step back
49 waitForBothSubprocesses(subprocessPromises),

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 50why, one step back
50 ...unpipeOnAbort(unpipeSignal, {sourceStream, mergedStream, sourceOptions, fileDescriptors, startTime}),

Improve piping processes (#834)ehmickybefore adoption1a47ea2

lines 51–54why, one step back
51 ]);
52 } finally {53 maxListenersController.abort();54 }

Improve spawning errors (#847)ehmickybefore adoption381dee2

line 55why, one step back
55};

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

line 56why, one step back
56

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

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

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

lines 58–59why, one step back
58// When invalid arguments are passed to `.pipe()`, we throw an error, which prevents awaiting them.
59// We need to ensure this does not create unhandled rejections.

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

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