@malept/cross-spawn-promise
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -25,10 +25,17 @@ /// <reference types="node" /> | ||
} | ||
export declare class ExitCodeError extends Error { | ||
export declare class ExitError extends Error { | ||
cmd: string; | ||
args: CrossSpawnArgs; | ||
code: number; | ||
stdout: string; | ||
stderr: string; | ||
constructor(cmd: string, args: CrossSpawnArgs, message: string, stdout: string, stderr: string); | ||
} | ||
export declare class ExitCodeError extends ExitError { | ||
code: number; | ||
constructor(cmd: string, args: CrossSpawnArgs, code: number, stdout: string, stderr: string); | ||
} | ||
export declare class ExitSignalError extends ExitError { | ||
signal: string; | ||
constructor(cmd: string, args: CrossSpawnArgs, signal: string, stdout: string, stderr: string); | ||
} | ||
/** | ||
@@ -35,0 +42,0 @@ * A wrapper around `cross-spawn`'s `spawn` function which can optionally log the command executed |
@@ -24,9 +24,7 @@ "use strict"; | ||
exports.CrossSpawnError = CrossSpawnError; | ||
class ExitCodeError extends Error { | ||
constructor(cmd, args, code, stdout, stderr) { | ||
const fullCommand = stringifyCommand(cmd, args); | ||
super(`Command failed with a non-zero return code (${code}):\n${fullCommand}\n${stdout}\n${stderr}`.trim()); | ||
class ExitError extends Error { | ||
constructor(cmd, args, message, stdout, stderr) { | ||
super(message); | ||
this.cmd = cmd; | ||
this.args = args; | ||
this.code = code; | ||
this.stdout = stdout; | ||
@@ -36,3 +34,19 @@ this.stderr = stderr; | ||
} | ||
exports.ExitError = ExitError; | ||
class ExitCodeError extends ExitError { | ||
constructor(cmd, args, code, stdout, stderr) { | ||
const fullCommand = stringifyCommand(cmd, args); | ||
super(cmd, args, `Command failed with a non-zero return code (${code}):\n${fullCommand}\n${stdout}\n${stderr}`.trim(), stdout, stderr); | ||
this.code = code; | ||
} | ||
} | ||
exports.ExitCodeError = ExitCodeError; | ||
class ExitSignalError extends ExitError { | ||
constructor(cmd, args, signal, stdout, stderr) { | ||
const fullCommand = stringifyCommand(cmd, args); | ||
super(cmd, args, `Command terminated via a signal (${signal}):\n${fullCommand}\n${stdout}\n${stderr}`.trim(), stdout, stderr); | ||
this.signal = signal; | ||
} | ||
} | ||
exports.ExitSignalError = ExitSignalError; | ||
/** | ||
@@ -54,3 +68,3 @@ * A wrapper around `cross-spawn`'s `spawn` function which can optionally log the command executed | ||
if (process.stdout) { | ||
process.stdout.on("data", data => { | ||
process.stdout.on("data", (data) => { | ||
stdout += data.toString(); | ||
@@ -61,10 +75,13 @@ }); | ||
process.stderr.on("data", | ||
/* istanbul ignore next */ data => { | ||
/* istanbul ignore next */ (data) => { | ||
stderr += data.toString(); | ||
}); | ||
} | ||
process.on("close", code => { | ||
process.on("close", (code, signal) => { | ||
if (code === 0) { | ||
resolve(stdout); | ||
} | ||
else if (code === null) { | ||
reject(new ExitSignalError(cmd, args, signal, stdout, stderr)); | ||
} | ||
else { | ||
@@ -74,3 +91,3 @@ reject(new ExitCodeError(cmd, args, code, stdout, stderr)); | ||
}); | ||
process.on("error", err => { | ||
process.on("error", (err) => { | ||
if (updateErrorCallback) { | ||
@@ -77,0 +94,0 @@ updateErrorCallback(err, !!logger); |
{ | ||
"name": "@malept/cross-spawn-promise", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Promisified version of cross-spawn", | ||
@@ -18,3 +18,3 @@ "main": "dist/src/index.js", | ||
"docs": "typedoc", | ||
"lint": "eslint --ext .ts .", | ||
"lint": "prettier --check . && eslint --ext .ts .", | ||
"prepare": "npm run build", | ||
@@ -45,7 +45,6 @@ "test": "yarn lint && yarn ava" | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.19.1", | ||
"prettier-eslint-cli": "^5.0.0", | ||
"prettier": "^2.0.1", | ||
"source-map-support": "^0.5.16", | ||
"ts-node": "^8.6.2", | ||
"typedoc": "^0.16.9", | ||
"typedoc": "^0.17.3", | ||
"typescript": "^3.7.5" | ||
@@ -97,4 +96,7 @@ }, | ||
"lint-staged": { | ||
"*.json": "prettier --write", | ||
"*.ts": "prettier-eslint --write" | ||
"*.{json,md,yml}": "prettier --write", | ||
"*.ts": [ | ||
"prettier --write", | ||
"eslint --fix" | ||
] | ||
}, | ||
@@ -101,0 +103,0 @@ "nyc": { |
@@ -14,7 +14,10 @@ # `@malept/cross-spawn-promise` | ||
If the spawned process is terminated by a signal on non-Windows platforms, an `ExitSignalError` is | ||
thrown with the original command, signal name, `stdout`, and `stderr` as properties. | ||
## Extra Options | ||
* `logger`: a `Function` such as `console.log` or `debug(name)` to log some information | ||
- `logger`: a `Function` such as `console.log` or `debug(name)` to log some information | ||
about the spawned process. | ||
* `updateErrorCallback`: a callback which mutates the error before it is re-thrown. Most commonly, | ||
- `updateErrorCallback`: a callback which mutates the error before it is re-thrown. Most commonly, | ||
this is used to augment the error message of `ENOENT` error to provide a more human-friendly | ||
@@ -21,0 +24,0 @@ message as to how to install the missing executable. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23720
20
139
28