From 3edada60f49ddf5f9468f2a3d1e1ae91aae07e91 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 2 Jul 2020 16:11:54 +0100 Subject: [PATCH 1/2] fix: add buffer require MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Future versions of webpack will not bundle node internals so we have to `require` them as they won't be globals any more. Weirdly `buffer` was already a dep of this module but wasn't used in the actual source 🤷‍♂️ --- src/duplex.js | 1 + test/transform.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/duplex.js b/src/duplex.js index ac7b9b7..ff4c040 100644 --- a/src/duplex.js +++ b/src/duplex.js @@ -1,6 +1,7 @@ const { Readable, Writable, Duplex } = require('stream') const getIterator = require('get-iterator') const Fifo = require('p-fifo') +const { Buffer } = require('buffer') const END_CHUNK = Buffer.alloc(0) module.exports = function toDuplex (duplex, options) { diff --git a/test/transform.test.js b/test/transform.test.js index 173474e..9982b2b 100644 --- a/test/transform.test.js +++ b/test/transform.test.js @@ -1,5 +1,6 @@ const test = require('ava') const { Readable } = require('stream') +const { Buffer } = require('buffer') const toStream = require('../') const { collect } = require('./helpers/streams') const { randomInt, randomBytes } = require('./helpers/random') From 89646101208d9d31b1837624073bf619f64edb2b Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 2 Jul 2020 16:45:20 +0100 Subject: [PATCH 2/2] fix: work around bug in node that makes writable test fail Exiting an async iterator in a pipline early causes a `ERR_STREAM_PREMATURE_CLOSE` to be thrown. This should be fixed in a future node release: https://github.com/nodejs/node/issues/23890 --- test/helpers/streams.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/helpers/streams.js b/test/helpers/streams.js index 55b1938..4ec4209 100644 --- a/test/helpers/streams.js +++ b/test/helpers/streams.js @@ -4,7 +4,8 @@ const { Writable, pipeline } = require('stream') function pipe (...streams) { return new Promise((resolve, reject) => { pipeline(...streams, err => { - if (err) return reject(err) + // work around bug in node to make 'should end mid stream' test pass - https://github.com/nodejs/node/issues/23890 + if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') return reject(err) resolve() }) })