GeezerVison is showing github.com — Add Node ESM build option (#20243) · react/react@504222d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: scripts/rollup/build.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,6 +46,7 @@ process.on('unhandledRejection', err => { | 46 | 46 |
| 47 | 47 | const { | 48 | 48 | NODE_ES2015, | | 49 | + NODE_ESM, | 49 | 50 | UMD_DEV, | 50 | 51 | UMD_PROD, | 51 | 52 | UMD_PROFILING, | @@ -259,12 +260,15 @@ function getFormat(bundleType) { | 259 | 260 | case RN_FB_PROD: | 260 | 261 | case RN_FB_PROFILING: | 261 | 262 | return `cjs`; | | 263 | + case NODE_ESM: | | 264 | + return `es`; | 262 | 265 | } | 263 | 266 | } | 264 | 267 |
| 265 | 268 | function isProductionBundleType(bundleType) { | 266 | 269 | switch (bundleType) { | 267 | 270 | case NODE_ES2015: | | 271 | + case NODE_ESM: | 268 | 272 | case UMD_DEV: | 269 | 273 | case NODE_DEV: | 270 | 274 | case FB_WWW_DEV: | @@ -290,6 +294,7 @@ function isProductionBundleType(bundleType) { | 290 | 294 | function isProfilingBundleType(bundleType) { | 291 | 295 | switch (bundleType) { | 292 | 296 | case NODE_ES2015: | | 297 | + case NODE_ESM: | 293 | 298 | case FB_WWW_DEV: | 294 | 299 | case FB_WWW_PROD: | 295 | 300 | case NODE_DEV: | @@ -729,6 +734,7 @@ async function buildEverything() { | 729 | 734 | for (const bundle of Bundles.bundles) { | 730 | 735 | bundles.push( | 731 | 736 | [bundle, NODE_ES2015], | | 737 | + [bundle, NODE_ESM], | 732 | 738 | [bundle, UMD_DEV], | 733 | 739 | [bundle, UMD_PROD], | 734 | 740 | [bundle, UMD_PROFILING], | |
Collapse file Copy file name to clipboardExpand all lines: scripts/rollup/bundles.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ const __EXPERIMENTAL__ = | 9 | 9 |
| 10 | 10 | const bundleTypes = { | 11 | 11 | NODE_ES2015: 'NODE_ES2015', | | 12 | + NODE_ESM: 'NODE_ESM', | 12 | 13 | UMD_DEV: 'UMD_DEV', | 13 | 14 | UMD_PROD: 'UMD_PROD', | 14 | 15 | UMD_PROFILING: 'UMD_PROFILING', | @@ -28,6 +29,7 @@ const bundleTypes = { | 28 | 29 |
| 29 | 30 | const { | 30 | 31 | NODE_ES2015, | | 32 | + NODE_ESM, | 31 | 33 | UMD_DEV, | 32 | 34 | UMD_PROD, | 33 | 35 | UMD_PROFILING, | @@ -777,6 +779,8 @@ function getFilename(bundle, bundleType) { | 777 | 779 | switch (bundleType) { | 778 | 780 | case NODE_ES2015: | 779 | 781 | return `${name}.js`; | | 782 | + case NODE_ESM: | | 783 | + return `${name}.js`; | 780 | 784 | case UMD_DEV: | 781 | 785 | return `${name}.development.js`; | 782 | 786 | case UMD_PROD: | |
Collapse file Copy file name to clipboardExpand all lines: scripts/rollup/packaging.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ const { | 17 | 17 |
| 18 | 18 | const { | 19 | 19 | NODE_ES2015, | | 20 | + NODE_ESM, | 20 | 21 | UMD_DEV, | 21 | 22 | UMD_PROD, | 22 | 23 | UMD_PROFILING, | @@ -45,6 +46,8 @@ function getBundleOutputPath(bundleType, filename, packageName) { | 45 | 46 | switch (bundleType) { | 46 | 47 | case NODE_ES2015: | 47 | 48 | return `build/node_modules/${packageName}/cjs/${filename}`; | | 49 | + case NODE_ESM: | | 50 | + return `build/node_modules/${packageName}/esm/${filename}`; | 48 | 51 | case NODE_DEV: | 49 | 52 | case NODE_PROD: | 50 | 53 | case NODE_PROFILING: | |
Collapse file Copy file name to clipboard +60Lines changed: 60 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +module.exports = { | | 4 | + env: { | | 5 | + commonjs: true, | | 6 | + browser: true, | | 7 | + }, | | 8 | + globals: { | | 9 | + // ES 6 | | 10 | + Map: true, | | 11 | + Set: true, | | 12 | + Proxy: true, | | 13 | + Symbol: true, | | 14 | + WeakMap: true, | | 15 | + WeakSet: true, | | 16 | + Uint16Array: true, | | 17 | + Reflect: true, | | 18 | + // Vendor specific | | 19 | + MSApp: true, | | 20 | + __REACT_DEVTOOLS_GLOBAL_HOOK__: true, | | 21 | + // CommonJS / Node | | 22 | + process: true, | | 23 | + setImmediate: true, | | 24 | + Buffer: true, | | 25 | + // Trusted Types | | 26 | + trustedTypes: true, | | 27 | + | | 28 | + // Scheduler profiling | | 29 | + SharedArrayBuffer: true, | | 30 | + Int32Array: true, | | 31 | + ArrayBuffer: true, | | 32 | + | | 33 | + TaskController: true, | | 34 | + | | 35 | + // Flight | | 36 | + Uint8Array: true, | | 37 | + Promise: true, | | 38 | + | | 39 | + // Flight Webpack | | 40 | + __webpack_chunk_load__: true, | | 41 | + __webpack_require__: true, | | 42 | + | | 43 | + // jest | | 44 | + expect: true, | | 45 | + jest: true, | | 46 | + }, | | 47 | + parserOptions: { | | 48 | + ecmaVersion: 2015, | | 49 | + sourceType: 'module', | | 50 | + }, | | 51 | + rules: { | | 52 | + 'no-undef': 'error', | | 53 | + 'no-shadow-restricted-names': 'error', | | 54 | + }, | | 55 | + | | 56 | + // These plugins aren't used, but eslint complains if an eslint-ignore comment | | 57 | + // references unused plugins. An alternate approach could be to strip | | 58 | + // eslint-ignore comments as part of the build. | | 59 | + plugins: ['jest', 'no-for-of-loops', 'react', 'react-internal'], | | 60 | +}; |
Collapse file Copy file name to clipboardExpand all lines: scripts/rollup/validate/index.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ const Packaging = require('../packaging'); | 9 | 9 |
| 10 | 10 | const { | 11 | 11 | NODE_ES2015, | | 12 | + NODE_ESM, | 12 | 13 | UMD_DEV, | 13 | 14 | UMD_PROD, | 14 | 15 | UMD_PROFILING, | @@ -34,6 +35,8 @@ function getFormat(bundleType) { | 34 | 35 | return 'umd'; | 35 | 36 | case NODE_ES2015: | 36 | 37 | return 'cjs2015'; | | 38 | + case NODE_ESM: | | 39 | + return 'esm'; | 37 | 40 | case NODE_DEV: | 38 | 41 | case NODE_PROD: | 39 | 42 | case NODE_PROFILING: | @@ -64,6 +67,7 @@ function getESLintInstance(format) { | 64 | 67 | const esLints = { | 65 | 68 | cjs: getESLintInstance('cjs'), | 66 | 69 | cjs2015: getESLintInstance('cjs2015'), | | 70 | + esm: getESLintInstance('esm'), | 67 | 71 | rn: getESLintInstance('rn'), | 68 | 72 | fb: getESLintInstance('fb'), | 69 | 73 | umd: getESLintInstance('umd'), | |
Collapse file Copy file name to clipboardExpand all lines: scripts/rollup/wrappers.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ const reactVersion = require('../../package.json').version; | 5 | 5 |
| 6 | 6 | const { | 7 | 7 | NODE_ES2015, | | 8 | + NODE_ESM, | 8 | 9 | UMD_DEV, | 9 | 10 | UMD_PROD, | 10 | 11 | UMD_PROFILING, | @@ -40,6 +41,17 @@ ${license} | 40 | 41 |
| 41 | 42 | 'use strict'; | 42 | 43 |
| | 44 | +${source}`; | | 45 | + }, | | 46 | + | | 47 | + /***************** NODE_ESM *****************/ | | 48 | + [NODE_ESM](source, globalName, filename, moduleType) { | | 49 | + return `/** @license React v${reactVersion} | | 50 | + * ${filename} | | 51 | + * | | 52 | +${license} | | 53 | + */ | | 54 | +
| 43 | 55 | ${source}`; | 44 | 56 | }, | 45 | 57 |
| |
|