@rushstack/node-core-library
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -94,5 +94,13 @@ /// <reference types="node" /> | ||
* Whether or not to throw when the process completes with a non-zero exit code. Defaults to false. | ||
* | ||
* @defaultValue false | ||
*/ | ||
throwOnNonZeroExitCode?: boolean; | ||
/** | ||
* Whether or not to throw when the process is terminated by a signal. Defaults to false. | ||
* | ||
* @defaultValue false | ||
*/ | ||
throwOnSignal?: boolean; | ||
/** | ||
* The encoding of the output. If not provided, the output will not be collected. | ||
@@ -142,2 +150,6 @@ */ | ||
exitCode: number | null; | ||
/** | ||
* The process signal that terminated the process. If the process exited normally, this will be null. | ||
*/ | ||
signal: string | null; | ||
} | ||
@@ -144,0 +156,0 @@ /** |
@@ -304,3 +304,3 @@ "use strict"; | ||
static async waitForExitAsync(childProcess, options = {}) { | ||
const { throwOnNonZeroExitCode = false, encoding } = options; | ||
const { throwOnNonZeroExitCode, throwOnSignal, encoding } = options; | ||
if (encoding && (!childProcess.stdout || !childProcess.stderr)) { | ||
@@ -321,3 +321,3 @@ throw new Error('An encoding was specified, but stdout and/or stderr on the child process are not defined'); | ||
let errorThrown = undefined; | ||
const promiseExitCode = await new Promise((resolve, reject) => { | ||
const { exitCode, signal } = await new Promise((resolve, reject) => { | ||
if (encoding) { | ||
@@ -335,28 +335,33 @@ childProcess.stdout.on('data', (chunk) => { | ||
}); | ||
childProcess.on('close', (exitCode, signal) => { | ||
childProcess.on('close', (closeExitCode, closeSignal) => { | ||
if (errorThrown) { | ||
reject(errorThrown); | ||
} | ||
if (signal) { | ||
reject(new Error(`Process terminated by ${signal}`)); | ||
if (closeSignal && throwOnSignal) { | ||
reject(new Error(`Process terminated by ${closeSignal}`)); | ||
} | ||
else if (exitCode !== 0 && throwOnNonZeroExitCode) { | ||
reject(new Error(`Process exited with code ${exitCode}`)); | ||
else if (closeExitCode !== 0 && throwOnNonZeroExitCode) { | ||
reject(new Error(`Process exited with code ${closeExitCode}`)); | ||
} | ||
else { | ||
resolve(exitCode); | ||
resolve({ exitCode: closeExitCode, signal: closeSignal }); | ||
} | ||
}); | ||
}); | ||
const result = { | ||
exitCode: promiseExitCode | ||
}; | ||
let stdout; | ||
let stderr; | ||
if (encoding === 'buffer') { | ||
result.stdout = Buffer.concat(collectedStdout); | ||
result.stderr = Buffer.concat(collectedStderr); | ||
stdout = Buffer.concat(collectedStdout); | ||
stderr = Buffer.concat(collectedStderr); | ||
} | ||
else if (encoding) { | ||
result.stdout = collectedStdout.join(''); | ||
result.stderr = collectedStderr.join(''); | ||
else if (encoding !== undefined) { | ||
stdout = collectedStdout.join(''); | ||
stderr = collectedStderr.join(''); | ||
} | ||
const result = { | ||
stdout: stdout, | ||
stderr: stderr, | ||
exitCode, | ||
signal | ||
}; | ||
return result; | ||
@@ -383,3 +388,3 @@ } | ||
// Don't collect output in the result since we process it directly | ||
Executable.waitForExitAsync(process, { throwOnNonZeroExitCode: true }) | ||
Executable.waitForExitAsync(process, { throwOnNonZeroExitCode: true, throwOnSignal: true }) | ||
]); | ||
@@ -386,0 +391,0 @@ return processInfoByIdMap; |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
1069242
13837