Skip to content

Commit

Permalink
Declare browser 'stream' fallback in package.json imports
Browse files Browse the repository at this point in the history
The browser field does not seem to be properly processed by Rollup.

Unclear if the 'default' condition is ever relevant, but the same fallback
as browser is used, since it's only needed to throw a more user-friendly error.
  • Loading branch information
larabr committed Jan 17, 2024
1 parent cd4d126 commit 1e2f3e2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/browser-fallbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const NodeReadableStream = null;
4 changes: 3 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-prototype-builtins */
import { isArrayStream } from './writer.js';
import { Readable as NodeNativeReadableStream } from 'stream';

// eslint-disable-next-line import/no-unresolved
import { Readable as NodeNativeReadableStream } from '#node:stream'; // conditional entrypoint, see package.json
const isNode = typeof globalThis.process === 'object' &&
typeof globalThis.process.versions === 'object';

Expand Down
36 changes: 27 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
},
"imports": {
"#node:stream": {
"node": "stream",
"browser": "./lib/browser-fallbacks.js",
"default": "./lib/browser-fallbacks.js"
}
},
"types": "./lib/index.d.ts",
"main": "./lib/index.js",
"browser": {
"stream": false
"#node:stream": false
},
"engines": {
"node": ">= 16.5.0"
Expand All @@ -31,7 +38,7 @@
"homepage": "https://github.com/openpgpjs/web-stream-tools#readme",
"devDependencies": {
"@openpgp/jsdoc": "^3.6.11",
"@types/node": "^18.11.9",
"@types/node": "^20.11.4",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"chai": "^4.3.7",
Expand Down

0 comments on commit 1e2f3e2

Please sign in to comment.