2017-04-05 16:47:29 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-04-25 07:55:44 -04:00
|
|
|
const rollup = require('rollup');
|
2023-02-20 17:35:56 +11:00
|
|
|
const babel = require('@rollup/plugin-babel').babel;
|
2018-05-14 17:49:41 +01:00
|
|
|
const closure = require('./plugins/closure-plugin');
|
2023-01-05 15:41:49 -05:00
|
|
|
const flowRemoveTypes = require('flow-remove-types');
|
2025-02-16 09:38:13 -06:00
|
|
|
const {dts} = require('rollup-plugin-dts');
|
2017-11-08 22:37:11 +00:00
|
|
|
const prettier = require('rollup-plugin-prettier');
|
2023-02-20 17:35:56 +11:00
|
|
|
const replace = require('@rollup/plugin-replace');
|
2025-02-16 09:38:13 -06:00
|
|
|
const typescript = require('@rollup/plugin-typescript');
|
2017-11-08 22:37:11 +00:00
|
|
|
const stripBanner = require('rollup-plugin-strip-banner');
|
2017-04-05 16:47:29 +01:00
|
|
|
const chalk = require('chalk');
|
2023-02-20 17:35:56 +11:00
|
|
|
const resolve = require('@rollup/plugin-node-resolve').nodeResolve;
|
2017-04-05 16:47:29 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
|
const argv = require('minimist')(process.argv.slice(2));
|
|
|
|
|
const Modules = require('./modules');
|
|
|
|
|
const Bundles = require('./bundles');
|
2017-12-06 20:11:32 +00:00
|
|
|
const Stats = require('./stats');
|
|
|
|
|
const Sync = require('./sync');
|
2017-04-05 16:47:29 +01:00
|
|
|
const sizes = require('./plugins/sizes-plugin');
|
2017-11-30 12:11:00 +00:00
|
|
|
const useForks = require('./plugins/use-forks-plugin');
|
2023-02-21 13:18:24 -05:00
|
|
|
const dynamicImports = require('./plugins/dynamic-imports');
|
2017-04-05 16:47:29 +01:00
|
|
|
const Packaging = require('./packaging');
|
2020-04-02 17:52:32 -07:00
|
|
|
const {asyncRimRaf} = require('./utils');
|
2023-01-06 04:56:31 +08:00
|
|
|
const codeFrame = require('@babel/code-frame');
|
2017-11-08 22:37:11 +00:00
|
|
|
const Wrappers = require('./wrappers');
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2019-10-18 19:35:33 -07:00
|
|
|
const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL;
|
|
|
|
|
|
|
|
|
|
// Default to building in experimental mode. If the release channel is set via
|
|
|
|
|
// an environment variable, then check if it's "experimental".
|
|
|
|
|
const __EXPERIMENTAL__ =
|
|
|
|
|
typeof RELEASE_CHANNEL === 'string'
|
|
|
|
|
? RELEASE_CHANNEL === 'experimental'
|
|
|
|
|
: true;
|
2019-10-18 14:36:59 -07:00
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
// Errors in promises should be fatal.
|
|
|
|
|
let loggedErrors = new Set();
|
|
|
|
|
process.on('unhandledRejection', err => {
|
|
|
|
|
if (loggedErrors.has(err)) {
|
|
|
|
|
// No need to print it twice.
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
throw err;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const {
|
2020-05-28 15:56:34 -07:00
|
|
|
NODE_ES2015,
|
2023-02-21 13:18:24 -05:00
|
|
|
ESM_DEV,
|
|
|
|
|
ESM_PROD,
|
2017-12-06 20:11:32 +00:00
|
|
|
NODE_DEV,
|
|
|
|
|
NODE_PROD,
|
2018-06-11 13:16:27 -07:00
|
|
|
NODE_PROFILING,
|
2022-11-17 13:15:56 -08:00
|
|
|
BUN_DEV,
|
|
|
|
|
BUN_PROD,
|
2018-04-18 13:16:50 -07:00
|
|
|
FB_WWW_DEV,
|
|
|
|
|
FB_WWW_PROD,
|
2018-06-26 13:28:41 -07:00
|
|
|
FB_WWW_PROFILING,
|
2018-04-18 13:16:50 -07:00
|
|
|
RN_OSS_DEV,
|
|
|
|
|
RN_OSS_PROD,
|
2018-06-11 13:16:27 -07:00
|
|
|
RN_OSS_PROFILING,
|
2018-04-18 13:16:50 -07:00
|
|
|
RN_FB_DEV,
|
|
|
|
|
RN_FB_PROD,
|
2018-06-26 13:28:41 -07:00
|
|
|
RN_FB_PROFILING,
|
2022-10-14 23:29:17 -04:00
|
|
|
BROWSER_SCRIPT,
|
2025-02-16 09:38:13 -06:00
|
|
|
CJS_DTS,
|
|
|
|
|
ESM_DTS,
|
2017-12-06 20:11:32 +00:00
|
|
|
} = Bundles.bundleTypes;
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2020-05-28 15:04:25 -07:00
|
|
|
const {getFilename} = Bundles;
|
|
|
|
|
|
2018-11-07 20:46:41 -08:00
|
|
|
function parseRequestedNames(names, toCase) {
|
|
|
|
|
let result = [];
|
|
|
|
|
for (let i = 0; i < names.length; i++) {
|
|
|
|
|
let splitNames = names[i].split(',');
|
|
|
|
|
for (let j = 0; j < splitNames.length; j++) {
|
|
|
|
|
let name = splitNames[j].trim();
|
|
|
|
|
if (!name) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (toCase === 'uppercase') {
|
|
|
|
|
name = name.toUpperCase();
|
|
|
|
|
} else if (toCase === 'lowercase') {
|
|
|
|
|
name = name.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
result.push(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
Fix existing usage of names/type in build command (#30450)
https://github.com/facebook/react/pull/30422 broke existing build
shortcuts.
Revert the usage of `names` (`_`) and `type` args.
`yarn build-for-devtools` / `yarn build-for-devtools-dev` / `yarn
build-for-devtools-prod` should all work again.
Moved the bundleType documentation into description so they can be fuzzy
matched. But a build like `yarn build --type FB_WWW_PROD` still works
when matched exactly.
There's probably a better way to document the positional `names` arg in
the `--help` command, but didn't see it when browsing the yargs docs so
let's just fix the existing builds for now.
Now:
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--ci Run tests in CI [choices: "circleci", "github"]
--type Build the given bundle type. (NODE_ES2015,ESM_DEV,ESM_PROD,NODE_DEV,NODE_PROD,NODE_PROFILING,BUN_DEV,BUN_PROD,FB_WWW_DEV,FB_WWW_PROD,FB_WWW_PROFILING,RN_OSS_DE
V,RN_OSS_PROD,RN_OSS_PROFILING,RN_FB_DEV,RN_FB_PROD,RN_FB_PROFILING,BROWSER_SCRIPT) [string]
--pretty Force pretty output. [boolean]
--sync-fbsource Include to sync build to fbsource. [string]
--sync-www Include to sync build to www. [string]
--unsafe-partial Do not clean ./build first.
```
2024-07-25 07:44:57 -04:00
|
|
|
const argvType = Array.isArray(argv.type) ? argv.type : [argv.type];
|
|
|
|
|
const requestedBundleTypes = parseRequestedNames(
|
|
|
|
|
argv.type ? argvType : [],
|
|
|
|
|
'uppercase'
|
|
|
|
|
);
|
2018-11-07 20:46:41 -08:00
|
|
|
|
Fix existing usage of names/type in build command (#30450)
https://github.com/facebook/react/pull/30422 broke existing build
shortcuts.
Revert the usage of `names` (`_`) and `type` args.
`yarn build-for-devtools` / `yarn build-for-devtools-dev` / `yarn
build-for-devtools-prod` should all work again.
Moved the bundleType documentation into description so they can be fuzzy
matched. But a build like `yarn build --type FB_WWW_PROD` still works
when matched exactly.
There's probably a better way to document the positional `names` arg in
the `--help` command, but didn't see it when browsing the yargs docs so
let's just fix the existing builds for now.
Now:
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--ci Run tests in CI [choices: "circleci", "github"]
--type Build the given bundle type. (NODE_ES2015,ESM_DEV,ESM_PROD,NODE_DEV,NODE_PROD,NODE_PROFILING,BUN_DEV,BUN_PROD,FB_WWW_DEV,FB_WWW_PROD,FB_WWW_PROFILING,RN_OSS_DE
V,RN_OSS_PROD,RN_OSS_PROFILING,RN_FB_DEV,RN_FB_PROD,RN_FB_PROFILING,BROWSER_SCRIPT) [string]
--pretty Force pretty output. [boolean]
--sync-fbsource Include to sync build to fbsource. [string]
--sync-www Include to sync build to www. [string]
--unsafe-partial Do not clean ./build first.
```
2024-07-25 07:44:57 -04:00
|
|
|
const names = argv._;
|
Update yarn build options (#30422)
Improve command documentation and make it easier to build specific
bundle types
**Before**
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--ci Run tests in CI [choices: "circleci", "github"]
✨ Done in 0.69s.
```
**After**
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--bundle Build the given bundle type.
[choices: "NODE_ES2015", "ESM_DEV", "ESM_PROD", "NODE_DEV", "NODE_PROD", "NODE_PROFILING", "BUN_DEV", "BUN_PROD", "FB_WWW_DEV", "FB_WWW_PROD",
"FB_WWW_PROFILING", "RN_OSS_DEV", "RN_OSS_PROD", "RN_OSS_PROFILING", "RN_FB_DEV", "RN_FB_PROD", "RN_FB_PROFILING", "BROWSER_SCRIPT"]
--ci Run tests in CI [choices: "circleci", "github"]
--names Build for matched bundle names. Example: "react-test,index.js". [array]
--pretty Force pretty output. [boolean]
--sync-fbsource Include to sync build to fbsource. [string]
--sync-www Include to sync build to www. [string]
--unsafe-partial Do not clean ./build first. [boolean]
✨ Done in 0.61s.
```
Changes
- Use yargs to document existing options: `pretty`, `sync-fbsource`,
`sync-www`, `unsafe-partial`.
- Move `_` arg to `names` option for consistency with other options and
discoverability through yargs help
- Add `bundle` option in place of `argv.type` that allows choices of any
BundleType to be passed in directly.
2024-07-23 11:27:51 -04:00
|
|
|
const requestedBundleNames = parseRequestedNames(
|
Fix existing usage of names/type in build command (#30450)
https://github.com/facebook/react/pull/30422 broke existing build
shortcuts.
Revert the usage of `names` (`_`) and `type` args.
`yarn build-for-devtools` / `yarn build-for-devtools-dev` / `yarn
build-for-devtools-prod` should all work again.
Moved the bundleType documentation into description so they can be fuzzy
matched. But a build like `yarn build --type FB_WWW_PROD` still works
when matched exactly.
There's probably a better way to document the positional `names` arg in
the `--help` command, but didn't see it when browsing the yargs docs so
let's just fix the existing builds for now.
Now:
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--ci Run tests in CI [choices: "circleci", "github"]
--type Build the given bundle type. (NODE_ES2015,ESM_DEV,ESM_PROD,NODE_DEV,NODE_PROD,NODE_PROFILING,BUN_DEV,BUN_PROD,FB_WWW_DEV,FB_WWW_PROD,FB_WWW_PROFILING,RN_OSS_DE
V,RN_OSS_PROD,RN_OSS_PROFILING,RN_FB_DEV,RN_FB_PROD,RN_FB_PROFILING,BROWSER_SCRIPT) [string]
--pretty Force pretty output. [boolean]
--sync-fbsource Include to sync build to fbsource. [string]
--sync-www Include to sync build to www. [string]
--unsafe-partial Do not clean ./build first.
```
2024-07-25 07:44:57 -04:00
|
|
|
names ? names : [],
|
Update yarn build options (#30422)
Improve command documentation and make it easier to build specific
bundle types
**Before**
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--ci Run tests in CI [choices: "circleci", "github"]
✨ Done in 0.69s.
```
**After**
```
% yarn build --help
yarn run v1.22.19
$ node ./scripts/rollup/build-all-release-channels.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--releaseChannel, -r Build the given release channel. [string] [choices: "experimental", "stable"]
--index, -i Worker id. [number]
--total, -t Total number of workers. [number]
--bundle Build the given bundle type.
[choices: "NODE_ES2015", "ESM_DEV", "ESM_PROD", "NODE_DEV", "NODE_PROD", "NODE_PROFILING", "BUN_DEV", "BUN_PROD", "FB_WWW_DEV", "FB_WWW_PROD",
"FB_WWW_PROFILING", "RN_OSS_DEV", "RN_OSS_PROD", "RN_OSS_PROFILING", "RN_FB_DEV", "RN_FB_PROD", "RN_FB_PROFILING", "BROWSER_SCRIPT"]
--ci Run tests in CI [choices: "circleci", "github"]
--names Build for matched bundle names. Example: "react-test,index.js". [array]
--pretty Force pretty output. [boolean]
--sync-fbsource Include to sync build to fbsource. [string]
--sync-www Include to sync build to www. [string]
--unsafe-partial Do not clean ./build first. [boolean]
✨ Done in 0.61s.
```
Changes
- Use yargs to document existing options: `pretty`, `sync-fbsource`,
`sync-www`, `unsafe-partial`.
- Move `_` arg to `names` option for consistency with other options and
discoverability through yargs help
- Add `bundle` option in place of `argv.type` that allows choices of any
BundleType to be passed in directly.
2024-07-23 11:27:51 -04:00
|
|
|
'lowercase'
|
|
|
|
|
);
|
2017-12-08 00:41:25 +00:00
|
|
|
const forcePrettyOutput = argv.pretty;
|
2019-04-25 07:55:44 -04:00
|
|
|
const isWatchMode = argv.watch;
|
2017-12-06 20:11:32 +00:00
|
|
|
const syncFBSourcePath = argv['sync-fbsource'];
|
|
|
|
|
const syncWWWPath = argv['sync-www'];
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2020-04-01 12:08:37 -07:00
|
|
|
// Non-ES2015 stuff applied before closure compiler.
|
|
|
|
|
const babelPlugins = [
|
|
|
|
|
// These plugins filter out non-ES2015.
|
|
|
|
|
['@babel/plugin-proposal-class-properties', {loose: true}],
|
|
|
|
|
'syntax-trailing-function-commas',
|
|
|
|
|
// These use loose mode which avoids embedding a runtime.
|
|
|
|
|
// TODO: Remove object spread from the source. Prefer Object.assign instead.
|
|
|
|
|
[
|
|
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
|
|
|
|
{loose: true, useBuiltIns: true},
|
|
|
|
|
],
|
|
|
|
|
['@babel/plugin-transform-template-literals', {loose: true}],
|
|
|
|
|
// TODO: Remove for...of from the source. It requires a runtime to be embedded.
|
|
|
|
|
'@babel/plugin-transform-for-of',
|
|
|
|
|
// TODO: Remove array spread from the source. Prefer .apply instead.
|
|
|
|
|
['@babel/plugin-transform-spread', {loose: true, useBuiltIns: true}],
|
|
|
|
|
'@babel/plugin-transform-parameters',
|
|
|
|
|
// TODO: Remove array destructuring from the source. Requires runtime.
|
|
|
|
|
['@babel/plugin-transform-destructuring', {loose: true, useBuiltIns: true}],
|
2022-02-23 19:34:24 -05:00
|
|
|
// Transform Object spread to shared/assign
|
|
|
|
|
require('../babel/transform-object-assign'),
|
2020-04-01 12:08:37 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const babelToES5Plugins = [
|
|
|
|
|
// These plugins transform DEV mode. Closure compiler deals with these in PROD.
|
|
|
|
|
'@babel/plugin-transform-literals',
|
|
|
|
|
'@babel/plugin-transform-arrow-functions',
|
|
|
|
|
'@babel/plugin-transform-block-scoped-functions',
|
|
|
|
|
'@babel/plugin-transform-shorthand-properties',
|
|
|
|
|
'@babel/plugin-transform-computed-properties',
|
|
|
|
|
['@babel/plugin-transform-block-scoping', {throwIfClosureRequired: true}],
|
|
|
|
|
];
|
|
|
|
|
|
2019-12-14 18:09:25 +00:00
|
|
|
function getBabelConfig(
|
|
|
|
|
updateBabelOptions,
|
|
|
|
|
bundleType,
|
|
|
|
|
packageName,
|
|
|
|
|
externals,
|
[RFC] Codemod invariant -> throw new Error (#22435)
* Hoist error codes import to module scope
When this code was written, the error codes map (`codes.json`) was
created on-the-fly, so we had to lazily require from inside the visitor.
Because `codes.json` is now checked into source, we can import it a
single time in module scope.
* Minify error constructors in production
We use a script to minify our error messages in production. Each message
is assigned an error code, defined in `scripts/error-codes/codes.json`.
Then our build script replaces the messages with a link to our
error decoder page, e.g. https://reactjs.org/docs/error-decoder.html/?invariant=92
This enables us to write helpful error messages without increasing the
bundle size.
Right now, the script only works for `invariant` calls. It does not work
if you throw an Error object. This is an old Facebookism that we don't
really need, other than the fact that our error minification script
relies on it.
So, I've updated the script to minify error constructors, too:
Input:
Error(`A ${adj} message that contains ${noun}`);
Output:
Error(formatProdErrorMessage(ERR_CODE, adj, noun));
It only works for constructors that are literally named Error, though we
could add support for other names, too.
As a next step, I will add a lint rule to enforce that errors written
this way must have a corresponding error code.
* Minify "no fallback UI specified" error in prod
This error message wasn't being minified because it doesn't use
invariant. The reason it didn't use invariant is because this particular
error is created without begin thrown — it doesn't need to be thrown
because it's located inside the error handling part of the runtime.
Now that the error minification script supports Error constructors, we
can minify it by assigning it a production error code in
`scripts/error-codes/codes.json`.
To support the use of Error constructors more generally, I will add a
lint rule that enforces each message has a corresponding error code.
* Lint rule to detect unminified errors
Adds a lint rule that detects when an Error constructor is used without
a corresponding production error code.
We already have this for `invariant`, but not for regular errors, i.e.
`throw new Error(msg)`. There's also nothing that enforces the use of
`invariant` besides convention.
There are some packages where we don't care to minify errors. These are
packages that run in environments where bundle size is not a concern,
like react-pg. I added an override in the ESLint config to ignore these.
* Temporarily add invariant codemod script
I'm adding this codemod to the repo temporarily, but I'll revert it
in the same PR. That way we don't have to check it in but it's still
accessible (via the PR) if we need it later.
* [Automated] Codemod invariant -> Error
This commit contains only automated changes:
npx jscodeshift -t scripts/codemod-invariant.js packages --ignore-pattern="node_modules/**/*"
yarn linc --fix
yarn prettier
I will do any manual touch ups in separate commits so they're easier
to review.
* Remove temporary codemod script
This reverts the codemod script and ESLint config I added temporarily
in order to perform the invariant codemod.
* Manual touch ups
A few manual changes I made after the codemod ran.
* Enable error code transform per package
Currently we're not consistent about which packages should have their
errors minified in production and which ones should.
This adds a field to the bundle configuration to control whether to
apply the transform. We should decide what the criteria is going
forward. I think it's probably a good idea to minify any package that
gets sent over the network. So yes to modules that run in the browser,
and no to modules that run on the server and during development only.
2021-09-30 15:01:28 -04:00
|
|
|
isDevelopment,
|
|
|
|
|
bundle
|
2019-12-14 18:09:25 +00:00
|
|
|
) {
|
2017-10-25 02:55:00 +03:00
|
|
|
let options = {
|
2018-03-23 19:51:04 +00:00
|
|
|
exclude: '/**/node_modules/**',
|
2020-04-01 12:08:37 -07:00
|
|
|
babelrc: false,
|
|
|
|
|
configFile: false,
|
2017-10-25 02:55:00 +03:00
|
|
|
presets: [],
|
2020-04-01 12:08:37 -07:00
|
|
|
plugins: [...babelPlugins],
|
2023-02-20 17:35:56 +11:00
|
|
|
babelHelpers: 'bundled',
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
sourcemap: false,
|
2017-10-25 02:55:00 +03:00
|
|
|
};
|
2019-12-14 18:09:25 +00:00
|
|
|
if (isDevelopment) {
|
2024-07-12 14:39:38 -04:00
|
|
|
options.plugins.push(...babelToES5Plugins);
|
2019-12-14 18:09:25 +00:00
|
|
|
}
|
2017-10-25 02:55:00 +03:00
|
|
|
if (updateBabelOptions) {
|
|
|
|
|
options = updateBabelOptions(options);
|
|
|
|
|
}
|
2021-10-31 18:37:32 -04:00
|
|
|
// Controls whether to replace error messages with error codes in production.
|
|
|
|
|
// By default, error messages are replaced in production.
|
|
|
|
|
if (!isDevelopment && bundle.minifyWithProdErrorCodes !== false) {
|
|
|
|
|
options.plugins.push(require('../error-codes/transform-error-messages'));
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 19:34:24 -05:00
|
|
|
return options;
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
Update Rollup to 3.x (#26442)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR:
- Updates Rollup from 2.x to latest 3.x, and updates associated plugins
- Updates deprecated / altered config settings in the Rollup plugin
pipeline
- Fixes some file extension and import issues related to use of ESM in
`react-dom-webpack-server`
- Removes a now-obsolete `strip-unused-imports` Rollup plugin
- <s>Fixes an _existing_ bug with the Rollup 2.x plugin pipeline on
`main` that was causing parts of `DOMProperty.js` to get left out of the
`react-dom-webpack-server` JS bundles, by adding a new plugin to tell
Rollup to treat that file as if it as side effects</s>
This PR should be functionally identical to the other existing "Rollup 3
upgrade" PR at #26078 . I'm filing this as a near-duplicate because I'm
ready to push this change through ASAP so that I can follow it up with a
PR that adds sourcemap support, that PR's artifact diffing seems like
it's possibly stuck and I want to compare the build results, and I've
got this set up against latest `main`.
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This gets React's build setup updated to the latest Rollup version,
which is generally a good practice, but also ensures that any further
Rollup config tweaks can be done using the current Rollup docs as a
reference.
## How did you test this change?
<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
- Made builds from the latest `main`
- Updated Rollup package versions and cross-compared the changes I
needed to make locally to get successful builds vs #26078
- Diffed the output folders between `main` and this PR, and confirmed
that the bundle contents are identical (with the exception of version
strings and the `react-dom-webpack-server` bundle fix re-adding missing
`DOMProperty.js` content)
2023-03-24 14:08:41 -04:00
|
|
|
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 = [
|
|
|
|
|
'art/core/transform',
|
|
|
|
|
'art/modes/current',
|
|
|
|
|
'art/modes/fast-noSideEffects',
|
|
|
|
|
'art/modes/svg',
|
2023-03-25 00:05:23 +00:00
|
|
|
'JSResourceReferenceImpl',
|
|
|
|
|
'error-stack-parser',
|
|
|
|
|
'neo-async',
|
|
|
|
|
'webpack/lib/dependencies/ModuleDependency',
|
|
|
|
|
'webpack/lib/dependencies/NullDependency',
|
|
|
|
|
'webpack/lib/Template',
|
Update Rollup to 3.x (#26442)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR:
- Updates Rollup from 2.x to latest 3.x, and updates associated plugins
- Updates deprecated / altered config settings in the Rollup plugin
pipeline
- Fixes some file extension and import issues related to use of ESM in
`react-dom-webpack-server`
- Removes a now-obsolete `strip-unused-imports` Rollup plugin
- <s>Fixes an _existing_ bug with the Rollup 2.x plugin pipeline on
`main` that was causing parts of `DOMProperty.js` to get left out of the
`react-dom-webpack-server` JS bundles, by adding a new plugin to tell
Rollup to treat that file as if it as side effects</s>
This PR should be functionally identical to the other existing "Rollup 3
upgrade" PR at #26078 . I'm filing this as a near-duplicate because I'm
ready to push this change through ASAP so that I can follow it up with a
PR that adds sourcemap support, that PR's artifact diffing seems like
it's possibly stuck and I want to compare the build results, and I've
got this set up against latest `main`.
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This gets React's build setup updated to the latest Rollup version,
which is generally a good practice, but also ensures that any further
Rollup config tweaks can be done using the current Rollup docs as a
reference.
## How did you test this change?
<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
- Made builds from the latest `main`
- Updated Rollup package versions and cross-compared the changes I
needed to make locally to get successful builds vs #26078
- Diffed the output folders between `main` and this PR, and confirmed
that the bundle contents are identical (with the exception of version
strings and the `react-dom-webpack-server` bundle fix re-adding missing
`DOMProperty.js` content)
2023-03-24 14:08:41 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (modulesWithCommonJsExports.includes(id)) {
|
|
|
|
|
return 'default';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For all other modules, handle imports without any import helper utils
|
|
|
|
|
return 'esModule';
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-22 08:16:59 -07:00
|
|
|
function getRollupOutputOptions(
|
|
|
|
|
outputPath,
|
|
|
|
|
format,
|
|
|
|
|
globals,
|
|
|
|
|
globalName,
|
|
|
|
|
bundleType
|
|
|
|
|
) {
|
|
|
|
|
const isProduction = isProductionBundleType(bundleType);
|
|
|
|
|
|
2020-02-25 13:54:27 -08:00
|
|
|
return {
|
|
|
|
|
file: outputPath,
|
|
|
|
|
format,
|
|
|
|
|
globals,
|
|
|
|
|
freeze: !isProduction,
|
Update Rollup to 3.x (#26442)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR:
- Updates Rollup from 2.x to latest 3.x, and updates associated plugins
- Updates deprecated / altered config settings in the Rollup plugin
pipeline
- Fixes some file extension and import issues related to use of ESM in
`react-dom-webpack-server`
- Removes a now-obsolete `strip-unused-imports` Rollup plugin
- <s>Fixes an _existing_ bug with the Rollup 2.x plugin pipeline on
`main` that was causing parts of `DOMProperty.js` to get left out of the
`react-dom-webpack-server` JS bundles, by adding a new plugin to tell
Rollup to treat that file as if it as side effects</s>
This PR should be functionally identical to the other existing "Rollup 3
upgrade" PR at #26078 . I'm filing this as a near-duplicate because I'm
ready to push this change through ASAP so that I can follow it up with a
PR that adds sourcemap support, that PR's artifact diffing seems like
it's possibly stuck and I want to compare the build results, and I've
got this set up against latest `main`.
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This gets React's build setup updated to the latest Rollup version,
which is generally a good practice, but also ensures that any further
Rollup config tweaks can be done using the current Rollup docs as a
reference.
## How did you test this change?
<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
- Made builds from the latest `main`
- Updated Rollup package versions and cross-compared the changes I
needed to make locally to get successful builds vs #26078
- Diffed the output folders between `main` and this PR, and confirmed
that the bundle contents are identical (with the exception of version
strings and the `react-dom-webpack-server` bundle fix re-adding missing
`DOMProperty.js` content)
2023-03-24 14:08:41 -04:00
|
|
|
interop: getRollupInteropValue,
|
2020-02-25 13:54:27 -08:00
|
|
|
name: globalName,
|
|
|
|
|
sourcemap: false,
|
|
|
|
|
esModule: false,
|
2023-02-20 17:35:56 +11:00
|
|
|
exports: 'auto',
|
2020-02-25 13:54:27 -08:00
|
|
|
};
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFormat(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
2020-05-28 15:56:34 -07:00
|
|
|
case NODE_ES2015:
|
2017-04-05 16:47:29 +01:00
|
|
|
case NODE_DEV:
|
|
|
|
|
case NODE_PROD:
|
2018-06-11 13:16:27 -07:00
|
|
|
case NODE_PROFILING:
|
2022-11-17 13:15:56 -08:00
|
|
|
case BUN_DEV:
|
|
|
|
|
case BUN_PROD:
|
2018-04-18 13:16:50 -07:00
|
|
|
case FB_WWW_DEV:
|
|
|
|
|
case FB_WWW_PROD:
|
2018-06-26 13:28:41 -07:00
|
|
|
case FB_WWW_PROFILING:
|
2018-04-18 13:16:50 -07:00
|
|
|
case RN_OSS_DEV:
|
|
|
|
|
case RN_OSS_PROD:
|
2018-06-11 13:16:27 -07:00
|
|
|
case RN_OSS_PROFILING:
|
2018-04-18 13:16:50 -07:00
|
|
|
case RN_FB_DEV:
|
|
|
|
|
case RN_FB_PROD:
|
2018-06-26 13:28:41 -07:00
|
|
|
case RN_FB_PROFILING:
|
2025-02-16 09:38:13 -06:00
|
|
|
case CJS_DTS:
|
2017-04-05 16:47:29 +01:00
|
|
|
return `cjs`;
|
2023-02-21 13:18:24 -05:00
|
|
|
case ESM_DEV:
|
|
|
|
|
case ESM_PROD:
|
2025-02-16 09:38:13 -06:00
|
|
|
case ESM_DTS:
|
2020-11-13 08:57:45 -05:00
|
|
|
return `es`;
|
2022-10-14 23:29:17 -04:00
|
|
|
case BROWSER_SCRIPT:
|
|
|
|
|
return `iife`;
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 22:37:11 +00:00
|
|
|
function isProductionBundleType(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
2020-05-28 15:56:34 -07:00
|
|
|
case NODE_ES2015:
|
2023-02-09 19:45:05 -05:00
|
|
|
return true;
|
2023-02-21 13:18:24 -05:00
|
|
|
case ESM_DEV:
|
2017-11-08 22:37:11 +00:00
|
|
|
case NODE_DEV:
|
2022-11-17 13:15:56 -08:00
|
|
|
case BUN_DEV:
|
2018-04-18 13:16:50 -07:00
|
|
|
case FB_WWW_DEV:
|
|
|
|
|
case RN_OSS_DEV:
|
|
|
|
|
case RN_FB_DEV:
|
2017-11-08 22:37:11 +00:00
|
|
|
return false;
|
2023-02-21 13:18:24 -05:00
|
|
|
case ESM_PROD:
|
2017-11-08 22:37:11 +00:00
|
|
|
case NODE_PROD:
|
2022-11-17 13:15:56 -08:00
|
|
|
case BUN_PROD:
|
2018-06-11 13:16:27 -07:00
|
|
|
case NODE_PROFILING:
|
2018-04-18 13:16:50 -07:00
|
|
|
case FB_WWW_PROD:
|
2018-06-26 13:28:41 -07:00
|
|
|
case FB_WWW_PROFILING:
|
2018-04-18 13:16:50 -07:00
|
|
|
case RN_OSS_PROD:
|
2018-06-11 13:16:27 -07:00
|
|
|
case RN_OSS_PROFILING:
|
2018-04-18 13:16:50 -07:00
|
|
|
case RN_FB_PROD:
|
2018-06-26 13:28:41 -07:00
|
|
|
case RN_FB_PROFILING:
|
2022-10-14 23:29:17 -04:00
|
|
|
case BROWSER_SCRIPT:
|
2025-02-16 09:38:13 -06:00
|
|
|
case CJS_DTS:
|
|
|
|
|
case ESM_DTS:
|
2017-11-08 22:37:11 +00:00
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error(`Unknown type: ${bundleType}`);
|
|
|
|
|
}
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-11 13:16:27 -07:00
|
|
|
function isProfilingBundleType(bundleType) {
|
|
|
|
|
switch (bundleType) {
|
2020-05-28 15:56:34 -07:00
|
|
|
case NODE_ES2015:
|
2018-06-11 13:16:27 -07:00
|
|
|
case FB_WWW_DEV:
|
|
|
|
|
case FB_WWW_PROD:
|
|
|
|
|
case NODE_DEV:
|
|
|
|
|
case NODE_PROD:
|
2022-11-17 13:15:56 -08:00
|
|
|
case BUN_DEV:
|
|
|
|
|
case BUN_PROD:
|
2018-06-11 13:16:27 -07:00
|
|
|
case RN_FB_DEV:
|
|
|
|
|
case RN_FB_PROD:
|
|
|
|
|
case RN_OSS_DEV:
|
|
|
|
|
case RN_OSS_PROD:
|
2023-02-21 13:18:24 -05:00
|
|
|
case ESM_DEV:
|
|
|
|
|
case ESM_PROD:
|
2022-10-14 23:29:17 -04:00
|
|
|
case BROWSER_SCRIPT:
|
2025-02-16 09:38:13 -06:00
|
|
|
case CJS_DTS:
|
|
|
|
|
case ESM_DTS:
|
2018-06-11 13:16:27 -07:00
|
|
|
return false;
|
2018-06-26 13:28:41 -07:00
|
|
|
case FB_WWW_PROFILING:
|
2018-06-11 13:16:27 -07:00
|
|
|
case NODE_PROFILING:
|
2018-06-26 13:28:41 -07:00
|
|
|
case RN_FB_PROFILING:
|
2018-06-11 13:16:27 -07:00
|
|
|
case RN_OSS_PROFILING:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error(`Unknown type: ${bundleType}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
function getBundleTypeFlags(bundleType) {
|
|
|
|
|
const isFBWWWBundle =
|
|
|
|
|
bundleType === FB_WWW_DEV ||
|
|
|
|
|
bundleType === FB_WWW_PROD ||
|
|
|
|
|
bundleType === FB_WWW_PROFILING;
|
|
|
|
|
const isRNBundle =
|
|
|
|
|
bundleType === RN_OSS_DEV ||
|
|
|
|
|
bundleType === RN_OSS_PROD ||
|
|
|
|
|
bundleType === RN_OSS_PROFILING ||
|
|
|
|
|
bundleType === RN_FB_DEV ||
|
|
|
|
|
bundleType === RN_FB_PROD ||
|
|
|
|
|
bundleType === RN_FB_PROFILING;
|
|
|
|
|
|
|
|
|
|
const isFBRNBundle =
|
|
|
|
|
bundleType === RN_FB_DEV ||
|
|
|
|
|
bundleType === RN_FB_PROD ||
|
|
|
|
|
bundleType === RN_FB_PROFILING;
|
|
|
|
|
|
|
|
|
|
const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
isFBWWWBundle,
|
|
|
|
|
isRNBundle,
|
|
|
|
|
isFBRNBundle,
|
|
|
|
|
shouldStayReadable,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-09 16:54:28 +01:00
|
|
|
function forbidFBJSImports() {
|
2018-06-19 16:03:45 +01:00
|
|
|
return {
|
2018-09-09 16:54:28 +01:00
|
|
|
name: 'forbidFBJSImports',
|
2018-06-19 16:03:45 +01:00
|
|
|
resolveId(importee, importer) {
|
|
|
|
|
if (/^fbjs\//.test(importee)) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Don't import ${importee} (found in ${importer}). ` +
|
|
|
|
|
`Use the utilities in packages/shared/ instead.`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 16:47:29 +01:00
|
|
|
function getPlugins(
|
|
|
|
|
entry,
|
2017-10-25 02:55:00 +03:00
|
|
|
externals,
|
|
|
|
|
updateBabelOptions,
|
2017-04-05 16:47:29 +01:00
|
|
|
filename,
|
2017-12-23 14:22:59 -05:00
|
|
|
packageName,
|
2017-04-05 16:47:29 +01:00
|
|
|
bundleType,
|
2017-10-25 02:55:00 +03:00
|
|
|
globalName,
|
2017-10-11 14:29:26 -04:00
|
|
|
moduleType,
|
2020-03-12 11:38:32 -07:00
|
|
|
pureExternalModules,
|
|
|
|
|
bundle
|
2017-04-05 16:47:29 +01:00
|
|
|
) {
|
2025-02-16 09:38:13 -06:00
|
|
|
// Short-circuit if we're only building a .d.ts bundle
|
|
|
|
|
if (bundleType === CJS_DTS || bundleType === ESM_DTS) {
|
|
|
|
|
return [dts({tsconfig: bundle.tsconfig})];
|
|
|
|
|
}
|
2023-08-17 15:17:46 -07:00
|
|
|
try {
|
|
|
|
|
const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
|
|
|
|
|
const isProduction = isProductionBundleType(bundleType);
|
|
|
|
|
const isProfiling = isProfilingBundleType(bundleType);
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
|
2024-06-08 11:15:57 -04:00
|
|
|
const needsMinifiedByClosure =
|
2025-02-16 09:38:13 -06:00
|
|
|
bundleType !== ESM_PROD &&
|
|
|
|
|
bundleType !== ESM_DEV &&
|
|
|
|
|
// TODO(@poteto) figure out ICE in closure compiler for eslint-plugin-react-hooks (ts)
|
|
|
|
|
bundle.tsconfig == null;
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
|
2023-08-17 15:17:46 -07:00
|
|
|
return [
|
|
|
|
|
// Keep dynamic imports as externals
|
|
|
|
|
dynamicImports(),
|
2025-02-16 09:38:13 -06:00
|
|
|
bundle.tsconfig != null
|
|
|
|
|
? typescript({tsconfig: bundle.tsconfig})
|
|
|
|
|
: {
|
|
|
|
|
name: 'rollup-plugin-flow-remove-types',
|
|
|
|
|
transform(code) {
|
|
|
|
|
const transformed = flowRemoveTypes(code);
|
|
|
|
|
return {
|
|
|
|
|
code: transformed.toString(),
|
|
|
|
|
map: null,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-08-17 15:17:46 -07:00
|
|
|
// Shim any modules that need forking in this environment.
|
|
|
|
|
useForks(forks),
|
|
|
|
|
// Ensure we don't try to bundle any fbjs modules.
|
|
|
|
|
forbidFBJSImports(),
|
|
|
|
|
// Use Node resolution mechanism.
|
|
|
|
|
resolve({
|
|
|
|
|
// skip: externals, // TODO: options.skip was removed in @rollup/plugin-node-resolve 3.0.0
|
2022-10-14 23:29:17 -04:00
|
|
|
}),
|
2023-08-17 15:17:46 -07:00
|
|
|
// Remove license headers from individual modules
|
|
|
|
|
stripBanner({
|
|
|
|
|
exclude: 'node_modules/**/*',
|
2020-02-20 23:09:30 +01:00
|
|
|
}),
|
2023-08-17 15:17:46 -07:00
|
|
|
// Compile to ES2015.
|
|
|
|
|
babel(
|
|
|
|
|
getBabelConfig(
|
|
|
|
|
updateBabelOptions,
|
2017-12-23 14:22:59 -05:00
|
|
|
bundleType,
|
|
|
|
|
packageName,
|
2023-08-17 15:17:46 -07:00
|
|
|
externals,
|
|
|
|
|
!isProduction,
|
|
|
|
|
bundle
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
// Remove 'use strict' from individual source files.
|
|
|
|
|
{
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
name: "remove 'use strict'",
|
2023-08-17 15:17:46 -07:00
|
|
|
transform(source) {
|
|
|
|
|
return source.replace(/['"]use strict["']/g, '');
|
|
|
|
|
},
|
2017-04-05 16:47:29 +01:00
|
|
|
},
|
2023-08-17 15:17:46 -07:00
|
|
|
// Turn __DEV__ and process.env checks into constants.
|
|
|
|
|
replace({
|
|
|
|
|
preventAssignment: true,
|
|
|
|
|
values: {
|
|
|
|
|
__DEV__: isProduction ? 'false' : 'true',
|
|
|
|
|
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
|
|
|
|
|
'process.env.NODE_ENV': isProduction
|
|
|
|
|
? "'production'"
|
|
|
|
|
: "'development'",
|
|
|
|
|
__EXPERIMENTAL__,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
{
|
2023-11-09 16:00:21 +00:00
|
|
|
name: 'top-level-definitions',
|
2023-08-17 15:17:46 -07:00
|
|
|
renderChunk(source) {
|
2023-11-09 16:00:21 +00:00
|
|
|
return Wrappers.wrapWithTopLevelDefinitions(
|
2023-08-17 15:17:46 -07:00
|
|
|
source,
|
|
|
|
|
bundleType,
|
|
|
|
|
globalName,
|
|
|
|
|
filename,
|
|
|
|
|
moduleType,
|
|
|
|
|
bundle.wrapWithModuleBoundaries
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
Run Closure on non-minified prod builds, too (#28827)
In #26446 we started publishing non-minified versions of our production
build artifacts, along with source maps, for easier debugging of React
when running in production mode.
The way it's currently set up is that these builds are generated
*before* Closure compiler has run. Which means it's missing many of the
optimizations that are in the final build, like dead code elimination.
This PR changes the build process to run Closure on the non-minified
production builds, too, by moving the sourcemap generation to later in
the pipeline.
The non-minified builds will still preserve the original symbol names,
and we'll use Prettier to add back whitespace. This is the exact same
approach we've been using for years to generate production builds for
Meta.
The idea is that the only difference between the minified and non-
minified builds is whitespace and symbol mangling. The semantic
structure of the program should be identical.
To implement this, I disabled symbol mangling when running Closure
compiler. Then, in a later step, the symbols are mangled by Terser. This
is when the source maps are generated.
2024-04-19 14:22:38 -04:00
|
|
|
// For production builds, compile with Closure. We do this even for the
|
|
|
|
|
// "non-minified" production builds because Closure is much better at
|
|
|
|
|
// minification than what most applications use. During this step, we do
|
|
|
|
|
// preserve the original symbol names, though, so the resulting code is
|
|
|
|
|
// relatively readable.
|
|
|
|
|
//
|
|
|
|
|
// For the minified builds, the names will be mangled later.
|
|
|
|
|
//
|
|
|
|
|
// We don't bother with sourcemaps at this step. The sourcemaps we publish
|
|
|
|
|
// are only for whitespace and symbol renaming; they don't map back to
|
|
|
|
|
// before Closure was applied.
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
needsMinifiedByClosure &&
|
Run Closure on non-minified prod builds, too (#28827)
In #26446 we started publishing non-minified versions of our production
build artifacts, along with source maps, for easier debugging of React
when running in production mode.
The way it's currently set up is that these builds are generated
*before* Closure compiler has run. Which means it's missing many of the
optimizations that are in the final build, like dead code elimination.
This PR changes the build process to run Closure on the non-minified
production builds, too, by moving the sourcemap generation to later in
the pipeline.
The non-minified builds will still preserve the original symbol names,
and we'll use Prettier to add back whitespace. This is the exact same
approach we've been using for years to generate production builds for
Meta.
The idea is that the only difference between the minified and non-
minified builds is whitespace and symbol mangling. The semantic
structure of the program should be identical.
To implement this, I disabled symbol mangling when running Closure
compiler. Then, in a later step, the symbols are mangled by Terser. This
is when the source maps are generated.
2024-04-19 14:22:38 -04:00
|
|
|
closure({
|
|
|
|
|
compilation_level: 'SIMPLE',
|
|
|
|
|
language_in: 'ECMASCRIPT_2020',
|
|
|
|
|
language_out:
|
|
|
|
|
bundleType === NODE_ES2015
|
|
|
|
|
? 'ECMASCRIPT_2020'
|
|
|
|
|
: bundleType === BROWSER_SCRIPT
|
2024-07-22 16:09:01 -04:00
|
|
|
? 'ECMASCRIPT5'
|
|
|
|
|
: 'ECMASCRIPT5_STRICT',
|
Run Closure on non-minified prod builds, too (#28827)
In #26446 we started publishing non-minified versions of our production
build artifacts, along with source maps, for easier debugging of React
when running in production mode.
The way it's currently set up is that these builds are generated
*before* Closure compiler has run. Which means it's missing many of the
optimizations that are in the final build, like dead code elimination.
This PR changes the build process to run Closure on the non-minified
production builds, too, by moving the sourcemap generation to later in
the pipeline.
The non-minified builds will still preserve the original symbol names,
and we'll use Prettier to add back whitespace. This is the exact same
approach we've been using for years to generate production builds for
Meta.
The idea is that the only difference between the minified and non-
minified builds is whitespace and symbol mangling. The semantic
structure of the program should be identical.
To implement this, I disabled symbol mangling when running Closure
compiler. Then, in a later step, the symbols are mangled by Terser. This
is when the source maps are generated.
2024-04-19 14:22:38 -04:00
|
|
|
emit_use_strict:
|
|
|
|
|
bundleType !== BROWSER_SCRIPT &&
|
|
|
|
|
bundleType !== ESM_PROD &&
|
|
|
|
|
bundleType !== ESM_DEV,
|
|
|
|
|
env: 'CUSTOM',
|
|
|
|
|
warning_level: 'QUIET',
|
|
|
|
|
source_map_include_content: true,
|
|
|
|
|
use_types_for_optimization: false,
|
|
|
|
|
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
|
|
|
|
|
assume_function_wrapper: true,
|
|
|
|
|
|
2024-04-20 11:23:46 -04:00
|
|
|
// Don't rename symbols (variable names, functions, etc). We leave
|
|
|
|
|
// this up to the application to handle, if they want. Otherwise gzip
|
|
|
|
|
// takes care of it.
|
Run Closure on non-minified prod builds, too (#28827)
In #26446 we started publishing non-minified versions of our production
build artifacts, along with source maps, for easier debugging of React
when running in production mode.
The way it's currently set up is that these builds are generated
*before* Closure compiler has run. Which means it's missing many of the
optimizations that are in the final build, like dead code elimination.
This PR changes the build process to run Closure on the non-minified
production builds, too, by moving the sourcemap generation to later in
the pipeline.
The non-minified builds will still preserve the original symbol names,
and we'll use Prettier to add back whitespace. This is the exact same
approach we've been using for years to generate production builds for
Meta.
The idea is that the only difference between the minified and non-
minified builds is whitespace and symbol mangling. The semantic
structure of the program should be identical.
To implement this, I disabled symbol mangling when running Closure
compiler. Then, in a later step, the symbols are mangled by Terser. This
is when the source maps are generated.
2024-04-19 14:22:38 -04:00
|
|
|
renaming: false,
|
|
|
|
|
}),
|
|
|
|
|
needsMinifiedByClosure &&
|
|
|
|
|
// Add the whitespace back
|
Generate sourcemaps for production build artifacts (#26446)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR updates the Rollup build pipeline to generate sourcemaps for
production build artifacts like `react-dom.production.min.js`.
It requires the Rollup v3 changes that were just merged in #26442 .
Sourcemaps are currently _only_ generated for build artifacts that are
_truly_ "production" - no sourcemaps will be generated for development,
profiling, UMD, or `shouldStayReadable` artifacts.
The generated sourcemaps contain the bundled source contents right
before that chunk was minified by Closure, and _not_ the original source
files like `react-reconciler/src/*`. This better reflects the actual
code that is running as part of the bundle, with all the feature flags
and transformations that were applied to the source files to generate
that bundle. The sourcemaps _do_ still show comments and original
function names, thus improving debuggability for production usage.
Fixes #20186 .
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This allows React users to actually debug a readable version of the
React bundle in production scenarios. It also allows other tools like
[Replay](https://replay.io) to do a better job inspecting the React
source when stepping through.
## How did you test this change?
- Generated numerous sourcemaps with various combinations of the React
bundle selections
- Viewed those sourcemaps in
https://evanw.github.io/source-map-visualization/ and confirmed via the
visualization that the generated mappings appear to be correct
I've attached a set of production files + their sourcemaps here:
[react-sourcemap-examples.zip](https://github.com/facebook/react/files/11023466/react-sourcemap-examples.zip)
You can drag JS+sourcemap file pairs into
https://evanw.github.io/source-map-visualization/ for viewing.
Examples:
- `react.production.min.js`:

- `react-dom.production.min.js`:

- `use-sync-external-store/with-selector.production.min.js`:

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
2023-11-07 13:59:27 -05:00
|
|
|
prettier({
|
|
|
|
|
parser: 'flow',
|
|
|
|
|
singleQuote: false,
|
|
|
|
|
trailingComma: 'none',
|
|
|
|
|
bracketSpacing: true,
|
|
|
|
|
}),
|
Run Closure on non-minified prod builds, too (#28827)
In #26446 we started publishing non-minified versions of our production
build artifacts, along with source maps, for easier debugging of React
when running in production mode.
The way it's currently set up is that these builds are generated
*before* Closure compiler has run. Which means it's missing many of the
optimizations that are in the final build, like dead code elimination.
This PR changes the build process to run Closure on the non-minified
production builds, too, by moving the sourcemap generation to later in
the pipeline.
The non-minified builds will still preserve the original symbol names,
and we'll use Prettier to add back whitespace. This is the exact same
approach we've been using for years to generate production builds for
Meta.
The idea is that the only difference between the minified and non-
minified builds is whitespace and symbol mangling. The semantic
structure of the program should be identical.
To implement this, I disabled symbol mangling when running Closure
compiler. Then, in a later step, the symbols are mangled by Terser. This
is when the source maps are generated.
2024-04-19 14:22:38 -04:00
|
|
|
{
|
|
|
|
|
name: 'license-and-signature-header',
|
2023-11-09 16:00:21 +00:00
|
|
|
renderChunk(source) {
|
|
|
|
|
return Wrappers.wrapWithLicenseHeader(
|
|
|
|
|
source,
|
|
|
|
|
bundleType,
|
|
|
|
|
globalName,
|
|
|
|
|
filename,
|
|
|
|
|
moduleType
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-08-17 15:17:46 -07:00
|
|
|
// Record bundle size.
|
|
|
|
|
sizes({
|
|
|
|
|
getSize: (size, gzip) => {
|
|
|
|
|
const currentSizes = Stats.currentBuildResults.bundleSizes;
|
|
|
|
|
const recordIndex = currentSizes.findIndex(
|
|
|
|
|
record =>
|
|
|
|
|
record.filename === filename && record.bundleType === bundleType
|
|
|
|
|
);
|
|
|
|
|
const index = recordIndex !== -1 ? recordIndex : currentSizes.length;
|
|
|
|
|
currentSizes[index] = {
|
|
|
|
|
filename,
|
|
|
|
|
bundleType,
|
|
|
|
|
packageName,
|
|
|
|
|
size,
|
|
|
|
|
gzip,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
].filter(Boolean);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(
|
|
|
|
|
chalk.red(`There was an error preparing plugins for entry "${entry}"`)
|
|
|
|
|
);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
function shouldSkipBundle(bundle, bundleType) {
|
2017-04-07 16:17:36 +01:00
|
|
|
const shouldSkipBundleType = bundle.bundleTypes.indexOf(bundleType) === -1;
|
|
|
|
|
if (shouldSkipBundleType) {
|
2017-12-06 20:11:32 +00:00
|
|
|
return true;
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
2017-04-07 16:17:36 +01:00
|
|
|
if (requestedBundleTypes.length > 0) {
|
2024-07-31 15:02:36 +02:00
|
|
|
const hasRequestedBundleType = requestedBundleTypes.some(requestedType =>
|
|
|
|
|
bundleType.includes(requestedType)
|
2017-04-07 16:17:36 +01:00
|
|
|
);
|
2024-07-31 15:02:36 +02:00
|
|
|
if (!hasRequestedBundleType) {
|
2017-12-06 20:11:32 +00:00
|
|
|
return true;
|
2017-04-07 16:17:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (requestedBundleNames.length > 0) {
|
2022-04-11 21:01:48 -04:00
|
|
|
// If the name ends with `something/index` we only match if the
|
|
|
|
|
// entry ends in something. Such as `react-dom/index` only matches
|
|
|
|
|
// `react-dom` but not `react-dom/server`. Everything else is fuzzy
|
|
|
|
|
// search.
|
|
|
|
|
const entryLowerCase = bundle.entry.toLowerCase() + '/index.js';
|
2017-04-07 16:17:36 +01:00
|
|
|
const isAskingForDifferentNames = requestedBundleNames.every(
|
2022-04-11 21:01:48 -04:00
|
|
|
requestedName => {
|
|
|
|
|
const matchEntry = entryLowerCase.indexOf(requestedName) !== -1;
|
|
|
|
|
if (!bundle.name) {
|
|
|
|
|
return !matchEntry;
|
|
|
|
|
}
|
|
|
|
|
const matchName =
|
|
|
|
|
bundle.name.toLowerCase().indexOf(requestedName) !== -1;
|
|
|
|
|
return !matchEntry && !matchName;
|
|
|
|
|
}
|
2017-04-07 16:17:36 +01:00
|
|
|
);
|
|
|
|
|
if (isAskingForDifferentNames) {
|
2017-12-06 20:11:32 +00:00
|
|
|
return true;
|
2017-04-07 16:17:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-06 20:11:32 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 18:26:36 +01:00
|
|
|
function resolveEntryFork(resolvedEntry, isFBBundle, isDev) {
|
2020-02-25 13:54:27 -08:00
|
|
|
// Pick which entry point fork to use:
|
|
|
|
|
// .modern.fb.js
|
|
|
|
|
// .classic.fb.js
|
|
|
|
|
// .fb.js
|
|
|
|
|
// .stable.js
|
|
|
|
|
// .experimental.js
|
|
|
|
|
// .js
|
2024-06-19 14:19:48 -04:00
|
|
|
// or any of those plus .development.js
|
2020-02-25 13:54:27 -08:00
|
|
|
|
|
|
|
|
if (isFBBundle) {
|
|
|
|
|
const resolvedFBEntry = resolvedEntry.replace(
|
|
|
|
|
'.js',
|
|
|
|
|
__EXPERIMENTAL__ ? '.modern.fb.js' : '.classic.fb.js'
|
|
|
|
|
);
|
2025-02-13 18:26:36 +01:00
|
|
|
const devFBEntry = resolvedFBEntry.replace('.js', '.development.js');
|
|
|
|
|
if (isDev && fs.existsSync(devFBEntry)) {
|
|
|
|
|
return devFBEntry;
|
2024-06-19 14:19:48 -04:00
|
|
|
}
|
2020-02-25 13:54:27 -08:00
|
|
|
if (fs.existsSync(resolvedFBEntry)) {
|
|
|
|
|
return resolvedFBEntry;
|
|
|
|
|
}
|
|
|
|
|
const resolvedGenericFBEntry = resolvedEntry.replace('.js', '.fb.js');
|
2025-02-13 18:26:36 +01:00
|
|
|
const devGenericFBEntry = resolvedGenericFBEntry.replace(
|
2024-06-19 14:19:48 -04:00
|
|
|
'.js',
|
|
|
|
|
'.development.js'
|
|
|
|
|
);
|
2025-02-13 18:26:36 +01:00
|
|
|
if (isDev && fs.existsSync(devGenericFBEntry)) {
|
|
|
|
|
return devGenericFBEntry;
|
2024-06-19 14:19:48 -04:00
|
|
|
}
|
2020-02-25 13:54:27 -08:00
|
|
|
if (fs.existsSync(resolvedGenericFBEntry)) {
|
|
|
|
|
return resolvedGenericFBEntry;
|
|
|
|
|
}
|
|
|
|
|
// Even if it's a FB bundle we fallthrough to pick stable or experimental if we don't have an FB fork.
|
|
|
|
|
}
|
|
|
|
|
const resolvedForkedEntry = resolvedEntry.replace(
|
|
|
|
|
'.js',
|
|
|
|
|
__EXPERIMENTAL__ ? '.experimental.js' : '.stable.js'
|
|
|
|
|
);
|
2024-06-19 14:19:48 -04:00
|
|
|
const devForkedEntry = resolvedForkedEntry.replace('.js', '.development.js');
|
2025-02-13 18:26:36 +01:00
|
|
|
if (isDev && fs.existsSync(devForkedEntry)) {
|
2024-06-19 14:19:48 -04:00
|
|
|
return devForkedEntry;
|
|
|
|
|
}
|
2020-02-25 13:54:27 -08:00
|
|
|
if (fs.existsSync(resolvedForkedEntry)) {
|
|
|
|
|
return resolvedForkedEntry;
|
|
|
|
|
}
|
|
|
|
|
// Just use the plain .js one.
|
|
|
|
|
return resolvedEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
async function createBundle(bundle, bundleType) {
|
2020-05-28 15:04:25 -07:00
|
|
|
const filename = getFilename(bundle, bundleType);
|
2017-04-20 11:18:33 -07:00
|
|
|
const logKey =
|
|
|
|
|
chalk.white.bold(filename) + chalk.dim(` (${bundleType.toLowerCase()})`);
|
2017-04-05 16:47:29 +01:00
|
|
|
const format = getFormat(bundleType);
|
2017-10-25 02:55:00 +03:00
|
|
|
const packageName = Packaging.getPackageName(bundle.entry);
|
|
|
|
|
|
2024-04-17 11:15:27 -07:00
|
|
|
const {isFBWWWBundle, isFBRNBundle} = getBundleTypeFlags(bundleType);
|
2020-07-20 13:37:04 -04:00
|
|
|
|
2025-02-13 18:26:36 +01:00
|
|
|
const resolvedEntry = resolveEntryFork(
|
2020-02-25 13:54:27 -08:00
|
|
|
require.resolve(bundle.entry),
|
2024-06-19 14:19:48 -04:00
|
|
|
isFBWWWBundle || isFBRNBundle,
|
|
|
|
|
!isProductionBundleType(bundleType)
|
2020-02-25 13:54:27 -08:00
|
|
|
);
|
2017-10-25 02:55:00 +03:00
|
|
|
|
2018-05-18 00:16:03 +08:00
|
|
|
const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
|
2017-10-25 02:55:00 +03:00
|
|
|
let externals = Object.keys(peerGlobals);
|
2024-04-17 11:15:27 -07:00
|
|
|
|
|
|
|
|
const deps = Modules.getDependencies(bundleType, bundle.entry);
|
|
|
|
|
externals = externals.concat(deps);
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2017-11-02 19:50:03 +00:00
|
|
|
const importSideEffects = Modules.getImportSideEffects();
|
|
|
|
|
const pureExternalModules = Object.keys(importSideEffects).filter(
|
|
|
|
|
module => !importSideEffects[module]
|
|
|
|
|
);
|
|
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
const rollupConfig = {
|
|
|
|
|
input: resolvedEntry,
|
2017-12-11 16:54:12 +00:00
|
|
|
treeshake: {
|
2023-02-20 13:04:26 +08:00
|
|
|
moduleSideEffects: (id, external) =>
|
|
|
|
|
!(external && pureExternalModules.includes(id)),
|
2023-02-20 17:35:56 +11:00
|
|
|
propertyReadSideEffects: false,
|
2017-12-11 16:54:12 +00:00
|
|
|
},
|
2017-12-06 20:11:32 +00:00
|
|
|
external(id) {
|
|
|
|
|
const containsThisModule = pkg => id === pkg || id.startsWith(pkg + '/');
|
|
|
|
|
const isProvidedByDependency = externals.some(containsThisModule);
|
2024-04-17 11:15:27 -07:00
|
|
|
if (isProvidedByDependency) {
|
2021-03-24 02:43:55 +00:00
|
|
|
if (id.indexOf('/src/') !== -1) {
|
|
|
|
|
throw Error(
|
|
|
|
|
'You are trying to import ' +
|
|
|
|
|
id +
|
|
|
|
|
' but ' +
|
|
|
|
|
externals.find(containsThisModule) +
|
|
|
|
|
' is one of npm dependencies, ' +
|
|
|
|
|
'so it will not contain that source file. You probably want ' +
|
|
|
|
|
'to create a new bundle entry point for it instead.'
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-12-06 20:11:32 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return !!peerGlobals[id];
|
|
|
|
|
},
|
|
|
|
|
onwarn: handleRollupWarning,
|
|
|
|
|
plugins: getPlugins(
|
|
|
|
|
bundle.entry,
|
|
|
|
|
externals,
|
|
|
|
|
bundle.babel,
|
|
|
|
|
filename,
|
2017-12-23 14:22:59 -05:00
|
|
|
packageName,
|
2017-12-06 20:11:32 +00:00
|
|
|
bundleType,
|
|
|
|
|
bundle.global,
|
|
|
|
|
bundle.moduleType,
|
2020-03-12 11:38:32 -07:00
|
|
|
pureExternalModules,
|
|
|
|
|
bundle
|
2017-12-06 20:11:32 +00:00
|
|
|
),
|
2020-02-20 23:09:30 +01:00
|
|
|
output: {
|
|
|
|
|
externalLiveBindings: false,
|
|
|
|
|
freeze: false,
|
Update Rollup to 3.x (#26442)
<!--
Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.
Before submitting a pull request, please make sure the following is
done:
1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
10. If you haven't already, complete the CLA.
Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->
## Summary
This PR:
- Updates Rollup from 2.x to latest 3.x, and updates associated plugins
- Updates deprecated / altered config settings in the Rollup plugin
pipeline
- Fixes some file extension and import issues related to use of ESM in
`react-dom-webpack-server`
- Removes a now-obsolete `strip-unused-imports` Rollup plugin
- <s>Fixes an _existing_ bug with the Rollup 2.x plugin pipeline on
`main` that was causing parts of `DOMProperty.js` to get left out of the
`react-dom-webpack-server` JS bundles, by adding a new plugin to tell
Rollup to treat that file as if it as side effects</s>
This PR should be functionally identical to the other existing "Rollup 3
upgrade" PR at #26078 . I'm filing this as a near-duplicate because I'm
ready to push this change through ASAP so that I can follow it up with a
PR that adds sourcemap support, that PR's artifact diffing seems like
it's possibly stuck and I want to compare the build results, and I've
got this set up against latest `main`.
<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This gets React's build setup updated to the latest Rollup version,
which is generally a good practice, but also ensures that any further
Rollup config tweaks can be done using the current Rollup docs as a
reference.
## How did you test this change?
<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
If you leave this empty, your PR will very likely be closed.
-->
- Made builds from the latest `main`
- Updated Rollup package versions and cross-compared the changes I
needed to make locally to get successful builds vs #26078
- Diffed the output folders between `main` and this PR, and confirmed
that the bundle contents are identical (with the exception of version
strings and the `react-dom-webpack-server` bundle fix re-adding missing
`DOMProperty.js` content)
2023-03-24 14:08:41 -04:00
|
|
|
interop: getRollupInteropValue,
|
2020-02-20 23:09:30 +01:00
|
|
|
esModule: false,
|
|
|
|
|
},
|
2017-12-06 20:11:32 +00:00
|
|
|
};
|
2020-04-02 17:52:32 -07:00
|
|
|
const mainOutputPath = Packaging.getBundleOutputPath(
|
2022-10-14 23:29:17 -04:00
|
|
|
bundle,
|
2017-12-06 20:11:32 +00:00
|
|
|
bundleType,
|
|
|
|
|
filename,
|
|
|
|
|
packageName
|
|
|
|
|
);
|
2022-11-17 13:15:56 -08:00
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
const rollupOutputOptions = getRollupOutputOptions(
|
|
|
|
|
mainOutputPath,
|
|
|
|
|
format,
|
|
|
|
|
peerGlobals,
|
2018-05-22 08:16:59 -07:00
|
|
|
bundle.global,
|
|
|
|
|
bundleType
|
2017-12-06 20:11:32 +00:00
|
|
|
);
|
|
|
|
|
|
2019-04-25 07:55:44 -04:00
|
|
|
if (isWatchMode) {
|
|
|
|
|
rollupConfig.output = [rollupOutputOptions];
|
|
|
|
|
const watcher = rollup.watch(rollupConfig);
|
|
|
|
|
watcher.on('event', async event => {
|
|
|
|
|
switch (event.code) {
|
|
|
|
|
case 'BUNDLE_START':
|
|
|
|
|
console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`);
|
|
|
|
|
break;
|
|
|
|
|
case 'BUNDLE_END':
|
|
|
|
|
console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`);
|
|
|
|
|
break;
|
|
|
|
|
case 'ERROR':
|
|
|
|
|
case 'FATAL':
|
|
|
|
|
console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`);
|
|
|
|
|
handleRollupError(event.error);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`);
|
|
|
|
|
try {
|
|
|
|
|
const result = await rollup.rollup(rollupConfig);
|
|
|
|
|
await result.write(rollupOutputOptions);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`);
|
|
|
|
|
handleRollupError(error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`);
|
2017-12-06 20:11:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleRollupWarning(warning) {
|
|
|
|
|
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
|
2023-02-20 17:35:56 +11:00
|
|
|
const match = warning.message.match(/external module "([^"]+)"/);
|
2017-12-06 20:11:32 +00:00
|
|
|
if (!match || typeof match[1] !== 'string') {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Could not parse a Rollup warning. ' + 'Fix this method.'
|
2017-11-27 17:57:28 +00:00
|
|
|
);
|
|
|
|
|
}
|
2017-12-06 20:11:32 +00:00
|
|
|
const importSideEffects = Modules.getImportSideEffects();
|
|
|
|
|
const externalModule = match[1];
|
|
|
|
|
if (typeof importSideEffects[externalModule] !== 'boolean') {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'An external module "' +
|
|
|
|
|
externalModule +
|
|
|
|
|
'" is used in a DEV-only code path ' +
|
|
|
|
|
'but we do not know if it is safe to omit an unused require() to it in production. ' +
|
|
|
|
|
'Please add it to the `importSideEffects` list in `scripts/rollup/modules.js`.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// Don't warn. We will remove side effectless require() in a later pass.
|
|
|
|
|
return;
|
2017-11-27 17:57:28 +00:00
|
|
|
}
|
2018-05-21 15:38:46 +01:00
|
|
|
|
2020-02-20 23:09:30 +01:00
|
|
|
if (warning.code === 'CIRCULAR_DEPENDENCY') {
|
|
|
|
|
// Ignored
|
|
|
|
|
} else if (typeof warning.code === 'string') {
|
2018-05-21 15:38:46 +01:00
|
|
|
// This is a warning coming from Rollup itself.
|
|
|
|
|
// These tend to be important (e.g. clashes in namespaced exports)
|
|
|
|
|
// so we'll fail the build on any of them.
|
|
|
|
|
console.error();
|
|
|
|
|
console.error(warning.message || warning);
|
|
|
|
|
console.error();
|
|
|
|
|
process.exit(1);
|
|
|
|
|
} else {
|
|
|
|
|
// The warning is from one of the plugins.
|
|
|
|
|
// Maybe it's not important, so just print it.
|
|
|
|
|
console.warn(warning.message || warning);
|
|
|
|
|
}
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
function handleRollupError(error) {
|
|
|
|
|
loggedErrors.add(error);
|
|
|
|
|
if (!error.code) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.error(
|
|
|
|
|
`\x1b[31m-- ${error.code}${error.plugin ? ` (${error.plugin})` : ''} --`
|
|
|
|
|
);
|
2018-05-14 17:49:41 +01:00
|
|
|
console.error(error.stack);
|
|
|
|
|
if (error.loc && error.loc.file) {
|
|
|
|
|
const {file, line, column} = error.loc;
|
2017-12-06 20:11:32 +00:00
|
|
|
// This looks like an error from Rollup, e.g. missing export.
|
|
|
|
|
// We'll use the accurate line numbers provided by Rollup but
|
|
|
|
|
// use Babel code frame because it looks nicer.
|
|
|
|
|
const rawLines = fs.readFileSync(file, 'utf-8');
|
|
|
|
|
// column + 1 is required due to rollup counting column start position from 0
|
|
|
|
|
// whereas babel-code-frame counts from 1
|
|
|
|
|
const frame = codeFrame(rawLines, line, column + 1, {
|
|
|
|
|
highlightCode: true,
|
|
|
|
|
});
|
|
|
|
|
console.error(frame);
|
2018-05-14 17:49:41 +01:00
|
|
|
} else if (error.codeFrame) {
|
2017-12-06 20:11:32 +00:00
|
|
|
// This looks like an error from a plugin (e.g. Babel).
|
|
|
|
|
// In this case we'll resort to displaying the provided code frame
|
|
|
|
|
// because we can't be sure the reported location is accurate.
|
|
|
|
|
console.error(error.codeFrame);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
async function buildEverything() {
|
2019-11-08 19:41:40 +00:00
|
|
|
if (!argv['unsafe-partial']) {
|
|
|
|
|
await asyncRimRaf('build');
|
|
|
|
|
}
|
2019-05-29 21:30:16 -07:00
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
// Run them serially for better console output
|
|
|
|
|
// and to avoid any potential race conditions.
|
2019-05-29 14:34:50 -07:00
|
|
|
|
|
|
|
|
let bundles = [];
|
2018-02-09 16:11:22 +00:00
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
2017-12-06 20:11:32 +00:00
|
|
|
for (const bundle of Bundles.bundles) {
|
2019-05-29 14:34:50 -07:00
|
|
|
bundles.push(
|
2020-05-28 15:56:34 -07:00
|
|
|
[bundle, NODE_ES2015],
|
2023-02-21 13:18:24 -05:00
|
|
|
[bundle, ESM_DEV],
|
|
|
|
|
[bundle, ESM_PROD],
|
2019-05-29 14:34:50 -07:00
|
|
|
[bundle, NODE_DEV],
|
|
|
|
|
[bundle, NODE_PROD],
|
|
|
|
|
[bundle, NODE_PROFILING],
|
2022-11-17 13:15:56 -08:00
|
|
|
[bundle, BUN_DEV],
|
|
|
|
|
[bundle, BUN_PROD],
|
2020-02-13 20:33:53 +00:00
|
|
|
[bundle, FB_WWW_DEV],
|
|
|
|
|
[bundle, FB_WWW_PROD],
|
|
|
|
|
[bundle, FB_WWW_PROFILING],
|
2019-05-29 14:34:50 -07:00
|
|
|
[bundle, RN_OSS_DEV],
|
|
|
|
|
[bundle, RN_OSS_PROD],
|
2020-05-28 15:04:25 -07:00
|
|
|
[bundle, RN_OSS_PROFILING],
|
|
|
|
|
[bundle, RN_FB_DEV],
|
|
|
|
|
[bundle, RN_FB_PROD],
|
2022-10-14 23:29:17 -04:00
|
|
|
[bundle, RN_FB_PROFILING],
|
2025-02-16 09:38:13 -06:00
|
|
|
[bundle, BROWSER_SCRIPT],
|
|
|
|
|
[bundle, CJS_DTS],
|
|
|
|
|
[bundle, ESM_DTS]
|
2019-05-29 14:34:50 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 22:16:23 +01:00
|
|
|
bundles = bundles.filter(([bundle, bundleType]) => {
|
|
|
|
|
return !shouldSkipBundle(bundle, bundleType);
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-29 18:51:17 -04:00
|
|
|
if (process.env.CI_TOTAL && process.env.CI_INDEX) {
|
|
|
|
|
const nodeTotal = parseInt(process.env.CI_TOTAL, 10);
|
|
|
|
|
const nodeIndex = parseInt(process.env.CI_INDEX, 10);
|
2019-05-29 14:34:50 -07:00
|
|
|
bundles = bundles.filter((_, i) => i % nodeTotal === nodeIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
|
|
|
for (const [bundle, bundleType] of bundles) {
|
|
|
|
|
await createBundle(bundle, bundleType);
|
2017-12-06 20:11:32 +00:00
|
|
|
}
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
await Packaging.copyAllShims();
|
|
|
|
|
await Packaging.prepareNpmPackages();
|
2017-04-05 16:47:29 +01:00
|
|
|
|
2017-12-06 20:11:32 +00:00
|
|
|
if (syncFBSourcePath) {
|
2018-04-18 13:16:50 -07:00
|
|
|
await Sync.syncReactNative(syncFBSourcePath);
|
2017-12-06 20:11:32 +00:00
|
|
|
} else if (syncWWWPath) {
|
|
|
|
|
await Sync.syncReactDom('build/facebook-www', syncWWWPath);
|
2017-04-05 16:47:29 +01:00
|
|
|
}
|
2017-12-06 20:11:32 +00:00
|
|
|
|
|
|
|
|
console.log(Stats.printResults());
|
2017-12-07 22:47:56 +00:00
|
|
|
if (!forcePrettyOutput) {
|
|
|
|
|
Stats.saveResults();
|
|
|
|
|
}
|
2017-12-06 20:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildEverything();
|