From 5702a3378adedba0c8b305eff743798fcedb5c34 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sat, 10 Mar 2018 12:31:28 -0500 Subject: [PATCH 1/3] execa: options are not required to be mutable --- types/execa/execa-tests.ts | 89 +++++++++++++++++++------------------- types/execa/index.d.ts | 45 +++++++++++++++---- 2 files changed, 82 insertions(+), 52 deletions(-) diff --git a/types/execa/execa-tests.ts b/types/execa/execa-tests.ts index 2525091f2a..ecc966d3d5 100644 --- a/types/execa/execa-tests.ts +++ b/types/execa/execa-tests.ts @@ -1,46 +1,38 @@ import assert = require('assert'); import execa = require('execa'); -import { PassThrough } from "stream"; +import { PassThrough } from 'stream'; -execa('unicorns') - .then(result => { - assert(result.cmd === 'unicorns'); - assert(result.code === 0); - assert(result.failed === false); - assert(result.killed === false); - assert(result.signal === null); - assert(result.stderr === 'bad unicorns'); - assert(result.stdout === 'good unicorns'); - assert(result.timedOut === false); - }); +execa('unicorns').then(result => { + assert(result.cmd === 'unicorns'); + assert(result.code === 0); + assert(result.failed === false); + assert(result.killed === false); + assert(result.signal === null); + assert(result.stderr === 'bad unicorns'); + assert(result.stdout === 'good unicorns'); + assert(result.timedOut === false); +}); -execa('foo') - .catch(error => { - assert(error.cmd === 'foo'); - assert(error.code === 128); - assert(error.failed === true); - assert(error.killed === false); - assert(error.signal === 'SIGINT'); - assert(error.stderr === 'stderr'); - assert(error.stdout === 'stdout'); - assert(error.timedOut === false); - }); +execa('foo').catch(error => { + assert(error.cmd === 'foo'); + assert(error.code === 128); + assert(error.failed === true); + assert(error.killed === false); + assert(error.signal === 'SIGINT'); + assert(error.stderr === 'stderr'); + assert(error.stdout === 'stdout'); + assert(error.timedOut === false); +}); -execa('noop', ['foo']) - .then(result => result.stderr.toLocaleLowerCase()); +execa('noop', ['foo']).then(result => result.stderr.toLocaleLowerCase()); -execa.stdout('unicorns') - .then(stdout => stdout.toLocaleLowerCase()); -execa.stdout('echo', ['unicorns']) - .then(stdout => stdout.toLocaleLowerCase()); +execa.stdout('unicorns').then(stdout => stdout.toLocaleLowerCase()); +execa.stdout('echo', ['unicorns']).then(stdout => stdout.toLocaleLowerCase()); -execa.stderr('unicorns') - .then(stderr => stderr.toLocaleLowerCase()); -execa.stderr('echo', ['unicorns']) - .then(stderr => stderr.toLocaleLowerCase()); +execa.stderr('unicorns').then(stderr => stderr.toLocaleLowerCase()); +execa.stderr('echo', ['unicorns']).then(stderr => stderr.toLocaleLowerCase()); -execa.shell('echo unicorns') - .then(result => result.stdout.toLocaleLowerCase()); +execa.shell('echo unicorns').then(result => result.stdout.toLocaleLowerCase()); { let result: string; @@ -54,14 +46,14 @@ execa.shell('echo unicorns') execa('echo', ['unicorns']).stdout.pipe(process.stdout); execa('echo', ['unicorns']).stderr.pipe(process.stderr); -execa('forever', {extendEnv: false}).pid; -execa('forever', {argv0: 'hi'}).pid; -execa('forever', {localDir: '~'}).pid; -execa('forever', {reject: false}).pid; -execa('forever', {cleanup: false}).pid; -execa('forever', {stdin: 1}).pid; -execa('forever', {stdout: 'ignore'}).pid; -execa('forever', {stderr: undefined}).pid; +execa('forever', { extendEnv: false }).pid; +execa('forever', { argv0: 'hi' }).pid; +execa('forever', { localDir: '~' }).pid; +execa('forever', { reject: false }).pid; +execa('forever', { cleanup: false }).pid; +execa('forever', { stdin: 1 }).pid; +execa('forever', { stdout: 'ignore' }).pid; +execa('forever', { stderr: undefined }).pid; async () => { const { stdout } = await execa('noop', ['foo'], { stripEof: false }); @@ -119,7 +111,9 @@ async () => { } async () => { - const { timedOut, code } = await execa('delay', ['3000', '22'], { timeout: 9000 }); + const { timedOut, code } = await execa('delay', ['3000', '22'], { + timeout: 9000 + }); assert(timedOut === true); assert(code === 22); }; @@ -131,3 +125,10 @@ async () => { assert(stdout === 'foo'); }; + +const args: ReadonlyArray = ['bar']; +const stdio: ReadonlyArray<'ignore'> = ['ignore']; +execa('foo', args); +execa('foo', args, { + stdio +}); diff --git a/types/execa/index.d.ts b/types/execa/index.d.ts index c3aced26ee..f771105736 100644 --- a/types/execa/index.d.ts +++ b/types/execa/index.d.ts @@ -23,7 +23,11 @@ declare namespace execa { * Think of this as a mix of `child_process.execFile` and `child_process.spawn`. * @returns a `child_process` instance which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. */ - (file: string, args?: string[], options?: Options): ExecaChildProcess; + ( + file: string, + args?: ReadonlyArray, + options?: Options + ): ExecaChildProcess; (file: string, options?: Options): ExecaChildProcess; /** @@ -32,7 +36,11 @@ declare namespace execa { * Think of this as a mix of `child_process.execFile` and `child_process.spawn`. * @returns a `child_process` instance which is enhanced to also be a `Promise` for `stdout`. */ - stdout(file: string, args?: string[], options?: Options): Promise; + stdout( + file: string, + args?: ReadonlyArray, + options?: Options + ): Promise; stdout(file: string, options?: Options): Promise; /** @@ -41,7 +49,11 @@ declare namespace execa { * Think of this as a mix of `child_process.execFile` and `child_process.spawn`. * @returns a `child_process` instance which is enhanced to also be a `Promise` for `stderr`. */ - stderr(file: string, args?: string[], options?: Options): Promise; + stderr( + file: string, + args?: ReadonlyArray, + options?: Options + ): Promise; stderr(file: string, options?: Options): Promise; /** @@ -59,7 +71,11 @@ declare namespace execa { * @returns the same result object as `child_process.spawnSync`. * @throws an `Error` if the command fails. */ - sync(file: string, args?: string[], options?: SyncOptions): ExecaReturns; + sync( + file: string, + args?: ReadonlyArray, + options?: SyncOptions + ): ExecaReturns; sync(file: string, options?: SyncOptions): ExecaReturns; /** @@ -71,7 +87,14 @@ declare namespace execa { shellSync(command: string, options?: Options): ExecaReturns; } - type StdIOOption = 'pipe' | 'ipc' | 'ignore' | Stream | number | null | undefined; + type StdIOOption = + | 'pipe' + | 'ipc' + | 'ignore' + | Stream + | number + | null + | undefined; interface CommonOptions { /** @@ -103,7 +126,7 @@ declare namespace execa { * * @see https://nodejs.org/api/child_process.html#child_process_options_stdio */ - stdio?: 'pipe' | 'ignore' | 'inherit' | StdIOOption[]; + stdio?: 'pipe' | 'ignore' | 'inherit' | ReadonlyArray; /** * Prepare child to run independently of its parent process. * Specific behavior depends on the platform. @@ -253,10 +276,16 @@ declare namespace execa { type ExecaError = Error & ExecaReturns; interface ExecaChildPromise { - catch(onrejected?: ((reason: ExecaError) => TResult | PromiseLike) | null): Promise; + catch( + onrejected?: + | ((reason: ExecaError) => TResult | PromiseLike) + | null + ): Promise; } - type ExecaChildProcess = ChildProcess & ExecaChildPromise & Promise; + type ExecaChildProcess = ChildProcess & + ExecaChildPromise & + Promise; } declare var execa: execa.ExecaStatic; From f5a5393e685ceec3132eb7471a2096555381772a Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sat, 10 Mar 2018 12:59:48 -0500 Subject: [PATCH 2/3] execa: add missing 'inherit' to StdIOOption --- types/execa/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/execa/index.d.ts b/types/execa/index.d.ts index f771105736..992d046a03 100644 --- a/types/execa/index.d.ts +++ b/types/execa/index.d.ts @@ -91,6 +91,7 @@ declare namespace execa { | 'pipe' | 'ipc' | 'ignore' + | 'inherit' | Stream | number | null From 2249f0eb21db02b2984ac52dfd857f00c9caa84e Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sat, 10 Mar 2018 13:04:24 -0500 Subject: [PATCH 3/3] execa: bump version --- types/execa/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/execa/index.d.ts b/types/execa/index.d.ts index 992d046a03..067d36c368 100644 --- a/types/execa/index.d.ts +++ b/types/execa/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for execa 0.8 +// Type definitions for execa 0.9 // Project: https://github.com/sindresorhus/execa#readme // Definitions by: Douglas Duteil // BendingBender