Skip to content
Myr

sync.js

This file

Path

lib/sync.js

90 lines · 3.5 KiB · JavaScript

Last changed by

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

History of this file

Take it

Improve spawning errors (#847)ehmickybefore adoption381dee2

line 1why, one step back
1import {spawnSync} from 'node:child_process';

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 2why, one step back
2import {handleCommand, handleOptions} from './arguments/options.js';

Split files (#837)ehmickybefore adoption672c2d7

line 3why, one step back
3import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

line 4why, one step back
4import {handleOutput, handleResult} from './return/output.js';

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 5–7why, one step back
5import {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 back
8import {logEarlyResult} from './verbose/complete.js';

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 9why, one step back
9import {getSyncExitResult} from './exit/code.js';

Split files (#837)ehmickybefore adoption672c2d7

line 10why, one step back
10

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 11why, one step back
11export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

lines 12–13why, one step back
12 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 back
14 return handleResult(result, verboseInfo, options);

Split files (#837)ehmickybefore adoption672c2d7

lines 15–17why, one step back
15};
1617const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 18why, one step back
18 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);

Print process completion with verbose option (#887)ehmickybefore adoption7264bcf

lines 19–21why, one step back
19
20 try {21 const syncOptions = normalizeSyncOptions(rawOptions);

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 22why, one step back
22 const {file, args, options} = handleOptions(rawFile, rawArgs, syncOptions);

Print process completion with verbose option (#887)ehmickybefore adoption7264bcf

line 23why, one step back
23 validateSyncOptions(options);

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

lines 24–25why, one step back
24 const fileDescriptors = handleInputSync(options, verboseInfo);
25 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};

Print process completion with verbose option (#887)ehmickybefore adoption7264bcf

line 26why, one step back
26 } catch (error) {

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 27why, one step back
27 logEarlyResult(error, startTime, verboseInfo);

Print process completion with verbose option (#887)ehmickybefore adoption7264bcf

lines 28–29why, one step back
28 throw error;
29 }

Split files (#837)ehmickybefore adoption672c2d7

lines 30–33why, one step back
30};
3132const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;33

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

line 34why, one step back
34const validateSyncOptions = ({ipc, detached, cancelSignal}) => {

Split files (#837)ehmickybefore adoption672c2d7

line 35why, one step back
35 if (ipc) {

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

line 36why, one step back
36 throwInvalidSyncOption('ipc: true');

Split files (#837)ehmickybefore adoption672c2d7

line 37why, one step back
37 }

Improve validation of `execaSync()` options (#940)ehmickybefore adoptionf6e1ac1

lines 38–49why, one step back
38
39 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 back
50};

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

line 51why, one step back
51

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 52why, one step back
52const spawnSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 53–55why, one step back
53 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 back
56 }
57

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 58–59why, one step back
58 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 back
60 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 61why, one step back
61 return getSyncResult({error, exitCode, signal, stdio, options, command, escapedCommand, startTime});

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

line 62why, one step back
62};

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 63–74why, one step back
63
64const 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 back
75

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 76–78why, one step back
76const getSyncResult = ({error, exitCode, signal, stdio, options, command, escapedCommand, startTime}) => error === undefined
77 ? makeSuccessResult({command, escapedCommand, stdio, options, startTime})78 : makeError({

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 79–81why, one step back
79 error,
80 command,81 escapedCommand,

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 82why, one step back
82 timedOut: error.code === 'ETIMEDOUT',

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

line 83why, one step back
83 isCanceled: false,

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 84why, one step back
84 exitCode,

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 85–87why, one step back
85 signal,
86 stdio,87 options,

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 88why, one step back
88 startTime,

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

lines 89–90why, one step back
89 isSync: true,
90 });