async.js
This file
Path
lib/stdio/async.js
67 lines · 2.6 KiB · JavaScript
Last changed by
Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
History of this fileTake it
Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 1why, one step back1import {createReadStream, createWriteStream} from 'node:fs';Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
line 2why, one step back2import {Buffer} from 'node:buffer';Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 3why, one step back3import {Readable, Writable} from 'node:stream';Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca
line 4why, one step back4import mergeStreams from '@sindresorhus/merge-streams';Split `input`/`inputFile` options to their own file (#629)ehmickybefore adoption0b8e297
line 5why, one step back5import {handleInput} from './handle.js';Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4
line 6why, one step back6import {TYPE_TO_MESSAGE} from './type.js';Separate generator -> Duplex utility (#698)ehmickybefore adoption214b6ab
line 7why, one step back7import {generatorToDuplexStream, pipeGenerator} from './generator.js';Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 8–9why, one step back89// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async modeFix `encoding` option (#696)ehmickybefore adoptionb6f9fa2
line 10why, one step back10export const handleInputAsync = options => handleInput(addPropertiesAsync, options, false);Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 11why, one step back11Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4
lines 12–15why, one step back12const forbiddenIfAsync = ({type, optionName}) => {13 throw new TypeError(`The \`${optionName}\` option cannot be ${TYPE_TO_MESSAGE[type]}.`);14};15Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 16–17why, one step back16const addPropertiesAsync = {17 input: {Separate generator -> Duplex utility (#698)ehmickybefore adoption214b6ab
line 18why, one step back18 generator: generatorToDuplexStream,Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
lines 19–20why, one step back19 fileUrl: ({value}) => ({value: createReadStream(value)}),20 filePath: ({value}) => ({value: createReadStream(value.file)}),Fix Node.js streams not being cleaned up on process error (#660)ehmickybefore adoption61a1623
lines 21–22why, one step back21 webStream: ({value}) => ({value: Readable.fromWeb(value)}),22 iterable: ({value}) => ({value: Readable.from(value)}),Validate `input` option's type (#668)ehmickybefore adoption65742c6
lines 23–24why, one step back23 string: ({value}) => ({value: Readable.from(value)}),24 uint8Array: ({value}) => ({value: Readable.from(Buffer.from(value))}),Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 25–26why, one step back25 },26 output: {Separate generator -> Duplex utility (#698)ehmickybefore adoption214b6ab
line 27why, one step back27 generator: generatorToDuplexStream,Improve syntax of `std*: filePath` option (#671)ehmickybefore adoption90e0e13
lines 28–29why, one step back28 fileUrl: ({value}) => ({value: createWriteStream(value)}),29 filePath: ({value}) => ({value: createWriteStream(value.file)}),Fix Node.js streams not being cleaned up on process error (#660)ehmickybefore adoption61a1623
line 30why, one step back30 webStream: ({value}) => ({value: Writable.fromWeb(value)}),Allow `stdin: uint8Array` option (#670)ehmickybefore adoption2ac81d4
lines 31–32why, one step back31 iterable: forbiddenIfAsync,32 uint8Array: forbiddenIfAsync,Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 33–36why, one step back33 },34};3536// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async modeFix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca
line 37why, one step back37// When multiple input streams are used, we merge them to ensure the output stream ends only once each input stream has endedSimplify `std*` options logic (#691)ehmickybefore adoption98b0ee3
line 38why, one step back38export const pipeOutputAsync = (spawned, stdioStreamsGroups) => {Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca
lines 39–40why, one step back39 const inputStreamsGroups = {};40Simplify `std*` options logic (#691)ehmickybefore adoption98b0ee3
line 41why, one step back41 for (const stdioStreams of stdioStreamsGroups) {Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 42why, one step back42 for (const generatorStream of stdioStreams.filter(({type}) => type === 'generator')) {Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 43why, one step back43 pipeGenerator(spawned, generatorStream);Simplify `std*` options logic (#691)ehmickybefore adoption98b0ee3
line 44why, one step back44 }Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
line 45why, one step back45Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 46why, one step back46 for (const nonGeneratorStream of stdioStreams.filter(({type}) => type !== 'generator')) {Allow passing generators to the `std*` options (#693)ehmickybefore adoptione8f6bbd
lines 47–48why, one step back47 pipeStdioOption(spawned, nonGeneratorStream, inputStreamsGroups);48 }Refactor `stdio` options (#623)ehmickybefore adoption2d76897
line 49why, one step back49 }Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca
lines 50–54why, one step back5051 for (const [index, inputStreams] of Object.entries(inputStreamsGroups)) {52 const value = inputStreams.length === 1 ? inputStreams[0] : mergeStreams(inputStreams);53 value.pipe(spawned.stdio[index]);54 }Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 55–56why, one step back55};56Simplify `std*` options logic (#691)ehmickybefore adoption98b0ee3
line 57why, one step back57const pipeStdioOption = (spawned, {type, value, direction, index}, inputStreamsGroups) => {Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 58–62why, one step back58 if (type === 'native') {59 return;60 }6162 if (direction === 'output') {Simplify `std*` options logic (#691)ehmickybefore adoption98b0ee3
line 63why, one step back63 spawned.stdio[index].pipe(value);Allow using the `input`, `inputFile` and `stdin` options together (#666)ehmickybefore adoptionbeabd25
lines 64–65why, one step back64 } else {65 inputStreamsGroups[index] = [...(inputStreamsGroups[index] ?? []), value];Refactor `stdio` options (#623)ehmickybefore adoption2d76897
lines 66–67why, one step back66 }67};