Skip to content

Commit 220dece

Browse files
authored
[compiler] Switch to esbuild (facebook#31963)
This migrates the compiler's bundler to esbuild instead of rollup. Unlike React, our bundling use cases are far simpler since the majority of our packages are meant to be run on node. Rollup was adding considerable build time overhead whereas esbuild remains fast and has all the functionality we need out of the box. ### Before ``` time yarn workspaces run build yarn workspaces v1.22.22 > babel-plugin-react-compiler yarn run v1.22.22 $ rimraf dist && rollup --config --bundleConfigAsCjs src/index.ts → dist/index.js... (!) Circular dependencies # ... created dist/index.js in 15.5s ✨ Done in 16.45s. > eslint-plugin-react-compiler yarn run v1.22.22 $ rimraf dist && rollup --config --bundleConfigAsCjs src/index.ts → dist/index.js... (!) Circular dependencies # ... created dist/index.js in 9.1s ✨ Done in 10.11s. > make-read-only-util yarn run v1.22.22 warning package.json: No license field $ tsc ✨ Done in 1.81s. > react-compiler-healthcheck yarn run v1.22.22 $ rimraf dist && rollup --config --bundleConfigAsCjs src/index.ts → dist/index.js... (!) Circular dependencies # ... created dist/index.js in 8.7s ✨ Done in 10.43s. > react-compiler-runtime yarn run v1.22.22 $ rimraf dist && rollup --config --bundleConfigAsCjs src/index.ts → dist/index.js... (!) src/index.ts (1:0): Module level directives cause errors when bundled, "use no memo" in "src/index.ts" was ignored. # ... created dist/index.js in 1.1s ✨ Done in 1.82s. > snap yarn run v1.22.22 $ rimraf dist && concurrently -n snap,runtime "tsc --build" "yarn --silent workspace react-compiler-runtime build --silent" $ rimraf dist && rollup --config --bundleConfigAsCjs --silent [runtime] yarn --silent workspace react-compiler-runtime build --silent exited with code 0 [snap] tsc --build exited with code 0 ✨ Done in 5.73s. ✨ Done in 47.30s. yarn workspaces run build 75.92s user 5.48s system 170% cpu 47.821 total ``` ### After ``` time yarn workspaces run build yarn workspaces v1.22.22 > babel-plugin-react-compiler yarn run v1.22.22 $ rimraf dist && scripts/build.js ✨ Done in 1.02s. > eslint-plugin-react-compiler yarn run v1.22.22 $ rimraf dist && scripts/build.js ✨ Done in 0.93s. > make-read-only-util yarn run v1.22.22 warning package.json: No license field $ rimraf dist && scripts/build.js ✨ Done in 0.89s. > react-compiler-healthcheck yarn run v1.22.22 $ rimraf dist && scripts/build.js ✨ Done in 0.58s. > react-compiler-runtime yarn run v1.22.22 $ rimraf dist && scripts/build.js ✨ Done in 0.48s. > snap yarn run v1.22.22 $ rimraf dist && concurrently -n snap,runtime "tsc --build" "yarn --silent workspace react-compiler-runtime build" $ rimraf dist && scripts/build.js [runtime] yarn --silent workspace react-compiler-runtime build exited with code 0 [snap] tsc --build exited with code 0 ✨ Done in 4.69s. ✨ Done in 9.46s. yarn workspaces run build 9.70s user 0.99s system 103% cpu 10.329 total ``` --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31963). * facebook#31964 * __->__ facebook#31963 * facebook#31962
1 parent c784273 commit 220dece

File tree

20 files changed

+515
-654
lines changed

20 files changed

+515
-654
lines changed

compiler/apps/playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "cd ../.. && concurrently --kill-others -n compiler,runtime,playground \"yarn workspace babel-plugin-react-compiler run build --watch\" \"yarn workspace react-compiler-runtime run build --watch\" \"wait-on packages/babel-plugin-react-compiler/dist/index.js && cd apps/playground && NODE_ENV=development next dev\"",
6+
"dev": "cd ../.. && concurrently --kill-others -n compiler,runtime,playground \"yarn workspace babel-plugin-react-compiler run watch\" \"yarn workspace react-compiler-runtime run watch\" \"wait-on packages/babel-plugin-react-compiler/dist/index.js && cd apps/playground && NODE_ENV=development next dev\"",
77
"build:compiler": "cd ../.. && concurrently -n compiler,runtime \"yarn workspace babel-plugin-react-compiler run build\" \"yarn workspace react-compiler-runtime run build\"",
88
"build": "yarn build:compiler && next build",
99
"postbuild": "node ./scripts/downloadFonts.js",
10+
"preinstall": "cd ../.. && yarn install --frozen-lockfile",
1011
"postinstall": "./scripts/link-compiler.sh",
1112
"vercel-build": "yarn build",
1213
"start": "next start",

compiler/package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"start": "yarn workspace playground run start",
1616
"next": "yarn workspace playground run dev",
1717
"build": "yarn workspaces run build",
18-
"dev": "echo 'DEPRECATED: use `cd apps/playground && yarn dev` instead!' && sleep 5 && cd apps/playground && yarn dev",
18+
"dev": "cd apps/playground && yarn dev",
1919
"test": "yarn workspaces run test",
2020
"snap": "yarn workspace babel-plugin-react-compiler run snap",
2121
"snap:build": "yarn workspace snap run build",
@@ -26,22 +26,15 @@
2626
"react-is": "0.0.0-experimental-4beb1fd8-20241118"
2727
},
2828
"devDependencies": {
29-
"@rollup/plugin-commonjs": "^28.0.2",
30-
"@rollup/plugin-json": "^6.1.0",
31-
"@rollup/plugin-node-resolve": "^16.0.0",
32-
"@rollup/plugin-terser": "^0.4.4",
33-
"@rollup/plugin-typescript": "^12.1.2",
3429
"@tsconfig/strictest": "^2.0.5",
3530
"concurrently": "^7.4.0",
31+
"esbuild": "^0.24.2",
3632
"folder-hash": "^4.0.4",
3733
"object-assign": "^4.1.1",
3834
"ora": "5.4.1",
3935
"prettier": "^3.3.3",
4036
"prettier-plugin-hermes-parser": "^0.26.0",
4137
"prompt-promise": "^1.0.3",
42-
"rollup": "^4.22.4",
43-
"rollup-plugin-banner2": "^1.2.3",
44-
"rollup-plugin-prettier": "^4.1.1",
4538
"typescript": "^5.4.3",
4639
"wait-on": "^7.2.0",
4740
"yargs": "^17.7.2"

compiler/packages/babel-plugin-react-compiler/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
"!*.tsbuildinfo"
1010
],
1111
"scripts": {
12-
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
12+
"build": "rimraf dist && scripts/build.js",
1313
"test": "./scripts/link-react-compiler-runtime.sh && yarn snap:ci",
1414
"jest": "yarn build && ts-node node_modules/.bin/jest",
1515
"snap": "node ../snap/dist/main.js",
1616
"snap:build": "yarn workspace snap run build",
1717
"snap:ci": "yarn snap:build && yarn snap",
1818
"ts:analyze-trace": "scripts/ts-analyze-trace.sh",
19-
"lint": "yarn eslint src"
19+
"lint": "yarn eslint src",
20+
"watch": "scripts/build.js --watch"
2021
},
2122
"dependencies": {
2223
"@babel/types": "^7.19.0"

compiler/packages/babel-plugin-react-compiler/rollup.config.js

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright (c) Meta Platforms, Inc. and affiliates.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
const esbuild = require('esbuild');
11+
const yargs = require('yargs');
12+
const path = require('path');
13+
14+
const argv = yargs(process.argv.slice(2))
15+
.options('w', {
16+
alias: 'watch',
17+
default: false,
18+
type: 'boolean',
19+
})
20+
.parse();
21+
22+
const config = {
23+
entryPoints: [path.join(__dirname, '../src/index.ts')],
24+
outfile: path.join(__dirname, '../dist/index.js'),
25+
bundle: true,
26+
external: ['@babel/types'],
27+
format: 'cjs',
28+
platform: 'node',
29+
banner: {
30+
js: `/**
31+
* Copyright (c) Meta Platforms, Inc. and affiliates.
32+
*
33+
* This source code is licensed under the MIT license found in the
34+
* LICENSE file in the root directory of this source tree.
35+
*
36+
* @lightSyntaxTransform
37+
* @noflow
38+
* @nolint
39+
* @preventMunge
40+
* @preserve-invariant-messages
41+
*/
42+
43+
"use no memo";`,
44+
},
45+
};
46+
47+
async function main() {
48+
if (argv.w) {
49+
const ctx = await esbuild.context(config);
50+
await ctx.watch();
51+
console.log('watching for changes...');
52+
} else {
53+
await esbuild.build({
54+
sourcemap: true,
55+
minify: false,
56+
...config,
57+
});
58+
}
59+
}
60+
61+
main();

compiler/packages/eslint-plugin-react-compiler/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"description": "ESLint plugin to display errors found by the React compiler.",
55
"main": "dist/index.js",
66
"scripts": {
7-
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
8-
"test": "tsc && jest"
7+
"build": "rimraf dist && scripts/build.js",
8+
"test": "tsc && jest",
9+
"watch": "scripts/build.js --watch"
910
},
1011
"files": [
1112
"dist"

compiler/packages/eslint-plugin-react-compiler/rollup.config.js

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright (c) Meta Platforms, Inc. and affiliates.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
const esbuild = require('esbuild');
11+
const yargs = require('yargs');
12+
const path = require('path');
13+
14+
const argv = yargs(process.argv.slice(2))
15+
.options('w', {
16+
alias: 'watch',
17+
default: false,
18+
type: 'boolean',
19+
})
20+
.parse();
21+
22+
const config = {
23+
entryPoints: [path.join(__dirname, '../src/index.ts')],
24+
outfile: path.join(__dirname, '../dist/index.js'),
25+
bundle: true,
26+
external: [
27+
'@babel/core',
28+
'@babel/plugin-proposal-private-methods',
29+
'hermes-parser',
30+
'zod',
31+
'zod-validation-error',
32+
],
33+
format: 'cjs',
34+
platform: 'node',
35+
banner: {
36+
js: `/**
37+
* Copyright (c) Meta Platforms, Inc. and affiliates.
38+
*
39+
* This source code is licensed under the MIT license found in the
40+
* LICENSE file in the root directory of this source tree.
41+
*
42+
* @lightSyntaxTransform
43+
* @noflow
44+
* @nolint
45+
* @preventMunge
46+
* @preserve-invariant-messages
47+
*/
48+
49+
"use no memo";`,
50+
},
51+
};
52+
53+
async function main() {
54+
if (argv.w) {
55+
const ctx = await esbuild.context(config);
56+
await ctx.watch();
57+
console.log('watching for changes...');
58+
} else {
59+
await esbuild.build({
60+
sourcemap: true,
61+
minify: false,
62+
...config,
63+
});
64+
}
65+
}
66+
67+
main();

compiler/packages/make-read-only-util/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"name": "make-read-only-util",
33
"version": "0.0.1",
4+
"license": "MIT",
45
"files": [
56
"src"
67
],
78
"scripts": {
8-
"build": "tsc",
9-
"test": "jest src"
9+
"build": "rimraf dist && scripts/build.js",
10+
"test": "jest src",
11+
"watch": "scripts/build.js --watch"
1012
},
1113
"dependencies": {
1214
"invariant": "^2.2.4",

0 commit comments

Comments
 (0)