sync.js
This file
Path
lib/sync.js
59 lines · 2.4 KiB · JavaScript
Last changed by
Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
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
lines 5–8why, one step back5import {handleInputSync, pipeOutputSync} from './stdio/sync.js';6import {isFailedExit} from './exit/code.js';78export const execaSync = (rawFile, rawArgs, rawOptions) => {Improve `verbose` option (#883)ehmickybefore adoption7d0943f
lines 9–10why, one step back9 const {file, args, command, escapedCommand, options, stdioStreamsGroups} = handleSyncArguments(rawFile, rawArgs, rawOptions);10 const result = spawnProcessSync({file, args, options, command, escapedCommand, stdioStreamsGroups});Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 11why, one step back11 return handleResult(result, options);Split files (#837)ehmickybefore adoption672c2d7
lines 12–14why, one step back12};1314const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {Improve input validation (#838)ehmickybefore adoption8ee137c
line 15why, one step back15 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
line 16why, one step back16 const {command, escapedCommand, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);Split files (#837)ehmickybefore adoption672c2d7
line 17why, one step back17 const syncOptions = normalizeSyncOptions(rawOptions);Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 18why, one step back18 const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);Split files (#837)ehmickybefore adoption672c2d7
line 19why, one step back19 validateSyncOptions(options);Print output with `verbose` option (#884)ehmickybefore adoption6fda30f
line 20why, one step back20 const stdioStreamsGroups = handleInputSync(options, verboseInfo);Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 21why, one step back21 return {file, args, command, escapedCommand, options, stdioStreamsGroups};Split files (#837)ehmickybefore adoption672c2d7
lines 22–30why, one step back22};2324const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;2526const validateSyncOptions = ({ipc}) => {27 if (ipc) {28 throw new TypeError('The "ipc: true" option cannot be used with synchronous methods.');29 }30};Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
line 31why, one step back31Improve `verbose` option (#883)ehmickybefore adoption7d0943f
line 32why, one step back32const spawnProcessSync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {Refactor `reject` option (#868)ehmickybefore adoption1f8a55c
lines 33–59why, one step back33 let syncResult;34 try {35 syncResult = spawnSync(file, args, options);36 } catch (error) {37 return makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options});38 }3940 pipeOutputSync(stdioStreamsGroups, syncResult);4142 const output = syncResult.output || Array.from({length: 3});43 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));44 return getSyncResult(syncResult, {stdio, options, command, escapedCommand});45};4647const getSyncResult = ({error, status, signal}, {stdio, options, command, escapedCommand}) => error !== undefined || isFailedExit(status, signal)48 ? makeError({49 error,50 command,51 escapedCommand,52 timedOut: error && error.code === 'ETIMEDOUT',53 isCanceled: false,54 exitCode: status,55 signal,56 stdio,57 options,58 })59 : makeSuccessResult({command, escapedCommand, stdio, options});