Skip to content

Commit

Permalink
fix: Incorrect entries in stream exports (#362)
Browse files Browse the repository at this point in the history
* fix: Ensure streams have valid `.mjs` output modules

* fix: browser/import export condition order

* docs: Add changeset

* fix: Correct stream types

* refactor: Drop stream-node "browser" export condition
  • Loading branch information
rschristian authored May 24, 2024
1 parent f5e3345 commit 3044ac2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-snakes-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-render-to-string': patch
---

Correct stream exports
8 changes: 3 additions & 5 deletions config/node-13-exports.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const fs = require('fs');

const snakeCaseToCamelCase = str =>
str.replace(/([-_][a-z])/g, group => group.toUpperCase().replace('-', ''));

const copy = name => {
const copy = (filename) => {
// Copy .module.js --> .mjs for Node 13 compat.
const filename = name.includes('-') ? snakeCaseToCamelCase(name) : name;
fs.writeFileSync(
`${process.cwd()}/dist/${filename}.mjs`,
fs.readFileSync(`${process.cwd()}/dist/${filename}.module.js`)
Expand All @@ -14,3 +10,5 @@ const copy = name => {

copy('index');
copy('jsx');
copy('stream');
copy('stream-node');
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
"require": "./dist/jsx.js"
},
"./stream": {
"types": "./stream.d.ts",
"import": "./dist/stream.mjs",
"types": "./dist/stream.d.ts",
"browser": "./dist/stream.module.js",
"import": "./dist/stream.mjs",
"require": "./dist/stream.js"
},
"./stream-node": {
"types": "./stream-node.d.ts",
"types": "./dist/stream-node.d.ts",
"import": "./dist/stream-node.mjs",
"browser": "./dist/stream-node.module.js",
"require": "./dist/stream-node.js"
},
"./package.json": "./package.json"
Expand Down Expand Up @@ -171,4 +170,4 @@
"publishConfig": {
"provenance": true
}
}
}

0 comments on commit 3044ac2

Please sign in to comment.