fix: correct createParser/createGenerator hook types in NormalModuleFactory#20999
Conversation
🦋 Changeset detectedLatest commit: 1c4c874 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR updates Webpack’s public typings and internal JSDoc so NormalModuleFactory parser/generator hooks (and related helpers) expose the correct option types per module type (notably HTML and WebAssembly), and so parser/generator factory methods return more specific types for known module-type strings.
Changes:
- Fix
NormalModuleFactorygenerator hook typings for"html"to useHtmlGeneratorOptions(exposingextract) and for WebAssembly generator hooks to useEmptyGeneratorOptions(instead of leaking parser option types). - Add JSDoc-driven type maps in
NormalModuleFactoryand propagate them intoNormalModuleCreateDatato narrow parser/generator fields by moduletype. - Regenerate
types.d.tsto reflect these hook/type improvements.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
types.d.ts |
Regenerated public typings to correct hook option types and add type-dependent parser/generator return types; introduces an unexpected rename of NormalModuleCreateData (see comment). |
lib/NormalModuleFactory.js |
Introduces tuple-to-type mapping typedefs and applies them to getParser/createParser/getGenerator/createGenerator return types; fixes HTML/WebAssembly generator option typedefs. |
lib/NormalModule.js |
Makes NormalModuleCreateData generic and narrows parser/generator fields via imported type maps from NormalModuleFactory. |
lib/html/HtmlModulesPlugin.js |
Removes an unnecessary cast when constructing HtmlGenerator now that generatorOptions is correctly typed. |
.changeset/fix-create-parser-generator-hook-types.md |
Adds a changeset describing the typings fixes and new generic behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…duleFactory` - Use the real `HtmlGeneratorOptions` type for the `html` entry instead of aliasing it to `EmptyGeneratorOptions` (the `extract` option was hidden from `createGenerator`/`generator` hook types). - Replace `EmptyParserOptions` with `EmptyGeneratorOptions` in the `webassembly/async` and `webassembly/sync` rows so generator hooks no longer leak parser-options types.
…enerator` Add a `TupleToTypeMap` helper that derives a record from the existing `ParsersAndGeneratorsByTypes` tuple, and template the four factory methods over the module-type string so callers get the specific class for known types (e.g. `JavascriptParser` for `"javascript/auto"`, `CssGenerator` for `"css"`) instead of the base `Parser` / `Generator`.
Template `NormalModuleCreateData` on `T extends NormalModuleTypes | ""` so `parser`, `parserOptions`, `generator`, and `generatorOptions` are narrowed to the specific class / options derived from `ParsersAndGeneratorsByTypes` for the given `type`. Existing callers keep the wide default (`NormalModuleTypes | ""`).
d0002e8 to
1c4c874
Compare
|
This PR is packaged and the instant preview is available (294197c). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@294197c
yarn add -D webpack@https://pkg.pr.new/webpack@294197c
pnpm add -D webpack@https://pkg.pr.new/webpack@294197c |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20999 +/- ##
==========================================
+ Coverage 90.93% 90.94% +0.01%
==========================================
Files 573 573
Lines 58986 58986
Branches 15898 15898
==========================================
+ Hits 53636 53644 +8
+ Misses 5350 5342 -8
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:
|
Merging this PR will improve performance by 21.69%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
HtmlGeneratorOptionstype for thehtmlentry instead of aliasing it toEmptyGeneratorOptions(theextractoption was hidden fromcreateGenerator/generatorhook types).EmptyParserOptionswithEmptyGeneratorOptionsin thewebassembly/asyncandwebassembly/syncrows so generator hooks no longer leak parser-options types.