Skip to content

Commit

Permalink
Build: Simplify tsconfig.json files (#68326)
Browse files Browse the repository at this point in the history
TypeScript 5.5 introduced a configDir variable that can be used
for templating tsconfig.json files. This significantly reduces
repitition in tsconfig.json files.

- Add standardized configuration to base tsconfig.json file.
- Remove redundant configuration from package tsconfig.json files.
- Remove redundant file globs (e.g. src instead of src/**/*).

---
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
  • Loading branch information
sirreal authored Dec 27, 2024
1 parent e726912 commit ca61601
Show file tree
Hide file tree
Showing 59 changed files with 85 additions and 260 deletions.
1 change: 1 addition & 0 deletions bin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noEmit": true,
"outDir": ".cache"
},
"include": [],
"files": [
"./api-docs/update-api-docs.js",
"./plugin/config.js",
Expand Down
35 changes: 27 additions & 8 deletions bin/validate-tsconfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,33 @@ for ( const packageName of packagesWithTypes ) {
hasErrors = true;
}

const packageJson = JSON.parse(
readFileSync( `packages/${ packageName }/package.json`, 'utf8' )
);
const tsconfigJson = JSON.parse(
stripJsonComments(
readFileSync( `packages/${ packageName }/tsconfig.json`, 'utf8' )
)
);
let packageJson;
try {
packageJson = JSON.parse(
readFileSync( `packages/${ packageName }/package.json`, 'utf8' )
);
} catch ( e ) {
console.error(
`Error parsing package.json for package ${ packageName }`
);
throw e;
}
let tsconfigJson;
try {
tsconfigJson = JSON.parse(
stripJsonComments(
readFileSync(
`packages/${ packageName }/tsconfig.json`,
'utf8'
)
)
);
} catch ( e ) {
console.error(
`Error parsing tsconfig.json for package ${ packageName }`
);
throw e;
}
if ( packageJson.dependencies ) {
for ( const dependency of Object.keys( packageJson.dependencies ) ) {
if ( dependency.startsWith( '@wordpress/' ) ) {
Expand Down
7 changes: 1 addition & 6 deletions packages/a11y/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"references": [ { "path": "../dom-ready" }, { "path": "../i18n" } ],
"include": [ "src/**/*" ]
"references": [ { "path": "../dom-ready" }, { "path": "../i18n" } ]
}
7 changes: 1 addition & 6 deletions packages/api-fetch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"references": [ { "path": "../i18n" }, { "path": "../url" } ],
"include": [ "src/**/*" ],
"exclude": [ "**/test/**/*" ]
"exclude": [ "**/test" ]
}
7 changes: 1 addition & 6 deletions packages/autop/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"references": [ { "path": "../dom-ready" } ],
"include": [ "src/**/*" ]
"references": [ { "path": "../dom-ready" } ]
}
7 changes: 1 addition & 6 deletions packages/blob/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"include": [ "src/**/*" ]
"extends": "../../tsconfig.base.json"
}
7 changes: 2 additions & 5 deletions packages/block-editor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"references": [
{ "path": "../a11y" },
{ "path": "../api-fetch" },
Expand Down Expand Up @@ -37,5 +33,6 @@
// NOTE: This package is being progressively typed. You are encouraged to
// expand this array with files which can be type-checked. At some point in
// the future, this can be simplified to an `includes` of `src/**/*`.
"files": [ "src/components/block-context/index.js", "src/utils/dom.js" ]
"files": [ "src/components/block-context/index.js", "src/utils/dom.js" ],
"include": []
}
2 changes: 0 additions & 2 deletions packages/block-library/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [ "gutenberg-env" ],
"strictNullChecks": true
},
Expand Down
7 changes: 1 addition & 6 deletions packages/block-serialization-default-parser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"include": [ "src/**/*" ]
"extends": "../../tsconfig.base.json"
}
3 changes: 0 additions & 3 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [
"gutenberg-env",
"gutenberg-test-env",
Expand Down Expand Up @@ -31,7 +29,6 @@
{ "path": "../rich-text" },
{ "path": "../warning" }
],
"include": [ "src/**/*" ],
"exclude": [
"src/**/*.android.js",
"src/**/*.ios.js",
Expand Down
5 changes: 1 addition & 4 deletions packages/core-data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"checkJs": false,
"noImplicitAny": false
},
Expand All @@ -23,6 +21,5 @@
{ "path": "../undo-manager" },
{ "path": "../url" },
{ "path": "../warning" }
],
"include": [ "src/**/*" ]
]
}
5 changes: 1 addition & 4 deletions packages/data-controls/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [ "gutenberg-env" ]
},
"references": [
{ "path": "../api-fetch" },
{ "path": "../data" },
{ "path": "../deprecated" }
],
"include": [ "src/**/*" ]
]
}
5 changes: 1 addition & 4 deletions packages/data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"checkJs": false
},
"references": [
Expand All @@ -14,6 +12,5 @@
{ "path": "../is-shallow-equal" },
{ "path": "../priority-queue" },
{ "path": "../redux-routine" }
],
"include": [ "src/**/*" ]
]
}
3 changes: 0 additions & 3 deletions packages/dataviews/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [
"gutenberg-env",
"gutenberg-test-env",
Expand All @@ -22,7 +20,6 @@
{ "path": "../private-apis" },
{ "path": "../warning" }
],
"include": [ "src" ],
"exclude": [
"src/**/*.android.js",
"src/**/*.ios.js",
Expand Down
7 changes: 1 addition & 6 deletions packages/date/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"references": [ { "path": "../deprecated" } ],
"include": [ "src/**/*" ]
"references": [ { "path": "../deprecated" } ]
}
7 changes: 1 addition & 6 deletions packages/deprecated/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"references": [ { "path": "../hooks" } ],
"include": [ "src/**/*" ]
"references": [ { "path": "../hooks" } ]
}
6 changes: 3 additions & 3 deletions packages/docgen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "lib",
"declarationDir": "build-types"
"rootDir": "lib"
},
"include": [ "lib/get-leading-comments.js" ]
"files": [ "lib/get-leading-comments.js" ],
"include": []
}
7 changes: 1 addition & 6 deletions packages/dom-ready/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"include": [ "src/**/*" ]
"extends": "../../tsconfig.base.json"
}
3 changes: 0 additions & 3 deletions packages/dom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [ "gutenberg-env" ]
},
"include": [ "src/**/*" ],
"references": [ { "path": "../deprecated" } ]
}
5 changes: 1 addition & 4 deletions packages/e2e-test-utils-playwright/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
"module": "Node16",
"moduleResolution": "node16",
"types": [ "node" ],
"rootDir": "src",
"noEmit": false,
"outDir": "build",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "build-types",
"emitDeclarationOnly": false,
"allowJs": true,
"checkJs": false
},
"include": [ "src/**/*" ]
}
}
5 changes: 1 addition & 4 deletions packages/editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"checkJs": false
},
"references": [
Expand Down Expand Up @@ -34,6 +32,5 @@
{ "path": "../url" },
{ "path": "../warning" },
{ "path": "../wordcount" }
],
"include": [ "src" ]
]
}
6 changes: 1 addition & 5 deletions packages/element/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",

