async.js
This file
Path
lib/stdio/async.js
46 lines · 1.4 KiB · JavaScript
Last changed by
Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
History of this fileTake it
Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 1–2why, one step back1import {createReadStream, createWriteStream} from 'node:fs';2import {Readable, Writable} from 'node:stream';Split `input`/`inputFile` options to their own file (#629)ehmickybefore adoption0b8e297
line 3why, one step back3import {handleInput} from './handle.js';Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 4–9why, one step back45// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode6export const handleInputAsync = options => handleInput(addPropertiesAsync, options);78const addPropertiesAsync = {9 input: {Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 10–12why, one step back10 filePath: ({value}) => ({value: createReadStream(value), autoDestroy: true}),11 webStream: ({value}) => ({value: Readable.fromWeb(value), autoDestroy: true}),12 iterable: ({value}) => ({value: Readable.from(value), autoDestroy: true}),Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 13–14why, one step back13 },14 output: {Allow `stdin`/`stdout`/`stderr` to be an array (#643)ehmickybefore adoption7efd50c
lines 15–16why, one step back15 filePath: ({value}) => ({value: createWriteStream(value), autoDestroy: true}),16 webStream: ({value}) => ({value: Writable.fromWeb(value), autoDestroy: true}),Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 17–24why, one step back17 iterable({optionName}) {18 throw new TypeError(`The \`${optionName}\` option cannot be an iterable.`);19 },20 },21};2223// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async mode24export const pipeOutputAsync = (spawned, stdioStreams) => {Refactor `stdio` option logic (#639)ehmickybefore adoptiond6b4553
lines 25–26why, one step back25 for (const stdioStream of stdioStreams) {26 pipeStdioOption(spawned.stdio[stdioStream.index], stdioStream);Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 27–46why, one step back27 }28};2930const pipeStdioOption = (childStream, {type, value, direction}) => {31 if (type === 'native') {32 return;33 }3435 if (direction === 'output') {36 childStream.pipe(value);37 return;38 }3940 if (type === 'stringOrBuffer') {41 childStream.end(value);42 return;43 }4445 value.pipe(childStream);46};