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 f3b1e03 commit 7e58c89
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 39 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 @@ -410,6 +413,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

0 comments on commit 7e58c89

Please sign in to comment.