diff --git a/.changeset/silver-lemons-sort.md b/.changeset/silver-lemons-sort.md new file mode 100644 index 00000000..a1127c96 --- /dev/null +++ b/.changeset/silver-lemons-sort.md @@ -0,0 +1,5 @@ +--- +'preact-render-to-string': patch +--- + +Fix error in commonjs entry point diff --git a/config/node-commonjs.js b/config/node-commonjs.js index 9dacbdc4..18e82ce7 100644 --- a/config/node-commonjs.js +++ b/config/node-commonjs.js @@ -1,21 +1,32 @@ const fs = require('fs'); const path = require('path'); +const assert = require('assert/strict'); // This file will only export default exports in commonjs bundles // instead of guarding them behind a `.default` property. const filePath = (file) => path.join(process.cwd(), 'dist', file); -// Main entry -fs.copyFileSync(filePath('index.js'), filePath('commonjs.js')); -fs.copyFileSync(filePath('index.js.map'), filePath('commonjs.js.map')); - -const source = `module.exports = require('./commonjs').default;`; -fs.writeFileSync(filePath('index.js'), source, 'utf-8'); - // JSX entry fs.copyFileSync(filePath('jsx.js'), filePath('jsx-entry.js')); fs.copyFileSync(filePath('jsx.js.map'), filePath('jsx-entry.js.map')); -const sourceJsx = `module.exports = require('./jsx-entry').default;`; +const sourceJsx = [ + `const entry = require('./jsx-entry');`, + `entry.default.render = entry.render;`, + `entry.default.shallowRender = entry.shallowRender;`, + `module.exports = entry.default;` +].join('\n'); fs.writeFileSync(filePath('jsx.js'), sourceJsx, 'utf-8'); + +// Verify CJS entries +const main = require(filePath('index.js')); +assert(typeof main === 'function', 'Default export is a function'); + +const jsx = require(filePath('jsx.js')); +assert(typeof jsx === 'function', 'Default export is a function'); +assert(typeof jsx.render === 'function', 'render entry is a function'); +assert( + typeof jsx.shallowRender === 'function', + 'shallowRender entry is a function' +); diff --git a/package-lock.json b/package-lock.json index 5d0d99de..fe9beeb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "preact-render-to-string", - "version": "5.2.6", + "version": "6.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "preact-render-to-string", - "version": "5.2.6", + "version": "6.0.0", "license": "MIT", "dependencies": { "pretty-format": "^3.8.0"