Skip to content
Myr

Remove `execa.stdout()` and `execa.stderr()` (#234)

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 b5dfb0b · Browse files · 5 files+7 added−93 removed
This commit

State

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

Diff stats

5 files+7 added−93 removed

  • other:+7 added−93 removed

5 files+7 added−93 removed

modified:index.d.ts-40 removed
354 unmodified lines
355 Buffer356 >;357358 /**359 Same as `execa()`, but returns only `stdout`.360361 @param file - The program/script to execute.362 @param arguments - Arguments to pass to `file` on execution.363 @returns The contents of the executed process' `stdout`.364 */365 stdout(366 file: string,367 arguments?: readonly string[],368 options?: execa.Options369 ): Promise<string>;370 stdout(371 file: string,372 arguments?: readonly string[],373 options?: execa.Options<null>374 ): Promise<Buffer>;375 stdout(file: string, options?: execa.Options): Promise<string>;376 stdout(file: string, options?: execa.Options<null>): Promise<Buffer>;377378 /**379 Same as `execa()`, but returns only `stderr`.380381 @param file - The program/script to execute.382 @param arguments - Arguments to pass to `file` on execution.383 @returns The contents of the executed process' `stderr`.384 */385 stderr(386 file: string,387 arguments?: readonly string[],388 options?: execa.Options389 ): Promise<string>;390 stderr(391 file: string,392 arguments?: readonly string[],393 options?: execa.Options<null>394 ): Promise<Buffer>;395 stderr(file: string, options?: execa.Options): Promise<string>;396 stderr(file: string, options?: execa.Options<null>): Promise<Buffer>;397398 /**359 Execute a file synchronously.360361 This method throws an `Error` if the command fails.362
22 unmodified lines
modified:index.js-12 removed
418 unmodified lines
419};420421module.exports = execa;422423// TODO: set `stderr: 'ignore'` when that option is implemented424module.exports.stdout = async (...args) => {425 const {stdout} = await execa(...args);426 return stdout;427};428429// TODO: set `stdout: 'ignore'` when that option is implemented430module.exports.stderr = async (...args) => {431 const {stderr} = await execa(...args);432 return stderr;433};434423module.exports.sync = (command, args, options) => {424 const parsed = handleArgs(command, args, options);425 const joinedCommand = joinCommand(command, args);426
35 unmodified lines
modified:index.test-d.ts-14 removed
modified:readme.md-10 removed
129 unmodified lines
130The spawned process can be canceled with the `.cancel()` method on the promise, which causes the promise to reject an error with a `.isCanceled = true` property, provided the process gets canceled. The process will not be canceled if it has already exited.131132The promise result is an `Object` with `stdout`, `stderr` and `all` properties.133134### execa.stdout(file, [arguments], [options])135### execa.stdout(command, [options])136137Same as `execa()`, but returns only `stdout`.138139### execa.stderr(file, [arguments], [options])140### execa.stderr(command, [options])141142Same as `execa()`, but returns only `stderr`.143134### execa.sync(file, [arguments], [options])135### execa.sync(command, [options])136137Execute a file synchronously.
208 unmodified lines
modified:test.js+7 added-17 removed
37 unmodified lines
38 t.true(Buffer.isBuffer(stdout));39 t.is(stdout.toString(), 'foo');40});4142test('execa.stdout()', async t => {43 const stdout = await execa.stdout('noop', ['foo']);44 t.is(stdout, 'foo');45});4647test('execa.stderr()', async t => {48 const stderr = await execa.stderr('noop-err', ['foo']);49 t.is(stderr, 'foo');50});5142test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {43 const result = await execa('noop-132');44 t.is(result.all, '132');45});
416 unmodified lines
462 });463}464465test('use environment variables by default', async t => {476 const result = await execa.stdout('environment');466 const {stdout} = await execa('environment');467478 t.deepEqual(result.split('\n'), [468 t.deepEqual(stdout.split('\n'), [469 'foo',470 'undefined'471 ]);472});473474test('extend environment variables by default', async t => {485 const result = await execa.stdout('environment', [], {env: {BAR: 'bar'}});475 const {stdout} = await execa('environment', [], {env: {BAR: 'bar'}});476487 t.deepEqual(result.split('\n'), [477 t.deepEqual(stdout.split('\n'), [478 'foo',479 'bar'480 ]);481});482483test('do not extend environment with `extendEnv: false`', async t => {494 const result = await execa.stdout('environment', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});484 const {stdout} = await execa('environment', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});485496 t.deepEqual(result.split('\n'), [486 t.deepEqual(stdout.split('\n'), [487 'undefined',488 'bar'489 ]);490});
12 unmodified lines
503504test('use extend environment with `extendEnv: true` and `shell: true`', async t => {505 process.env.TEST = 'test';506 const command = process.platform === 'win32' ? 'echo %TEST%' : 'echo $TEST';517 const stdout = await execa.stdout(command, {shell: true, env: {}, extendEnv: true});507 const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true});508 t.is(stdout, 'test');509 delete process.env.TEST;510});511
136 unmodified lines