"noImplicitAny": false,
"strictNullChecks": false
},
"references": [ { "path": "../escape-html" } ],
"include": [ "src/**/*" ]
"references": [ { "path": "../escape-html" } ]
}
7 changes: 1 addition & 6 deletions packages/escape-html/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"include": [ "src/**/*" ]
"extends": "../../tsconfig.base.json"
}
6 changes: 3 additions & 3 deletions packages/eslint-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "CommonJS",
"rootDir": "rules",
"declarationDir": "build-types"
"rootDir": "rules"
},
"references": [ { "path": "../prettier-config" } ],
// NOTE: This package is being progressively typed. You are encouraged to
// expand this array with files which can be type-checked. At some point in
// the future, this can be simplified to an `includes` of `src/**/*`.
"files": [ "rules/dependency-group.js", "rules/no-unsafe-wp-apis.js" ]
"files": [ "rules/dependency-group.js", "rules/no-unsafe-wp-apis.js" ],
"include": []
}
5 changes: 1 addition & 4 deletions packages/fields/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"checkJs": false
},
"references": [
Expand All @@ -29,6 +27,5 @@
{ "path": "../url" },
{ "path": "../block-editor" },
{ "path": "../warning" }
],
"include": [ "src" ]
]
}
5 changes: 1 addition & 4 deletions packages/hooks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [ "gutenberg-env" ]
},
"include": [ "src/**/*" ]
}
}
7 changes: 1 addition & 6 deletions packages/html-entities/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types"
},
"include": [ "src/**/*" ]
"extends": "../../tsconfig.base.json"
}
Loading

1 comment on commit ca61601

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in ca61601.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12513509112
📝 Reported issues:

Please sign in to comment.