1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
- const assert = require ( 'assert/strict' ) ;
4
3
5
4
// This file will only export default exports in commonjs bundles
6
5
// instead of guarding them behind a `.default` property.
7
6
8
7
const filePath = ( file ) => path . join ( process . cwd ( ) , 'dist' , file ) ;
9
8
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
+
10
22
// JSX entry
11
23
fs . copyFileSync ( filePath ( 'jsx.js' ) , filePath ( 'jsx-entry.js' ) ) ;
12
24
fs . copyFileSync ( filePath ( 'jsx.js.map' ) , filePath ( 'jsx-entry.js.map' ) ) ;
@@ -18,15 +30,3 @@ const sourceJsx = [
18
30
`module.exports = entry.default;`
19
31
] . join ( '\n' ) ;
20
32
fs . 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