async.js
This file
Path
lib/async.js
106 lines · 4.6 KiB · JavaScript
Last changed by
Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
line 1why, one step back1import {setMaxListeners} from 'node:events';Improve spawning errors (#847)ehmickybefore adoption381dee2
line 2why, one step back2import {spawn} from 'node:child_process';Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 3why, one step back3import {normalizeArguments, handleCommand, handleArguments} from './arguments/options.js';Improve spawning errors (#847)ehmickybefore adoption381dee2
line 4why, one step back4import {makeError, makeSuccessResult} from './return/error.js';Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 5why, one step back5import {handleOutput, handleResult} from './return/output.js';Improve spawning errors (#847)ehmickybefore adoption381dee2
lines 6–7why, one step back6import {handleEarlyError} from './return/early-error.js';7import {handleInputAsync, pipeOutputAsync} from './stdio/async.js';Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 8why, one step back8import {subprocessKill} from './exit/kill.js';Split files (#837)ehmickybefore adoption672c2d7
line 9why, one step back9import {cleanupOnExit} from './exit/cleanup.js';Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 10–11why, one step back10import {pipeToSubprocess} from './pipe/setup.js';11import {SUBPROCESS_OPTIONS} from './pipe/validate.js';Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 12why, one step back12import {logEarlyResult} from './verbose/complete.js';Split files (#837)ehmickybefore adoption672c2d7
line 13why, one step back13import {makeAllStream} from './stream/all.js';Add `.readable()`, `.writable()` and `.duplex()` methods (#912)ehmickybefore adoption666f7f9
line 14why, one step back14import {addConvertedStreams} from './convert/add.js';Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 15why, one step back15import {getSubprocessResult} from './stream/resolve.js';Split files (#837)ehmickybefore adoption672c2d7
lines 16–18why, one step back16import {mergePromise} from './promise.js';1718export const execa = (rawFile, rawArgs, rawOptions) => {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 19–20why, one step back19 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors, stdioState} = handleAsyncArguments(rawFile, rawArgs, rawOptions);20 const {subprocess, promise} = spawnSubprocessAsync({file, args, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors, stdioState});Allow piping process to any file descriptor (#903)ehmickybefore adoption6642cd2
line 21why, one step back21 subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, boundOptions: {}});Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 22why, one step back22 mergePromise(subprocess, promise);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 23why, one step back23 SUBPROCESS_OPTIONS.set(subprocess, {options, fileDescriptors});Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 24why, one step back24 return subprocess;Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4
lines 25–26why, one step back25};26Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 27–28why, one step back27const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {28 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 29why, one step back29 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 30–33why, one step back3031 try {32 const {file, args, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);33 const options = handleAsyncOptions(normalizedOptions);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 34–35why, one step back34 const {fileDescriptors, stdioState} = handleInputAsync(options, verboseInfo);35 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors, stdioState};Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 36why, one step back36 } catch (error) {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 37why, one step back37 logEarlyResult(error, startTime, verboseInfo);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 38–39why, one step back38 throw error;39 }Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 40why, one step back40};Split files (#837)ehmickybefore adoption672c2d7
line 41why, one step back41Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 42why, one step back42// Prevent passing the `timeout` option directly to `child_process.spawn()`Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
lines 43–49why, one step back43const handleAsyncOptions = ({timeout, signal, cancelSignal, ...options}) => {44 if (signal !== undefined) {45 throw new TypeError('The "signal" option has been renamed to "cancelSignal" instead.');46 }4748 return {...options, timeoutDuration: timeout, signal: cancelSignal};49};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 50why, one step back50Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 51why, one step back51const spawnSubprocessAsync = ({file, args, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors, stdioState}) => {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 52why, one step back52 let subprocess;Split files (#837)ehmickybefore adoption672c2d7
line 53why, one step back53 try {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 54why, one step back54 subprocess = spawn(file, args, options);Split files (#837)ehmickybefore adoption672c2d7
line 55why, one step back55 } catch (error) {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 56why, one step back56 return handleEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, verboseInfo});Split files (#837)ehmickybefore adoption672c2d7
lines 57–61why, one step back57 }5859 const controller = new AbortController();60 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);61Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 62why, one step back62 const originalStreams = [...subprocess.stdio];Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 63why, one step back63 pipeOutputAsync(subprocess, fileDescriptors, stdioState, controller);Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 64why, one step back64 cleanupOnExit(subprocess, options, controller);Split files (#837)ehmickybefore adoption672c2d7
line 65why, one step back65Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 66–67why, one step back66 subprocess.kill = subprocessKill.bind(undefined, {kill: subprocess.kill.bind(subprocess), subprocess, options, controller});67 subprocess.all = makeAllStream(subprocess, options);Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9
line 68why, one step back68 addConvertedStreams(subprocess, options);Split files (#837)ehmickybefore adoption672c2d7
line 69why, one step back69Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 70why, one step back70 const promise = handlePromise({subprocess, options, startTime, verboseInfo, fileDescriptors, originalStreams, command, escapedCommand, controller});Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 71why, one step back71 return {subprocess, promise};Split files (#837)ehmickybefore adoption672c2d7
lines 72–73why, one step back72};73Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 74why, one step back74const handlePromise = async ({subprocess, options, startTime, verboseInfo, fileDescriptors, originalStreams, command, escapedCommand, controller}) => {Split files (#837)ehmickybefore adoption672c2d7
lines 75–81why, one step back75 const context = {timedOut: false};7677 const [78 errorInfo,79 [exitCode, signal],80 stdioResults,81 allResult,Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 82why, one step back82 ] = await getSubprocessResult({subprocess, options, context, fileDescriptors, originalStreams, controller});Split files (#837)ehmickybefore adoption672c2d7
lines 83–86why, one step back83 controller.abort();8485 const stdio = stdioResults.map(stdioResult => handleOutput(options, stdioResult));86 const all = handleOutput(options, allResult);Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 87why, one step back87 const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime});Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 88why, one step back88 return handleResult(result, verboseInfo, options);Split files (#837)ehmickybefore adoption672c2d7
line 89why, one step back89};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 90why, one step back90Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 91why, one step back91const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime}) => 'error' in errorInfoRefactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 92–102why, one step back92 ? makeError({93 error: errorInfo.error,94 command,95 escapedCommand,96 timedOut: context.timedOut,97 isCanceled: options.signal?.aborted === true,98 exitCode,99 signal,100 stdio,101 all,102 options,Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 103why, one step back103 startTime,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 104why, one step back104 isSync: false,Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 105why, one step back105 })Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 106why, one step back106 : makeSuccessResult({command, escapedCommand, stdio, all, options, startTime});