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

Build: Simplify tsconfig.json files #68326

Merged
merged 3 commits into from
Dec 27, 2024
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
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 }`
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for handling errors here.

);
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",
Copy link
Member

@manzoorwanijk manzoorwanijk Dec 26, 2024

Choose a reason for hiding this comment

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

While we are here, why do we need this "$schema" in ever tsconfig.json file? Don't the IDEs and TS automatically infer that?

Copy link
Member

Choose a reason for hiding this comment

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

I see that it was added in #59861

Copy link
Member Author

Choose a reason for hiding this comment

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

Some might infer it based on the filename, but including it ensures that supporting environments will use the appropriate schema. There's little downside to including it and the benefits are significant.

"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
Loading