Skip to content

Commit c860868

Browse files
committed
[compiler] Migrate compiler packages to tsup
Currently in the `compiler` workspace, we invoke esbuild directly to build most packages (with the exception of `snap`). This has been mostly fine, but does not allow us to do things like generate type declaration files. I would like #32416 to be able to consume the merged eslint-plugin-react-compiler from source rather than via npm, and one of the things that has come up from my exploration in that stack using the compiler from source is that babel-plugin-react-compiler is missing type declarations. [`tsup`](https://github.com/egoist/tsup) is esbuild based so build performance is comparable. It it is a little bit slower now because we also generate d.ts files, but it's still much faster than rollup which we used prior to esbuild. ``` # build all compiler packages $ time yarn build ✨ Done in 30.69s. yarn build 43.57s user 3.20s system 150% cpu 31.061 total ``` I still need to test if this unblocks #32416 but this stack can be landed independently though as we could probably just release type declarations on npm. No one should be using the compiler directly, but if they really wanted to, lack of type declarations would not stop them (cf React secret internals). Note that I still kept esbuild as we still use it directly for forgive.
1 parent cc68006 commit c860868

File tree

19 files changed

+515
-296
lines changed

19 files changed

+515
-296
lines changed

compiler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"prettier-plugin-hermes-parser": "^0.26.0",
3838
"prompt-promise": "^1.0.3",
3939
"rimraf": "^5.0.10",
40+
"tsup": "^8.4.0",
4041
"typescript": "^5.4.3",
4142
"wait-on": "^7.2.0",
4243
"yargs": "^17.7.2"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
"!*.tsbuildinfo"
1010
],
1111
"scripts": {
12-
"build": "rimraf dist && scripts/build.js",
12+
"build": "rimraf dist && tsup",
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",
1919
"lint": "yarn eslint src",
20-
"watch": "scripts/build.js --watch"
20+
"watch": "yarn build --watch"
2121
},
2222
"dependencies": {
2323
"@babel/types": "^7.19.0"

compiler/packages/babel-plugin-react-compiler/scripts/build.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
"moduleResolution": "Bundler",
66
"rootDir": "src",
77
"outDir": "dist",
8-
// https://github.com/microsoft/TypeScript/issues/30925
9-
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
108
"jsx": "react-jsxdev",
119
// weaken strictness from preset
1210
"importsNotUsedAsValues": "remove",
@@ -16,7 +14,6 @@
1614
"target": "ES2015",
1715
// ideally turn off only during dev, or on a per-file basis
1816
"noUnusedLocals": false,
19-
"composite": true,
2017
"removeComments": true
2118
},
2219
"exclude": [
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {defineConfig} from 'tsup';
2+
3+
export default defineConfig({
4+
entry: ['./src/index.ts'],
5+
outDir: './dist',
6+
external: ['@babel/types'],
7+
splitting: false,
8+
sourcemap: false,
9+
dts: true,
10+
bundle: true,
11+
format: 'cjs',
12+
platform: 'node',
13+
banner: {
14+
js: `/**
15+
* Copyright (c) Meta Platforms, Inc. and affiliates.
16+
*
17+
* This source code is licensed under the MIT license found in the
18+
* LICENSE file in the root directory of this source tree.
19+
*
20+
* @lightSyntaxTransform
21+
* @noflow
22+
* @nolint
23+
* @preventMunge
24+
* @preserve-invariant-messages
25+
*/
26+
27+
"use no memo";`,
28+
},
29+
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +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 && scripts/build.js",
8-
"test": "tsc && jest",
9-
"watch": "scripts/build.js --watch"
7+
"build": "rimraf dist && tsup",
8+
"test": "jest",
9+
"watch": "yarn build --watch"
1010
},
1111
"files": [
1212
"dist"

compiler/packages/eslint-plugin-react-compiler/scripts/build.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

compiler/packages/eslint-plugin-react-compiler/src/index.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@
77

88
import ReactCompilerRule from './rules/ReactCompilerRule';
99

10-
module.exports = {
11-
rules: {
12-
'react-compiler': ReactCompilerRule,
13-
},
14-
configs: {
15-
recommended: {
16-
plugins: {
17-
'react-compiler': {
18-
rules: {
19-
'react-compiler': ReactCompilerRule,
20-
},
10+
const meta = {
11+
name: 'eslint-plugin-react-compiler',
12+
};
13+
14+
const rules = {
15+
'react-compiler': ReactCompilerRule,
16+
};
17+
18+
const configs = {
19+
recommended: {
20+
plugins: {
21+
'react-compiler': {
22+
rules: {
23+
'react-compiler': ReactCompilerRule,
2124
},
2225
},
23-
rules: {
24-
'react-compiler/react-compiler': 'error',
25-
},
26+
},
27+
rules: {
28+
'react-compiler/react-compiler': 'error',
2629
},
2730
},
2831
};
32+
33+
export {configs, rules, meta};

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"rootDir": "../",
77
"noEmit": true,
88
"jsx": "react-jsxdev",
9-
"paths": {
10-
"*": ["./src/types/*"]
11-
},
129

1310
// weaken strictness from preset
1411
"importsNotUsedAsValues": "remove",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {defineConfig} from 'tsup';
2+
3+
export default defineConfig({
4+
entry: ['./src/index.ts'],
5+
outDir: './dist',
6+
external: [
7+
'@babel/core',
8+
'@babel/plugin-proposal-private-methods',
9+
'hermes-parser',
10+
'zod',
11+
'zod-validation-error',
12+
],
13+
splitting: false,
14+
sourcemap: false,
15+
dts: true,
16+
bundle: true,
17+
format: 'cjs',
18+
platform: 'node',
19+
banner: {
20+
js: `/**
21+
* Copyright (c) Meta Platforms, Inc. and affiliates.
22+
*
23+
* This source code is licensed under the MIT license found in the
24+
* LICENSE file in the root directory of this source tree.
25+
*
26+
* @lightSyntaxTransform
27+
* @noflow
28+
* @nolint
29+
* @preventMunge
30+
* @preserve-invariant-messages
31+
*/
32+
33+
"use no memo";`,
34+
},
35+
});

0 commit comments

Comments
 (0)