From 15fe4d2ff14b6efe6e0f4037772f8a001b465364 Mon Sep 17 00:00:00 2001 From: Kirk Scheibelhut Date: Sun, 7 Apr 2019 00:34:06 -0700 Subject: [PATCH] Stop closing STDOUT/STDERR in lib/streams.ts (#5419) Fixes #5403 for Node versions prior to v10.12.0. --- lib/streams.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/streams.ts b/lib/streams.ts index acf44e32b4..0e93facb3a 100644 --- a/lib/streams.ts +++ b/lib/streams.ts @@ -366,11 +366,14 @@ export class WriteStream { this.drainListeners.push(resolve); }); }; - options.end = function () { - return new Promise(resolve => { - this.nodeWritableStream!.end(() => resolve()); - }); - }; + // Prior to Node v10.12.0, attempting to close STDOUT or STDERR will throw + if (nodeStream !== process.stdout && nodeStream !== process.stderr) { + options.end = function () { + return new Promise(resolve => { + this.nodeWritableStream!.end(() => resolve()); + }); + }; + } } if (options.write) this._write = options.write; @@ -671,11 +674,14 @@ export class ObjectWriteStream { } }; - options.end = function () { - return new Promise(resolve => { - this.nodeWritableStream!.end(() => resolve()); - }); - }; + // Prior to Node v10.12.0, attempting to close STDOUT or STDERR will throw + if (nodeStream !== process.stdout && nodeStream !== process.stderr) { + options.end = function () { + return new Promise(resolve => { + this.nodeWritableStream!.end(() => resolve()); + }); + }; + } } if (options.write) this._write = options.write;