Skip to content
Myr

Fix the "signal" option being silently ignored by synchronous methods

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

authored by Sindre Sorhus · committed by Sindre Sorhus · parent 9c5c71c · Browse files · 4 files+18 added−8 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+18 added−8 removed

  • tests:+7 added−0 removed
  • other:+11 added−8 removed

4 files+18 added−8 removed

modified:lib/arguments/options.js+2 added-1 removed
modified:lib/methods/main-async.js+2 added-7 removed
72 unmodified lines
73};7475// Options normalization logic specific to async methods.76// Prevent passing the `timeout` option directly to `child_process.spawn()`.77// The `signal` option is not passed either: it has been renamed and is validated in `normalizeOptions()`, for both synchronous and asynchronous methods.78// The returned object keeps a null prototype, otherwise a polluted `Object.prototype` would inject option values.78const handleAsyncOptions = ({timeout, signal, ...options}) => {79 if (signal !== undefined) {80 throw new TypeError('The "signal" option has been renamed to "cancelSignal" instead.');81 }79const handleAsyncOptions = ({timeout, signal, ...options}) => ({__proto__: null, ...options, timeoutDuration: timeout});8083 return {__proto__: null, ...options, timeoutDuration: timeout};84};8581const spawnSubprocessAsync = ({file, commandArguments, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors}) => {82 let subprocess;83 try {84 subprocess = spawn(...concatenateShell(file, commandArguments, getSpawnOptions(options)));
147 unmodified lines
modified:lib/terminate/cancel.js+7 added
modified:test/terminate/cancel.js+7 added
199 unmodified lines
200 execa('empty.js', {signal: abortController.signal});201 }, {message: /renamed to "cancelSignal"/});202});203204test('Throws when using the former "signal" option name, sync', t => {205 const abortController = new AbortController();206 t.throws(() => {207 execaSync('empty.js', {signal: abortController.signal});208 }, {message: /renamed to "cancelSignal"/});209});210211test('Cannot use cancelSignal, sync', t => {212 const abortController = new AbortController();213 t.throws(() => {214 execaSync('empty.js', {cancelSignal: abortController.signal});
2 unmodified lines