Skip to content
Myr

Separate spawned.kill() features into own file (#312)

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

authored by ehmicky · committed by Sindre Sorhus · parent ec10a4c · Browse files · 4 files+338 added−313 removed
This commit

State

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

Diff stats

4 files+338 added−313 removed

  • tests:+245 added−234 removed
  • other:+93 added−79 removed

4 files+338 added−313 removed

added:lib/kill.js+92 added
1'use strict';2const os = require('os');3const onExit = require('signal-exit');45const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;67// Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior8const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => {9 const killResult = kill(signal);10 setKillTimeout(kill, signal, options, killResult);11 return killResult;12};1314const setKillTimeout = (kill, signal, options, killResult) => {15 if (!shouldForceKill(signal, options, killResult)) {16 return;17 }1819 const timeout = getForceKillAfterTimeout(options);20 setTimeout(() => {21 kill('SIGKILL');22 }, timeout).unref();23};2425const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {26 return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;27};2829const isSigterm = signal => {30 return signal === os.constants.signals.SIGTERM ||31 (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');32};3334const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {35 if (forceKillAfterTimeout === true) {36 return DEFAULT_FORCE_KILL_TIMEOUT;37 }3839 if (!Number.isInteger(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {40 throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);41 }4243 return forceKillAfterTimeout;44};4546// `childProcess.cancel()`47const spawnedCancel = (spawned, context) => {48 const killResult = spawned.kill();4950 if (killResult) {51 context.isCanceled = true;52 }53};5455// `timeout` option handling56const setupTimeout = (spawned, {timeout, killSignal}, context) => {57 if (timeout > 0) {58 return setTimeout(() => {59 context.timedOut = true;60 spawned.kill(killSignal);61 }, timeout);62 }63};6465// `cleanup` option handling66const setExitHandler = (spawned, {cleanup, detached}) => {67 if (!cleanup || detached) {68 return;69 }7071 return onExit(() => {72 spawned.kill();73 });74};7576const cleanup = (timeoutId, removeExitHandler) => {77 if (timeoutId !== undefined) {78 clearTimeout(timeoutId);79 }8081 if (removeExitHandler !== undefined) {82 removeExitHandler();83 }84};8586module.exports = {87 spawnedKill,88 spawnedCancel,89 setupTimeout,90 setExitHandler,91 cleanup92};
added:test/kill.js+243 added
1import path from 'path';2import test from 'ava';3import pEvent from 'p-event';4import isRunning from 'is-running';5import execa from '..';67process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;89const TIMEOUT_REGEXP = /timed out after/;1011test('kill("SIGKILL") should terminate cleanly', async t => {12 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});13 await pEvent(subprocess, 'message');1415 subprocess.kill('SIGKILL');1617 const {signal} = await t.throwsAsync(subprocess);18 t.is(signal, 'SIGKILL');19});2021// `SIGTERM` cannot be caught on Windows, and it always aborts the process (like `SIGKILL` on Unix).22// Therefore, this feature and those tests do not make sense on Windows.23if (process.platform !== 'win32') {24 test('`forceKillAfterTimeout: false` should not kill after a timeout', async t => {25 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});26 await pEvent(subprocess, 'message');2728 subprocess.kill('SIGTERM', {forceKillAfterTimeout: false});2930 t.true(isRunning(subprocess.pid));31 subprocess.kill('SIGKILL');32 });3334 test('`forceKillAfterTimeout: number` should kill after a timeout', async t => {35 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});36 await pEvent(subprocess, 'message');3738 subprocess.kill('SIGTERM', {forceKillAfterTimeout: 50});3940 const {signal} = await t.throwsAsync(subprocess);41 t.is(signal, 'SIGKILL');42 });4344 test('`forceKillAfterTimeout: true` should kill after a timeout', async t => {45 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});46 await pEvent(subprocess, 'message');4748 subprocess.kill('SIGTERM', {forceKillAfterTimeout: true});4950 const {signal} = await t.throwsAsync(subprocess);51 t.is(signal, 'SIGKILL');52 });5354 test('kill() with no arguments should kill after a timeout', async t => {55 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});56 await pEvent(subprocess, 'message');5758 subprocess.kill();5960 const {signal} = await t.throwsAsync(subprocess);61 t.is(signal, 'SIGKILL');62 });6364 test('`forceKillAfterTimeout` should not be a float', t => {65 t.throws(() => {66 execa('noop').kill('SIGTERM', {forceKillAfterTimeout: 0.5});67 }, {instanceOf: TypeError, message: /non-negative integer/});68 });6970 test('`forceKillAfterTimeout` should not be negative', t => {71 t.throws(() => {72 execa('noop').kill('SIGTERM', {forceKillAfterTimeout: -1});73 }, {instanceOf: TypeError, message: /non-negative integer/});74 });75}7677test('execa() returns a promise with kill()', t => {78 const {kill} = execa('noop', ['foo']);79 t.is(typeof kill, 'function');80});8182test('timeout kills the process if it times out', async t => {83 const {killed, timedOut} = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));84 t.false(killed);85 t.true(timedOut);86});8788test('timeout kills the process if it times out, in sync mode', async t => {89 const {killed, timedOut} = await t.throws(() => {90 execa.sync('forever', {timeout: 1, message: TIMEOUT_REGEXP});91 });92 t.false(killed);93 t.true(timedOut);94});9596test('timeout does not kill the process if it does not time out', async t => {97 const {timedOut} = await execa('delay', ['500'], {timeout: 1e8});98 t.false(timedOut);99});100101test('timedOut is false if no timeout was set', async t => {102 const {timedOut} = await execa('noop');103 t.false(timedOut);104});105106test('timedOut will be false if no timeout was set and zero exit code in sync mode', t => {107 const {timedOut} = execa.sync('noop');108 t.false(timedOut);109});110111// When child process exits before parent process112const spawnAndExit = async (t, cleanup, detached) => {113 await t.notThrowsAsync(execa('sub-process-exit', [cleanup, detached]));114};115116test('spawnAndExit', spawnAndExit, false, false);117test('spawnAndExit cleanup', spawnAndExit, true, false);118test('spawnAndExit detached', spawnAndExit, false, true);119test('spawnAndExit cleanup detached', spawnAndExit, true, true);120121// When parent process exits before child process122const spawnAndKill = async (t, signal, cleanup, detached, isKilled) => {123 const subprocess = execa('sub-process', [cleanup, detached], {stdio: ['ignore', 'ignore', 'ignore', 'ipc']});124125 const pid = await pEvent(subprocess, 'message');126 t.true(Number.isInteger(pid));127 t.true(isRunning(pid));128129 process.kill(subprocess.pid, signal);130131 await t.throwsAsync(subprocess);132133 t.false(isRunning(subprocess.pid));134 t.is(isRunning(pid), !isKilled);135136 if (!isKilled) {137 process.kill(pid, 'SIGKILL');138 }139};140141// Without `options.cleanup`:142// - on Windows subprocesses are killed if `options.detached: false`, but not143// if `options.detached: true`144// - on Linux subprocesses are never killed regardless of `options.detached`145// With `options.cleanup`, subprocesses are always killed146// - `options.cleanup` with SIGKILL is a noop, since it cannot be handled147const exitIfWindows = process.platform === 'win32';148test('spawnAndKill SIGTERM', spawnAndKill, 'SIGTERM', false, false, exitIfWindows);149test('spawnAndKill SIGKILL', spawnAndKill, 'SIGKILL', false, false, exitIfWindows);150test('spawnAndKill cleanup SIGTERM', spawnAndKill, 'SIGTERM', true, false, true);151test('spawnAndKill cleanup SIGKILL', spawnAndKill, 'SIGKILL', true, false, exitIfWindows);152test('spawnAndKill detached SIGTERM', spawnAndKill, 'SIGTERM', false, true, false);153test('spawnAndKill detached SIGKILL', spawnAndKill, 'SIGKILL', false, true, false);154test('spawnAndKill cleanup detached SIGTERM', spawnAndKill, 'SIGTERM', true, true, false);155test('spawnAndKill cleanup detached SIGKILL', spawnAndKill, 'SIGKILL', true, true, false);156157// See #128158test('removes exit handler on exit', async t => {159 // FIXME: This relies on `signal-exit` internals160 const ee = process.__signal_exit_emitter__;161162 const child = execa('noop');163 const listener = ee.listeners('exit').pop();164165 await new Promise((resolve, reject) => {166 child.on('error', reject);167 child.on('exit', resolve);168 });169170 const included = ee.listeners('exit').includes(listener);171 t.false(included);172});173174test('cancel method kills the subprocess', t => {175 const subprocess = execa('node');176 subprocess.cancel();177 t.true(subprocess.killed);178});179180test('result.isCanceled is false when spawned.cancel() isn\'t called (success)', async t => {181 const {isCanceled} = await execa('noop');182 t.false(isCanceled);183});184185test('result.isCanceled is false when spawned.cancel() isn\'t called (failure)', async t => {186 const {isCanceled} = await t.throwsAsync(execa('fail'));187 t.false(isCanceled);188});189190test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (success)', t => {191 const {isCanceled} = execa.sync('noop');192 t.false(isCanceled);193});194195test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)', t => {196 const {isCanceled} = t.throws(() => {197 execa.sync('fail');198 });199 t.false(isCanceled);200});201202test('calling cancel method throws an error with message "Command was canceled"', async t => {203 const subprocess = execa('noop');204 subprocess.cancel();205 await t.throwsAsync(subprocess, {message: /Command was canceled/});206});207208test('error.isCanceled is true when cancel method is used', async t => {209 const subprocess = execa('noop');210 subprocess.cancel();211 const {isCanceled} = await t.throwsAsync(subprocess);212 t.true(isCanceled);213});214215test('error.isCanceled is false when kill method is used', async t => {216 const subprocess = execa('noop');217 subprocess.kill();218 const {isCanceled} = await t.throwsAsync(subprocess);219 t.false(isCanceled);220});221222test('calling cancel method twice should show the same behaviour as calling it once', async t => {223 const subprocess = execa('noop');224 subprocess.cancel();225 subprocess.cancel();226 const {isCanceled} = await t.throwsAsync(subprocess);227 t.true(isCanceled);228 t.true(subprocess.killed);229});230231test('calling cancel method on a successfully completed process does not make result.isCanceled true', async t => {232 const subprocess = execa('noop');233 const {isCanceled} = await subprocess;234 subprocess.cancel();235 t.false(isCanceled);236});237238test('calling cancel method on a process which has been killed does not make error.isCanceled true', async t => {239 const subprocess = execa('noop');240 subprocess.kill();241 const {isCanceled} = await t.throwsAsync(subprocess);242 t.false(isCanceled);243});
modified:test/test.js+2 added-234 removed
3 unmodified lines
4import test from 'ava';5import getStream from 'get-stream';6import isRunning from 'is-running';7import tempfile from 'tempfile';8import pEvent from 'p-event';8import execa from '..';910process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;11process.env.FOO = 'foo';1214const TIMEOUT_REGEXP = /timed out after/;13const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;1415test('execa()', async t => {16 const {stdout} = await execa('noop', ['foo']);
69 unmodified lines
86 const {exitCode} = execa.sync('fail', {reject: false});87 t.is(exitCode, 2);88});8992test('kill("SIGKILL") should terminate cleanly', async t => {93 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});94 await pEvent(subprocess, 'message');9596 subprocess.kill('SIGKILL');9798 const {signal} = await t.throwsAsync(subprocess);99 t.is(signal, 'SIGKILL');100});101102// `SIGTERM` cannot be caught on Windows, and it always aborts the process (like `SIGKILL` on Unix).103// Therefore, this feature and those tests do not make sense on Windows.104if (process.platform !== 'win32') {105 test('`forceKillAfterTimeout: false` should not kill after a timeout', async t => {106 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});107 await pEvent(subprocess, 'message');108109 subprocess.kill('SIGTERM', {forceKillAfterTimeout: false});110111 t.true(isRunning(subprocess.pid));112 subprocess.kill('SIGKILL');113 });114115 test('`forceKillAfterTimeout: number` should kill after a timeout', async t => {116 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});117 await pEvent(subprocess, 'message');118119 subprocess.kill('SIGTERM', {forceKillAfterTimeout: 50});120121 const {signal} = await t.throwsAsync(subprocess);122 t.is(signal, 'SIGKILL');123 });124125 test('`forceKillAfterTimeout: true` should kill after a timeout', async t => {126 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});127 await pEvent(subprocess, 'message');128129 subprocess.kill('SIGTERM', {forceKillAfterTimeout: true});130131 const {signal} = await t.throwsAsync(subprocess);132 t.is(signal, 'SIGKILL');133 });134135 test('kill() with no arguments should kill after a timeout', async t => {136 const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']});137 await pEvent(subprocess, 'message');138139 subprocess.kill();140141 const {signal} = await t.throwsAsync(subprocess);142 t.is(signal, 'SIGKILL');143 });144145 test('`forceKillAfterTimeout` should not be a float', t => {146 t.throws(() => {147 execa('noop').kill('SIGTERM', {forceKillAfterTimeout: 0.5});148 }, {instanceOf: TypeError, message: /non-negative integer/});149 });150151 test('`forceKillAfterTimeout` should not be negative', t => {152 t.throws(() => {153 execa('noop').kill('SIGTERM', {forceKillAfterTimeout: -1});154 }, {instanceOf: TypeError, message: /non-negative integer/});155 });156}15790test('stripFinalNewline: true', async t => {91 const {stdout} = await execa('noop', ['foo']);92 t.is(stdout, 'foo');93});
109 unmodified lines
203 child.emit('error', new Error('test'));204 await t.throwsAsync(child, /test/);205});206275test('execa() returns a promise with kill() and pid', t => {276 const {kill, pid} = execa('noop', ['foo']);277 t.is(typeof kill, 'function');207test('execa() returns a promise with pid', t => {208 const {pid} = execa('noop', ['foo']);209 t.is(typeof pid, 'number');210});211212test('child_process.spawn() propagated errors have correct shape', t => {
71 unmodified lines
284 await t.throwsAsync(execa('non-executable', {input: 'Hey!'}), /EACCES/);285 });286}287357test('timeout kills the process if it times out', async t => {358 const {killed, timedOut} = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));359 t.false(killed);360 t.true(timedOut);361});362363test('timeout kills the process if it times out, in sync mode', async t => {364 const {killed, timedOut} = await t.throws(() => {365 execa.sync('forever', {timeout: 1, message: TIMEOUT_REGEXP});366 });367 t.false(killed);368 t.true(timedOut);369});370371test('timeout does not kill the process if it does not time out', async t => {372 const {timedOut} = await execa('delay', ['500'], {timeout: 1e8});373 t.false(timedOut);374});375376test('timedOut is false if no timeout was set', async t => {377 const {timedOut} = await execa('noop');378 t.false(timedOut);379});380381test('timedOut will be false if no timeout was set and zero exit code in sync mode', t => {382 const {timedOut} = execa.sync('noop');383 t.false(timedOut);384});385288const command = async (t, expected, ...args) => {289 const {command: failCommand} = await t.throwsAsync(execa('fail', args));290 t.is(failCommand, `fail${expected}`);291
6 unmodified lines
298test(command, ' foo bar', 'foo', 'bar');299test(command, ' baz quz', 'baz', 'quz');300test(command, '');301400// When child process exits before parent process401const spawnAndExit = async (t, cleanup, detached) => {402 await t.notThrowsAsync(execa('sub-process-exit', [cleanup, detached]));403};404405test('spawnAndExit', spawnAndExit, false, false);406test('spawnAndExit cleanup', spawnAndExit, true, false);407test('spawnAndExit detached', spawnAndExit, false, true);408test('spawnAndExit cleanup detached', spawnAndExit, true, true);409410// When parent process exits before child process411const spawnAndKill = async (t, signal, cleanup, detached, isKilled) => {412 const subprocess = execa('sub-process', [cleanup, detached], {stdio: ['ignore', 'ignore', 'ignore', 'ipc']});413414 const pid = await pEvent(subprocess, 'message');415 t.true(Number.isInteger(pid));416 t.true(isRunning(pid));417418 process.kill(subprocess.pid, signal);419420 await t.throwsAsync(subprocess);421422 t.false(isRunning(subprocess.pid));423 t.is(isRunning(pid), !isKilled);424425 if (!isKilled) {426 process.kill(pid, 'SIGKILL');427 }428};429430// Without `options.cleanup`:431// - on Windows subprocesses are killed if `options.detached: false`, but not432// if `options.detached: true`433// - on Linux subprocesses are never killed regardless of `options.detached`434// With `options.cleanup`, subprocesses are always killed435// - `options.cleanup` with SIGKILL is a noop, since it cannot be handled436const exitIfWindows = process.platform === 'win32';437test('spawnAndKill SIGTERM', spawnAndKill, 'SIGTERM', false, false, exitIfWindows);438test('spawnAndKill SIGKILL', spawnAndKill, 'SIGKILL', false, false, exitIfWindows);439test('spawnAndKill cleanup SIGTERM', spawnAndKill, 'SIGTERM', true, false, true);440test('spawnAndKill cleanup SIGKILL', spawnAndKill, 'SIGKILL', true, false, exitIfWindows);441test('spawnAndKill detached SIGTERM', spawnAndKill, 'SIGTERM', false, true, false);442test('spawnAndKill detached SIGKILL', spawnAndKill, 'SIGKILL', false, true, false);443test('spawnAndKill cleanup detached SIGTERM', spawnAndKill, 'SIGTERM', true, true, false);444test('spawnAndKill cleanup detached SIGKILL', spawnAndKill, 'SIGKILL', true, true, false);445302if (process.platform !== 'win32') {303 test('write to fast-exit process', async t => {304 // Try-catch here is necessary, because this test is not 100% accurate305 // Sometimes process can manage to accept input before exiting
54 unmodified lines
360361 process.kill(pid, 'SIGKILL');362});363508// See #128509test('removes exit handler on exit', async t => {510 // FIXME: This relies on `signal-exit` internals511 const ee = process.__signal_exit_emitter__;512513 const child = execa('noop');514 const listener = ee.listeners('exit').pop();515516 await new Promise((resolve, reject) => {517 child.on('error', reject);518 child.on('exit', resolve);519 });520521 const included = ee.listeners('exit').includes(listener);522 t.false(included);523});524364test('promise methods are not enumerable', t => {365 const descriptors = Object.getOwnPropertyDescriptors(execa('noop'));366 // eslint-disable-next-line promise/prefer-await-to-then367 t.false(descriptors.then.enumerable);
39 unmodified lines
407 t.is(message, 'called');408 });409}410572test('cancel method kills the subprocess', t => {573 const subprocess = execa('node');574 subprocess.cancel();575 t.true(subprocess.killed);576});577578test('result.isCanceled is false when spawned.cancel() isn\'t called (success)', async t => {579 const {isCanceled} = await execa('noop');580 t.false(isCanceled);581});582583test('result.isCanceled is false when spawned.cancel() isn\'t called (failure)', async t => {584 const {isCanceled} = await t.throwsAsync(execa('fail'));585 t.false(isCanceled);586});587588test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (success)', t => {589 const {isCanceled} = execa.sync('noop');590 t.false(isCanceled);591});592593test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)', t => {594 const {isCanceled} = t.throws(() => {595 execa.sync('fail');596 });597 t.false(isCanceled);598});599600test('calling cancel method throws an error with message "Command was canceled"', async t => {601 const subprocess = execa('noop');602 subprocess.cancel();603 await t.throwsAsync(subprocess, {message: /Command was canceled/});604});605606test('error.isCanceled is true when cancel method is used', async t => {607 const subprocess = execa('noop');608 subprocess.cancel();609 const {isCanceled} = await t.throwsAsync(subprocess);610 t.true(isCanceled);611});612613test('error.isCanceled is false when kill method is used', async t => {614 const subprocess = execa('noop');615 subprocess.kill();616 const {isCanceled} = await t.throwsAsync(subprocess);617 t.false(isCanceled);618});619620test('calling cancel method twice should show the same behaviour as calling it once', async t => {621 const subprocess = execa('noop');622 subprocess.cancel();623 subprocess.cancel();624 const {isCanceled} = await t.throwsAsync(subprocess);625 t.true(isCanceled);626 t.true(subprocess.killed);627});628629test('calling cancel method on a successfully completed process does not make result.isCanceled true', async t => {630 const subprocess = execa('noop');631 const {isCanceled} = await subprocess;632 subprocess.cancel();633 t.false(isCanceled);634});635636test('calling cancel method on a process which has been killed does not make error.isCanceled true', async t => {637 const subprocess = execa('noop');638 subprocess.kill();639 const {isCanceled} = await t.throwsAsync(subprocess);640 t.false(isCanceled);641});642411test('allow commands with spaces and no array arguments', async t => {412 const {stdout} = await execa('command with space');413 t.is(stdout, '');414});
40 unmodified lines
modified:index.js+1 added-79 removed
1'use strict';2const path = require('path');3const os = require('os');3const childProcess = require('child_process');4const crossSpawn = require('cross-spawn');5const stripFinalNewline = require('strip-final-newline');6const npmRunPath = require('npm-run-path');7const isStream = require('is-stream');8const getStream = require('get-stream');9const mergeStream = require('merge-stream');10const pFinally = require('p-finally');12const onExit = require('signal-exit');11const makeError = require('./lib/error');12const normalizeStdio = require('./lib/stdio');13const {spawnedKill, spawnedCancel, setupTimeout, setExitHandler, cleanup} = require('./lib/kill');1415const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;17const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;1617const SPACES_REGEXP = / +/g;1819const handleArgs = (file, args, options = {}) => {
167 unmodified lines
187188 return spawned;189};190193const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => {194 const killResult = kill(signal);195 setKillTimeout(kill, signal, options, killResult);196 return killResult;197};198199const setKillTimeout = (kill, signal, options, killResult) => {200 if (!shouldForceKill(signal, options, killResult)) {201 return;202 }203204 const timeout = getForceKillAfterTimeout(options);205 setTimeout(() => {206 kill('SIGKILL');207 }, timeout).unref();208};209210const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {211 return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;212};213214const isSigterm = signal => {215 return signal === os.constants.signals.SIGTERM ||216 (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');217};218219const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {220 if (forceKillAfterTimeout === true) {221 return DEFAULT_FORCE_KILL_TIMEOUT;222 }223224 if (!Number.isInteger(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {225 throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);226 }227228 return forceKillAfterTimeout;229};230231const spawnedCancel = (spawned, context) => {232 const killResult = spawned.kill();233234 if (killResult) {235 context.isCanceled = true;236 }237};238191const handleSpawned = (spawned, context) => {192 return new Promise((resolve, reject) => {193 spawned.on('exit', (code, signal) => {194 if (context.timedOut) {
15 unmodified lines
210 }211 });212};213262const setupTimeout = (spawned, {timeout, killSignal}, context) => {263 if (timeout > 0) {264 return setTimeout(() => {265 context.timedOut = true;266 spawned.kill(killSignal);267 }, timeout);268 }269};270271// #115272const setExitHandler = (spawned, {cleanup, detached}) => {273 if (!cleanup || detached) {274 return;275 }276277 return onExit(() => {278 spawned.kill();279 });280};281282const cleanup = (timeoutId, removeExitHandler) => {283 if (timeoutId !== undefined) {284 clearTimeout(timeoutId);285 }286287 if (removeExitHandler !== undefined) {288 removeExitHandler();289 }290};291214const execa = (file, args, options) => {215 const parsed = handleArgs(file, args, options);216 const command = joinCommand(file, args);217
198 unmodified lines