From e05b87f92b3f3e88671b77a88fd11ff1ccf7745e Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:50:57 +0100 Subject: [PATCH] Avoid importing Node's stream lib just to inform that Node native streams are no longer support A more generic check suffices, and requires no special handling in browsers. Also, TS will warn on unexpected input type. --- lib/node-utils/browser-fallback.js | 1 - lib/node-utils/index.js | 1 - lib/node-utils/node.js | 2 -- lib/node-utils/package.json | 9 --------- lib/util.js | 4 ++-- 5 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 lib/node-utils/browser-fallback.js delete mode 100644 lib/node-utils/index.js delete mode 100644 lib/node-utils/node.js delete mode 100644 lib/node-utils/package.json diff --git a/lib/node-utils/browser-fallback.js b/lib/node-utils/browser-fallback.js deleted file mode 100644 index 583e9f1..0000000 --- a/lib/node-utils/browser-fallback.js +++ /dev/null @@ -1 +0,0 @@ -export const NodeReadableStream = null; diff --git a/lib/node-utils/index.js b/lib/node-utils/index.js deleted file mode 100644 index e9464dc..0000000 --- a/lib/node-utils/index.js +++ /dev/null @@ -1 +0,0 @@ -export { NodeReadableStream } from './node.js'; diff --git a/lib/node-utils/node.js b/lib/node-utils/node.js deleted file mode 100644 index 2df111a..0000000 --- a/lib/node-utils/node.js +++ /dev/null @@ -1,2 +0,0 @@ -// This file is only included in the Node build -export { Readable as NodeReadableStream } from 'node:stream'; diff --git a/lib/node-utils/package.json b/lib/node-utils/package.json deleted file mode 100644 index 6b51f4a..0000000 --- a/lib/node-utils/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "module", - "browser": { - "./node.js": "./browser-fallback.js" - }, - "exports": { - ".": "./index.js" - } -} diff --git a/lib/util.js b/lib/util.js index 21b9fb7..e732fbe 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,6 +1,5 @@ /* eslint-disable no-prototype-builtins */ import { isArrayStream } from './writer.js'; -import { NodeReadableStream as NodeNativeReadableStream } from './node-utils/index.js'; const isNode = typeof globalThis.process === 'object' && typeof globalThis.process.versions === 'object'; @@ -16,7 +15,8 @@ function isStream(input) { if (globalThis.ReadableStream && globalThis.ReadableStream.prototype.isPrototypeOf(input)) { return 'web'; } - if (NodeNativeReadableStream && NodeNativeReadableStream.prototype.isPrototypeOf(input)) { + // try and detect a node native stream without having to import its class + if (input && !(input instanceof globalThis.ReadableStream) && typeof input._read === 'function' && typeof input._readableState === 'object') { throw new Error('Native Node streams are no longer supported: please manually convert the stream to a WebStream, using e.g. `stream.Readable.toWeb`'); } if (input && input.getReader) {