Skip to content
Myr

Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 195369f · Browse files · 6 files+50 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+50 added−50 removed

  • tests:+21 added−21 removed
  • other:+29 added−29 removed

6 files+50 added−50 removed

modified:lib/kill.js+14 added-14 removed
modified:test/kill.js+21 added-21 removed
8 unmodified lines
9setFixtureDir();1011const TIMEOUT_REGEXP = /timed out after/;1213const spawnNoKillable = async (forceKillAfterTimeout, options) => {13const spawnNoKillable = async (forceKillAfterDelay, options) => {14 const subprocess = execa('no-killable.js', {15 stdio: ['pipe', 'pipe', 'pipe', 'ipc'],16 forceKillAfterTimeout,16 forceKillAfterDelay,17 ...options,18 });19 await pEvent(subprocess, 'message');20 return {subprocess};
11 unmodified lines
3233// `SIGTERM` cannot be caught on Windows, and it always aborts the process (like `SIGKILL` on Unix).34// Therefore, this feature and those tests do not make sense on Windows.35if (process.platform !== 'win32') {36 const testNoForceKill = async (t, forceKillAfterTimeout, killArgument) => {37 const {subprocess} = await spawnNoKillable(forceKillAfterTimeout);36 const testNoForceKill = async (t, forceKillAfterDelay, killArgument) => {37 const {subprocess} = await spawnNoKillable(forceKillAfterDelay);3839 subprocess.kill(killArgument);4041 await setTimeout(6e3);
4 unmodified lines
46 t.true(isTerminated);47 t.is(signal, 'SIGKILL');48 };4950 test('`forceKillAfterTimeout: false` should not kill after a timeout', testNoForceKill, false);51 test('`forceKillAfterTimeout` should not kill after a timeout with other signals', testNoForceKill, true, 'SIGINT');50 test('`forceKillAfterDelay: false` should not kill after a timeout', testNoForceKill, false);51 test('`forceKillAfterDelay` should not kill after a timeout with other signals', testNoForceKill, true, 'SIGINT');5253 const testForceKill = async (t, forceKillAfterTimeout, killArgument) => {54 const {subprocess} = await spawnNoKillable(forceKillAfterTimeout);53 const testForceKill = async (t, forceKillAfterDelay, killArgument) => {54 const {subprocess} = await spawnNoKillable(forceKillAfterDelay);5556 subprocess.kill(killArgument);5758 const {isTerminated, signal} = await t.throwsAsync(subprocess);59 t.true(isTerminated);60 t.is(signal, 'SIGKILL');61 };6263 test('`forceKillAfterTimeout: number` should kill after a timeout', testForceKill, 50);64 test('`forceKillAfterTimeout: true` should kill after a timeout', testForceKill, true);65 test('`forceKillAfterTimeout: undefined` should kill after a timeout', testForceKill, undefined);66 test('`forceKillAfterTimeout` should kill after a timeout with the killSignal', testForceKill, 50, 'SIGTERM');63 test('`forceKillAfterDelay: number` should kill after a timeout', testForceKill, 50);64 test('`forceKillAfterDelay: true` should kill after a timeout', testForceKill, true);65 test('`forceKillAfterDelay: undefined` should kill after a timeout', testForceKill, undefined);66 test('`forceKillAfterDelay` should kill after a timeout with the killSignal', testForceKill, 50, 'SIGTERM');6768 const testInvalidForceKill = async (t, forceKillAfterTimeout) => {68 const testInvalidForceKill = async (t, forceKillAfterDelay) => {69 t.throws(() => {70 execa('empty.js', {forceKillAfterTimeout});70 execa('empty.js', {forceKillAfterDelay});71 }, {instanceOf: TypeError, message: /non-negative integer/});72 };7374 test('`forceKillAfterTimeout` should not be NaN', testInvalidForceKill, Number.NaN);75 test('`forceKillAfterTimeout` should not be negative', testInvalidForceKill, -1);74 test('`forceKillAfterDelay` should not be NaN', testInvalidForceKill, Number.NaN);75 test('`forceKillAfterDelay` should not be negative', testInvalidForceKill, -1);7677 test('`forceKillAfterTimeout` works with the "signal" option', async t => {77 test('`forceKillAfterDelay` works with the "signal" option', async t => {78 const abortController = new AbortController();79 const {subprocess} = await spawnNoKillable(1, {signal: abortController.signal});80 abortController.abort();81 const {isTerminated, signal, isCanceled} = await t.throwsAsync(subprocess);
1 unmodified line
83 t.is(signal, undefined);84 t.true(isCanceled);85 });8687 test.serial('`forceKillAfterTimeout` works with the "timeout" option', async t => {87 test.serial('`forceKillAfterDelay` works with the "timeout" option', async t => {88 const {subprocess} = await spawnNoKillable(1, {timeout: 2e3});89 const {isTerminated, signal, timedOut} = await t.throwsAsync(subprocess);90 t.true(isTerminated);91 t.is(signal, 'SIGTERM');92 t.true(timedOut);93 });9495 test('`forceKillAfterTimeout` works with the "maxBuffer" option', async t => {95 test('`forceKillAfterDelay` works with the "maxBuffer" option', async t => {96 const {subprocess} = await spawnNoKillable(1, {maxBuffer: 1});97 const {isTerminated, signal} = await t.throwsAsync(subprocess);98 t.false(isTerminated);99 t.is(signal, undefined);100 });101102 test('`forceKillAfterTimeout` works with "error" events on childProcess', async t => {102 test('`forceKillAfterDelay` works with "error" events on childProcess', async t => {103 const {subprocess} = await spawnNoKillable(1);104 subprocess.emit('error', new Error('test'));105 const {isTerminated, signal} = await t.throwsAsync(subprocess);106 t.false(isTerminated);107 t.is(signal, undefined);108 });109110 test('`forceKillAfterTimeout` works with "error" events on childProcess.stdout', async t => {110 test('`forceKillAfterDelay` works with "error" events on childProcess.stdout', async t => {111 const {subprocess} = await spawnNoKillable(1);112 subprocess.stdout.destroy(new Error('test'));113 const {isTerminated, signal} = await t.throwsAsync(subprocess);114 t.false(isTerminated);
193 unmodified lines
modified:index.d.ts+1 added-1 removed
484 unmodified lines
485 Also, this does not work on Windows, because Windows [doesn't support signals](https://nodejs.org/api/process.html#process_signal_events): `SIGKILL` and `SIGTERM` both terminate the process immediately. Other packages (such as [`taskkill`](https://github.com/sindresorhus/taskkill)) can be used to achieve fail-safe termination on Windows.486487 @default 5000488 */489 forceKillAfterTimeout?: number | false;489 forceKillAfterDelay?: number | false;490491 /**492 If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`.493
792 unmodified lines
modified:index.js+4 added-4 removed
8 unmodified lines
9import {makeError} from './lib/error.js';10import {handleInputAsync, pipeOutputAsync} from './lib/stdio/async.js';11import {handleInputSync, pipeOutputSync} from './lib/stdio/sync.js';12import {normalizeStdioNode} from './lib/stdio/normalize.js';13import {spawnedKill, validateTimeout, normalizeForceKillAfterTimeout} from './lib/kill.js';13import {spawnedKill, validateTimeout, normalizeForceKillAfterDelay} from './lib/kill.js';14import {addPipeMethods} from './lib/pipe.js';15import {getSpawnedResult, makeAllStream} from './lib/stream.js';16import {mergePromise} from './lib/promise.js';17import {joinCommand, parseCommand, parseTemplates, getEscapedCommand} from './lib/command.js';
34 unmodified lines
52 const options = addDefaultOptions(initialOptions);53 validateTimeout(options);54 options.shell = normalizeFileUrl(options.shell);55 options.env = getEnv(options);56 options.forceKillAfterTimeout = normalizeForceKillAfterTimeout(options.forceKillAfterTimeout);56 options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);5758 if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {59 // #11660 args.unshift('/q');
19 unmodified lines
80 all = false,81 windowsHide = true,82 verbose = verboseDefault,83 killSignal = 'SIGTERM',84 forceKillAfterTimeout = true,84 forceKillAfterDelay = true,85 ...options86}) => ({87 ...options,88 maxBuffer,
10 unmodified lines
99 all,100 windowsHide,101 verbose,102 killSignal,103 forceKillAfterTimeout,103 forceKillAfterDelay,104});105106const handleOutput = (options, value) => {107 if (value === undefined || value === null) {
236 unmodified lines
modified:index.test-d.ts+8 added-8 removed
1185 unmodified lines
1186execa('unicorns', {killSignal: 'SIGTERM'});1187execaSync('unicorns', {killSignal: 'SIGTERM'});1188execa('unicorns', {killSignal: 9});1189execaSync('unicorns', {killSignal: 9});1190execa('unicorns', {forceKillAfterTimeout: false});1191execaSync('unicorns', {forceKillAfterTimeout: false});1192execa('unicorns', {forceKillAfterTimeout: 42});1193execaSync('unicorns', {forceKillAfterTimeout: 42});1194execa('unicorns', {forceKillAfterTimeout: undefined});1195execaSync('unicorns', {forceKillAfterTimeout: undefined});1196expectError(execa('unicorns', {forceKillAfterTimeout: 'true'}));1197expectError(execaSync('unicorns', {forceKillAfterTimeout: 'true'}));1190execa('unicorns', {forceKillAfterDelay: false});1191execaSync('unicorns', {forceKillAfterDelay: false});1192execa('unicorns', {forceKillAfterDelay: 42});1193execaSync('unicorns', {forceKillAfterDelay: 42});1194execa('unicorns', {forceKillAfterDelay: undefined});1195execaSync('unicorns', {forceKillAfterDelay: undefined});1196expectError(execa('unicorns', {forceKillAfterDelay: 'true'}));1197expectError(execaSync('unicorns', {forceKillAfterDelay: 'true'}));1198execa('unicorns', {signal: new AbortController().signal});1199expectError(execaSync('unicorns', {signal: new AbortController().signal}));1200execa('unicorns', {windowsVerbatimArguments: true});1201execaSync('unicorns', {windowsVerbatimArguments: true});
112 unmodified lines
modified:readme.md+2 added-2 removed
48 unmodified lines
49- [Cleans up](#cleanup) child processes when the parent process ends.50- Redirect [`stdin`](#stdin)/[`stdout`](#stdout-1)/[`stderr`](#stderr-1) from/to files, streams, iterables, strings, `Uint8Array` or [objects](docs/transform.md#object-mode).51- [Transform](docs/transform.md) `stdin`/`stdout`/`stderr` with simple functions.52- Iterate over [each text line](docs/transform.md#binary-data) output by the process.53- [Fail-safe process termination](#forcekillaftertimeout).53- [Fail-safe process termination](#forcekillafterdelay).54- Get [interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal.55- [Strips the final newline](#stripfinalnewline) from the output so you don't have to do `stdout.trim()`.56- Convenience methods to pipe processes' [input](#input) and [output](#redirect-output-to-a-file).57- Can specify file and arguments [as a single string](#execacommandcommand-options) without a shell.
695 unmodified lines
753Default: `SIGTERM`754755Signal value to be used when the spawned process will be killed.756757#### forceKillAfterTimeout757#### forceKillAfterDelay758759Type: `number | false`\760Default: `5000`761
179 unmodified lines