Skip to content

Commit

Permalink
refactor: extract base TS client config + upgrade TS + refactor TS se…
Browse files Browse the repository at this point in the history
…tup (#10065)
  • Loading branch information
slorber committed Apr 19, 2024
1 parent e736dcb commit f88da6c
Show file tree
Hide file tree
Showing 56 changed files with 149 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -32,7 +32,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
// tsconfigRootDir: __dirname,
// project: ['./tsconfig.json', './website/tsconfig.json'],
// project: ['./tsconfig.base.json', './website/tsconfig.base.json'],
},
globals: {
JSX: true,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests-e2e.yml
Expand Up @@ -10,7 +10,7 @@ on:
- yarn.lock
- jest.config.mjs
- packages/**
- tsconfig.json
- tsconfig.*.json
pull_request:
branches:
- main
Expand All @@ -20,7 +20,7 @@ on:
- yarn.lock
- jest.config.mjs
- packages/**
- tsconfig.json
- tsconfig.*.json
- admin/verdaccio.yaml
- .github/workflows/tests-e2e.yml

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-windows.yml
Expand Up @@ -10,7 +10,7 @@ on:
- yarn.lock
- jest.config.mjs
- packages/**
- tsconfig.json
- tsconfig.*.json

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Expand Up @@ -10,7 +10,7 @@ on:
- yarn.lock
- jest.config.mjs
- packages/**
- tsconfig.json
- tsconfig.*.json

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
53 changes: 26 additions & 27 deletions __tests__/validate-tsconfig.test.ts
Expand Up @@ -31,38 +31,37 @@ async function getTsconfigFiles(): Promise<TsconfigFile[]> {
}

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(),
}).unknown(),
otherwise: Joi.object({
noEmit: Joi.valid(false).required(),
incremental: Joi.valid(true).required(),
rootDir: Joi.valid('src').required(),
outDir: Joi.valid('lib').required(),
}).unknown(),
},
extends: Joi.valid(
'../../tsconfig.base.json',
'../../tsconfig.base.client.json',
),
compilerOptions: Joi.object({
rootDir: Joi.valid('src').required(),
outDir: Joi.valid('lib').required(),
tsBuildInfoFile: Joi.valid(
'lib/.tsbuildinfo',
'lib/.tsbuildinfo-client',
'lib/.tsbuildinfo-worker',
),
}).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;
}
});

tsconfigFiles
// Ignore noEmit configs
.filter((file) => !(file.content.compilerOptions!.noEmit === true))
.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;
}
});
});
});
4 changes: 2 additions & 2 deletions packages/create-docusaurus/tsconfig.build.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-docusaurus/tsconfig.json
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.build.json"}],
"compilerOptions": {
"noEmit": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-cssnano-preset/tsconfig.json
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-logger/tsconfig.json
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-mdx-loader/tsconfig.json
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"sourceMap": true,
"declarationMap": true,
"rootDir": "src",
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-client-redirects/tsconfig.json
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
12 changes: 3 additions & 9 deletions packages/docusaurus-plugin-content-blog/tsconfig.client.json
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.client.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
"moduleResolution": "bundler",
"module": "esnext",
"target": "esnext",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"tsBuildInfoFile": "lib/.tsbuildinfo-client"
},
"include": ["src/client", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/tsconfig.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
12 changes: 3 additions & 9 deletions packages/docusaurus-plugin-content-docs/tsconfig.client.json
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.client.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
"moduleResolution": "bundler",
"module": "esnext",
"target": "esnext",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"tsBuildInfoFile": "lib/.tsbuildinfo-client"
},
"include": ["src/client", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/tsconfig.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-pages/tsconfig.json
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
12 changes: 3 additions & 9 deletions packages/docusaurus-plugin-debug/tsconfig.client.json
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.client.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
"moduleResolution": "bundler",
"module": "esnext",
"target": "esnext",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"tsBuildInfoFile": "lib/.tsbuildinfo-client"
},
"include": ["src/theme", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-debug/tsconfig.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
12 changes: 3 additions & 9 deletions packages/docusaurus-plugin-google-analytics/tsconfig.client.json
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.client.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
"moduleResolution": "bundler",
"module": "esnext",
"target": "esnext",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"tsBuildInfoFile": "lib/.tsbuildinfo-client"
},
"include": ["src/analytics.ts", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-google-analytics/tsconfig.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
12 changes: 3 additions & 9 deletions packages/docusaurus-plugin-google-gtag/tsconfig.client.json
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.client.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
"moduleResolution": "bundler",
"module": "esnext",
"target": "esnext",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"tsBuildInfoFile": "lib/.tsbuildinfo-client"
},
"include": ["src/gtag.ts", "src/*.d.ts"],
"exclude": ["**/__tests__/**"]
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-google-gtag/tsconfig.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down
@@ -1,15 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.client.json",
"compilerOptions": {
"noEmit": false,
"composite": true,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
"moduleResolution": "bundler",
"module": "esnext",
"target": "esnext",
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"tsBuildInfoFile": "lib/.tsbuildinfo-client"
},
"include": ["src/*.d.ts"],
"exclude": ["**/__tests__/**"]
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-google-tag-manager/tsconfig.json
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"references": [{"path": "./tsconfig.client.json"}],
"compilerOptions": {
"noEmit": false,
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
},
Expand Down

0 comments on commit f88da6c

Please sign in to comment.