Refactor file descriptor-related logic (#861)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 295ef40 · Browse files · 3 files·+8 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+8 added−5 removed
- other:+8 added−5 removed
Provenance
- Commit
aeb8194- Tree
3153b64- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
295ef40
3 files changed+8 added−5 removed
modified:lib/stdio/direction.js+1 added-1 removed
19 unmodified lines2021222324242526272852 unmodified lines19 unmodified lines const direction = directions.find(Boolean); return stdioStreams.map(stdioStream => addDirection(stdioStream, direction));};
const getStreamDirection = stdioStream => KNOWN_DIRECTIONS[stdioStream.fdNumber] ?? guessStreamDirection[stdioStream.type](stdioStream.value);const getStreamDirection = ({fdNumber, type, value}) => KNOWN_DIRECTIONS[fdNumber] ?? guessStreamDirection[type](value);
// `stdin`/`stdout`/`stderr` have a known directionconst KNOWN_DIRECTIONS = ['input', 'output', 'output'];
52 unmodified linesmodified:lib/stream/resolve.js+3 added-3 removed
64 unmodified lines65666768696970717172737474757677786 unmodified lines64 unmodified lines
// Some `stdin`/`stdout`/`stderr` options create a stream, e.g. when passing a file path.// The `.pipe()` method automatically ends that stream when `childProcess` ends.// This makes sure we wait for the completion of those streams, in order to catch any error.const waitForCustomStreamsEnd = (stdioStreamsGroups, streamInfo) => stdioStreamsGroups.flatMap((stdioStreams, fdNumber) => stdioStreamsconst waitForCustomStreamsEnd = (stdioStreamsGroups, streamInfo) => stdioStreamsGroups.flat() .filter(({value}) => isStream(value, {checkOpen: false}) && !isStandardStream(value)) .map(({type, value}) => waitForStream(value, fdNumber, streamInfo, { .map(({type, value, fdNumber}) => waitForStream(value, fdNumber, streamInfo, { isSameDirection: type === 'generator', stopOnExit: type === 'native', }))); }));
const throwOnProcessError = async (spawned, {signal}) => { const [error] = await once(spawned, 'error', {signal}); throw error;6 unmodified linesmodified:lib/stream/wait.js+4 added-1 removed
44 unmodified lines45 // For example, `childProcess.stdin` is technically a Duplex, but can only be used as a writable.46 // Therefore, we need to use the file descriptor's direction (`stdin` is input, `stdout` is output, etc.).47 // However, while `childProcess.std*` and transforms follow that direction, any stream passed the `std*` option has the opposite direction.48 // For example, `childProcess.stdin` is a writable, but the `stdin` option is a readable.49-export const isInputFileDescriptor = (fdNumber, stdioStreamsGroups) => stdioStreamsGroups[fdNumber][0].direction === 'input';49+export const isInputFileDescriptor = (fdNumber, stdioStreamsGroups) => {50+ const [{direction}] = stdioStreamsGroups.find(stdioStreams => stdioStreams[0].fdNumber === fdNumber);51+ return direction === 'input';52+};53 54 // When `stream.destroy()` is called without an `error` argument, stream is aborted.55 // This is the only way to abort a readable stream, which can be useful in some instances.56 // Therefore, we ignore this error on readable streams.8 unmodified lines