sync.js
This file
Path
lib/sync.js
67 lines · 2.7 KiB · JavaScript
Last changed by
Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
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';Split files (#837)ehmickybefore adoption672c2d7
lines 7–9why, one step back7import {isFailedExit} from './exit/code.js';89export const execaSync = (rawFile, rawArgs, rawOptions) => {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 10why, one step back10 const {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups} = handleSyncArguments(rawFile, rawArgs, rawOptions);Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 11why, one step back11 const result = spawnSubprocessSync({file, args, options, command, escapedCommand, stdioStreamsGroups, 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–23why, one step back1819 try {20 const syncOptions = normalizeSyncOptions(rawOptions);21 const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);22 validateSyncOptions(options);23 const stdioStreamsGroups = handleInputSync(options, verboseInfo);Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 24why, one step back24 return {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups};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 back38Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 39why, one step back39const spawnSubprocessSync = ({file, args, options, command, escapedCommand, stdioStreamsGroups, 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) {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 44why, one step back44 return makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options, startTime});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 45–50why, one step back45 }4647 pipeOutputSync(stdioStreamsGroups, syncResult);4849 const output = syncResult.output || Array.from({length: 3});50 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 51why, one step back51 return getSyncResult(syncResult, {stdio, options, command, escapedCommand, startTime});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 52–53why, one step back52};53Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 54why, one step back54const getSyncResult = ({error, status, signal}, {stdio, options, command, escapedCommand, startTime}) => error !== undefined || isFailedExit(status, signal)Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 55–64why, one step back55 ? makeError({56 error,57 command,58 escapedCommand,59 timedOut: error && error.code === 'ETIMEDOUT',60 isCanceled: false,61 exitCode: status,62 signal,63 stdio,64 options,Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 65why, one step back65 startTime,Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 66why, one step back66 })Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 67why, one step back67 : makeSuccessResult({command, escapedCommand, stdio, options, startTime});