feat(types): use tsc to generate types#20754
Conversation
c719cf6 to
105b86c
Compare
|
|
This PR is packaged and the instant preview is available (cf5944a). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@cf5944a
yarn add -D webpack@https://pkg.pr.new/webpack@cf5944a
pnpm add -D webpack@https://pkg.pr.new/webpack@cf5944a |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20754 +/- ##
=======================================
Coverage 91.42% 91.42%
=======================================
Files 559 559
Lines 55103 55103
Branches 14529 14529
=======================================
+ Hits 50379 50380 +1
+ Misses 4724 4723 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bc893e8 to
e6e5ea6
Compare
Merging this PR will improve performance by 30.07%
Performance Changes
Comparing |
There was a problem hiding this comment.
Pull request overview
This PR aims to switch the project’s type declaration generation from webpack/tooling to using TypeScript (tsc), updating references and docs to align with a types/ output directory rather than a single types.d.ts file.
Changes:
- Updated package metadata and scripts to point TypeScript declarations to
types/index.d.tsand add abuild:types/publish-time generation step. - Rewired JSDoc type imports in benchmark code/configs to import types from the package root instead of
types.d.ts. - Adjusted configs/ignores/docs to treat
types/as generated output (gitignored, prettier/cspell ignored, docs updated).
Reviewed changes
Copilot reviewed 37 out of 39 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.validation.json | Validates generated declarations via types/index.d.ts |
| tsconfig.types.json | Introduces a dedicated tsconfig intended for emitting type declarations |
| package.json | Points types to types/index.d.ts, updates published files/scripts for type generation |
| test/BenchmarkTestCases.benchmark.mjs | Switches type imports to package-root module typings |
| test/benchmarkCases/**/webpack.config.mjs | Updates config typing to use package-root Configuration type |
| lib/Dependency.js | Adds explicit symbol JSDoc casting for better TS inference/emit |
| lib/dependencies/HarmonyImportSpecifierDependency.js | Adds explicit symbol JSDoc casting |
| lib/dependencies/HarmonyExportImportedSpecifierDependency.js | Adds explicit symbol JSDoc casting |
| lib/dependencies/CommonJsExportRequireDependency.js | Adds explicit symbol JSDoc casting |
| cspell.json | Updates ignore from types.d.ts to types/** |
| CONTRIBUTING.md | Updates contributor guidance to reference types/ output |
| AGENTS.md | Updates repo structure/workflow docs to reference types/ |
| .prettierignore | Ignores generated types output |
| .gitignore | Ignores generated /types output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "extends": "./tsconfig", | ||
| "compilerOptions": { | ||
| "rootDir": "lib" | ||
| }, | ||
| "include": ["declarations.d.ts", "declarations/*.d.ts", "lib/**/*.js"] |
There was a problem hiding this comment.
tsconfig.types.json extends tsconfig.json, which sets noEmit: true (tsconfig.json:8). As a result, yarn build:types (tsc -p tsconfig.types.json) will not emit any .d.ts files, so types/index.d.ts won’t be produced. Additionally, rootDir: "lib" conflicts with the included declarations.d.ts / declarations/*.d.ts (outside lib/), which can trigger TS6059. Consider overriding noEmit, enabling declaration emit (e.g., declaration + emitDeclarationOnly), configuring an explicit output dir (e.g., declarationDir/outDir to types/), and adjusting/removing rootDir so included declaration files are compatible.
| @@ -26,29 +26,31 @@ | |||
| "schemas/", | |||
| "SECURITY.md", | |||
| "module.d.ts", | |||
| "types.d.ts" | |||
| "types/" | |||
| ], | |||
There was a problem hiding this comment.
package.json now points types to types/index.d.ts, but the repo doesn’t contain types/ (it’s gitignored) and the current build:types config (see tsconfig.types.json + base noEmit) won’t generate it. Also, emitted .d.ts files from lib/** are very likely to retain type references like import("../declarations/WebpackOptions") (e.g., lib/index.js), but declarations/ and declarations.d.ts are not included in the published files list—this would make the published type declarations resolve to missing paths. Ensure the build generates types/index.d.ts and either bundles/copies the declarations* typings into types/ or includes declarations/ + declarations.d.ts in the published package.
| "types/" | ||
| ], | ||
| "scripts": { | ||
| "prepare": "husky", |
There was a problem hiding this comment.
Generating types/ only in prepublishOnly won’t cover workflows that rely on npm pack/packing (which runs prepack, not prepublishOnly). Since types/ is now ignored and expected to be generated, consider moving this to prepack (or adding prepack as well) so packed artifacts consistently include generated declarations.
| "prepare": "husky", | |
| "prepare": "husky", | |
| "prepack": "yarn build:types", |
| *.check.js | ||
| *.check.d.ts | ||
| types.d.ts | ||
| types |
There was a problem hiding this comment.
In .prettierignore, the pattern types will match any path segment named types, not just the intended root types/ output directory. To avoid accidentally skipping formatting in unrelated nested types/ folders (if they ever appear), prefer a more specific ignore like /types/ or types/.
| types | |
| /types/ |
| ``` | ||
|
|
||
| Then, automatically generate the type declarations by running `yarn fix` locally, and the changes you have made will be reflected in `types.d.ts`. | ||
| Then, automatically generate the type declarations by running `yarn fix` locally, and the changes you have made will be reflected in the `types/` directory. |
There was a problem hiding this comment.
CONTRIBUTING.md now says running yarn fix will regenerate type declarations into types/, but yarn fix currently runs fix:code && fix:special && fmt and does not call build:types. Given types/ is gitignored and AGENTS.md says it’s generated at publish time, this instruction looks incorrect/out-of-date. Update the doc to reference the actual command developers should run locally to generate/validate types (e.g., yarn build:types or yarn validate:types), or adjust scripts so yarn fix produces types/ as stated.
| Then, automatically generate the type declarations by running `yarn fix` locally, and the changes you have made will be reflected in the `types/` directory. | |
| Then, automatically generate the type declarations by running `yarn build:types` locally, and the changes you have made will be reflected in the `types/` directory. |
|
Let's close right now, we will revisit it later |
Ref: https://discord.com/channels/1180618526436888586/1371080839341019237/1486887261902602452
This PR replaces the usage of
webpack/toolingto generate types to using the start TSC. It's a draft while I investigate to ensure there are no regressions.