async.js
This file
Path
lib/async.js
105 lines · 4.6 KiB · JavaScript
Last changed by
Allow template strings with all methods (#933)ehmickybefore adoption8074d85
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';Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 3why, one step back3import {handleCommand, handleOptions} 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–17why, one step back16import {mergePromise} from './promise.js';17Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 18why, one step back18export const execaCoreAsync = (rawFile, rawArgs, rawOptions, createNested) => {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 template strings with all methods (#933)ehmickybefore adoption8074d85
line 21why, one step back21 subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, boundOptions: {}, createNested});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
line 27why, one step back27const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 28why, one step back28 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 29–30why, one step back2930 try {Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 31why, one step back31 const {file, args, options: normalizedOptions} = handleOptions(rawFile, rawArgs, rawOptions);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 32why, one step back32 const options = handleAsyncOptions(normalizedOptions);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 33–34why, one step back33 const {fileDescriptors, stdioState} = handleInputAsync(options, verboseInfo);34 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors, stdioState};Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 35why, one step back35 } catch (error) {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 36why, one step back36 logEarlyResult(error, startTime, verboseInfo);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 37–38why, one step back37 throw error;38 }Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 39why, one step back39};Split files (#837)ehmickybefore adoption672c2d7
line 40why, one step back40Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 41why, one step back41// Prevent passing the `timeout` option directly to `child_process.spawn()`Rename `signal` option to `cancelSignal` (#880)ehmickybefore adoption231beaf
lines 42–48why, one step back42const handleAsyncOptions = ({timeout, signal, cancelSignal, ...options}) => {43 if (signal !== undefined) {44 throw new TypeError('The "signal" option has been renamed to "cancelSignal" instead.');45 }4647 return {...options, timeoutDuration: timeout, signal: cancelSignal};48};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 49why, one step back49Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 50why, one step back50const spawnSubprocessAsync = ({file, args, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors, stdioState}) => {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 51why, one step back51 let subprocess;Split files (#837)ehmickybefore adoption672c2d7
line 52why, one step back52 try {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 53why, one step back53 subprocess = spawn(file, args, options);Split files (#837)ehmickybefore adoption672c2d7
line 54why, one step back54 } catch (error) {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 55why, one step back55 return handleEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, verboseInfo});Split files (#837)ehmickybefore adoption672c2d7
lines 56–60why, one step back56 }5758 const controller = new AbortController();59 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);60Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 61why, one step back61 const originalStreams = [...subprocess.stdio];Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 62why, one step back62 pipeOutputAsync(subprocess, fileDescriptors, stdioState, controller);Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 63why, one step back63 cleanupOnExit(subprocess, options, controller);Split files (#837)ehmickybefore adoption672c2d7
line 64why, one step back64Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 65–66why, one step back65 subprocess.kill = subprocessKill.bind(undefined, {kill: subprocess.kill.bind(subprocess), subprocess, options, controller});66 subprocess.all = makeAllStream(subprocess, options);Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9
line 67why, one step back67 addConvertedStreams(subprocess, options);Split files (#837)ehmickybefore adoption672c2d7
line 68why, one step back68Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 69why, one step back69 const promise = handlePromise({subprocess, options, startTime, verboseInfo, fileDescriptors, originalStreams, command, escapedCommand, controller});Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 70why, one step back70 return {subprocess, promise};Split files (#837)ehmickybefore adoption672c2d7
lines 71–72why, one step back71};72Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 73why, one step back73const handlePromise = async ({subprocess, options, startTime, verboseInfo, fileDescriptors, originalStreams, command, escapedCommand, controller}) => {Split files (#837)ehmickybefore adoption672c2d7
lines 74–80why, one step back74 const context = {timedOut: false};7576 const [77 errorInfo,78 [exitCode, signal],79 stdioResults,80 allResult,Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 81why, one step back81 ] = await getSubprocessResult({subprocess, options, context, fileDescriptors, originalStreams, controller});Split files (#837)ehmickybefore adoption672c2d7
lines 82–85why, one step back82 controller.abort();8384 const stdio = stdioResults.map(stdioResult => handleOutput(options, stdioResult));85 const all = handleOutput(options, allResult);Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 86why, one step back86 const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime});Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 87why, one step back87 return handleResult(result, verboseInfo, options);Split files (#837)ehmickybefore adoption672c2d7
line 88why, one step back88};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 89why, one step back89Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 90why, one step back90const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime}) => 'error' in errorInfoRefactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 91–101why, one step back91 ? makeError({92 error: errorInfo.error,93 command,94 escapedCommand,95 timedOut: context.timedOut,96 isCanceled: options.signal?.aborted === true,97 exitCode,98 signal,99 stdio,100 all,101 options,Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 102why, one step back102 startTime,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 103why, one step back103 isSync: false,Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 104why, one step back104 })Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 105why, one step back105 : makeSuccessResult({command, escapedCommand, stdio, all, options, startTime});