Skip to content

Commit

Permalink
Revert to CJS but allow dynamic imports in CJS
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Feb 20, 2023
1 parent 8214f57 commit af0c5a3
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @flow
*/

export * from '../src/ReactFlightDOMClientNode.js';
export * from './src/ReactFlightDOMClientNode';

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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');
}
Original file line number Diff line number Diff line change
@@ -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');
}
16 changes: 4 additions & 12 deletions packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,23 @@
"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"
},
"./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",
"edge-light": "./server.edge.js",
"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"
},
Expand All @@ -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/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @flow
*/

export * from '../src/ReactFlightDOMClientNode.js';
export * from './src/ReactFlightDOMServerNode';
4 changes: 4 additions & 0 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
19 changes: 19 additions & 0 deletions scripts/rollup/plugins/dynamic-imports.js
Original file line number Diff line number Diff line change
@@ -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;
},
};
};
2 changes: 1 addition & 1 deletion scripts/rollup/validate/eslintrc.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
IS_REACT_ACT_ENVIRONMENT: 'readonly',
},
parserOptions: {
ecmaVersion: 5,
ecmaVersion: 2020,
sourceType: 'script',
},
rules: {
Expand Down
2 changes: 0 additions & 2 deletions scripts/shared/inlinedHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
76 changes: 39 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit af0c5a3

Please sign in to comment.