main-sync.js
This file
Path
lib/methods/main-sync.js
163 lines · 4.6 KiB · JavaScript
Last changed by
Fix Node 24-specific deprecation warning (#1199)ehmickybefore adoption1ac5b91
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
lines 1–2why, one step back1import {spawnSync} from 'node:child_process';2import {handleCommand} from '../arguments/command.js';Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
line 3why, one step back3import {normalizeOptions} from '../arguments/options.js';Fix Node 24-specific deprecation warning (#1199)ehmickybefore adoption1ac5b91
line 4why, one step back4import {concatenateShell} from '../arguments/shell.js';Rename files (#977)ehmickybefore adoption4b2e316
lines 5–14why, one step back5import {makeError, makeEarlyError, makeSuccessResult} from '../return/result.js';6import {handleResult} from '../return/reject.js';7import {handleStdioSync} from '../stdio/handle-sync.js';8import {stripNewline} from '../io/strip-newline.js';9import {addInputOptionsSync} from '../io/input-sync.js';10import {transformOutputSync} from '../io/output-sync.js';11import {getMaxBufferSync} from '../io/max-buffer.js';12import {getAllSync} from '../resolve/all-sync.js';13import {getExitResultSync} from '../resolve/exit-sync.js';14Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 15why, one step back15// Main shared logic for all sync methods: `execaSync()`, `$.sync()`Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 16–27why, one step back16export const execaCoreSync = (rawFile, rawArguments, rawOptions) => {17 const {file, commandArguments, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArguments, rawOptions);18 const result = spawnSubprocessSync({19 file,20 commandArguments,21 options,22 command,23 escapedCommand,24 verboseInfo,25 fileDescriptors,26 startTime,27 });Rename files (#977)ehmickybefore adoption4b2e316
lines 28–30why, one step back28 return handleResult(result, verboseInfo, options);29};30Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 31why, one step back31// Compute arguments to pass to `child_process.spawnSync()`Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 32–33why, one step back32const handleSyncArguments = (rawFile, rawArguments, rawOptions) => {33 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArguments, rawOptions);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 34–47why, one step back34 const syncOptions = normalizeSyncOptions(rawOptions);35 const {file, commandArguments, options} = normalizeOptions(rawFile, rawArguments, syncOptions);36 validateSyncOptions(options);37 const fileDescriptors = handleStdioSync(options, verboseInfo);38 return {39 file,40 commandArguments,41 command,42 escapedCommand,43 startTime,44 verboseInfo,45 options,46 fileDescriptors,47 };Rename files (#977)ehmickybefore adoption4b2e316
lines 48–49why, one step back48};49Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 50why, one step back50// Options normalization logic specific to sync methodsRename files (#977)ehmickybefore adoption4b2e316
lines 51–52why, one step back51const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;52Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 53why, one step back53// Options validation logic specific to sync methodsAdd `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 54–58why, one step back54const validateSyncOptions = ({ipc, ipcInput, detached, cancelSignal}) => {55 if (ipcInput) {56 throwInvalidSyncOption('ipcInput');57 }58Rename files (#977)ehmickybefore adoption4b2e316
lines 59–75why, one step back59 if (ipc) {60 throwInvalidSyncOption('ipc: true');61 }6263 if (detached) {64 throwInvalidSyncOption('detached: true');65 }6667 if (cancelSignal) {68 throwInvalidSyncOption('cancelSignal');69 }70};7172const throwInvalidSyncOption = value => {73 throw new TypeError(`The "${value}" option cannot be used with synchronous methods.`);74};75Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 76–85why, one step back76const spawnSubprocessSync = ({file, commandArguments, options, command, escapedCommand, verboseInfo, fileDescriptors, startTime}) => {77 const syncResult = runSubprocessSync({78 file,79 commandArguments,80 options,81 command,82 escapedCommand,83 fileDescriptors,84 startTime,85 });Rename files (#977)ehmickybefore adoption4b2e316
lines 86–90why, one step back86 if (syncResult.failed) {87 return syncResult;88 }8990 const {resultError, exitCode, signal, timedOut, isMaxBuffer} = getExitResultSync(syncResult, options);Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 91–97why, one step back91 const {output, error = resultError} = transformOutputSync({92 fileDescriptors,93 syncResult,94 options,95 isMaxBuffer,96 verboseInfo,97 });Rename files (#977)ehmickybefore adoption4b2e316
lines 98–99why, one step back98 const stdio = output.map((stdioOutput, fdNumber) => stripNewline(stdioOutput, options, fdNumber));99 const all = stripNewline(getAllSync(output, options), options, 'all');Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 100–112why, one step back100 return getSyncResult({101 error,102 exitCode,103 signal,104 timedOut,105 isMaxBuffer,106 stdio,107 all,108 options,109 command,110 escapedCommand,111 startTime,112 });Rename files (#977)ehmickybefore adoption4b2e316
lines 113–114why, one step back113};114Upgrade xo (#980)ehmickybefore adoptionccfa412
line 115why, one step back115const runSubprocessSync = ({file, commandArguments, options, command, escapedCommand, fileDescriptors, startTime}) => {Rename files (#977)ehmickybefore adoption4b2e316
lines 116–118why, one step back116 try {117 addInputOptionsSync(fileDescriptors, options);118 const normalizedOptions = normalizeSpawnSyncOptions(options);Fix Node 24-specific deprecation warning (#1199)ehmickybefore adoption1ac5b91
line 119why, one step back119 return spawnSync(...concatenateShell(file, commandArguments, normalizedOptions));Rename files (#977)ehmickybefore adoption4b2e316
line 120why, one step back120 } catch (error) {Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 121–129why, one step back121 return makeEarlyError({122 error,123 command,124 escapedCommand,125 fileDescriptors,126 options,127 startTime,128 isSync: true,129 });Rename files (#977)ehmickybefore adoption4b2e316
lines 130–132why, one step back130 }131};132Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 133why, one step back133// The `encoding` option is handled by Execa, not by `child_process.spawnSync()`Rename files (#977)ehmickybefore adoption4b2e316
lines 134–136why, one step back134const normalizeSpawnSyncOptions = ({encoding, maxBuffer, ...options}) => ({...options, encoding: 'buffer', maxBuffer: getMaxBufferSync(maxBuffer)});135136const getSyncResult = ({error, exitCode, signal, timedOut, isMaxBuffer, stdio, all, options, command, escapedCommand, startTime}) => error === undefinedUpgrade xo (#980)ehmickybefore adoptionccfa412
lines 137–141why, one step back137 ? makeSuccessResult({138 command,139 escapedCommand,140 stdio,141 all,Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 142why, one step back142 ipcOutput: [],Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 143–145why, one step back143 options,144 startTime,145 })Rename files (#977)ehmickybefore adoption4b2e316
lines 146–151why, one step back146 : makeError({147 error,148 command,149 escapedCommand,150 timedOut,151 isCanceled: false,Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 152why, one step back152 isGracefullyCanceled: false,Rename files (#977)ehmickybefore adoption4b2e316
line 153why, one step back153 isMaxBuffer,Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 154why, one step back154 isForcefullyTerminated: false,Rename files (#977)ehmickybefore adoption4b2e316
lines 155–158why, one step back155 exitCode,156 signal,157 stdio,158 all,Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 159why, one step back159 ipcOutput: [],Rename files (#977)ehmickybefore adoption4b2e316
lines 160–163why, one step back160 options,161 startTime,162 isSync: true,163 });