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-02-20 17:35:56 +11:00
|
|
|
const commonjs = require('@rollup/plugin-commonjs');
|
2023-01-05 15:41:49 -05:00
|
|
|
const flowRemoveTypes = require('flow-remove-types');
|
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');
|
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');
|
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
|
|
|
const path = require('path');
|
2017-04-05 16:47:29 +01:00
|
|
|
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
|
|
|
UMD_DEV,
|
|
|
|
|
UMD_PROD,
|
2018-09-13 17:44:08 -07:00
|
|
|
UMD_PROFILING,
|
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,
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const requestedBundleTypes = argv.type
|
|
|
|
|
? parseRequestedNames([argv.type], 'uppercase')
|
|
|
|
|
: [];
|
|
|
|
|
const requestedBundleNames = parseRequestedNames(argv._, '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
|
|
|
) {
|
|
|
|
|
const canAccessReactObject =
|
|
|
|
|
packageName === 'react' || externals.indexOf('react') !== -1;
|
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) {
|
|
|
|
|
options.plugins.push(
|
2020-04-01 12:08:37 -07:00
|
|
|
...babelToES5Plugins,
|
2019-12-14 18:09:25 +00:00
|
|
|
// Turn console.error/warn() into a custom wrapper
|
|
|
|
|
[
|
|
|
|
|
require('../babel/transform-replace-console-calls'),
|
|
|
|
|
{
|
|
|
|
|
shouldError: !canAccessReactObject,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
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) {
|
|
|
|
|
case UMD_DEV:
|
|
|
|
|
case UMD_PROD:
|
2018-09-13 17:44:08 -07:00
|
|
|
case UMD_PROFILING:
|
2017-04-05 16:47:29 +01:00
|
|
|
return `umd`;
|
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:
|
2017-04-05 16:47:29 +01:00
|
|
|
return `cjs`;
|
2023-02-21 13:18:24 -05:00
|
|
|
case ESM_DEV:
|
|
|
|
|
case ESM_PROD:
|
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 UMD_DEV:
|
|
|
|
|
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 UMD_PROD:
|
|
|
|
|
case NODE_PROD:
|
2022-11-17 13:15:56 -08:00
|
|
|
case BUN_PROD:
|
2018-09-13 17:44:08 -07:00
|
|
|
case UMD_PROFILING:
|
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:
|
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:
|
2018-06-11 13:16:27 -07:00
|
|
|
case UMD_DEV:
|
|
|
|
|
case UMD_PROD:
|
2022-10-14 23:29:17 -04:00
|
|
|
case BROWSER_SCRIPT:
|
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:
|
2018-09-13 17:44:08 -07:00
|
|
|
case UMD_PROFILING:
|
2018-06-11 13:16:27 -07:00
|
|
|
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 isUMDBundle =
|
|
|
|
|
bundleType === UMD_DEV ||
|
|
|
|
|
bundleType === UMD_PROD ||
|
|
|
|
|
bundleType === UMD_PROFILING;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
const shouldBundleDependencies =
|
|
|
|
|
bundleType === UMD_DEV ||
|
|
|
|
|
bundleType === UMD_PROD ||
|
|
|
|
|
bundleType === UMD_PROFILING;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
isUMDBundle,
|
|
|
|
|
isFBWWWBundle,
|
|
|
|
|
isRNBundle,
|
|
|
|
|
isFBRNBundle,
|
|
|
|
|
shouldBundleDependencies,
|
|
|
|
|
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
|
|
|
) {
|
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
|
|
|
|
|
|
|
|
const {isUMDBundle, shouldStayReadable} = getBundleTypeFlags(bundleType);
|
|
|
|
|
|
|
|
|
|
const needsMinifiedByClosure = isProduction && bundleType !== ESM_PROD;
|
|
|
|
|
|
|
|
|
|
// Any other packages that should specifically _not_ have sourcemaps
|
|
|
|
|
const sourcemapPackageExcludes = [
|
|
|
|
|
// Having `//#sourceMappingUrl` for the `react-debug-tools` prod bundle breaks
|
|
|
|
|
// `ReactDevToolsHooksIntegration-test.js`, because it changes Node's generated
|
|
|
|
|
// stack traces and thus alters the hook name parsing behavior.
|
|
|
|
|
// Also, this is an internal-only package that doesn't need sourcemaps anyway
|
|
|
|
|
'react-debug-tools',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Generate sourcemaps for true "production" build artifacts
|
|
|
|
|
// that will be used by bundlers, such as `react-dom.production.min.js`.
|
|
|
|
|
// Also include profiling builds as well.
|
|
|
|
|
// UMD builds are rarely used and not worth having sourcemaps.
|
|
|
|
|
const needsSourcemaps =
|
|
|
|
|
needsMinifiedByClosure &&
|
|
|
|
|
!isUMDBundle &&
|
|
|
|
|
!sourcemapPackageExcludes.includes(entry) &&
|
|
|
|
|
!shouldStayReadable;
|
|
|
|
|
|
2023-08-17 15:17:46 -07:00
|
|
|
return [
|
|
|
|
|
// Keep dynamic imports as externals
|
|
|
|
|
dynamicImports(),
|
|
|
|
|
{
|
|
|
|
|
name: 'rollup-plugin-flow-remove-types',
|
|
|
|
|
transform(code) {
|
|
|
|
|
const transformed = flowRemoveTypes(code);
|
|
|
|
|
return {
|
|
|
|
|
code: transformed.toString(),
|
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
|
|
|
map: null,
|
2023-08-17 15:17:46 -07:00
|
|
|
};
|
|
|
|
|
},
|
2023-02-20 17:35:56 +11:00
|
|
|
},
|
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',
|
|
|
|
|
__UMD__: isUMDBundle ? 'true' : 'false',
|
|
|
|
|
'process.env.NODE_ENV': isProduction
|
|
|
|
|
? "'production'"
|
|
|
|
|
: "'development'",
|
|
|
|
|
__EXPERIMENTAL__,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
// The CommonJS plugin *only* exists to pull "art" into "react-art".
|
|
|
|
|
// I'm going to port "art" to ES modules to avoid this problem.
|
|
|
|
|
// Please don't enable this for anything else!
|
|
|
|
|
isUMDBundle && entry === 'react-art' && commonjs(),
|
|
|
|
|
// License and haste headers, top-level `if` blocks.
|
|
|
|
|
{
|
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: 'license-and-headers',
|
2023-08-17 15:17:46 -07:00
|
|
|
renderChunk(source) {
|
|
|
|
|
return Wrappers.wrapBundle(
|
|
|
|
|
source,
|
|
|
|
|
bundleType,
|
|
|
|
|
globalName,
|
|
|
|
|
filename,
|
|
|
|
|
moduleType,
|
|
|
|
|
bundle.wrapWithModuleBoundaries
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
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
|
|
|
// Apply dead code elimination and/or minification.
|
|
|
|
|
// closure doesn't yet support leaving ESM imports intact
|
|
|
|
|
needsMinifiedByClosure &&
|
|
|
|
|
closure(
|
|
|
|
|
{
|
|
|
|
|
compilation_level: 'SIMPLE',
|
|
|
|
|
language_in: 'ECMASCRIPT_2020',
|
|
|
|
|
language_out:
|
|
|
|
|
bundleType === NODE_ES2015
|
|
|
|
|
? 'ECMASCRIPT_2020'
|
|
|
|
|
: bundleType === BROWSER_SCRIPT
|
|
|
|
|
? 'ECMASCRIPT5'
|
|
|
|
|
: 'ECMASCRIPT5_STRICT',
|
|
|
|
|
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: !isUMDBundle,
|
|
|
|
|
renaming: !shouldStayReadable,
|
|
|
|
|
},
|
|
|
|
|
{needsSourcemaps}
|
|
|
|
|
),
|
|
|
|
|
// Add the whitespace back if necessary.
|
|
|
|
|
shouldStayReadable &&
|
|
|
|
|
prettier({
|
|
|
|
|
parser: 'flow',
|
|
|
|
|
singleQuote: false,
|
|
|
|
|
trailingComma: 'none',
|
|
|
|
|
bracketSpacing: true,
|
|
|
|
|
}),
|
|
|
|
|
needsSourcemaps && {
|
|
|
|
|
name: 'generate-prod-bundle-sourcemaps',
|
|
|
|
|
async renderChunk(codeAfterLicense, chunk, options, meta) {
|
|
|
|
|
// We want to generate a sourcemap that shows the production bundle source
|
|
|
|
|
// as it existed before Closure Compiler minified that chunk, rather than
|
|
|
|
|
// showing the "original" individual source files. This better shows
|
|
|
|
|
// what is actually running in the app.
|
|
|
|
|
|
|
|
|
|
// Use a path like `node_modules/react/cjs/react.production.min.js.map` for the sourcemap file
|
|
|
|
|
const finalSourcemapPath = options.file.replace('.js', '.js.map');
|
|
|
|
|
const finalSourcemapFilename = path.basename(finalSourcemapPath);
|
|
|
|
|
const outputFolder = path.dirname(options.file);
|
|
|
|
|
|
|
|
|
|
// Read the sourcemap that Closure wrote to disk
|
|
|
|
|
const sourcemapAfterClosure = JSON.parse(
|
|
|
|
|
fs.readFileSync(finalSourcemapPath, 'utf8')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Represent the "original" bundle as a file with no `.min` in the name
|
|
|
|
|
const filenameWithoutMin = filename.replace('.min', '');
|
|
|
|
|
// There's _one_ artifact where the incoming filename actually contains
|
|
|
|
|
// a folder name: "use-sync-external-store-shim/with-selector.production.js".
|
|
|
|
|
// The output path already has the right structure, but we need to strip this
|
|
|
|
|
// down to _just_ the JS filename.
|
|
|
|
|
const preMinifiedFilename = path.basename(filenameWithoutMin);
|
|
|
|
|
|
|
|
|
|
// CC generated a file list that only contains the tempfile name.
|
|
|
|
|
// Replace that with a more meaningful "source" name for this bundle
|
|
|
|
|
// that represents "the bundled source before minification".
|
|
|
|
|
sourcemapAfterClosure.sources = [preMinifiedFilename];
|
|
|
|
|
sourcemapAfterClosure.file = filename;
|
|
|
|
|
|
|
|
|
|
// We'll write the pre-minified source to disk as a separate file.
|
|
|
|
|
// Because it sits on disk, there's no need to have it in the `sourcesContent` array.
|
|
|
|
|
// That also makes the file easier to read, and available for use by scripts.
|
|
|
|
|
// This should be the only file in the array.
|
|
|
|
|
const [preMinifiedBundleSource] =
|
|
|
|
|
sourcemapAfterClosure.sourcesContent;
|
|
|
|
|
|
|
|
|
|
// Remove this entirely - we're going to write the file to disk instead.
|
|
|
|
|
delete sourcemapAfterClosure.sourcesContent;
|
|
|
|
|
|
|
|
|
|
const preMinifiedBundlePath = path.join(
|
|
|
|
|
outputFolder,
|
|
|
|
|
preMinifiedFilename
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Write the original source to disk as a separate file
|
|
|
|
|
fs.writeFileSync(preMinifiedBundlePath, preMinifiedBundleSource);
|
|
|
|
|
|
|
|
|
|
// Overwrite the Closure-generated file with the final combined sourcemap
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
|
finalSourcemapPath,
|
|
|
|
|
JSON.stringify(sourcemapAfterClosure)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add the sourcemap URL to the actual bundle, so that tools pick it up
|
|
|
|
|
const sourceWithMappingUrl =
|
|
|
|
|
codeAfterLicense +
|
|
|
|
|
`\n//# sourceMappingURL=${finalSourcemapFilename}`;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
code: sourceWithMappingUrl,
|
|
|
|
|
map: null,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
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) {
|
|
|
|
|
const isAskingForDifferentType = requestedBundleTypes.every(
|
|
|
|
|
requestedType => bundleType.indexOf(requestedType) === -1
|
|
|
|
|
);
|
|
|
|
|
if (isAskingForDifferentType) {
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-25 13:54:27 -08:00
|
|
|
function resolveEntryFork(resolvedEntry, isFBBundle) {
|
|
|
|
|
// Pick which entry point fork to use:
|
|
|
|
|
// .modern.fb.js
|
|
|
|
|
// .classic.fb.js
|
|
|
|
|
// .fb.js
|
|
|
|
|
// .stable.js
|
|
|
|
|
// .experimental.js
|
|
|
|
|
// .js
|
|
|
|
|
|
|
|
|
|
if (isFBBundle) {
|
|
|
|
|
const resolvedFBEntry = resolvedEntry.replace(
|
|
|
|
|
'.js',
|
|
|
|
|
__EXPERIMENTAL__ ? '.modern.fb.js' : '.classic.fb.js'
|
|
|
|
|
);
|
|
|
|
|
if (fs.existsSync(resolvedFBEntry)) {
|
|
|
|
|
return resolvedFBEntry;
|
|
|
|
|
}
|
|
|
|
|
const resolvedGenericFBEntry = resolvedEntry.replace('.js', '.fb.js');
|
|
|
|
|
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'
|
|
|
|
|
);
|
|
|
|
|
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);
|
|
|
|
|
|
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
|
|
|
const {isFBWWWBundle, isFBRNBundle, shouldBundleDependencies} =
|
|
|
|
|
getBundleTypeFlags(bundleType);
|
2020-07-20 13:37:04 -04:00
|
|
|
|
2020-02-25 13:54:27 -08:00
|
|
|
let resolvedEntry = resolveEntryFork(
|
|
|
|
|
require.resolve(bundle.entry),
|
2020-07-20 13:37:04 -04:00
|
|
|
isFBWWWBundle || isFBRNBundle
|
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);
|
|
|
|
|
if (!shouldBundleDependencies) {
|
|
|
|
|
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);
|
|
|
|
|
if (!shouldBundleDependencies && 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, UMD_DEV],
|
|
|
|
|
[bundle, UMD_PROD],
|
|
|
|
|
[bundle, UMD_PROFILING],
|
|
|
|
|
[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],
|
|
|
|
|
[bundle, BROWSER_SCRIPT]
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-31 18:37:32 -04:00
|
|
|
if (process.env.CIRCLE_NODE_TOTAL) {
|
2019-05-29 14:34:50 -07:00
|
|
|
// In CI, parallelize bundles across multiple tasks.
|
|
|
|
|
const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL, 10);
|
|
|
|
|
const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX, 10);
|
|
|
|
|
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();
|