Skip to content

Commit

Permalink
Update Rollup and related plugins to their most recent versions (#24916)
Browse files Browse the repository at this point in the history
Update Rollup and related plugins to their most recent versions +
resolve any breaking changes/deprecations/etc along the way. I made each
change piece by piece, so the commit history tells a pretty good story
of what was changed where/how/why.

fixes #24894

For the full deepdive/context, see:

- #24894

The inspiration for this came from @jasonwilliams 's PR for attempting
to add sourcemap output support to React's builds:

- #20186
  - #21946

But I figured that it would be useful to minimise the scope of changes
in that PR, and to modernise the build tooling along the way.

If any of these updates rely on a node version later than `10.x`, then
the following PR may have to land first, otherwise things might break on
AppVeyor:

- #24891
  - #24892

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
  • Loading branch information
0xdevalias and sebmarkbage authored Feb 20, 2023
1 parent bc38a3d commit 6b6d061
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 322 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +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",
"abortcontroller-polyfill": "^1.7.5",
"art": "0.10.1",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
Expand Down Expand Up @@ -85,13 +89,9 @@
"random-seed": "^0.3.0",
"react-lifecycles-compat": "^3.0.4",
"rimraf": "^3.0.0",
"rollup": "^1.19.4",
"rollup-plugin-babel": "^4.0.1",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^2.1.1",
"rollup": "^2.76.0",
"rollup-plugin-prettier": "^3.0.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-strip-banner": "^0.2.0",
"rollup-plugin-strip-banner": "^2.0.0",
"semver": "^7.1.1",
"targz": "^1.0.1",
"through2": "^3.0.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/react-devtools-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"@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 @@ -55,10 +58,7 @@
"os-name": "^3.1.0",
"parse-filepath": "^1.0.2",
"raw-loader": "^3.1.0",
"rollup": "^1.19.4",
"rollup-plugin-babel": "^4.0.1",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^2.1.1",
"rollup": "^2.76.0",
"source-map-js": "^0.6.2",
"sourcemap-codec": "^1.4.8",
"style-loader": "^0.23.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const {
const {emptyDirSync} = require('fs-extra');
const {resolve} = require('path');
const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const babel = require('@rollup/plugin-babel').babel;
const commonjs = require('@rollup/plugin-commonjs');
const jsx = require('acorn-jsx');
const rollupResolve = require('rollup-plugin-node-resolve');
const rollupResolve = require('@rollup/plugin-node-resolve').nodeResolve;
const {encode, decode} = require('sourcemap-codec');
const {generateEncodedHookMap} = require('../generateHookMap');
const {parse} = require('@babel/parser');
Expand Down Expand Up @@ -323,7 +323,11 @@ async function bundle() {
plugins: [
rollupResolve(),
commonjs(),
babel({presets: ['@babel/preset-react'], sourceMap: true}),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-react'],
sourceMap: true,
}),
],
external: ['react'],
});
Expand Down
6 changes: 3 additions & 3 deletions packages/react-dom/src/test-utils/FizzTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import * as tmp from 'tmp';
import * as fs from 'fs';
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import {rollup} from 'rollup';
import path from 'path';

Expand All @@ -30,7 +30,7 @@ async function getRollupResult(scriptSrc: string): Promise<string | null> {
input: require.resolve(scriptSrc),
onwarn: console.warn,
plugins: [
replace({__DEV__: 'true'}),
replace({__DEV__: 'true', preventAssignment: true}),
resolve({
rootDir: path.join(__dirname, '..', '..', '..'),
}),
Expand Down
28 changes: 17 additions & 11 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const babel = require('@rollup/plugin-babel').babel;
const closure = require('./plugins/closure-plugin');
const commonjs = require('rollup-plugin-commonjs');
const commonjs = require('@rollup/plugin-commonjs');
const flowRemoveTypes = require('flow-remove-types');
const prettier = require('rollup-plugin-prettier');
const replace = require('rollup-plugin-replace');
const replace = require('@rollup/plugin-replace');
const stripBanner = require('rollup-plugin-strip-banner');
const chalk = require('chalk');
const resolve = require('rollup-plugin-node-resolve');
const resolve = require('@rollup/plugin-node-resolve').nodeResolve;
const fs = require('fs');
const argv = require('minimist')(process.argv.slice(2));
const Modules = require('./modules');
Expand Down Expand Up @@ -146,6 +146,7 @@ function getBabelConfig(
configFile: false,
presets: [],
plugins: [...babelPlugins],
babelHelpers: 'bundled',
};
if (isDevelopment) {
options.plugins.push(
Expand Down Expand Up @@ -189,6 +190,7 @@ function getRollupOutputOptions(
name: globalName,
sourcemap: false,
esModule: false,
exports: 'auto',
};
}

Expand Down Expand Up @@ -342,7 +344,7 @@ function getPlugins(
forbidFBJSImports(),
// Use Node resolution mechanism.
resolve({
skip: externals,
// skip: externals, // TODO: options.skip was removed in @rollup/plugin-node-resolve 3.0.0
}),
// Remove license headers from individual modules
stripBanner({
Expand All @@ -367,11 +369,14 @@ function getPlugins(
},
// Turn __DEV__ and process.env checks into constants.
replace({
__DEV__: isProduction ? 'false' : 'true',
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
__UMD__: isUMDBundle ? 'true' : 'false',
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
__EXPERIMENTAL__,
preventAssignment: true,
values: {
__DEV__: isProduction ? 'false' : 'true',
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
__UMD__: isUMDBundle ? 'true' : 'false',
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
__EXPERIMENTAL__,
},
}),
// The CommonJS plugin *only* exists to pull "art" into "react-art".
// I'm going to port "art" to ES modules to avoid this problem.
Expand Down Expand Up @@ -566,6 +571,7 @@ async function createBundle(bundle, bundleType) {
treeshake: {
moduleSideEffects: (id, external) =>
!(external && pureExternalModules.includes(id)),
propertyReadSideEffects: false,
},
external(id) {
const containsThisModule = pkg => id === pkg || id.startsWith(pkg + '/');
Expand Down Expand Up @@ -655,7 +661,7 @@ async function createBundle(bundle, bundleType) {

function handleRollupWarning(warning) {
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
const match = warning.message.match(/external module '([^']+)'/);
const match = warning.message.match(/external module "([^"]+)"/);
if (!match || typeof match[1] !== 'string') {
throw new Error(
'Could not parse a Rollup warning. ' + 'Fix this method.'
Expand Down
Loading

0 comments on commit 6b6d061

Please sign in to comment.