Skip to content

Commit 61819a6

Browse files
refactor(types): let plugins declare their stats keys (#22849)
* refactor(types): name the stats plugin-key fallback type * fix(types): stop stats hook maps taking caller-chosen payload types * refactor(types): let plugins declare their stats keys * fix(types): type a stats merge by the merged type its key declares * refactor(types): type webpack's own stats taps from the key registries * docs(types): state the merge tap a merged stats key needs * refactor(types): type stats groups by path through StatsFactoryGroupKeys groupResults taps now check createGroup against the group shape of their array path (assets, modules, reasons) instead of object, and plugins declare their own group shapes by declaration merging.
1 parent 1454e5c commit 61819a6

9 files changed

Lines changed: 629 additions & 818 deletions

‎cspell.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"atlaskit",
2525
"atrule",
2626
"ATTLIST",
27+
"augmentable",
2728
"autocapitalize",
2829
"autoclean",
2930
"autocrlf",

‎eslint.config.mjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ export default defineConfig([
153153
plugins: { jsdoc: getJsdocPlugin() },
154154
rules: {
155155
// The keywords an option type states for `tooling/generate-schemas.js`,
156-
// which JSON Schema has and JSDoc does not
156+
// which JSON Schema has and JSDoc does not, and `augmentable`, which
157+
// `tooling/generate-types.js` exports for declaration merging
157158
"jsdoc/check-tag-names": [
158159
"error",
159160
{
@@ -180,7 +181,8 @@ export default defineConfig([
180181
"tsType",
181182
"typeOnly",
182183
"properties",
183-
"not"
184+
"not",
185+
"augmentable"
184186
]
185187
}
186188
]

‎lib/index.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const getCli = memoize(() => ({
109109
/** @typedef {import("./config/defineConfig").ConfigurationFactory} ConfigurationFactory */
110110
/** @typedef {import("./config/defineConfig").DefineConfigInput} DefineConfigInput */
111111
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
112+
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAssetGroup} StatsAssetGroup */
112113
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
113114
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
114115
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkOrigin} StatsChunkOrigin */
@@ -117,8 +118,10 @@ const getCli = memoize(() => ({
117118
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsLogging} StatsLogging */
118119
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsLoggingEntry} StatsLoggingEntry */
119120
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
121+
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleGroup} StatsModuleGroup */
120122
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleIssuer} StatsModuleIssuer */
121123
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleReason} StatsModuleReason */
124+
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleReasonGroup} StatsModuleReasonGroup */
122125
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
123126
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
124127
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */

‎lib/stats/DefaultStatsFactoryPlugin.js‎

Lines changed: 114 additions & 130 deletions
Large diffs are not rendered by default.

‎lib/stats/DefaultStatsPrinterPlugin.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
* KnownStatsPrinterContext,
3535
* KnownStatsPrinterFormatters,
3636
* StatsPrinterContext,
37-
* StatsPrinterContextWithExtra
37+
* StatsPrinterContextWithExtra,
38+
* StatsPrinterItemNameKeys,
39+
* StatsPrinterPrintKeys
3840
* } from "./StatsPrinter"
3941
*/
4042

@@ -868,7 +870,7 @@ const ERROR_PRINTERS = {
868870
* @typedef {Printers<KnownStatsLoggingEntry, `loggingEntry(${LogTypeEnum}).loggingEntry`> &
869871
* { ["loggingEntry(clear).loggingEntry"]?: SimplePrinter<KnownStatsLoggingEntry, "logging"> } &
870872
* { ["loggingEntry.trace[]"]?: SimplePrinter<Exclude<KnownStatsLoggingEntry["trace"], undefined>[number], "logging"> } &
871-
* { loggingGroup?: SimplePrinter<KnownStatsLogging[], "logging"> } &
873+
* { loggingGroup?: SimplePrinter<StatsPrinterPrintKeys["loggingGroup"], "logging"> } &
872874
* Printers<KnownStatsLogging & { name: string }, `loggingGroup`> &
873875
* Exclamation<KnownStatsLogging, "loggingGroup.separator", "loggingGroup">} LogEntryPrinters
874876
*/
@@ -928,7 +930,8 @@ const MODULE_TRACE_DEPENDENCY_PRINTERS = {
928930
};
929931

930932
/**
931-
* @type {Record<string, string | ((item: KnownStatsLoggingEntry) => string)>}
933+
* Item names by array path, typed from `StatsPrinterItemNameKeys` where the path is in it.
934+
* @type {{ [K in keyof StatsPrinterItemNameKeys]: string | ((item: StatsPrinterItemNameKeys[K]) => string) } & Record<"asset.chunks[]" | "asset.auxiliaryChunks[]" | "asset.chunkNames[]" | "asset.chunkIdHints[]" | "asset.auxiliaryChunkNames[]" | "asset.auxiliaryChunkIdHints[]" | "chunkGroup.assets[]" | "chunkGroup.auxiliaryAssets[]" | "chunkGroupChild.assets[]" | "chunkGroupChild.auxiliaryAssets[]" | "chunkGroup.children[]" | "chunkGroupChildGroup.children[]", string>}
932935
*/
933936
const ITEM_NAMES = {
934937
"compilation.assets[]": "asset",
@@ -1744,7 +1747,9 @@ class DefaultStatsPrinterPlugin {
17441747
});
17451748
}
17461749

1747-
for (const key of Object.keys(ITEM_NAMES)) {
1750+
for (const key of /** @type {(keyof typeof ITEM_NAMES)[]} */ (
1751+
Object.keys(ITEM_NAMES)
1752+
)) {
17481753
const itemName = ITEM_NAMES[key];
17491754
stats.hooks.getItemName
17501755
.for(key)

0 commit comments

Comments
 (0)