Socket
Socket
Sign inDemoInstall

execa

Package Overview
Dependencies
19
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 3.0.0

30

index.d.ts

@@ -42,3 +42,3 @@ /// <reference types="node"/>

/**
Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.
Buffer the output from the spawned process. When set to `false`, you must read the output of `stdout` and `stderr` (or `all` if the `all` option is `true`). Otherwise the returned promise will not be resolved/rejected.

@@ -80,2 +80,9 @@ If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data.

/**
Add an `.all` property on the promise and the resolved value. The property contains the output of the process with `stdout` and `stderr` interleaved.
@default false
*/
readonly all?: boolean;
/**
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.

@@ -227,7 +234,2 @@

/**
The textual exit code of the process that was run.
*/
exitCodeName: string;
/**
The output of the process on stdout.

@@ -281,4 +283,8 @@ */

The output of the process with `stdout` and `stderr` interleaved.
This is `undefined` if either:
- the `all` option is `false` (default value)
- `execa.sync()` was used
*/
all: StdoutErrorType;
all?: StdoutErrorType;

@@ -311,4 +317,8 @@ /**

The output of the process with `stdout` and `stderr` interleaved.
This is `undefined` if either:
- the `all` option is `false` (default value)
- `execa.sync()` was used
*/
all: StdoutErrorType;
all?: StdoutErrorType;

@@ -350,3 +360,5 @@ /**

This is `undefined` when both `stdout` and `stderr` options are set to [`'pipe'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
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)
*/

@@ -353,0 +365,0 @@ all?: ReadableStream;

@@ -43,2 +43,3 @@ 'use strict';

cleanup: true,
all: false,
...options,

@@ -107,3 +108,3 @@ windowsHide: true

