Skip to content

Commit ee48754

Browse files
Use multiple TypeScript projects (#16430)
Co-authored-by: Babel Bot <[email protected]>
1 parent 941cee2 commit ee48754

File tree

163 files changed

+5399
-948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+5399
-948
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ jobs:
194194
- name: Extract artifacts
195195
run: tar -xf babel-artifact.tar; rm babel-artifact.tar
196196
- name: Lint
197-
run: make -j prepublish-prepare-dts lint-ci
197+
run: make -j lint-ci check-compat-data
198198
- name: Ensure cwd does not contain uncommitted changes
199199
run: |
200-
node ./scripts/assert-dir-git-clean.js "prepublish-prepare-dts lint-ci"
200+
node ./scripts/assert-dir-git-clean.js "lint-ci check-compat-data"
201201
202202
test:
203203
name: Test on Node.js # GitHub will add ${{ matrix.node-version }} to this title
@@ -287,7 +287,7 @@ jobs:
287287
BABEL_8_BREAKING: true
288288
STRIP_BABEL_8_FLAG: true
289289
- name: Lint
290-
run: make -j tscheck lint-ci
290+
run: make -j lint-ci check-compat-data
291291
env:
292292
BABEL_ENV: test
293293
BABEL_8_BREAKING: true

Gulpfile.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ async function generateTypeHelpers(helperKind, filename = "index.ts") {
154154
* @typedef {("asserts" | "validators")} TraverseHelperKind
155155
* @param {TraverseHelperKind} helperKind
156156
*/
157-
function generateTraverseHelpers(helperKind) {
157+
function generateTraverseHelpers(helperKind, outBase = "") {
158158
return generateHelpers(
159159
`./packages/babel-traverse/scripts/generators/${helperKind}.js`,
160-
`./packages/babel-traverse/src/path/generated/`,
160+
`./packages/babel-traverse/src/${outBase}/generated/`,
161161
`${helperKind}.d.ts`,
162162
`@babel/traverse -> ${helperKind}`
163163
);
@@ -757,8 +757,9 @@ gulp.task("generate-type-helpers", () => {
757757
generateTypeHelpers("constants"),
758758
generateTypeHelpers("validators"),
759759
generateTypeHelpers("ast-types"),
760-
generateTraverseHelpers("asserts"),
761-
generateTraverseHelpers("validators"),
760+
generateTraverseHelpers("asserts", "path"),
761+
generateTraverseHelpers("validators", "path"),
762+
generateTraverseHelpers("visitor-types"),
762763
]);
763764
});
764765

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ build-plugin-transform-runtime-dist:
5555
watch:
5656
$(MAKEJS) watch
5757

58-
code-quality: tscheck lint
58+
code-quality: lint
5959

6060
tscheck:
6161
$(MAKEJS) tscheck
6262

63-
lint-ci: lint check-compat-data
63+
clean-ts:
64+
$(MAKEJS) clean-ts
65+
66+
lint-ci:
67+
$(MAKEJS) lint-ci
6468

6569
generate-readme:
6670
$(NODE) scripts/generators/readmes.js
@@ -87,7 +91,7 @@ test: lint test-only
8791
clone-license:
8892
$(MAKEJS) clone-license
8993

90-
prepublish-prepare-dts:
94+
prepublish-prepare-dts: tscheck
9195
$(MAKEJS) prepublish-prepare-dts
9296

9397
prepublish-build:

Makefile.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile.source.mjs

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ const target = new Proxy(global.target, {
2121
});
2222
const SOURCES = ["packages", "codemods", "eslint"];
2323

24-
const EslintArgs = [
25-
"eslint",
26-
"scripts",
27-
"benchmark",
28-
...SOURCES,
29-
"*.{js,cjs,mjs,ts}",
30-
"--format",
31-
"codeframe",
32-
];
33-
3424
const YARN_PATH = shell.which("yarn").stdout;
3525
const NODE_PATH = process.execPath; // `yarn node` is so slow on Windows
3626

@@ -295,20 +285,26 @@ target["prepublish-build-standalone"] = function () {
295285
};
296286

297287
target["prepublish-prepare-dts"] = function () {
288+
target["clean-ts"]();
298289
target["tscheck"]();
290+
target["prepublish-prepare-dts-no-clean"]();
291+
};
299292

293+
target["prepublish-prepare-dts-no-clean"] = function () {
300294
yarn(["gulp", "bundle-dts"]);
301-
302295
target["build-typescript-legacy-typings"]();
303296
};
304297

305298
target["tscheck"] = function () {
306299
target["generate-tsconfig"]();
300+
node(["scripts/parallel-tsc/tsc.js", "."]);
301+
};
307302

308-
// ts doesn't generate declaration files after we remove the output directory by manually when incremental==true
303+
target["clean-ts"] = function () {
304+
// ts doesn't generate declaration files after we remove the output directory manually when incremental==true
309305
shell.rm("-rf", "tsconfig.tsbuildinfo");
306+
shell.rm("-rf", "*/*/tsconfig.tsbuildinfo");
310307
shell.rm("-rf", "dts");
311-
yarn(["tsc", "-b", "."]);
312308
};
313309

314310
target["generate-tsconfig"] = function () {
@@ -339,15 +335,49 @@ target["clone-license"] = function () {
339335
* DEV
340336
*/
341337

342-
target["lint"] = function () {
343-
env(
344-
() => {
345-
yarn(EslintArgs);
346-
},
347-
{
348-
BABEL_ENV: "test",
349-
}
338+
function eslint(...extraArgs) {
339+
const eslintEnv = { BABEL_ENV: "test" };
340+
const eslintArgs = ["--format", "codeframe", ...extraArgs.filter(Boolean)];
341+
342+
const packagesPackages = readdirSync("packages").filter(n =>
343+
existsSync(`packages/${n}/package.json`)
350344
);
345+
const chunks = [];
346+
// Linting everything at the same time needs too much memory and crashes
347+
// Do it in batches packages
348+
for (let i = 0, chunkSize = 40; i < packagesPackages.length; i += chunkSize) {
349+
chunks.push([
350+
`packages/{${packagesPackages.slice(i, i + chunkSize)}}/**/*`,
351+
]);
352+
}
353+
const rest = [
354+
"eslint",
355+
"codemods",
356+
"scripts",
357+
"benchmark",
358+
"*.{js,cjs,mjs,ts}",
359+
];
360+
chunks.push(rest);
361+
362+
if (process.env.ESLINT_GO_BRRRR) {
363+
// Run as a single process. Needs a lot of memory (12GB).
364+
env(() => yarn(["eslint", "packages", ...rest, ...eslintArgs]), eslintEnv);
365+
} else {
366+
for (const chunk of chunks) {
367+
env(() => yarn(["eslint", ...chunk, ...eslintArgs]), eslintEnv);
368+
}
369+
}
370+
}
371+
372+
target["lint"] = function () {
373+
env(() => target["tscheck"](), { TSCHECK_SILENT: "true" });
374+
eslint();
375+
};
376+
377+
target["lint-ci"] = function () {
378+
target["tscheck"]();
379+
eslint();
380+
target["prepublish-prepare-dts-no-clean"]();
351381
};
352382

353383
target["fix"] = function () {
@@ -356,7 +386,8 @@ target["fix"] = function () {
356386
};
357387

358388
target["fix-js"] = function () {
359-
yarn([...EslintArgs, "--fix"]);
389+
env(() => target["tscheck"](), { TSCHECK_SILENT: "true" });
390+
eslint("--fix");
360391
};
361392

362393
target["fix-json"] = function () {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* This file is automatically generated by scripts/generators/tsconfig.js */
2+
{
3+
"extends": [
4+
"../../tsconfig.base.json",
5+
"../../tsconfig.paths.json"
6+
],
7+
"include": [
8+
"../../codemods/babel-plugin-codemod-object-assign-to-object-spread/src/**/*.ts",
9+
"../../lib/globals.d.ts",
10+
"../../scripts/repo-utils/*.d.ts"
11+
],
12+
"references": [
13+
{
14+
"path": "../../packages/babel-helper-plugin-utils"
15+
}
16+
]
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* This file is automatically generated by scripts/generators/tsconfig.js */
2+
{
3+
"extends": [
4+
"../../tsconfig.base.json",
5+
"../../tsconfig.paths.json"
6+
],
7+
"include": [
8+
"../../codemods/babel-plugin-codemod-optional-catch-binding/src/**/*.ts",
9+
"../../lib/globals.d.ts",
10+
"../../scripts/repo-utils/*.d.ts"
11+
],
12+
"references": [
13+
{
14+
"path": "../../packages/babel-helper-plugin-utils"
15+
}
16+
]
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* This file is automatically generated by scripts/generators/tsconfig.js */
2+
{
3+
"extends": [
4+
"../../tsconfig.base.json",
5+
"../../tsconfig.paths.json"
6+
],
7+
"include": [
8+
"../../eslint/babel-eslint-parser/src/**/*.cts",
9+
"../../lib/globals.d.ts",
10+
"../../scripts/repo-utils/*.d.ts"
11+
],
12+
"references": [
13+
{
14+
"path": "../../packages/babel-helper-plugin-utils"
15+
}
16+
]
17+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"jest": "^30.0.0-alpha.2",
7070
"jest-light-runner": "^0.6.0",
7171
"jest-worker": "^30.0.0-alpha.2",
72+
"json5": "^2.2.3",
7273
"lint-staged": "^15.2.0",
7374
"mergeiterator": "^1.4.4",
7475
"picocolors": "^1.0.0",

packages/babel-cli/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* This file is automatically generated by scripts/generators/tsconfig.js */
2+
{
3+
"extends": [
4+
"../../tsconfig.base.json",
5+
"../../tsconfig.paths.json"
6+
],
7+
"include": [
8+
"../../packages/babel-cli/src/**/*.ts",
9+
"../../lib/globals.d.ts",
10+
"../../scripts/repo-utils/*.d.ts"
11+
],
12+
"references": [
13+
{
14+
"path": "../../packages/babel-helper-plugin-utils"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)