Don't use "composite": true in tsc (until it supports cycles) (#13242)
* [ts] Don't use project references * Commit `tsconfig.json` so it's ready-to-go * Remove `clean-tsconfig` task * Fix dts generation * Add comment * `yarn` * Review * Fix regexp
This commit is contained in:
parent
07440424d9
commit
175a51f94e
3
.gitignore
vendored
3
.gitignore
vendored
@ -71,8 +71,7 @@ packages/babel-standalone/babel.min.js
|
||||
!/packages/babel-eslint-plugin/LICENSE
|
||||
/.vscode
|
||||
|
||||
tsconfig.json
|
||||
tsconfig.tsbuildinfo
|
||||
/dts
|
||||
|
||||
/test/runtime-integration/*/output.js
|
||||
/test/runtime-integration/*/absolute-output.js
|
||||
|
||||
37
Gulpfile.mjs
37
Gulpfile.mjs
@ -2,7 +2,6 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
import { createRequire } from "module";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import plumber from "gulp-plumber";
|
||||
import through from "through2";
|
||||
import chalk from "chalk";
|
||||
@ -31,7 +30,6 @@ const monorepoRoot = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const defaultPackagesGlob = "./@(codemods|packages|eslint)/*";
|
||||
const defaultSourcesGlob = `${defaultPackagesGlob}/src/**/{*.js,*.cjs,!(*.d).ts}`;
|
||||
const defaultDtsGlob = `${defaultPackagesGlob}/lib/**/*.d.ts{,.map}`;
|
||||
|
||||
const babelStandalonePluginConfigGlob =
|
||||
"./packages/babel-standalone/scripts/pluginConfig.json";
|
||||
@ -61,6 +59,13 @@ function mapSrcToLib(srcPath) {
|
||||
return parts.join(path.sep);
|
||||
}
|
||||
|
||||
function mapToDts(packageName) {
|
||||
return packageName.replace(
|
||||
/(?<=\\|\/|^)(packages|eslint|codemods)(?=\\|\/)/,
|
||||
"dts"
|
||||
);
|
||||
}
|
||||
|
||||
function getIndexFromPackage(name) {
|
||||
try {
|
||||
fs.statSync(`./${name}/src/index.ts`);
|
||||
@ -193,12 +198,6 @@ export const all = {${allList}};`;
|
||||
.pipe(gulp.dest(dest));
|
||||
}
|
||||
|
||||
function unlink() {
|
||||
return through.obj(function (file, enc, callback) {
|
||||
fs.unlink(file.path, () => callback());
|
||||
});
|
||||
}
|
||||
|
||||
function finish(stream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("end", resolve);
|
||||
@ -422,19 +421,20 @@ function buildRollupDts(packages) {
|
||||
const sourcemap = process.env.NODE_ENV === "production";
|
||||
return Promise.all(
|
||||
packages.map(async packageName => {
|
||||
const input = `${packageName}/lib/index.d.ts`;
|
||||
fancyLog(`Bundling '${chalk.cyan(input)}' with rollup ...`);
|
||||
const input = `${mapToDts(packageName)}/src/index.d.ts`;
|
||||
const output = `${packageName}/lib/index.d.ts`;
|
||||
fancyLog(`Bundling '${chalk.cyan(output)}' with rollup ...`);
|
||||
|
||||
const bundle = await rollup({
|
||||
input,
|
||||
plugins: [rollupDts()],
|
||||
onwarn(warning, warn) {
|
||||
if (warning.code !== "CIRCULAR_DEPENDENCY") warn(warning);
|
||||
},
|
||||
});
|
||||
|
||||
await finish(
|
||||
gulp.src(`${packageName}/lib/**/*.d.ts{,.map}`).pipe(unlink())
|
||||
);
|
||||
|
||||
await bundle.write({
|
||||
file: `${packageName}/lib/index.d.ts`,
|
||||
file: output,
|
||||
format: "es",
|
||||
sourcemap: sourcemap,
|
||||
exports: "named",
|
||||
@ -443,13 +443,9 @@ function buildRollupDts(packages) {
|
||||
);
|
||||
}
|
||||
|
||||
function removeDts(exclude) {
|
||||
return getFiles(defaultDtsGlob, { exclude }).pipe(unlink());
|
||||
}
|
||||
|
||||
function copyDts(packages) {
|
||||
return getFiles(`${defaultPackagesGlob}/src/**/*.d.ts`, { include: packages })
|
||||
.pipe(rename(file => path.resolve(file.base, mapSrcToLib(file.relative))))
|
||||
.pipe(rename(file => path.resolve(file.base, mapToDts(file.relative))))
|
||||
.pipe(gulp.dest(monorepoRoot));
|
||||
}
|
||||
|
||||
@ -516,7 +512,6 @@ gulp.task(
|
||||
"bundle-dts",
|
||||
gulp.series("copy-dts", () => buildRollupDts(dtsBundles))
|
||||
);
|
||||
gulp.task("clean-dts", () => removeDts(/* exclude */ dtsBundles));
|
||||
|
||||
gulp.task("build-babel", () => buildBabel(/* exclude */ libBundles));
|
||||
|
||||
|
||||
13
Makefile
13
Makefile
@ -76,6 +76,7 @@ flowcheck-ci:
|
||||
code-quality: tscheck flow lint
|
||||
|
||||
tscheck: generate-tsconfig
|
||||
rm -rf dts
|
||||
$(YARN) tsc -b .
|
||||
|
||||
flow: build-flow-typings
|
||||
@ -109,13 +110,6 @@ clean: test-clean
|
||||
rm -rf packages/*/npm-debug*
|
||||
rm -rf node_modules/.cache
|
||||
|
||||
clean-tsconfig:
|
||||
rm -f tsconfig.json
|
||||
git clean packages/*/tsconfig.json -xfq
|
||||
git clean codemods/*/tsconfig.json -xfq
|
||||
git clean eslint/*/tsconfig.json -xfq
|
||||
rm -f */*/tsconfig.tsbuildinfo
|
||||
|
||||
test-clean:
|
||||
$(foreach source, $(SOURCES), \
|
||||
$(call clean-source-test, $(source)))
|
||||
@ -182,12 +176,9 @@ prepublish-build: clean-lib clean-runtime-helpers
|
||||
STRIP_BABEL_8_FLAG=true $(MAKE) prepublish-build-standalone clone-license prepublish-prepare-dts
|
||||
|
||||
prepublish-prepare-dts:
|
||||
$(MAKE) clean-tsconfig
|
||||
$(MAKE) tscheck
|
||||
$(YARN) gulp bundle-dts
|
||||
$(YARN) gulp clean-dts
|
||||
$(MAKE) build-typescript-legacy-typings
|
||||
$(MAKE) clean-tsconfig
|
||||
|
||||
prepublish:
|
||||
$(MAKE) check-yarn-bug-1882
|
||||
@ -259,7 +250,7 @@ clean-runtime-helpers:
|
||||
rm -f packages/babel-runtime-corejs3/helpers/**/*.mjs
|
||||
rm -rf packages/babel-runtime-corejs2/core-js
|
||||
|
||||
clean-all: clean-tsconfig
|
||||
clean-all:
|
||||
rm -rf node_modules
|
||||
rm -rf package-lock.json
|
||||
rm -rf .changelog
|
||||
|
||||
@ -52,7 +52,6 @@
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"fancy-log": "^1.3.3",
|
||||
"flow-bin": "^0.123.0",
|
||||
"globby": "^11.0.2",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-babel": "^8.0.0",
|
||||
"gulp-filter": "^5.1.0",
|
||||
|
||||
@ -2,16 +2,5 @@
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": [
|
||||
"./typings"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../babel-code-frame"
|
||||
},
|
||||
{
|
||||
"path": "../babel-helper-fixtures"
|
||||
},
|
||||
{
|
||||
"path": "../babel-helper-validator-identifier"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { createRequire } from "module";
|
||||
import { fileURLToPath } from "url";
|
||||
import globby from "globby";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const root = path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
@ -18,15 +14,9 @@ function getTsPkgs(subRoot) {
|
||||
.map(name => ({
|
||||
name: name.replace(/^babel-/, "@babel/"),
|
||||
dir: path.resolve(root, subRoot, name),
|
||||
relative: `./${subRoot}/${name}`,
|
||||
}))
|
||||
.filter(({ dir }) => {
|
||||
try {
|
||||
fs.statSync(path.join(dir, "src", "index.ts"));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
.filter(({ dir }) => fs.existsSync(path.join(dir, "src", "index.ts")));
|
||||
}
|
||||
|
||||
const tsPkgs = [
|
||||
@ -35,81 +25,18 @@ const tsPkgs = [
|
||||
...getTsPkgs("codemods"),
|
||||
];
|
||||
|
||||
function sourceDeps(packageDir) {
|
||||
const files = globby.sync(`src/**/*.ts`, {
|
||||
cwd: packageDir,
|
||||
onlyFiles: true,
|
||||
dot: true,
|
||||
ignore: ["**/node_modules/**"],
|
||||
});
|
||||
const result = new Set();
|
||||
for (const file of files) {
|
||||
const filename = path.join(packageDir, file);
|
||||
const source = fs.readFileSync(filename, { encoding: "utf8" });
|
||||
|
||||
for (const [importSource] of source.matchAll(
|
||||
/(?<=from\s*")@babel\/[^"/]+/g
|
||||
)) {
|
||||
result.add(importSource);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
for (const { dir } of tsPkgs) {
|
||||
const pkg = require(`${dir}/package.json`);
|
||||
|
||||
try {
|
||||
const tsconfig = require(`${dir}/tsconfig.json`);
|
||||
// Don't overwrite manually written configs
|
||||
if (!tsconfig.generated) continue;
|
||||
} catch {}
|
||||
|
||||
const deps = new Set([
|
||||
...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
|
||||
...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []),
|
||||
// todo(flow->ts): update dependencies in package.json if dependency declared incorrectly
|
||||
...sourceDeps(dir),
|
||||
]);
|
||||
|
||||
const references = [];
|
||||
for (const dep of deps) {
|
||||
if (!dep.startsWith("@babel/")) continue;
|
||||
for (const { name, dir: depDir } of tsPkgs) {
|
||||
if (name === dep) {
|
||||
references.push({ path: path.relative(dir, depDir) });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
path.resolve(dir, "tsconfig.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
generated: true,
|
||||
extends: "../../tsconfig.base.json",
|
||||
compilerOptions: {
|
||||
outDir: "./lib",
|
||||
rootDir: "./src",
|
||||
},
|
||||
include: ["./src/**/*"],
|
||||
references,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
path.resolve(root, `tsconfig.json`),
|
||||
"/* This file is automatically generated by scripts/generators/tconfig.js */\n" +
|
||||
JSON.stringify(
|
||||
{
|
||||
files: [],
|
||||
references: tsPkgs.map(({ dir }) => ({
|
||||
path: path.relative(root, dir),
|
||||
})),
|
||||
extends: "./tsconfig.base.json",
|
||||
include: tsPkgs.map(({ relative }) => `${relative}/src/**/*.ts`),
|
||||
compilerOptions: {
|
||||
paths: Object.fromEntries(
|
||||
tsPkgs.map(({ name, relative }) => [name, [`${relative}/src`]])
|
||||
),
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"composite": true,
|
||||
"declarationDir": "./dts",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
|
||||
114
tsconfig.json
Normal file
114
tsconfig.json
Normal file
@ -0,0 +1,114 @@
|
||||
/* This file is automatically generated by scripts/generators/tconfig.js */
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"include": [
|
||||
"./packages/babel-code-frame/src/**/*.ts",
|
||||
"./packages/babel-core/src/**/*.ts",
|
||||
"./packages/babel-generator/src/**/*.ts",
|
||||
"./packages/babel-helper-annotate-as-pure/src/**/*.ts",
|
||||
"./packages/babel-helper-explode-assignable-expression/src/**/*.ts",
|
||||
"./packages/babel-helper-fixtures/src/**/*.ts",
|
||||
"./packages/babel-helper-function-name/src/**/*.ts",
|
||||
"./packages/babel-helper-get-function-arity/src/**/*.ts",
|
||||
"./packages/babel-helper-hoist-variables/src/**/*.ts",
|
||||
"./packages/babel-helper-member-expression-to-functions/src/**/*.ts",
|
||||
"./packages/babel-helper-module-imports/src/**/*.ts",
|
||||
"./packages/babel-helper-module-transforms/src/**/*.ts",
|
||||
"./packages/babel-helper-optimise-call-expression/src/**/*.ts",
|
||||
"./packages/babel-helper-replace-supers/src/**/*.ts",
|
||||
"./packages/babel-helper-simple-access/src/**/*.ts",
|
||||
"./packages/babel-helper-split-export-declaration/src/**/*.ts",
|
||||
"./packages/babel-helper-transform-fixture-test-runner/src/**/*.ts",
|
||||
"./packages/babel-helper-validator-identifier/src/**/*.ts",
|
||||
"./packages/babel-helper-validator-option/src/**/*.ts",
|
||||
"./packages/babel-highlight/src/**/*.ts",
|
||||
"./packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/**/*.ts",
|
||||
"./packages/babel-plugin-proposal-async-do-expressions/src/**/*.ts",
|
||||
"./packages/babel-plugin-syntax-async-do-expressions/src/**/*.ts",
|
||||
"./packages/babel-template/src/**/*.ts",
|
||||
"./packages/babel-traverse/src/**/*.ts",
|
||||
"./packages/babel-types/src/**/*.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@babel/code-frame": [
|
||||
"./packages/babel-code-frame/src"
|
||||
],
|
||||
"@babel/core": [
|
||||
"./packages/babel-core/src"
|
||||
],
|
||||
"@babel/generator": [
|
||||
"./packages/babel-generator/src"
|
||||
],
|
||||
"@babel/helper-annotate-as-pure": [
|
||||
"./packages/babel-helper-annotate-as-pure/src"
|
||||
],
|
||||
"@babel/helper-explode-assignable-expression": [
|
||||
"./packages/babel-helper-explode-assignable-expression/src"
|
||||
],
|
||||
"@babel/helper-fixtures": [
|
||||
"./packages/babel-helper-fixtures/src"
|
||||
],
|
||||
"@babel/helper-function-name": [
|
||||
"./packages/babel-helper-function-name/src"
|
||||
],
|
||||
"@babel/helper-get-function-arity": [
|
||||
"./packages/babel-helper-get-function-arity/src"
|
||||
],
|
||||
"@babel/helper-hoist-variables": [
|
||||
"./packages/babel-helper-hoist-variables/src"
|
||||
],
|
||||
"@babel/helper-member-expression-to-functions": [
|
||||
"./packages/babel-helper-member-expression-to-functions/src"
|
||||
],
|
||||
"@babel/helper-module-imports": [
|
||||
"./packages/babel-helper-module-imports/src"
|
||||
],
|
||||
"@babel/helper-module-transforms": [
|
||||
"./packages/babel-helper-module-transforms/src"
|
||||
],
|
||||
"@babel/helper-optimise-call-expression": [
|
||||
"./packages/babel-helper-optimise-call-expression/src"
|
||||
],
|
||||
"@babel/helper-replace-supers": [
|
||||
"./packages/babel-helper-replace-supers/src"
|
||||
],
|
||||
"@babel/helper-simple-access": [
|
||||
"./packages/babel-helper-simple-access/src"
|
||||
],
|
||||
"@babel/helper-split-export-declaration": [
|
||||
"./packages/babel-helper-split-export-declaration/src"
|
||||
],
|
||||
"@babel/helper-transform-fixture-test-runner": [
|
||||
"./packages/babel-helper-transform-fixture-test-runner/src"
|
||||
],
|
||||
"@babel/helper-validator-identifier": [
|
||||
"./packages/babel-helper-validator-identifier/src"
|
||||
],
|
||||
"@babel/helper-validator-option": [
|
||||
"./packages/babel-helper-validator-option/src"
|
||||
],
|
||||
"@babel/highlight": [
|
||||
"./packages/babel-highlight/src"
|
||||
],
|
||||
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": [
|
||||
"./packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src"
|
||||
],
|
||||
"@babel/plugin-proposal-async-do-expressions": [
|
||||
"./packages/babel-plugin-proposal-async-do-expressions/src"
|
||||
],
|
||||
"@babel/plugin-syntax-async-do-expressions": [
|
||||
"./packages/babel-plugin-syntax-async-do-expressions/src"
|
||||
],
|
||||
"@babel/template": [
|
||||
"./packages/babel-template/src"
|
||||
],
|
||||
"@babel/traverse": [
|
||||
"./packages/babel-traverse/src"
|
||||
],
|
||||
"@babel/types": [
|
||||
"./packages/babel-types/src"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5632,7 +5632,6 @@ __metadata:
|
||||
eslint-plugin-prettier: ^3.1.2
|
||||
fancy-log: ^1.3.3
|
||||
flow-bin: ^0.123.0
|
||||
globby: ^11.0.2
|
||||
gulp: ^4.0.2
|
||||
gulp-babel: ^8.0.0
|
||||
gulp-filter: ^5.1.0
|
||||
@ -8804,7 +8803,7 @@ fsevents@^1.2.7:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"globby@npm:^11.0.1, globby@npm:^11.0.2":
|
||||
"globby@npm:^11.0.1":
|
||||
version: 11.0.2
|
||||
resolution: "globby@npm:11.0.2"
|
||||
dependencies:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user