const handlePromise = async () => {
const [{error, code, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
const [{error, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
const stdout = handleOutput(parsed.options, stdoutResult);

@@ -113,6 +114,6 @@ const stderr = handleOutput(parsed.options, stderrResult);

if (error || code !== 0 || signal !== null) {
if (error || exitCode !== 0 || signal !== null) {
const returnedError = makeError({
error,
code,
exitCode,
signal,

@@ -139,3 +140,2 @@ stdout,

exitCode: 0,
exitCodeName: 'SUCCESS',
stdout,

@@ -157,3 +157,3 @@ stderr,

spawned.all = makeAllStream(spawned);
spawned.all = makeAllStream(spawned, parsed.options);

@@ -188,9 +188,12 @@ return mergePromise(spawned, handlePromiseOnce);

result.stdout = handleOutput(parsed.options, result.stdout, result.error);
result.stderr = handleOutput(parsed.options, result.stderr, result.error);
const stdout = handleOutput(parsed.options, result.stdout, result.error);
const stderr = handleOutput(parsed.options, result.stderr, result.error);
if (result.error || result.status !== 0 || result.signal !== null) {
const error = makeError({
...result,
code: result.status,
stdout,
stderr,
error: result.error,
signal: result.signal,
exitCode: result.status,
command,

@@ -213,5 +216,4 @@ parsed,

exitCode: 0,
exitCodeName: 'SUCCESS',
stdout: result.stdout,
stderr: result.stderr,
stdout,
stderr,
failed: false,

@@ -218,0 +220,0 @@ timedOut: false,

'use strict';
const os = require('os');
const util = require('util');
const getCode = (error, code) => {
if (error && error.code) {
return [error.code, os.constants.errno[error.code]];
}
if (Number.isInteger(code)) {
return [util.getSystemErrorName(-code), code];
}
return [];
};
const getErrorPrefix = ({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled}) => {
const getErrorPrefix = ({timedOut, timeout, errorCode, signal, exitCode, isCanceled}) => {
if (timedOut) {

@@ -26,3 +11,7 @@ return `timed out after ${timeout} milliseconds`;

if (signal) {
if (errorCode !== undefined) {
return `failed with ${errorCode}`;
}
if (signal !== undefined) {
return `was killed with ${signal}`;

@@ -32,3 +21,3 @@ }

if (exitCode !== undefined) {
return `failed with exit code ${exitCode} (${exitCodeName})`;
return `failed with exit code ${exitCode}`;
}

@@ -45,3 +34,3 @@

signal,
code,
exitCode,
command,

@@ -53,5 +42,10 @@ timedOut,

}) => {
const [exitCodeName, exitCode] = getCode(error, code);
// `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
// We normalize them to `undefined`
exitCode = exitCode === null ? undefined : exitCode;
signal = signal === null ? undefined : signal;
const prefix = getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled});
const errorCode = error && error.code;
const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, exitCode, isCanceled});
const message = `Command ${prefix}: ${command}`;

@@ -67,5 +61,4 @@

error.command = command;
delete error.code;
error.exitCode = exitCode;
error.exitCodeName = exitCodeName;
error.signal = signal;
error.stdout = stdout;

@@ -86,5 +79,2 @@ error.stderr = stderr;

error.killed = killed && !timedOut;
// `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize
// it to `undefined`
error.signal = signal || undefined;

@@ -91,0 +81,0 @@ return error;

@@ -32,4 +32,4 @@ 'use strict';

return new Promise((resolve, reject) => {
spawned.on('exit', (code, signal) => {
resolve({code, signal});
spawned.on('exit', (exitCode, signal) => {
resolve({exitCode, signal});
});

@@ -36,0 +36,0 @@

@@ -22,4 +22,4 @@ 'use strict';

// `all` interleaves `stdout` and `stderr`
const makeAllStream = spawned => {
if (!spawned.stdout && !spawned.stderr) {
const makeAllStream = (spawned, {all}) => {
if (!all || (!spawned.stdout && !spawned.stderr)) {
return;

@@ -57,15 +57,6 @@ }

const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
if (!stream) {
if (!stream || !buffer) {
return;
}
if (!buffer) {
// TODO: Use `ret = util.promisify(stream.finished)(stream);` when targeting Node.js 10
return new Promise((resolve, reject) => {
stream
.once('end', resolve)
.once('error', reject);
});
}
if (encoding) {

@@ -88,3 +79,3 @@ return getStream(stream, {encoding, maxBuffer});

return Promise.all([
{error, code: error.code, signal: error.signal, timedOut: error.timedOut},
{error, signal: error.signal, timedOut: error.timedOut},
getBufferedData(stdout, stdoutPromise),

@@ -91,0 +82,0 @@ getBufferedData(stderr, stderrPromise),

{
"name": "execa",
"version": "2.1.0",
"version": "3.0.0",
"description": "Process execution for humans",

@@ -45,3 +45,3 @@ "license": "MIT",

"merge-stream": "^2.0.0",
"npm-run-path": "^3.0.0",
"npm-run-path": "^4.0.0",
"onetime": "^5.1.0",

@@ -48,0 +48,0 @@ "p-finally": "^2.0.0",

@@ -56,3 +56,3 @@ <img src="media/logo.svg" width="400">

try {
await execa('wrong', ['command']);
await execa('unknown', ['command']);
} catch (error) {

@@ -62,10 +62,10 @@ console.log(error);

{
message: 'Command failed with exit code 2 (ENOENT): wrong command spawn wrong ENOENT',
errno: -2,
syscall: 'spawn wrong',
path: 'wrong',
message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn unknown',
path: 'unknown',
spawnargs: ['command'],
command: 'wrong command',
exitCode: 2,
exitCodeName: 'ENOENT',
originalMessage: 'spawn unknown ENOENT',
command: 'unknown command',
stdout: '',

@@ -97,3 +97,3 @@ stderr: '',

try {
execa.sync('wrong', ['command']);
execa.sync('unknown', ['command']);
} catch (error) {

@@ -103,12 +103,13 @@ console.log(error);

{
message: 'Command failed with exit code 2 (ENOENT): wrong command spawnSync wrong ENOENT',
errno: -2,
syscall: 'spawnSync wrong',
path: 'wrong',
message: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawnSync unknown',
path: 'unknown',
spawnargs: ['command'],
command: 'wrong command',
exitCode: 2,
exitCodeName: 'ENOENT',
originalMessage: 'spawnSync unknown ENOENT',
command: 'unknown command',
stdout: '',
stderr: '',
all: '',
failed: true,

@@ -168,3 +169,5 @@ timedOut: false,

This is `undefined` when both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'pipe'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
This is `undefined` if either:
- the [`all` option](#all-2) is `false` (the default value)
- both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) 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)

@@ -225,8 +228,2 @@ ### execa.sync(file, [arguments], [options])

#### exitCodeName
Type: `string`
The textual exit code of the process that was run.
#### stdout

@@ -246,6 +243,10 @@

Type: `string | Buffer`
Type: `string | Buffer | undefined`
The output of the process on both stdout and stderr. `undefined` if `execa.sync()` was used.
The output of the process with `stdout` and `stderr` interleaved.
This is `undefined` if either:
- the [`all` option](#all-2) is `false` (the default value)
- `execa.sync()` was used
#### failed

@@ -322,3 +323,3 @@

Buffer the output from the spawned process. When buffering is disabled you must consume the output of the `stdout` and `stderr` streams because the promise will not be resolved/rejected until they have completed.
Buffer the output from the spawned process. When set to `false`, you must read the output of [`stdout`](#stdout-1) and [`stderr`](#stderr-1) (or [`all`](#all) if the [`all`](#all-2) option is `true`). Otherwise the returned promise will not be resolved/rejected.

@@ -355,2 +356,9 @@ If the spawned process fails, [`error.stdout`](#stdout), [`error.stderr`](#stderr), and [`error.all`](#all) will contain the buffered data.

#### all
Type: `boolean`<br>
Default: `false`
Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the process with `stdout` and `stderr` interleaved.
#### reject

@@ -357,0 +365,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc