Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/execa
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.4.0
Choose a base ref
...
head repository: sindresorhus/execa
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.0.0
Choose a head ref
  • 8 commits
  • 10 files changed
  • 4 contributors

Commits on Dec 13, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    74c3c49 View commit details
  2. Meta tweaks

    sindresorhus committed Dec 13, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4093556 View commit details

Commits on Dec 18, 2019

  1. Fix unref error (#400)

    * Update kill.js
    
    * Update kill.js
    
    * Update lib/kill.js
    
    Co-Authored-By: ehmicky <ehmicky@users.noreply.github.com>
    mifi and ehmicky committed Dec 18, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    09cd28a View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    bc520f9 View commit details
  3. Upgrade dependencies (#396)

    ehmicky authored and sindresorhus committed Dec 18, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    df08cfb View commit details
  4. Require Node.js 10

    sindresorhus committed Dec 18, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5a9c76f View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6201405 View commit details

Commits on Dec 19, 2019

  1. 4.0.0

    ehmicky committed Dec 19, 2019
    Copy the full SHA
    3a276a8 View commit details
Showing with 124 additions and 76 deletions.
  1. +0 −1 .travis.yml
  2. +11 −4 index.d.ts
  3. +2 −0 index.test-d.ts
  4. +5 −2 lib/error.js
  5. +15 −7 lib/kill.js
  6. +1 −6 lib/promise.js
  7. +8 −8 package.json
  8. +58 −47 readme.md
  9. +19 −1 test/error.js
  10. +5 −0 test/fixtures/echo-fail
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,5 @@ node_js:
- '13'
- '12'
- '10'
- '8'
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
15 changes: 11 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ declare namespace execa {
This can be either an absolute path or a path relative to the `cwd` option.
Requires `preferLocal` to be `true`.
For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.
@default process.execPath
@@ -336,14 +336,21 @@ declare namespace execa {
extends Error,
ExecaReturnBase<StdoutErrorType> {
/**
The error message.
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.
The child process stderr then stdout are appended to the end, separated with newlines and not interleaved.
*/
message: string;

/**
Original error message. This is `undefined` unless the child process exited due to an `error` event or a timeout.
This is the same as the `message` property except it does not include the child process stdout/stderr.
*/
shortMessage: string;

/**
Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa.
The `message` property contains both the `originalMessage` and some additional information added by Execa.
This is `undefined` unless the child process exited due to an `error` event or a timeout.
*/
originalMessage?: string;
}
2 changes: 2 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ try {
expectType<boolean>(execaError.killed);
expectType<string | undefined>(execaError.signal);
expectType<string | undefined>(execaError.signalDescription);
expectType<string>(execaError.shortMessage);
expectType<string | undefined>(execaError.originalMessage);
}

@@ -70,6 +71,7 @@ try {
expectType<boolean>(execaError.killed);
expectType<string | undefined>(execaError.signal);
expectType<string | undefined>(execaError.signalDescription);
expectType<string>(execaError.shortMessage);
expectType<string | undefined>(execaError.originalMessage);
}

7 changes: 5 additions & 2 deletions lib/error.js
Original file line number Diff line number Diff line change
@@ -47,15 +47,18 @@ const makeError = ({
const errorCode = error && error.code;

const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
const message = `Command ${prefix}: ${command}`;
const execaMessage = `Command ${prefix}: ${command}`;
const shortMessage = error instanceof Error ? `${execaMessage}\n${error.message}` : execaMessage;
const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');

if (error instanceof Error) {
error.originalMessage = error.message;
error.message = `${message}\n${error.message}`;
error.message = message;
} else {
error = new Error(message);
}

error.shortMessage = shortMessage;
error.command = command;
error.exitCode = exitCode;
error.signal = signal;
22 changes: 15 additions & 7 deletions lib/kill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const os = require('os');
const onExit = require('signal-exit');
const pFinally = require('p-finally');

const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;

@@ -18,9 +17,17 @@ const setKillTimeout = (kill, signal, options, killResult) => {
}

const timeout = getForceKillAfterTimeout(options);
setTimeout(() => {
const t = setTimeout(() => {
kill('SIGKILL');
}, timeout).unref();
}, timeout);

// Guarded because there's no `.unref()` when `execa` is used in the renderer
// process in Electron. This cannot be tested since we don't run tests in
// Electron.
// istanbul ignore else
if (t.unref) {
t.unref();
}
};

const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {
@@ -75,15 +82,15 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise
}, timeout);
});

const safeSpawnedPromise = pFinally(spawnedPromise, () => {
const safeSpawnedPromise = spawnedPromise.finally(() => {
clearTimeout(timeoutId);
});

return Promise.race([timeoutPromise, safeSpawnedPromise]);
};

// `cleanup` option handling
const setExitHandler = (spawned, {cleanup, detached}, timedPromise) => {
const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => {
if (!cleanup || detached) {
return timedPromise;
}
@@ -92,8 +99,9 @@ const setExitHandler = (spawned, {cleanup, detached}, timedPromise) => {
spawned.kill();
});

// TODO: Use native "finally" syntax when targeting Node.js 10
return pFinally(timedPromise, removeExitHandler);
return timedPromise.finally(() => {
removeExitHandler();
});
};

module.exports = {
7 changes: 1 addition & 6 deletions lib/promise.js
Original file line number Diff line number Diff line change
@@ -17,12 +17,7 @@ const mergePromiseProperty = (spawned, promise, property) => {
const mergePromise = (spawned, promise) => {
mergePromiseProperty(spawned, promise, 'then');
mergePromiseProperty(spawned, promise, 'catch');

// TODO: Remove the `if`-guard when targeting Node.js 10
if (Promise.prototype.finally) {
mergePromiseProperty(spawned, promise, 'finally');
}

mergePromiseProperty(spawned, promise, 'finally');
return spawned;
};

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "execa",
"version": "3.4.0",
"version": "4.0.0",
"description": "Process execution for humans",
"license": "MIT",
"repository": "sindresorhus/execa",
"funding": "https://github.com/sindresorhus/execa?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": "^8.12.0 || >=9.7.0"
"node": ">=10"
},
"scripts": {
"test": "xo && nyc ava && tsd"
@@ -45,21 +46,20 @@
"merge-stream": "^2.0.0",
"npm-run-path": "^4.0.0",
"onetime": "^5.1.0",
"p-finally": "^2.0.0",
"signal-exit": "^3.0.2",
"strip-final-newline": "^2.0.0"
},
"devDependencies": {
"@types/node": "^12.0.7",
"@types/node": "^12.12.18",
"ava": "^2.1.0",
"coveralls": "^3.0.4",
"get-node": "^5.0.0",
"coveralls": "^3.0.9",
"get-node": "^6.6.0",
"is-running": "^2.1.0",
"nyc": "^14.1.1",
"p-event": "^4.1.0",
"tempfile": "^3.0.0",
"tsd": "^0.7.3",
"xo": "^0.24.0"
"tsd": "^0.11.0",
"xo": "^0.25.3"
},
"nyc": {
"exclude": [
Loading