diff --git a/index.d.ts b/index.d.ts index fbf199aa8..9da7d16ea 100644 --- a/index.d.ts +++ b/index.d.ts @@ -334,7 +334,7 @@ declare namespace execa { interface ExecaSyncError extends Error, - ExecaReturnBase { + ExecaReturnBase { /** Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored. @@ -384,6 +384,15 @@ declare namespace execa { } interface ExecaChildPromise { + /** + Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr). + + This is `undefined` if either: + - the `all` option is `false` (the default value) + - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio) + */ + all?: ReadableStream; + catch( onRejected?: (reason: ExecaError) => ResultType | PromiseLike ): Promise | ResultType>; @@ -391,26 +400,17 @@ declare namespace execa { /** Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal), except if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`. */ - kill(signal?: string, options?: execa.KillOptions): void; + kill(signal?: string, options?: KillOptions): void; /** Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This is preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. */ cancel(): void; - - /** - Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr). - - This is `undefined` if either: - - the `all` option is `false` (the default value) - - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio) - */ - all?: ReadableStream; } type ExecaChildProcess = ChildProcess & - ExecaChildPromise & - Promise>; + ExecaChildPromise & + Promise>; } declare const execa: { @@ -432,7 +432,6 @@ declare const execa: { console.log(stdout); //=> 'unicorns' - // Cancelling a spawned process const subprocess = execa('node'); @@ -465,7 +464,7 @@ declare const execa: { ): execa.ExecaChildProcess; (file: string, options?: execa.Options): execa.ExecaChildProcess; (file: string, options?: execa.Options): execa.ExecaChildProcess< - Buffer + Buffer >; /** diff --git a/index.test-d.ts b/index.test-d.ts index 450cd40ff..edce1e13b 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType, expectError} from 'tsd'; -import {Readable as ReadableStream} from 'stream' +import {Readable as ReadableStream} from 'stream'; import execa = require('.'); import { ExecaReturnValue, @@ -12,7 +12,7 @@ import { try { const execaPromise = execa('unicorns'); execaPromise.cancel(); - expectType(execaPromise.all) + expectType(execaPromise.all); const unicornsResult = await execaPromise; expectType(unicornsResult.command); @@ -26,7 +26,7 @@ try { expectType(unicornsResult.killed); expectType(unicornsResult.signal); expectType(unicornsResult.signalDescription); -} catch (error) { +} catch (error) { // eslint-disable-line @typescript-eslint/no-implicit-any-catch const execaError: ExecaError = error; expectType(execaError.message); @@ -57,7 +57,7 @@ try { expectType(unicornsResult.killed); expectType(unicornsResult.signal); expectType(unicornsResult.signalDescription); -} catch (error) { +} catch (error) { // eslint-disable-line @typescript-eslint/no-implicit-any-catch const execaError: ExecaSyncError = error; expectType(execaError.message); diff --git a/lib/stdio.js b/lib/stdio.js index 6344d24fc..45129ed7e 100644 --- a/lib/stdio.js +++ b/lib/stdio.js @@ -1,20 +1,20 @@ 'use strict'; const aliases = ['stdin', 'stdout', 'stderr']; -const hasAlias = opts => aliases.some(alias => opts[alias] !== undefined); +const hasAlias = options => aliases.some(alias => options[alias] !== undefined); -const normalizeStdio = opts => { - if (!opts) { +const normalizeStdio = options => { + if (!options) { return; } - const {stdio} = opts; + const {stdio} = options; if (stdio === undefined) { - return aliases.map(alias => opts[alias]); + return aliases.map(alias => options[alias]); } - if (hasAlias(opts)) { + if (hasAlias(options)) { throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`); } @@ -33,8 +33,8 @@ const normalizeStdio = opts => { module.exports = normalizeStdio; // `ipc` is pushed unless it is already present -module.exports.node = opts => { - const stdio = normalizeStdio(opts); +module.exports.node = options => { + const stdio = normalizeStdio(options); if (stdio === 'ipc') { return 'ipc'; diff --git a/package.json b/package.json index 3bf402252..5d71f9ffa 100644 --- a/package.json +++ b/package.json @@ -39,27 +39,27 @@ "local" ], "dependencies": { - "cross-spawn": "^7.0.0", - "get-stream": "^5.0.0", - "human-signals": "^1.1.1", + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", "is-stream": "^2.0.0", "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.0", - "onetime": "^5.1.0", - "signal-exit": "^3.0.2", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", "strip-final-newline": "^2.0.0" }, "devDependencies": { - "@types/node": "^12.12.18", - "ava": "^2.1.0", - "coveralls": "^3.0.9", - "get-node": "^6.6.0", + "@types/node": "^14.14.10", + "ava": "^2.4.0", + "coveralls": "^3.1.0", + "get-node": "^11.0.1", "is-running": "^2.1.0", - "nyc": "^14.1.1", - "p-event": "^4.1.0", + "nyc": "^15.1.0", + "p-event": "^4.2.0", "tempfile": "^3.0.0", - "tsd": "^0.11.0", - "xo": "^0.25.3" + "tsd": "^0.13.1", + "xo": "^0.35.0" }, "nyc": { "exclude": [ diff --git a/test/error.js b/test/error.js index 5c2013603..c375bc076 100644 --- a/test/error.js +++ b/test/error.js @@ -41,9 +41,9 @@ test('exitCode is 0 on success', async t => { t.is(exitCode, 0); }); -const testExitCode = async (t, num) => { - const {exitCode} = await t.throwsAsync(execa('exit', [`${num}`]), {message: getExitRegExp(num)}); - t.is(exitCode, num); +const testExitCode = async (t, number) => { + const {exitCode} = await t.throwsAsync(execa('exit', [`${number}`]), {message: getExitRegExp(number)}); + t.is(exitCode, number); }; test('exitCode is 2', testExitCode, 2); diff --git a/test/kill.js b/test/kill.js index 6ca54a4a5..00c9bf7d5 100644 --- a/test/kill.js +++ b/test/kill.js @@ -63,7 +63,7 @@ if (process.platform !== 'win32') { test('`forceKillAfterTimeout` should not be NaN', t => { t.throws(() => { - execa('noop').kill('SIGTERM', {forceKillAfterTimeout: NaN}); + execa('noop').kill('SIGTERM', {forceKillAfterTimeout: Number.NaN}); }, {instanceOf: TypeError, message: /non-negative integer/}); }); diff --git a/test/stdio.js b/test/stdio.js index a7003f9fb..3f849e78b 100644 --- a/test/stdio.js +++ b/test/stdio.js @@ -1,4 +1,4 @@ -import util from 'util'; +import {inspect} from 'util'; import test from 'ava'; import normalizeStdio from '../lib/stdio'; @@ -13,7 +13,7 @@ const macro = (t, input, expected, func) => { t.deepEqual(func(input), expected); }; -const macroTitle = name => (title, input) => `${name} ${(util.inspect(input))}`; +const macroTitle = name => (title, input) => `${name} ${(inspect(input))}`; const stdioMacro = (...args) => macro(...args, normalizeStdio); stdioMacro.title = macroTitle('execa()');