diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.development.js b/packages/react-server-dom-webpack/client.node.unbundled.js similarity index 79% rename from packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.development.js rename to packages/react-server-dom-webpack/client.node.unbundled.js index 9251e4c7ff194..4f435353a20f0 100644 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.development.js +++ b/packages/react-server-dom-webpack/client.node.unbundled.js @@ -7,4 +7,4 @@ * @flow */ -export * from '../src/ReactFlightDOMClientNode.js'; +export * from './src/ReactFlightDOMClientNode'; diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js b/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js deleted file mode 100644 index 1d40bdf58054e..0000000000000 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -export * from '../src/ReactFlightDOMServerNode.js'; diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js b/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js deleted file mode 100644 index 1d40bdf58054e..0000000000000 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -export * from '../src/ReactFlightDOMServerNode.js'; diff --git a/packages/react-server-dom-webpack/npm/client.node.unbundled.js b/packages/react-server-dom-webpack/npm/client.node.unbundled.js new file mode 100644 index 0000000000000..17fe876fd388a --- /dev/null +++ b/packages/react-server-dom-webpack/npm/client.node.unbundled.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-server-dom-webpack-client.node.unbundled.production.min.js'); +} else { + module.exports = require('./cjs/react-server-dom-webpack-client.node.unbundled.development.js'); +} diff --git a/packages/react-server-dom-webpack/npm/server.node.unbundled.js b/packages/react-server-dom-webpack/npm/server.node.unbundled.js new file mode 100644 index 0000000000000..5f75de80942a2 --- /dev/null +++ b/packages/react-server-dom-webpack/npm/server.node.unbundled.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-server-dom-webpack-server.node.unbundled.production.min.js'); +} else { + module.exports = require('./cjs/react-server-dom-webpack-server.node.unbundled.development.js'); +} diff --git a/packages/react-server-dom-webpack/package.json b/packages/react-server-dom-webpack/package.json index e2764a7eccf0e..3f09719bb06e7 100644 --- a/packages/react-server-dom-webpack/package.json +++ b/packages/react-server-dom-webpack/package.json @@ -38,8 +38,7 @@ "worker": "./client.edge.js", "node": { "webpack": "./client.node.js", - "production": "./esm/react-server-dom-webpack-client.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-client.node.unbundled.development.js" + "default": "./client.node.unbundled.js" }, "browser": "./client.browser.js", "default": "./client.browser.js" @@ -47,10 +46,7 @@ "./client.browser": "./client.browser.js", "./client.edge": "./client.edge.js", "./client.node": "./client.node.js", - "./client.node.unbundled": { - "production": "./esm/react-server-dom-webpack-client.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-client.node.unbundled.development.js" - }, + "./client.node.unbundled": "./client.node.unbundled.js", "./server": { "react-server": { "workerd": "./server.edge.js", @@ -58,8 +54,7 @@ "deno": "./server.browser.js", "node": { "webpack": "./server.node.js", - "production": "./esm/react-server-dom-webpack-server.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-server.node.unbundled.development.js" + "default": "./server.node.unbundled.js" }, "browser": "./server.browser.js" }, @@ -68,10 +63,7 @@ "./server.browser": "./server.browser.js", "./server.edge": "./server.edge.js", "./server.node": "./server.node.js", - "./server.node.unbundled": { - "production": "./esm/react-server-dom-webpack-server.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-server.node.unbundled.development.js" - }, + "./server.node.unbundled": "./server.node.unbundled.js", "./node-loader": "./esm/react-server-dom-webpack-node-loader.production.min.js", "./node-register": "./node-register.js", "./src/*": "./src/*", diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.production.min.js b/packages/react-server-dom-webpack/server.node.unbundled.js similarity index 79% rename from packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.production.min.js rename to packages/react-server-dom-webpack/server.node.unbundled.js index 9251e4c7ff194..7726b9bb929d4 100644 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.production.min.js +++ b/packages/react-server-dom-webpack/server.node.unbundled.js @@ -7,4 +7,4 @@ * @flow */ -export * from '../src/ReactFlightDOMClientNode.js'; +export * from './src/ReactFlightDOMServerNode'; diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 25be58cbf15f8..5d44c64968a19 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -19,6 +19,7 @@ const Sync = require('./sync'); const sizes = require('./plugins/sizes-plugin'); const useForks = require('./plugins/use-forks-plugin'); const stripUnusedImports = require('./plugins/strip-unused-imports'); +const dynamicImports = require('./plugins/dynamic-imports'); const Packaging = require('./packaging'); const {asyncRimRaf} = require('./utils'); const codeFrame = require('@babel/code-frame'); @@ -332,6 +333,8 @@ function getPlugins( bundleType === RN_FB_PROFILING; const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput; return [ + // Keep dynamic imports as externals + dynamicImports(), { name: 'rollup-plugin-flow-remove-types', transform(code) { @@ -406,6 +409,7 @@ function getPlugins( process_common_js_modules: false, rewrite_polyfills: false, inject_libraries: false, + allow_dynamic_import: true, // Don't let it create global variables in the browser. // https://github.com/facebook/react/issues/10909 diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 66fe7bc875039..e4ff1cf8bf0f7 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -360,7 +360,7 @@ const bundles = [ externals: ['react', 'util', 'async_hooks', 'react-dom'], }, { - bundleTypes: [ESM_DEV, ESM_PROD], + bundleTypes: [NODE_DEV, NODE_PROD], moduleType: RENDERER, entry: 'react-server-dom-webpack/server.node.unbundled', global: 'ReactServerDOMServer', @@ -398,7 +398,7 @@ const bundles = [ externals: ['react', 'util'], }, { - bundleTypes: [ESM_DEV, ESM_PROD], + bundleTypes: [NODE_DEV, NODE_PROD], moduleType: RENDERER, entry: 'react-server-dom-webpack/client.node.unbundled', global: 'ReactServerDOMClient', diff --git a/scripts/rollup/plugins/dynamic-imports.js b/scripts/rollup/plugins/dynamic-imports.js new file mode 100644 index 0000000000000..10bda3f05a4f1 --- /dev/null +++ b/scripts/rollup/plugins/dynamic-imports.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +'use strict'; + +module.exports = function dynamicImports() { + return { + name: 'scripts/rollup/plugins/dynamic-imports', + renderDynamicImport({targetModuleId}) { + if (targetModuleId === null) { + return {left: 'import(', right: ')'}; + } + return null; + }, + }; +}; diff --git a/scripts/rollup/validate/eslintrc.cjs.js b/scripts/rollup/validate/eslintrc.cjs.js index 67d3c06dfc84e..64d3ddc8aeef7 100644 --- a/scripts/rollup/validate/eslintrc.cjs.js +++ b/scripts/rollup/validate/eslintrc.cjs.js @@ -53,7 +53,7 @@ module.exports = { IS_REACT_ACT_ENVIRONMENT: 'readonly', }, parserOptions: { - ecmaVersion: 5, + ecmaVersion: 2020, sourceType: 'script', }, rules: { diff --git a/scripts/shared/inlinedHostConfigs.js b/scripts/shared/inlinedHostConfigs.js index 41227972e6ae8..cf65774ca8048 100644 --- a/scripts/shared/inlinedHostConfigs.js +++ b/scripts/shared/inlinedHostConfigs.js @@ -33,8 +33,6 @@ module.exports = [ 'react-server-dom-webpack/client.node.unbundled', 'react-server-dom-webpack/server', 'react-server-dom-webpack/server.node.unbundled', - 'react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js', - 'react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js', 'react-server-dom-webpack/src/ReactFlightDOMServerNode.js', // react-server-dom-webpack/server.node 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations. 'react-devtools', diff --git a/yarn.lock b/yarn.lock index 9da46c996b1f2..2cd8fdcab456b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5146,7 +5146,7 @@ caw@^2.0.0, caw@^2.0.1: tunnel-agent "^0.6.0" url-to-options "^1.0.1" -chalk@2.4.2, chalk@2.x, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2: +chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -5163,6 +5163,14 @@ chalk@4.1.0, chalk@^4.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@4.x: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chalk@^1.0.0, chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" @@ -8678,46 +8686,40 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" -google-closure-compiler-java@^20200517.0.0: - version "20200517.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-java/-/google-closure-compiler-java-20200517.0.0.tgz#778370c22273c9085f4cf959ce063f8f112c02ac" - integrity sha512-JVZBiyyXwcYi6Yc3lO6dF2hMLJA4OzPm4/mgsem/tF1vk2HsWTnL3GTaBsPB2ENVZp0hoqsd4KgpPiG9ssNWxw== - -google-closure-compiler-js@^20200517.0.0: - version "20200517.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-js/-/google-closure-compiler-js-20200517.0.0.tgz#9cb0861f764073d1c4d3b7453b74073ccb1ecfb1" - integrity sha512-dz6dOUHx5nhdIqMRXacAYS8aJfLvw4IKxGg28Hq/zeeDPHlX3P3iBK20NgFDfT8zdushThymtMqChSy7C5eyfA== - -google-closure-compiler-linux@^20200517.0.0: - version "20200517.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-linux/-/google-closure-compiler-linux-20200517.0.0.tgz#2b9ecb634130060174aff5c52329a694ea4be68b" - integrity sha512-S5xPh6TtP+ESzZrmQLcDDqtZAsCVTbdI4VS98wQlN6IMZTd94nAnOCg9mrxQNAgop2t4sdsv/KuH0BGPUWEZ+w== - -google-closure-compiler-osx@^20200517.0.0: - version "20200517.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-osx/-/google-closure-compiler-osx-20200517.0.0.tgz#9394e9a2fd97e3729fc3bd2abcffff6aab2cfcaa" - integrity sha512-FWIcsKqLllLjdOBZd7azijVaObydgRd0obVNi63eUfC5MX6T4qxKumGCyor2UCNY6by2ESz+PlGqCFzFhZ6b2g== - -google-closure-compiler-windows@^20200517.0.0: - version "20200517.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler-windows/-/google-closure-compiler-windows-20200517.0.0.tgz#c5cdde438c29458666a83358567b12072924ed6c" - integrity sha512-UXhjRGwS8deTkRla/riyVq3psscgMuw78lepEPtq5NgbumgJzY2+IQP9q+4MVOfJW58Rv0JUWKAFOnBBSZWcAQ== - -google-closure-compiler@^20200517.0.0: - version "20200517.0.0" - resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20200517.0.0.tgz#6c47f99fc1be59bd4f9e23c5a8f2e66d64b54143" - integrity sha512-80W9zBS9Ajk1T5InWCfsoPohDmo5T1AAyw1rHh5+dgb/jPgwC65KhY+oJozTncf+/7tyQHJXozTARwhSlBUcMg== - dependencies: - chalk "2.x" - google-closure-compiler-java "^20200517.0.0" - google-closure-compiler-js "^20200517.0.0" +google-closure-compiler-java@^20230206.0.0: + version "20230206.0.0" + resolved "https://registry.yarnpkg.com/google-closure-compiler-java/-/google-closure-compiler-java-20230206.0.0.tgz#e615c1f17901b7f7906d891f132e2867e8a21019" + integrity sha512-OcnDf29yx4JNU13HpptADI2ckl9hEchktSHs2XSLQ/xStUAJQGQOl96to5IYh2VuFgn3Ssaw6M3c6At2pJr7wQ== + +google-closure-compiler-linux@^20230206.0.0: + version "20230206.0.0" + resolved "https://registry.yarnpkg.com/google-closure-compiler-linux/-/google-closure-compiler-linux-20230206.0.0.tgz#085f3782e6640f38aeb10512ff8e8f226c61dbc3" + integrity sha512-06N6w2elsnZMMA4Gf/vN2A3XzWvu+gUTrBczaw0KQL48GgdLq6OgAXrcopbGdi/K8Gz1WAcG0qf2ccG8dSqYNg== + +google-closure-compiler-osx@^20230206.0.0: + version "20230206.0.0" + resolved "https://registry.yarnpkg.com/google-closure-compiler-osx/-/google-closure-compiler-osx-20230206.0.0.tgz#62536d49652567c86efb44bbacc1c29111dd3442" + integrity sha512-lJ/Y4HTk+KdL6PhLmmalP/3DdzGK0mS0+htuFP6y4t9+QXiUKnpHWx/VDQ3Fwm2fWEzqDxfhX3R+wC9lBvFiAg== + +google-closure-compiler-windows@^20230206.0.0: + version "20230206.0.0" + resolved "https://registry.yarnpkg.com/google-closure-compiler-windows/-/google-closure-compiler-windows-20230206.0.0.tgz#7c3458f03ea940321a7c1a008da14f20b68ef4ef" + integrity sha512-4KPr7XPiOs8g4Ao3T+70egf14avCEne26XF4Mur4Fg5511ym1uEN+NlEyjBOAmfUFfaA7BYDsA8iBzDIetKrnw== + +google-closure-compiler@^20230206.0.0: + version "20230206.0.0" + resolved "https://registry.yarnpkg.com/google-closure-compiler/-/google-closure-compiler-20230206.0.0.tgz#8de9fdf36f33edb96d48473167aa18098ed49845" + integrity sha512-gGscQOcO/75AlHyw78v87u0nGKJHWqOrQ224Ks91HH1iISgF+xZ8GYosU/8s5VD66x3VD0tJKXM2rIoGOA1ycA== + dependencies: + chalk "4.x" + google-closure-compiler-java "^20230206.0.0" minimist "1.x" vinyl "2.x" vinyl-sourcemaps-apply "^0.2.0" optionalDependencies: - google-closure-compiler-linux "^20200517.0.0" - google-closure-compiler-osx "^20200517.0.0" - google-closure-compiler-windows "^20200517.0.0" + google-closure-compiler-linux "^20230206.0.0" + google-closure-compiler-osx "^20230206.0.0" + google-closure-compiler-windows "^20230206.0.0" got@^11.1.4: version "11.8.6"