diff --git a/package.json b/package.json index 812221c7bfae6..c0ce3d870c826 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "@babel/preset-flow": "^7.10.4", "@babel/preset-react": "^7.10.4", "@babel/traverse": "^7.11.0", - "@rollup/plugin-babel": "^5.3.1", - "@rollup/plugin-commonjs": "^22.0.1", - "@rollup/plugin-node-resolve": "^13.3.0", - "@rollup/plugin-replace": "^4.0.0", + "@rollup/plugin-babel": "^6.0.3", + "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-node-resolve": "^15.0.1", + "@rollup/plugin-replace": "^5.0.2", "abortcontroller-polyfill": "^1.7.5", "art": "0.10.1", "babel-plugin-syntax-trailing-function-commas": "^6.5.0", @@ -89,9 +89,9 @@ "random-seed": "^0.3.0", "react-lifecycles-compat": "^3.0.4", "rimraf": "^3.0.0", - "rollup": "^2.76.0", + "rollup": "^3.17.1", "rollup-plugin-prettier": "^3.0.0", - "rollup-plugin-strip-banner": "^2.0.0", + "rollup-plugin-strip-banner": "^3.0.0", "semver": "^7.1.1", "targz": "^1.0.1", "through2": "^3.0.1", diff --git a/packages/react-devtools-extensions/package.json b/packages/react-devtools-extensions/package.json index ff41a5d3d32dd..e4044629f5dec 100644 --- a/packages/react-devtools-extensions/package.json +++ b/packages/react-devtools-extensions/package.json @@ -27,9 +27,6 @@ "@babel/plugin-transform-modules-commonjs": "^7.10.4", "@babel/plugin-transform-react-jsx-source": "^7.10.5", "@babel/preset-react": "^7.10.4", - "@rollup/plugin-babel": "^5.3.1", - "@rollup/plugin-commonjs": "^22.0.1", - "@rollup/plugin-node-resolve": "^13.3.0", "acorn-jsx": "^5.2.0", "archiver": "^3.0.0", "babel-core": "^7.0.0-bridge", @@ -58,7 +55,6 @@ "os-name": "^3.1.0", "parse-filepath": "^1.0.2", "raw-loader": "^3.1.0", - "rollup": "^2.76.0", "source-map-js": "^0.6.2", "sourcemap-codec": "^1.4.8", "style-loader": "^0.23.1", diff --git a/packages/react-server-dom-webpack/package.json b/packages/react-server-dom-webpack/package.json index 3f09719bb06e7..f32d8cdeefd7d 100644 --- a/packages/react-server-dom-webpack/package.json +++ b/packages/react-server-dom-webpack/package.json @@ -66,7 +66,7 @@ "./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/*", + "./src/*": "./src/*.js", "./package.json": "./package.json" }, "main": "index.js", diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index bb33ea02c4e36..f7ce2760fb7bf 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -18,7 +18,6 @@ const Stats = require('./stats'); 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'); @@ -174,6 +173,31 @@ function getBabelConfig( return options; } +let getRollupInteropValue = id => { + // We're setting Rollup to assume that imports are ES modules unless otherwise specified. + // However, we also compile ES import syntax to `require()` using Babel. + // This causes Rollup to turn uses of `import SomeDefaultImport from 'some-module' into + // references to `SomeDefaultImport.default` due to CJS/ESM interop. + // Some CJS modules don't have a `.default` export, and the rewritten import is incorrect. + // Specifying `interop: 'default'` instead will have Rollup use the imported variable as-is, + // without adding a `.default` to the reference. + const modulesWithCommonJsExports = [ + 'JSResourceReferenceImpl', + 'error-stack-parser', + 'art/core/transform', + 'art/modes/current', + 'art/modes/fast-noSideEffects', + 'art/modes/svg', + ]; + + if (modulesWithCommonJsExports.includes(id)) { + return 'default'; + } + + // For all other modules, handle imports without any import helper utils + return 'esModule'; +}; + function getRollupOutputOptions( outputPath, format, @@ -188,7 +212,7 @@ function getRollupOutputOptions( format, globals, freeze: !isProduction, - interop: false, + interop: getRollupInteropValue, name: globalName, sourcemap: false, esModule: false, @@ -420,9 +444,6 @@ function getPlugins( assume_function_wrapper: !isUMDBundle, renaming: !shouldStayReadable, }), - // HACK to work around the fact that Rollup isn't removing unused, pure-module imports. - // Note that this plugin must be called after closure applies DCE. - isProduction && stripUnusedImports(pureExternalModules), // Add the whitespace back if necessary. shouldStayReadable && prettier({ @@ -616,7 +637,7 @@ async function createBundle(bundle, bundleType) { output: { externalLiveBindings: false, freeze: false, - interop: false, + interop: getRollupInteropValue, esModule: false, }, }; diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index e4ff1cf8bf0f7..f29fe5e17a433 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -442,7 +442,7 @@ const bundles = [ { bundleTypes: [NODE_ES2015], moduleType: RENDERER_UTILS, - entry: 'react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js', + entry: 'react-server-dom-webpack/src/ReactFlightWebpackNodeRegister', name: 'react-server-dom-webpack-node-register', global: 'ReactFlightWebpackNodeRegister', minifyWithProdErrorCodes: false, diff --git a/scripts/rollup/plugins/strip-unused-imports.js b/scripts/rollup/plugins/strip-unused-imports.js deleted file mode 100644 index a8b74142d811f..0000000000000 --- a/scripts/rollup/plugins/strip-unused-imports.js +++ /dev/null @@ -1,29 +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. - */ -'use strict'; - -module.exports = function stripUnusedImports(pureExternalModules) { - return { - name: 'scripts/rollup/plugins/strip-unused-imports', - renderChunk(code) { - pureExternalModules.forEach(module => { - // Ideally this would use a negative lookbehind: (?