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