11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
3- const assert = require ( 'assert/strict' ) ;
43
54// This file will only export default exports in commonjs bundles
65// instead of guarding them behind a `.default` property.
76
87const filePath = ( file ) => path . join ( process . cwd ( ) , 'dist' , file ) ;
98
9+ // Main entry
10+ fs . copyFileSync ( filePath ( 'index.js' ) , filePath ( 'commonjs.js' ) ) ;
11+ fs . copyFileSync ( filePath ( 'index.js.map' ) , filePath ( 'commonjs.js.map' ) ) ;
12+
13+ const source = [
14+ `const mod = require('./commonjs');` ,
15+ `mod.default.renderToStaticMarkup = mod.default;` ,
16+ `mod.default.renderToString = mod.default;` ,
17+ `mod.default.render = mod.default;` ,
18+ `module.exports = mod.default;`
19+ ] . join ( '\n' ) ;
20+ fs . writeFileSync ( filePath ( 'index.js' ) , source , 'utf-8' ) ;
21+
1022// JSX entry
1123fs . copyFileSync ( filePath ( 'jsx.js' ) , filePath ( 'jsx-entry.js' ) ) ;
1224fs . copyFileSync ( filePath ( 'jsx.js.map' ) , filePath ( 'jsx-entry.js.map' ) ) ;
@@ -18,15 +30,3 @@ const sourceJsx = [
1830 `module.exports = entry.default;`
1931] . join ( '\n' ) ;
2032fs . writeFileSync ( filePath ( 'jsx.js' ) , sourceJsx , 'utf-8' ) ;
21-
22- // Verify CJS entries
23- const main = require ( filePath ( 'index.js' ) ) ;
24- assert ( typeof main === 'function' , 'Default export is a function' ) ;
25-
26- const jsx = require ( filePath ( 'jsx.js' ) ) ;
27- assert ( typeof jsx === 'function' , 'Default export is a function' ) ;
28- assert ( typeof jsx . render === 'function' , 'render entry is a function' ) ;
29- assert (
30- typeof jsx . shallowRender === 'function' ,
31- 'shallowRender entry is a function'
32- ) ;
0 commit comments