Skip to content

Commit

Permalink
Avoid importing Node's stream lib just to inform that Node native str…
Browse files Browse the repository at this point in the history
…eams are no longer support

A more generic check suffices, and requires no special handling in browsers.
Also, TS will warn on unexpected input type.
  • Loading branch information
larabr committed Jan 19, 2024
1 parent 060c88f commit e05b87f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 15 deletions.
1 change: 0 additions & 1 deletion lib/node-utils/browser-fallback.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/node-utils/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/node-utils/node.js

This file was deleted.

9 changes: 0 additions & 9 deletions lib/node-utils/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) {
Expand Down

0 comments on commit e05b87f

Please sign in to comment.