sync.js
This file
Path
lib/sync.js
69 lines · 2.8 KiB · JavaScript
Last changed by
Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
History of this fileTake it
Improve spawning errors (#847)ehmickybefore adoption381dee2
line 1why, one step back1import {spawnSync} from 'node:child_process';Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 2why, one step back2import {normalizeArguments, handleCommand, handleArguments} 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';Split files (#837)ehmickybefore adoption672c2d7
line 5why, one step back5import {handleInputSync, pipeOutputSync} from './stdio/sync.js';Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 6why, one step back6import {logEarlyResult} from './verbose/complete.js';Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 7why, one step back7import {getSyncExitResult} from './exit/code.js';Split files (#837)ehmickybefore adoption672c2d7
lines 8–9why, one step back89export const execaSync = (rawFile, rawArgs, rawOptions) => {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 10–11why, one step back10 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArgs, rawOptions);11 const result = spawnSubprocessSync({file, args, options, command, escapedCommand, fileDescriptors, startTime});Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 12why, one step back12 return handleResult(result, verboseInfo, options);Split files (#837)ehmickybefore adoption672c2d7
lines 13–15why, one step back13};1415const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {Improve input validation (#838)ehmickybefore adoption8ee137c
line 16why, one step back16 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 17why, one step back17 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 18–22why, one step back1819 try {20 const syncOptions = normalizeSyncOptions(rawOptions);21 const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);22 validateSyncOptions(options);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
lines 23–24why, one step back23 const fileDescriptors = handleInputSync(options, verboseInfo);24 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
line 25why, one step back25 } catch (error) {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 26why, one step back26 logEarlyResult(error, startTime, verboseInfo);Print process completion with verbose option (#887)ehmickybefore adoption7264bcf
lines 27–28why, one step back27 throw error;28 }Split files (#837)ehmickybefore adoption672c2d7
lines 29–37why, one step back29};3031const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;3233const validateSyncOptions = ({ipc}) => {34 if (ipc) {35 throw new TypeError('The "ipc: true" option cannot be used with synchronous methods.');36 }37};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 38why, one step back38Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 39why, one step back39const spawnSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 40–43why, one step back40 let syncResult;41 try {42 syncResult = spawnSync(file, args, options);43 } catch (error) {Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 44why, one step back44 return makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: true});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 45–46why, one step back45 }46Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 47why, one step back47 const {error, exitCode, signal} = getSyncExitResult(syncResult);Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d
line 48why, one step back48 pipeOutputSync(fileDescriptors, syncResult);Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 49–51why, one step back4950 const output = syncResult.output || Array.from({length: 3});51 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 52why, one step back52 return getSyncResult({error, exitCode, signal, stdio, options, command, escapedCommand, startTime});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 53–54why, one step back53};54Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 55–57why, one step back55const getSyncResult = ({error, exitCode, signal, stdio, options, command, escapedCommand, startTime}) => error === undefined56 ? makeSuccessResult({command, escapedCommand, stdio, options, startTime})57 : makeError({Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 58–60why, one step back58 error,59 command,60 escapedCommand,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 61why, one step back61 timedOut: error.code === 'ETIMEDOUT',Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 62why, one step back62 isCanceled: false,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 63why, one step back63 exitCode,Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 64–66why, one step back64 signal,65 stdio,66 options,Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 67why, one step back67 startTime,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 68–69why, one step back68 isSync: true,69 });