wp build: Add TypeScript support#75011
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds TypeScript support to the wp-build package by converting key utility modules to TypeScript and using tsx to execute TypeScript files directly at runtime without pre-compilation.
Changes:
- Introduced shared TypeScript type definitions for package.json structures and configuration interfaces
- Converted
package-utils.mjsandphp-generator.mjsto TypeScript - Updated imports across the codebase to reference
.tsfiles and type definitions - Added
tsxandtypescriptas dependencies with updated tsconfig.json
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/wp-build/lib/types.ts | New file defining TypeScript interfaces for package.json, plugin config, routes, and PHP transformations |
| packages/wp-build/lib/package-utils.ts | Converted from .mjs to TypeScript with strict typing for package resolution utilities |
| packages/wp-build/lib/php-generator.ts | Converted from .mjs to TypeScript with proper type signatures for PHP template generation |
| packages/wp-build/lib/build.mjs | Updated shebang to use tsx and imports to reference .ts files |
| packages/wp-build/lib/wordpress-externals-plugin.mjs | Updated imports and JSDoc type references to use types.ts |
| packages/wp-build/lib/dependency-graph.mjs | Updated imports and JSDoc type references to use types.ts |
| packages/wp-build/lib/route-utils.mjs | Updated imports and JSDoc type references to use types.ts |
| packages/wp-build/package.json | Added tsx ^4.19.0 as dependency and typescript 5.9.3 as devDependency |
| packages/wp-build/tsconfig.json | Updated module system to NodeNext and added TypeScript-specific compiler options |
| package-lock.json | Added tsx 4.21.0 and its dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
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 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. |
|
Size Change: 0 B Total Size: 2.98 MB ℹ️ View Unchanged
|
|
I'd rather wait for Node 24 instead of introducing new complexity indirection with |
Yes, debugging works the same way with tsx --inspect-brk packages/wp-build/lib/build.mjs |
youknowriad
left a comment
There was a problem hiding this comment.
What does this mean for third-party users, do we need to "build" wp-build before shipping it? or we ask them to use tsx?
I'm also concerned about the perf impact for something that should be fast.
Personally, I'd rather wait for Node 24 here.
No impact. We don't need to build it. tsx handles it for us
tsx works the same way as Node strip types, by internally using ESBuild. There should hardly be any difference |
|
Alright. Let us wait for Node 24. |
|
Noting that we use a similar approach as this in the |
Follow up to #74651 (comment)
What?
Add TypeScript support to the
wp-buildpackage, usingtsxto execute it directly without the need to build it first.Why?
The
wp-buildpackage is getting massive as mentioned in #74651 (comment). It's better to have such a large package in TS to make it easy to refactor in future.How?
lib/types.tswith shared TypeScript interfaces (PackageJson,WpPluginConfig, etc.)lib/package-utils.mjsandlib/php-generator.mjsto TypeScript.mjsfiles to use JSDoc type imports fromtypes.tstsconfig.jsonandtsxdependency for running TypeScript directlyTesting Instructions
Run a full build to verify everything works:
Testing Instructions for Keyboard
Not applicable - this PR contains no UI changes.
Screenshots or screencast
Not applicable - this PR contains no UI changes.