refactor: make each tsconfig explicitly declare module and include/exclude (#7443)

This commit is contained in:
Joshua Chen 2022-05-18 12:48:28 +08:00 committed by GitHub
parent a0b0477dee
commit a555fd1dcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 223 additions and 47 deletions

View file

@ -62,7 +62,9 @@ describe('packages', () => {
const packageJsonFiles = await getPackagesJsonFiles();
packageJsonFiles
.filter((packageJsonFile) => packageJsonFile.content.name.startsWith('@'))
.filter((packageJsonFile) =>
packageJsonFile.content.name?.startsWith('@'),
)
.forEach((packageJsonFile) => {
if (packageJsonFile) {
// Unfortunately jest custom message do not exist in loops,

View file

@ -0,0 +1,66 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import fs from 'fs-extra';
import {Globby} from '@docusaurus/utils';
import {Joi} from '@docusaurus/utils-validation';
type TsconfigFile = {
file: string;
content: {
extends?: string;
compilerOptions: {
[key: string]: unknown;
};
};
};
async function getTsconfigFiles(): Promise<TsconfigFile[]> {
const files = await Globby('packages/*/tsconfig.*');
return Promise.all(
files.map((file) => fs.readJSON(file).then((content) => ({file, content}))),
);
}
const tsconfigSchema = Joi.object({
extends: '../../tsconfig.json',
compilerOptions: Joi.alternatives().conditional(
Joi.object({noEmit: true}).unknown(),
{
then: Joi.object({
noEmit: Joi.valid(true).required(),
incremental: Joi.forbidden(),
tsBuildInfoFile: Joi.forbidden(),
outDir: Joi.forbidden(),
module: Joi.valid('commonjs', 'es2020', 'esnext').required(),
}).unknown(),
otherwise: Joi.object({
noEmit: Joi.valid(false).required(),
incremental: Joi.valid(true).required(),
rootDir: Joi.valid('src').required(),
outDir: Joi.valid('lib').required(),
module: Joi.valid('commonjs', 'es2020', 'esnext').required(),
}).unknown(),
},
),
}).unknown();
describe('tsconfig files', () => {
it('contain all required fields', async () => {
const tsconfigFiles = await getTsconfigFiles();
tsconfigFiles.forEach((file) => {
try {
Joi.attempt(file.content, tsconfigSchema);
} catch (e) {
(
e as Error
).message += `\n${file.file} does not match the required schema.`;
throw e;
}
});
});
});

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"module": "es2020",
"incremental": true,
@ -8,6 +9,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/"],
"exclude": ["templates/"]
"include": ["src"],
"exclude": ["templates/", "**/__tests__/**"]
}

View file

@ -7,5 +7,6 @@
"module": "esnext",
"rootDir": "."
},
"include": ["bin"]
"include": ["bin"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,11 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,12 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"]
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,11 +1,14 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"]
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -7,5 +7,6 @@
"allowJs": true,
"rootDir": "."
},
"include": ["bin"]
"include": ["bin"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,10 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib",
"typeRoots": ["./types", "./node_modules/@types"]
}
"outDir": "lib"
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/client", "src/*.d.ts"]
"include": ["src/client", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/theme", "src/*.d.ts"]
"include": ["src/theme", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
@ -9,5 +10,5 @@
"outDir": "lib"
},
"include": ["src"],
"exclude": ["src/theme"]
"exclude": ["src/theme", "**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/analytics.ts", "src/*.d.ts"]
"include": ["src/analytics.ts", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
@ -9,5 +10,5 @@
"outDir": "lib"
},
"include": ["src"],
"exclude": ["src/analytics.ts"]
"exclude": ["src/analytics.ts", "**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/gtag.ts", "src/options.ts", "src/*.d.ts"]
"include": ["src/gtag.ts", "src/options.ts", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
@ -9,5 +10,5 @@
"outDir": "lib"
},
"include": ["src"],
"exclude": ["src/gtag.ts"]
"exclude": ["src/gtag.ts", "**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/theme", "src/*.d.ts"]
"include": ["src/theme", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
@ -9,5 +10,5 @@
"outDir": "lib"
},
"include": ["src"],
"exclude": ["src/theme"]
"exclude": ["src/theme", "**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -14,5 +15,6 @@
"src/*.d.ts",
"src/registerSw.ts",
"src/renderReloadPopup.tsx"
]
],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,11 +2,18 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"exclude": ["src/theme/", "src/registerSw.ts", "src/renderReloadPopup.tsx"]
"exclude": [
"src/theme/",
"src/registerSw.ts",
"src/renderReloadPopup.tsx",
"**/__tests__/**"
]
}

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,11 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -5,5 +5,6 @@
"module": "esnext",
"noEmit": true
},
"include": ["src/"]
"include": ["src/"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "esnext",
@ -10,5 +11,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"]
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"module": "esnext",
"target": "esnext"
},
"include": ["src/theme", "src/*.d.ts", "src/custom-buble.ts"]
"include": ["src/theme", "src/*.d.ts", "src/custom-buble.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,8 +2,10 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
},

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"module": "esnext",
"target": "esnext"
},
"include": ["src/theme", "src/client", "src/*.d.ts"]
"include": ["src/theme", "src/client", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,8 +2,10 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
},

View file

@ -1,12 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -12,9 +12,6 @@
"directory": "packages/docusaurus-types"
},
"license": "MIT",
"scripts": {
"test": "tsc -p ."
},
"dependencies": {
"commander": "^5.1.0",
"history": "^4.9.0",

View file

@ -1,12 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib",
"noEmitHelpers": false
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,11 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,11 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/client", "src/*.d.ts"]
"include": ["src/client", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}

View file

@ -11,5 +11,6 @@
"rootDir": ".",
"module": "esnext"
},
"include": ["bin"]
"include": ["bin"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -1,9 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib"
}
},
"include": ["src"],
"exclude": ["**/__tests__/**"]
}

View file

@ -2,13 +2,17 @@
"compilerOptions": {
/* Emit */
"target": "ES2020",
"module": "commonjs",
"lib": ["ESNext", "DOM"],
"lib": ["ESNext"],
"declaration": true,
// These two options will be selectively overridden in each project.
// Utility libraries will have source maps on, but plugins will not.
"declarationMap": false,
"sourceMap": false,
"jsx": "react-native",
"importHelpers": true,
"noEmitHelpers": true,
// Avoid accidentally using this config to build
"noEmit": true,
/* Strict Type-Checking Options */
"allowUnreachableCode": false,
@ -44,5 +48,5 @@
"isolatedModules": true,
"skipLibCheck": true // @types/webpack and webpack/types.d.ts are not the same thing
},
"exclude": ["node_modules", "**/__tests__/**", "**/lib/**/*"]
"exclude": ["node_modules", "**/lib/**/*"]
}