sync.js
This file
Path
lib/sync.js
90 lines · 3.5 KiB · JavaScript
Last changed by
Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
History of this fileTake it
Improve spawning errors (#847)ehmickybefore adoption381dee2
line 1why, one step back1import {spawnSync} from 'node:child_process';Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 2why, one step back2import {handleCommand, handleOptions} from './arguments/options.js';Split files (#837)ehmickybefore adoption672c2d7
line 3why, one step back3import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 4why, one step back4import {handleOutput, handleResult} from './return/output.js';Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 5–7why, one step back5import {handleInputSync} from './stdio/sync.js';6import {addInputOptionsSync} from './stdio/input-sync.js';7import {transformOutputSync} from './stdio/output-sync.js';Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 8why, one step back8import {logEarlyResult} from './verbose/complete.js';Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 9why, one step back9import {getSyncExitResult} from './exit/code.js';Split files (#837)ehmickybefore adoption672c2d7
line 10why, one step back10Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 11why, one step back11export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 12–13why, one step back12 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArgs, rawOptions);13 const result = spawnSubprocessSync({file, args, options, command, escapedCommand, fileDescriptors, startTime});Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 14why, one step back14 return handleResult(result, verboseInfo, options);Split files (#837)ehmickybefore adoption672c2d7
lines 15–17why, one step back15};1617const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 18why, one step back18 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 19–21why, one step back1920 try {21 const syncOptions = normalizeSyncOptions(rawOptions);Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 22why, one step back22 const {file, args, options} = handleOptions(rawFile, rawArgs, syncOptions);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 23why, one step back23 validateSyncOptions(options);Add support for `std*: ['pipe', 'inherit']` with `execaSync()` (#954)ehmickybefore adoptionc15edbc
line 24why, one step back24 const {fileDescriptors} = handleInputSync(options, verboseInfo);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 25why, one step back25 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 26why, one step back26 } catch (error) {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 27why, one step back27 logEarlyResult(error, startTime, verboseInfo);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 28–29why, one step back28 throw error;29 }Split files (#837)ehmickybefore adoption672c2d7
lines 30–33why, one step back30};3132const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;33Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
line 34why, one step back34const validateSyncOptions = ({ipc, detached, cancelSignal}) => {Split files (#837)ehmickybefore adoption672c2d7
line 35why, one step back35 if (ipc) {Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
line 36why, one step back36 throwInvalidSyncOption('ipc: true');Split files (#837)ehmickybefore adoption672c2d7
line 37why, one step back37 }Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1
lines 38–49why, one step back3839 if (detached) {40 throwInvalidSyncOption('detached: true');41 }4243 if (cancelSignal) {44 throwInvalidSyncOption('cancelSignal');45 }46};4748const throwInvalidSyncOption = value => {49 throw new TypeError(`The "${value}" option cannot be used with synchronous methods.`);Split files (#837)ehmickybefore adoption672c2d7
line 50why, one step back50};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 51why, one step back51Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 52why, one step back52const spawnSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 53–55why, one step back53 const syncResult = runSubprocessSync({file, args, options, command, escapedCommand, fileDescriptors, startTime});54 if (syncResult.failed) {55 return syncResult;Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 56–57why, one step back56 }57Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 58–59why, one step back58 const {resultError, exitCode, signal} = getSyncExitResult(syncResult);59 const {output, error = resultError} = transformOutputSync(fileDescriptors, syncResult, options);Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 60why, one step back60 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 61why, one step back61 return getSyncResult({error, exitCode, signal, stdio, options, command, escapedCommand, startTime});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 62why, one step back62};Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 63–74why, one step back6364const runSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {65 try {66 addInputOptionsSync(fileDescriptors, options);67 const normalizedOptions = normalizeSpawnSyncOptions(options);68 return spawnSync(file, args, normalizedOptions);69 } catch (error) {70 return makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: true});71 }72};7374const normalizeSpawnSyncOptions = ({encoding, ...options}) => ({...options, encoding: 'buffer'});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 75why, one step back75Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 76–78why, one step back76const getSyncResult = ({error, exitCode, signal, stdio, options, command, escapedCommand, startTime}) => error === undefined77 ? makeSuccessResult({command, escapedCommand, stdio, options, startTime})78 : makeError({Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 79–81why, one step back79 error,80 command,81 escapedCommand,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 82why, one step back82 timedOut: error.code === 'ETIMEDOUT',Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 83why, one step back83 isCanceled: false,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 84why, one step back84 exitCode,Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 85–87why, one step back85 signal,86 stdio,87 options,Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 88why, one step back88 startTime,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 89–90why, one step back89 isSync: true,90 });