Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion __tests__/validate-package-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
66 changes: 66 additions & 0 deletions __tests__/validate-tsconfig.test.ts
Original file line number Diff line number Diff line change
@@ -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;
}
});
});
});
5 changes: 3 additions & 2 deletions packages/create-docusaurus/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"module": "es2020",
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/"],
"exclude": ["templates/"]
"include": ["src"],
"exclude": ["templates/", "**/__tests__/**"]
}
3 changes: 2 additions & 1 deletion packages/create-docusaurus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"module": "esnext",
"rootDir": "."
},
"include": ["bin"]
"include": ["bin"],
"exclude": ["**/__tests__/**"]
}
6 changes: 5 additions & 1 deletion packages/docusaurus-cssnano-preset/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
6 changes: 5 additions & 1 deletion packages/docusaurus-logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
5 changes: 4 additions & 1 deletion packages/docusaurus-mdx-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
5 changes: 4 additions & 1 deletion packages/docusaurus-migrate/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
3 changes: 2 additions & 1 deletion packages/docusaurus-migrate/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"allowJs": true,
"rootDir": "."
},
"include": ["bin"]
"include": ["bin"],
"exclude": ["**/__tests__/**"]
}
9 changes: 6 additions & 3 deletions packages/docusaurus-plugin-client-redirects/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
6 changes: 5 additions & 1 deletion packages/docusaurus-plugin-content-blog/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
Expand All @@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/client", "src/*.d.ts"]
"include": ["src/client", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"module": "commonjs",
Expand Down
6 changes: 5 additions & 1 deletion packages/docusaurus-plugin-content-pages/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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__/**"]
}
4 changes: 3 additions & 1 deletion packages/docusaurus-plugin-debug/tsconfig.client.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
Expand All @@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/theme", "src/*.d.ts"]
"include": ["src/theme", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-debug/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"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"]
"exclude": ["src/theme", "**/__tests__/**"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
Expand All @@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/analytics.ts", "src/*.d.ts"]
"include": ["src/analytics.ts", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-google-analytics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"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/analytics.ts"]
"exclude": ["src/analytics.ts", "**/__tests__/**"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
Expand All @@ -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__/**"]
}
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-google-gtag/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"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/gtag.ts"]
"exclude": ["src/gtag.ts", "**/__tests__/**"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
Expand All @@ -9,5 +10,6 @@
"rootDir": "src",
"outDir": "lib"
},
"include": ["src/theme", "src/*.d.ts"]
"include": ["src/theme", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
}
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-ideal-image/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"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"]
"exclude": ["src/theme", "**/__tests__/**"]
}
4 changes: 3 additions & 1 deletion packages/docusaurus-plugin-pwa/tsconfig.client.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
Expand All @@ -14,5 +15,6 @@
"src/*.d.ts",
"src/registerSw.ts",
"src/renderReloadPopup.tsx"
]
],
"exclude": ["**/__tests__/**"]
}
Loading