resolve.js
This file
Path
lib/stream/resolve.js
85 lines · 3.7 KiB · JavaScript
Last changed by
Fix `lines` option (#957)ehmickybefore adoption15ab4e6
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
line 1why, one step back1import {once} from 'node:events';Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 2why, one step back2import {isStream as isNodeStream} from 'is-stream';Split files (#837)ehmickybefore adoption672c2d7
lines 3–6why, one step back3import {waitForSuccessfulExit} from '../exit/code.js';4import {errorSignal} from '../exit/kill.js';5import {throwOnTimeout} from '../exit/timeout.js';6import {isStandardStream} from '../utils.js';Add support for `std*: duplex` option (#937)ehmickybefore adoption6ca44fb
line 7why, one step back7import {TRANSFORM_TYPES} from '../stdio/generator.js';Split files (#837)ehmickybefore adoption672c2d7
line 8why, one step back8import {waitForAllStream} from './all.js';Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 9why, one step back9import {waitForSubprocessStream, getBufferedData} from './subprocess.js';Split files (#837)ehmickybefore adoption672c2d7
lines 10–12why, one step back10import {waitForExit} from './exit.js';11import {waitForStream} from './wait.js';12Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 13–15why, one step back13// Retrieve result of subprocess: exit code, signal, error, streams (stdout/stderr/all)14export const getSubprocessResult = async ({15 subprocess,Fix `lines` option (#957)ehmickybefore adoption15ab4e6
line 16why, one step back16 options: {encoding, buffer, maxBuffer, lines, timeoutDuration: timeout, stripFinalNewline},Split files (#837)ehmickybefore adoption672c2d7
line 17why, one step back17 context,Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 18why, one step back18 fileDescriptors,Split files (#837)ehmickybefore adoption672c2d7
lines 19–21why, one step back19 originalStreams,20 controller,21}) => {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 22why, one step back22 const exitPromise = waitForExit(subprocess);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 23why, one step back23 const streamInfo = {originalStreams, fileDescriptors, subprocess, exitPromise, propagating: false};Split files (#837)ehmickybefore adoption672c2d7
line 24why, one step back24Fix `lines` option (#957)ehmickybefore adoption15ab4e6
lines 25–26why, one step back25 const stdioPromises = waitForSubprocessStreams({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo});26 const allPromise = waitForAllStream({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo});Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 27why, one step back27 const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 28why, one step back28 const customStreamsEndPromises = waitForCustomStreamsEnd(fileDescriptors, streamInfo);Split files (#837)ehmickybefore adoption672c2d7
lines 29–39why, one step back2930 try {31 return await Promise.race([32 Promise.all([33 {},34 waitForSuccessfulExit(exitPromise),35 Promise.all(stdioPromises),36 allPromise,37 ...originalPromises,38 ...customStreamsEndPromises,39 ]),Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 40–42why, one step back40 throwOnSubprocessError(subprocess, controller),41 throwOnInternalError(subprocess, controller),42 ...throwOnTimeout(subprocess, timeout, context, controller),Split files (#837)ehmickybefore adoption672c2d7
lines 43–47why, one step back43 ]);44 } catch (error) {45 return Promise.all([46 {error},47 exitPromise,Fix `lines` option (#957)ehmickybefore adoption15ab4e6
lines 48–49why, one step back48 Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise))),49 getBufferedData(allPromise),Split files (#837)ehmickybefore adoption672c2d7
lines 50–55why, one step back50 Promise.allSettled(originalPromises),51 Promise.allSettled(customStreamsEndPromises),52 ]);53 }54};55Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 56why, one step back56// Read the contents of `subprocess.std*` and|or wait for its completionFix `lines` option (#957)ehmickybefore adoption15ab4e6
lines 57–58why, one step back57const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo}) =>58 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, lines, allMixed: false, stripFinalNewline, streamInfo}));Split files (#837)ehmickybefore adoption672c2d7
line 59why, one step back59Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 60why, one step back60// Transforms replace `subprocess.std*`, which means they are not exposed to users.Split files (#837)ehmickybefore adoption672c2d7
line 61why, one step back61// However, we still want to wait for their completion.Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 62–63why, one step back62const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>63 originalStreams.map((stream, fdNumber) => stream === subprocess.stdio[fdNumber]Split files (#837)ehmickybefore adoption672c2d7
line 64why, one step back64 ? undefinedRename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 65why, one step back65 : waitForStream(stream, fdNumber, streamInfo));Split files (#837)ehmickybefore adoption672c2d7
lines 66–67why, one step back6667// Some `stdin`/`stdout`/`stderr` options create a stream, e.g. when passing a file path.Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 68why, one step back68// The `.pipe()` method automatically ends that stream when `subprocess` ends.Split files (#837)ehmickybefore adoption672c2d7
line 69why, one step back69// This makes sure we wait for the completion of those streams, in order to catch any error.Simplify implementation (#955)ehmickybefore adoption8ad9ee7
line 70why, one step back70const waitForCustomStreamsEnd = (fileDescriptors, streamInfo) => fileDescriptors.flatMap(({stdioItems}, fdNumber) => stdioItemsRefactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 71–72why, one step back71 .filter(({value, stream = value}) => isNodeStream(stream, {checkOpen: false}) && !isStandardStream(stream))72 .map(({type, value, stream = value}) => waitForStream(stream, fdNumber, streamInfo, {Add support for `std*: duplex` option (#937)ehmickybefore adoption6ca44fb
line 73why, one step back73 isSameDirection: TRANSFORM_TYPES.has(type),Split files (#837)ehmickybefore adoption672c2d7
line 74why, one step back74 stopOnExit: type === 'native',Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 75why, one step back75 })));Split files (#837)ehmickybefore adoption672c2d7
line 76why, one step back76Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 77–78why, one step back77const throwOnSubprocessError = async (subprocess, {signal}) => {78 const [error] = await once(subprocess, 'error', {signal});Split files (#837)ehmickybefore adoption672c2d7
lines 79–81why, one step back79 throw error;80};81Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 82–83why, one step back82const throwOnInternalError = async (subprocess, {signal}) => {83 const [error] = await once(subprocess, errorSignal, {signal});Split files (#837)ehmickybefore adoption672c2d7
lines 84–85why, one step back84 throw error;85};