-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from preactjs/fix-cjs
Fix commonjs entry in v6
- Loading branch information
Showing
3 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'preact-render-to-string': patch | ||
--- | ||
|
||
Fix error in commonjs entry point |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.