- Version: 12.16.1
- Platform: Windows (64 bit) and MacOS
- Subsystem:
What steps will reproduce the bug?
The entire script can be found here (https://github.com/americanexpress/one-app/blob/master/scripts/dangers/bundle-sizes.js)
- Run the following code on Node 12.14.0 and below.
function getGzipSize(filePath) {
let bytesWritten = 0;
const byteCounter = new Writable({
write(chunk, encoding, callback) {
// we control the input stream, will always be a Buffer
bytesWritten += chunk.length;
callback();
},
});
return new Promise((res, rej) => {
fs.createReadStream(filePath)
.pipe(zlib.createGzip({ level: 9 }))
// writable streams do not fire the 'close' event anymore
// https://github.com/nodejs/node/issues/21122#issuecomment-414622251
.on('close', () => res(bytesWritten))
.pipe(byteCounter)
.on('error', rej);
});
}
- Switch to Node 12.16.1
How often does it reproduce? Is there a required condition?
Consistently.
What is the expected behavior?
With this certain piece of code, on close of the stream, a markdown file should be printed.
What do you see instead?
Nothing is printed due to it not closing.
Additional information
Switching close to end makes it work. Also, this comes from a discussion I had with @mcollina and @jasnell on Twitter.
What steps will reproduce the bug?
The entire script can be found here (https://github.com/americanexpress/one-app/blob/master/scripts/dangers/bundle-sizes.js)
How often does it reproduce? Is there a required condition?
Consistently.
What is the expected behavior?
With this certain piece of code, on close of the stream, a markdown file should be printed.
What do you see instead?
Nothing is printed due to it not closing.
Additional information
Switching
closetoendmakes it work. Also, this comes from a discussion I had with @mcollina and @jasnell on Twitter.