Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rollup to 3.x #26442

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions packages/react-devtools-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 27 additions & 6 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand All @@ -188,7 +212,7 @@ function getRollupOutputOptions(
format,
globals,
freeze: !isProduction,
interop: false,
interop: getRollupInteropValue,
name: globalName,
sourcemap: false,
esModule: false,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -616,7 +637,7 @@ async function createBundle(bundle, bundleType) {
output: {
externalLiveBindings: false,
freeze: false,
interop: false,
interop: getRollupInteropValue,
esModule: false,
},
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 0 additions & 29 deletions scripts/rollup/plugins/strip-unused-imports.js

This file was deleted.

16 changes: 13 additions & 3 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ if (process.env.NODE_ENV !== "production") {
${source}
return exports;
};
}`;
module.exports.default = module.exports;
gaearon marked this conversation as resolved.
Show resolved Hide resolved
Object.defineProperty(module.exports, "__esModule", { value: true });
}
`;
},

/***************** NODE_PROD (reconciler only) *****************/
Expand All @@ -366,10 +369,14 @@ ${source}
${license}
*/
module.exports = function $$$reconciler($$$hostConfig) {

var exports = {};
${source}
return exports;
};`;
};
module.exports.default = module.exports;
Object.defineProperty(module.exports, "__esModule", { value: true });
`;
},

/***************** NODE_PROFILING (reconciler only) *****************/
Expand All @@ -384,7 +391,10 @@ module.exports = function $$$reconciler($$$hostConfig) {
var exports = {};
${source}
return exports;
};`;
};
module.exports.default = module.exports;
Object.defineProperty(module.exports, "__esModule", { value: true });
`;
},
};

Expand Down
Loading