Skip to content
Myr

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 file

Take it

Improve spawning errors (#847)ehmickybefore adoption381dee2

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

Improve `verbose` option (#883)ehmickybefore adoption7d0943f

line 2why, one step back
2import {normalizeArguments, handleCommand, handleArguments} 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';

Split files (#837)ehmickybefore adoption672c2d7

line 5why, one step back
5import {handleInputSync, pipeOutputSync} from './stdio/sync.js';

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

line 6why, one step back
6import {logEarlyResult} from './verbose/complete.js';

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

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

Split files (#837)ehmickybefore adoption672c2d7

lines 8–9why, one step back
8
9export const execaSync = (rawFile, rawArgs, rawOptions) => {

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

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

Split files (#837)ehmickybefore adoption672c2d7

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

Improve input validation (#838)ehmickybefore adoption8ee137c

line 16why, one step back
16 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);

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

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

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

lines 18–22why, one step back
18
19 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 back
23 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 back
25 } catch (error) {

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

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

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

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

Split files (#837)ehmickybefore adoption672c2d7

lines 29–37why, one step back
29};
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 back
38

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

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

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 40–43why, one step back
40 let syncResult;
41 try {42 syncResult = spawnSync(file, args, options);43 } catch (error) {

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 44why, one step back
44 return makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: true});

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 45–46why, one step back
45 }
46

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

line 47why, one step back
47 const {error, exitCode, signal} = getSyncExitResult(syncResult);

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 48why, one step back
48 pipeOutputSync(fileDescriptors, syncResult);

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 49–51why, one step back
49
50 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 back
52 return getSyncResult({error, exitCode, signal, stdio, options, command, escapedCommand, startTime});

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 53–54why, one step back
53};
54

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

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

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 58–60why, one step back
58 error,
59 command,60 escapedCommand,

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

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

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

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

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

line 63why, one step back
63 exitCode,

Refactor `reject` option (#868)ehmickybefore adoption1f8a55c

lines 64–66why, one step back
64 signal,
65 stdio,66 options,

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

line 67why, one step back
67 startTime,

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

lines 68–69why, one step back
68 isSync: true,
69 });