-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
NPM Package: Introduce @wordpress/ts-config
#69030
base: trunk
Are you sure you want to change the base?
Conversation
This is an effort to address this issue by introducing the new I would appreciate your review and any feedback you may have. Thank you! |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @AdarshRawat1. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
"exclude": [ | ||
"${configDir}/**/*.android.js", | ||
"${configDir}/**/*.ios.js", | ||
"${configDir}/**/*.native.js", | ||
"${configDir}/**/benchmark", | ||
"${configDir}/packages/*/build-*/**", | ||
"${configDir}/packages/*/build/**", | ||
"${configDir}/**/test/**", | ||
"${configDir}/packages/**/react-native-*/**" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are specific to the Gutenberg repository and should remain in the root tsconfig.base.json
file, no?
It doesn't make sense for external developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously shared here too:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback. I see your point about the excludes being quite specific to Gutenberg. That said, many of these exclusions—such as build folders, benchmarks, and test directories—are commonly needed across different projects, not just within packages/.
Would it be worth refining the exclude rules to make them more broadly applicable while still avoiding Gutenberg-specific paths? If we can generalize them without including packages/, we might be able to create a more reusable configuration. I'd be happy to explore this further if you think it would be valuable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swissspidy , I'd appreciate your thoughts on the points mentioned above. Would you be so kind as to share your perspective on whether they are worth exploring further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generalizing the list would help a little bit, but then you risk excluding too many things, and you would still need some Gutenberg-specific exclusions anyway.
In my view we should:
- Undo the changes to the individual package's
tsconfig.json
files and keep"extends": "../../tsconfig.base.json",
there. - Have
/tsconfig.base.json
do"extends": "@wordpress/ts-config/tsconfig.base.json",
and keep defininginclude
andexclude
there- Aside: For some reason this PR didn't change
/tsconfig.base.json
yet, but that file will need to be modified either way
- Aside: For some reason this PR didn't change
- So basically
@wordpress/ts-config/tsconfig.base.json
would only definecompilerOptions
But I don't know what other projects typically do for this and I certainly don't want to be a deciding factor here, so I'll let others chime in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @swissspidy. As suggested, I'll wait for others to share their opinions on whether this change is needed.
cc: @WordPress/gutenberg-components
What?
Closes: #48954
This PR introduces a new
@wordpress/ts-config
package, allowing Gutenberg and external WordPress packages, plugins, and themes to share a common TypeScript configuration.Why?
Currently, Gutenberg's TypeScript configuration is defined in a central tsconfig.base.json, but it is loaded via relative paths across many
@wordpress/*
packages. This approach prevents external developers from reusing the configuration.By introducing
@wordpress/ts-config
, we align TypeScript with other existing configuration packages (e.g.,@wordpress/eslint-plugin
,@wordpress/prettier-config
) and improve maintainability.How?
Created
@wordpress/ts-config
containing thetsconfig.base.json
file.@wordpress/*
packages to extend TypeScript configuration via the new package instead of relative paths.test/
folder to use the package in thee2e/
andperformance/
folders.Key Changes:
1. Updated
typeRoots
PathstypeRoots
used./typings
and./node_modules/@types
, which only worked when the file was placed at the root level.../../typings
and../../node_modules/@types
to correctly reference the root frompackages/ts-config
.2. Introduced ${configDir} for Path Resolution
${configDir}
template variable, which ensures paths are resolved relative to the file that extends the config, rather than where the base config is located. Reference${configDir}
was already used for rootDir and declarationDir to handle paths relative to the extended configuration.${configDir}
to exclude patterns because it is essential to ensure that paths are correctly resolved relative to the extending project, not the ts-config package itself. Without this, paths would be incorrectly interpreted based on the location of@wordpress/ts-config
, causing unintended behavior.Testing Instructions
1. Install Dependencies
First, ensure all dependencies are installed:
2. Navigate to the @wordpress/ts-config Package
Move into the package directory:
cd packages/ts-config
3. Link the Package
Run the following command to create a global symlink:
4. Link the Package in Gutenberg Root
Navigate back to the Gutenberg root directory:
5. Verify the Linking
Check if the package is linked correctly:
Output:
6. Continue with build and development
npm run dev;