refactor: tighten CreateData type in NormalModuleFactory#20992
Conversation
CreateData now describes the fully-populated value passed to the
createModule, module, and createModuleClass hooks
(NormalModuleCreateData & { settings: ModuleSettings }), while
ResolveData.createData is typed as Partial<CreateData> to reflect the
empty initial state filled in by the bulk Object.assign during resolve.
Drops the now-redundant ModuleSettings and NormalModuleCreateData
casts at the construction site.
The createModule, module, and createModuleClass hook taps now receive the non-partial CreateData, so individual-field casts that only worked around the previous Partial-typed signature are no longer needed: - SideEffectsFlagPlugin: drop ModuleSettings cast on data.settings - AssetModulesPlugin: drop NormalModuleCreateData cast when passing createData to new NormalModule() - AsyncWebAssemblyModulesPlugin: drop the cast on the spread of createData into the AsyncWasmModule options - ConsumeSharedPlugin / ProvideSharedPlugin: drop string casts on the resource destructured from createData
🦋 Changeset detectedLatest commit: 28ddfcc 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 |
|
This PR is packaged and the instant preview is available (1989126). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@1989126
yarn add -D webpack@https://pkg.pr.new/webpack@1989126
pnpm add -D webpack@https://pkg.pr.new/webpack@1989126 |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your changes status has failed because you have indirect coverage changes. Learn more about Unexpected Coverage Changes and reasons for indirect coverage changes. Additional details and impacted files@@ Coverage Diff @@
## main #20992 +/- ##
=======================================
Coverage 90.94% 90.94%
=======================================
Files 573 573
Lines 58940 58941 +1
Branches 15888 15888
=======================================
+ Hits 53601 53604 +3
+ Misses 5339 5337 -2
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:
|
There was a problem hiding this comment.
Pull request overview
This PR refines the typing around NormalModuleFactory’s CreateData so that the data passed to createModule, module, and createModuleClass hooks is typed as fully-populated, while ResolveData.createData remains Partial<> to reflect its initial empty state during resolution.
Changes:
- Introduces a stricter
CreateData = NormalModuleCreateData & { settings: ModuleSettings }for module-creation hooks. - Types
ResolveData.createDataasPartial<CreateData>and adjustsNormalModuleFactory’s internal cast at the point where the data is known to be populated. - Removes now-redundant JSDoc casts in plugins that consume
createData/settings/resource.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
types.d.ts |
Updates generated public typings for CreateData and the NormalModuleFactory hook signatures. |
lib/NormalModuleFactory.js |
Tightens the local CreateData typedef, updates ResolveData.createData typing, and removes redundant casts at module construction/hook call sites. |
lib/wasm-async/AsyncWebAssemblyModulesPlugin.js |
Drops an unnecessary createData cast when creating AsyncWasmModule. |
lib/asset/AssetModulesPlugin.js |
Removes redundant cast when passing createData into NormalModule. |
lib/optimize/SideEffectsFlagPlugin.js |
Removes unused typedef import and redundant cast for data.settings. |
lib/sharing/ProvideSharedPlugin.js |
Removes redundant casts around resource now that CreateData.resource is non-optional at this hook stage. |
lib/sharing/ConsumeSharedPlugin.js |
Same: removes redundant casts around resource when looking up/creating consume-shared modules. |
.changeset/normal-module-factory-create-data-type.md |
Adds a changeset entry documenting the typing refinement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will not alter performance
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
CreateData now describes the fully-populated value passed to the
createModule, module, and createModuleClass hooks
(NormalModuleCreateData & { settings: ModuleSettings }), while
ResolveData.createData is typed as Partial to reflect the
empty initial state filled in by the bulk Object.assign during resolve.
Drops the now-redundant ModuleSettings and NormalModuleCreateData
casts at the construction site.