Fix ERR_STREAM_WRITE_AFTER_END

This commit is contained in:
Christian Koop 2020-11-24 19:13:26 +01:00
parent 00d37a9871
commit 70e656229c
No known key found for this signature in database
GPG Key ID: DECCA4CEE0E46D6D
3 changed files with 8 additions and 4 deletions

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -33,10 +33,12 @@ export function isNumeric(str: string): boolean {
export async function runCmd(cmd: string, args: string[], workingDir: string, logStreamOrFile: string | WriteStream, silent: boolean = false): Promise<void> {
return new Promise((resolve, reject) => {
const runningProcess = spawnProcess(cmd, args, {shell: true, cwd: workingDir, env: process.env});
const closeLogStream = typeof logStreamOrFile == 'string';
const logStream = typeof logStreamOrFile != 'string' ? logStreamOrFile :
createWriteStream(logStreamOrFile, {encoding: 'utf-8', flags: 'a' /* append */});
const runningProcess = spawnProcess(cmd, args, {shell: true, cwd: workingDir, env: process.env});
runningProcess.stdout.on('data', (data) => {
logStream.write(data);
@ -53,7 +55,9 @@ export async function runCmd(cmd: string, args: string[], workingDir: string, lo
});
runningProcess.on('close', (code) => {
if (closeLogStream) {
logStream.close();
}
if (code != 0) {
return reject({err: new Error(`process exited with code ${code}`), cmd, workingDir});