From 04be33299276220d8609f5d652048ce29702a78a Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 28 Mar 2023 11:00:57 +0200 Subject: [PATCH 1/3] Fix default commonjs entries --- config/node-commonjs.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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' +); From 016cc1235140535dbc7507e3c2ebd76d2f32d9b4 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 28 Mar 2023 11:01:09 +0200 Subject: [PATCH 2/3] Fix missing lock file update --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" From 8f4692c49277591819acb74808a0e28f7cb30c2f Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 28 Mar 2023 12:18:01 +0200 Subject: [PATCH 3/3] Add changeset --- .changeset/silver-lemons-sort.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/silver-lemons-sort.md 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