加入了node_modules
添加了新的功能项
This commit is contained in:
20
node_modules/execa/lib/terminate/cancel.js
generated
vendored
Normal file
20
node_modules/execa/lib/terminate/cancel.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import {onAbortedSignal} from '../utils/abort-signal.js';
|
||||
|
||||
// Validate the `cancelSignal` option
|
||||
export const validateCancelSignal = ({cancelSignal}) => {
|
||||
if (cancelSignal !== undefined && Object.prototype.toString.call(cancelSignal) !== '[object AbortSignal]') {
|
||||
throw new Error(`The \`cancelSignal\` option must be an AbortSignal: ${String(cancelSignal)}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Terminate the subprocess when aborting the `cancelSignal` option and `gracefulSignal` is `false`
|
||||
export const throwOnCancel = ({subprocess, cancelSignal, gracefulCancel, context, controller}) => cancelSignal === undefined || gracefulCancel
|
||||
? []
|
||||
: [terminateOnCancel(subprocess, cancelSignal, context, controller)];
|
||||
|
||||
const terminateOnCancel = async (subprocess, cancelSignal, context, {signal}) => {
|
||||
await onAbortedSignal(cancelSignal, signal);
|
||||
context.terminationReason ??= 'cancel';
|
||||
subprocess.kill();
|
||||
throw cancelSignal.reason;
|
||||
};
|
||||
16
node_modules/execa/lib/terminate/cleanup.js
generated
vendored
Normal file
16
node_modules/execa/lib/terminate/cleanup.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import {addAbortListener} from 'node:events';
|
||||
import {onExit} from 'signal-exit';
|
||||
|
||||
// If the `cleanup` option is used, call `subprocess.kill()` when the parent process exits
|
||||
export const cleanupOnExit = (subprocess, {cleanup, detached}, {signal}) => {
|
||||
if (!cleanup || detached) {
|
||||
return;
|
||||
}
|
||||
|
||||
const removeExitHandler = onExit(() => {
|
||||
subprocess.kill();
|
||||
});
|
||||
addAbortListener(signal, () => {
|
||||
removeExitHandler();
|
||||
});
|
||||
};
|
||||
71
node_modules/execa/lib/terminate/graceful.js
generated
vendored
Normal file
71
node_modules/execa/lib/terminate/graceful.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import {onAbortedSignal} from '../utils/abort-signal.js';
|
||||
import {sendAbort} from '../ipc/graceful.js';
|
||||
import {killOnTimeout} from './kill.js';
|
||||
|
||||
// Validate the `gracefulCancel` option
|
||||
export const validateGracefulCancel = ({gracefulCancel, cancelSignal, ipc, serialization}) => {
|
||||
if (!gracefulCancel) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cancelSignal === undefined) {
|
||||
throw new Error('The `cancelSignal` option must be defined when setting the `gracefulCancel` option.');
|
||||
}
|
||||
|
||||
if (!ipc) {
|
||||
throw new Error('The `ipc` option cannot be false when setting the `gracefulCancel` option.');
|
||||
}
|
||||
|
||||
if (serialization === 'json') {
|
||||
throw new Error('The `serialization` option cannot be \'json\' when setting the `gracefulCancel` option.');
|
||||
}
|
||||
};
|
||||
|
||||
// Send abort reason to the subprocess when aborting the `cancelSignal` option and `gracefulCancel` is `true`
|
||||
export const throwOnGracefulCancel = ({
|
||||
subprocess,
|
||||
cancelSignal,
|
||||
gracefulCancel,
|
||||
forceKillAfterDelay,
|
||||
context,
|
||||
controller,
|
||||
}) => gracefulCancel
|
||||
? [sendOnAbort({
|
||||
subprocess,
|
||||
cancelSignal,
|
||||
forceKillAfterDelay,
|
||||
context,
|
||||
controller,
|
||||
})]
|
||||
: [];
|
||||
|
||||
const sendOnAbort = async ({subprocess, cancelSignal, forceKillAfterDelay, context, controller: {signal}}) => {
|
||||
await onAbortedSignal(cancelSignal, signal);
|
||||
const reason = getReason(cancelSignal);
|
||||
await sendAbort(subprocess, reason);
|
||||
killOnTimeout({
|
||||
kill: subprocess.kill,
|
||||
forceKillAfterDelay,
|
||||
context,
|
||||
controllerSignal: signal,
|
||||
});
|
||||
context.terminationReason ??= 'gracefulCancel';
|
||||
throw cancelSignal.reason;
|
||||
};
|
||||
|
||||
// The default `reason` is a DOMException, which is not serializable with V8
|
||||
// See https://github.com/nodejs/node/issues/53225
|
||||
const getReason = ({reason}) => {
|
||||
if (!(reason instanceof DOMException)) {
|
||||
return reason;
|
||||
}
|
||||
|
||||
const error = new Error(reason.message);
|
||||
Object.defineProperty(error, 'stack', {
|
||||
value: reason.stack,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
return error;
|
||||
};
|
||||
93
node_modules/execa/lib/terminate/kill.js
generated
vendored
Normal file
93
node_modules/execa/lib/terminate/kill.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
import {setTimeout} from 'node:timers/promises';
|
||||
import {isErrorInstance} from '../return/final-error.js';
|
||||
import {normalizeSignalArgument} from './signal.js';
|
||||
|
||||
// Normalize the `forceKillAfterDelay` option
|
||||
export const normalizeForceKillAfterDelay = forceKillAfterDelay => {
|
||||
if (forceKillAfterDelay === false) {
|
||||
return forceKillAfterDelay;
|
||||
}
|
||||
|
||||
if (forceKillAfterDelay === true) {
|
||||
return DEFAULT_FORCE_KILL_TIMEOUT;
|
||||
}
|
||||
|
||||
if (!Number.isFinite(forceKillAfterDelay) || forceKillAfterDelay < 0) {
|
||||
throw new TypeError(`Expected the \`forceKillAfterDelay\` option to be a non-negative integer, got \`${forceKillAfterDelay}\` (${typeof forceKillAfterDelay})`);
|
||||
}
|
||||
|
||||
return forceKillAfterDelay;
|
||||
};
|
||||
|
||||
const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
|
||||
|
||||
// Monkey-patches `subprocess.kill()` to add `forceKillAfterDelay` behavior and `.kill(error)`
|
||||
export const subprocessKill = (
|
||||
{kill, options: {forceKillAfterDelay, killSignal}, onInternalError, context, controller},
|
||||
signalOrError,
|
||||
errorArgument,
|
||||
) => {
|
||||
const {signal, error} = parseKillArguments(signalOrError, errorArgument, killSignal);
|
||||
emitKillError(error, onInternalError);
|
||||
const killResult = kill(signal);
|
||||
setKillTimeout({
|
||||
kill,
|
||||
signal,
|
||||
forceKillAfterDelay,
|
||||
killSignal,
|
||||
killResult,
|
||||
context,
|
||||
controller,
|
||||
});
|
||||
return killResult;
|
||||
};
|
||||
|
||||
const parseKillArguments = (signalOrError, errorArgument, killSignal) => {
|
||||
const [signal = killSignal, error] = isErrorInstance(signalOrError)
|
||||
? [undefined, signalOrError]
|
||||
: [signalOrError, errorArgument];
|
||||
|
||||
if (typeof signal !== 'string' && !Number.isInteger(signal)) {
|
||||
throw new TypeError(`The first argument must be an error instance or a signal name string/integer: ${String(signal)}`);
|
||||
}
|
||||
|
||||
if (error !== undefined && !isErrorInstance(error)) {
|
||||
throw new TypeError(`The second argument is optional. If specified, it must be an error instance: ${error}`);
|
||||
}
|
||||
|
||||
return {signal: normalizeSignalArgument(signal), error};
|
||||
};
|
||||
|
||||
// Fails right away when calling `subprocess.kill(error)`.
|
||||
// Does not wait for actual signal termination.
|
||||
// Uses a deferred promise instead of the `error` event on the subprocess, as this is less intrusive.
|
||||
const emitKillError = (error, onInternalError) => {
|
||||
if (error !== undefined) {
|
||||
onInternalError.reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
const setKillTimeout = async ({kill, signal, forceKillAfterDelay, killSignal, killResult, context, controller}) => {
|
||||
if (signal === killSignal && killResult) {
|
||||
killOnTimeout({
|
||||
kill,
|
||||
forceKillAfterDelay,
|
||||
context,
|
||||
controllerSignal: controller.signal,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Forcefully terminate a subprocess after a timeout
|
||||
export const killOnTimeout = async ({kill, forceKillAfterDelay, context, controllerSignal}) => {
|
||||
if (forceKillAfterDelay === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await setTimeout(forceKillAfterDelay, undefined, {signal: controllerSignal});
|
||||
if (kill('SIGKILL')) {
|
||||
context.isForcefullyTerminated ??= true;
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
70
node_modules/execa/lib/terminate/signal.js
generated
vendored
Normal file
70
node_modules/execa/lib/terminate/signal.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import {constants} from 'node:os';
|
||||
import {signalsByName} from 'human-signals';
|
||||
|
||||
// Normalize signals for comparison purpose.
|
||||
// Also validate the signal exists.
|
||||
export const normalizeKillSignal = killSignal => {
|
||||
const optionName = 'option `killSignal`';
|
||||
if (killSignal === 0) {
|
||||
throw new TypeError(`Invalid ${optionName}: 0 cannot be used.`);
|
||||
}
|
||||
|
||||
return normalizeSignal(killSignal, optionName);
|
||||
};
|
||||
|
||||
export const normalizeSignalArgument = signal => signal === 0
|
||||
? signal
|
||||
: normalizeSignal(signal, '`subprocess.kill()`\'s argument');
|
||||
|
||||
const normalizeSignal = (signalNameOrInteger, optionName) => {
|
||||
if (Number.isInteger(signalNameOrInteger)) {
|
||||
return normalizeSignalInteger(signalNameOrInteger, optionName);
|
||||
}
|
||||
|
||||
if (typeof signalNameOrInteger === 'string') {
|
||||
return normalizeSignalName(signalNameOrInteger, optionName);
|
||||
}
|
||||
|
||||
throw new TypeError(`Invalid ${optionName} ${String(signalNameOrInteger)}: it must be a string or an integer.\n${getAvailableSignals()}`);
|
||||
};
|
||||
|
||||
const normalizeSignalInteger = (signalInteger, optionName) => {
|
||||
if (signalsIntegerToName.has(signalInteger)) {
|
||||
return signalsIntegerToName.get(signalInteger);
|
||||
}
|
||||
|
||||
throw new TypeError(`Invalid ${optionName} ${signalInteger}: this signal integer does not exist.\n${getAvailableSignals()}`);
|
||||
};
|
||||
|
||||
const getSignalsIntegerToName = () => new Map(Object.entries(constants.signals)
|
||||
.reverse()
|
||||
.map(([signalName, signalInteger]) => [signalInteger, signalName]));
|
||||
|
||||
const signalsIntegerToName = getSignalsIntegerToName();
|
||||
|
||||
const normalizeSignalName = (signalName, optionName) => {
|
||||
if (signalName in constants.signals) {
|
||||
return signalName;
|
||||
}
|
||||
|
||||
if (signalName.toUpperCase() in constants.signals) {
|
||||
throw new TypeError(`Invalid ${optionName} '${signalName}': please rename it to '${signalName.toUpperCase()}'.`);
|
||||
}
|
||||
|
||||
throw new TypeError(`Invalid ${optionName} '${signalName}': this signal name does not exist.\n${getAvailableSignals()}`);
|
||||
};
|
||||
|
||||
const getAvailableSignals = () => `Available signal names: ${getAvailableSignalNames()}.
|
||||
Available signal numbers: ${getAvailableSignalIntegers()}.`;
|
||||
|
||||
const getAvailableSignalNames = () => Object.keys(constants.signals)
|
||||
.sort()
|
||||
.map(signalName => `'${signalName}'`)
|
||||
.join(', ');
|
||||
|
||||
const getAvailableSignalIntegers = () => [...new Set(Object.values(constants.signals)
|
||||
.sort((signalInteger, signalIntegerTwo) => signalInteger - signalIntegerTwo))]
|
||||
.join(', ');
|
||||
|
||||
// Human-friendly description of a signal
|
||||
export const getSignalDescription = signal => signalsByName[signal].description;
|
||||
21
node_modules/execa/lib/terminate/timeout.js
generated
vendored
Normal file
21
node_modules/execa/lib/terminate/timeout.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import {setTimeout} from 'node:timers/promises';
|
||||
import {DiscardedError} from '../return/final-error.js';
|
||||
|
||||
// Validate `timeout` option
|
||||
export const validateTimeout = ({timeout}) => {
|
||||
if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
|
||||
throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
|
||||
}
|
||||
};
|
||||
|
||||
// Fails when the `timeout` option is exceeded
|
||||
export const throwOnTimeout = (subprocess, timeout, context, controller) => timeout === 0 || timeout === undefined
|
||||
? []
|
||||
: [killAfterTimeout(subprocess, timeout, context, controller)];
|
||||
|
||||
const killAfterTimeout = async (subprocess, timeout, context, {signal}) => {
|
||||
await setTimeout(timeout, undefined, {signal});
|
||||
context.terminationReason ??= 'timeout';
|
||||
subprocess.kill();
|
||||
throw new DiscardedError();
|
||||
};
|
||||
Reference in New Issue
Block a user