webpack 5.93.0 → 5.95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (344) hide show
  1. package/README.md +8 -5
  2. package/bin/webpack.js +6 -7
  3. package/hot/log.js +1 -2
  4. package/hot/only-dev-server.js +1 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +4 -3
  8. package/lib/AbstractMethodError.js +10 -5
  9. package/lib/AutomaticPrefetchPlugin.js +1 -1
  10. package/lib/BannerPlugin.js +12 -6
  11. package/lib/Cache.js +8 -10
  12. package/lib/CacheFacade.js +3 -3
  13. package/lib/CaseSensitiveModulesWarning.js +5 -7
  14. package/lib/Chunk.js +14 -11
  15. package/lib/ChunkGraph.js +58 -36
  16. package/lib/ChunkGroup.js +2 -3
  17. package/lib/ChunkTemplate.js +43 -0
  18. package/lib/CleanPlugin.js +10 -11
  19. package/lib/CodeGenerationResults.js +6 -5
  20. package/lib/CommentCompilationWarning.js +0 -1
  21. package/lib/Compilation.js +223 -191
  22. package/lib/Compiler.js +81 -82
  23. package/lib/ConcatenationScope.js +3 -6
  24. package/lib/ConditionalInitFragment.js +6 -7
  25. package/lib/ConstPlugin.js +7 -15
  26. package/lib/ContextExclusionPlugin.js +3 -3
  27. package/lib/ContextModule.js +33 -20
  28. package/lib/ContextModuleFactory.js +89 -44
  29. package/lib/ContextReplacementPlugin.js +10 -9
  30. package/lib/DefinePlugin.js +75 -68
  31. package/lib/DelegatedModule.js +7 -3
  32. package/lib/DelegatedModuleFactoryPlugin.js +36 -22
  33. package/lib/DelegatedPlugin.js +4 -0
  34. package/lib/DependenciesBlock.js +0 -1
  35. package/lib/Dependency.js +10 -14
  36. package/lib/DllEntryPlugin.js +4 -2
  37. package/lib/DllModuleFactory.js +1 -0
  38. package/lib/DllPlugin.js +9 -7
  39. package/lib/DllReferencePlugin.js +30 -15
  40. package/lib/EntryPlugin.js +1 -3
  41. package/lib/EnvironmentPlugin.js +6 -2
  42. package/lib/ErrorHelpers.js +11 -12
  43. package/lib/EvalDevToolModulePlugin.js +10 -12
  44. package/lib/EvalSourceMapDevToolPlugin.js +15 -13
  45. package/lib/ExportsInfo.js +185 -120
  46. package/lib/ExternalModule.js +41 -15
  47. package/lib/ExternalModuleFactoryPlugin.js +23 -10
  48. package/lib/FileSystemInfo.js +791 -422
  49. package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
  50. package/lib/FlagDependencyExportsPlugin.js +12 -11
  51. package/lib/FlagDependencyUsagePlugin.js +1 -1
  52. package/lib/Generator.js +2 -5
  53. package/lib/GraphHelpers.js +3 -2
  54. package/lib/HookWebpackError.js +8 -10
  55. package/lib/HotModuleReplacementPlugin.js +78 -64
  56. package/lib/IgnoreErrorModuleFactory.js +3 -3
  57. package/lib/IgnorePlugin.js +1 -3
  58. package/lib/IgnoreWarningsPlugin.js +6 -9
  59. package/lib/InitFragment.js +2 -3
  60. package/lib/LibManifestPlugin.js +4 -3
  61. package/lib/MainTemplate.js +72 -19
  62. package/lib/Module.js +25 -9
  63. package/lib/ModuleBuildError.js +4 -11
  64. package/lib/ModuleDependencyError.js +5 -5
  65. package/lib/ModuleDependencyWarning.js +5 -5
  66. package/lib/ModuleError.js +1 -5
  67. package/lib/ModuleFilenameHelpers.js +29 -46
  68. package/lib/ModuleGraph.js +7 -6
  69. package/lib/ModuleGraphConnection.js +6 -6
  70. package/lib/ModuleInfoHeaderPlugin.js +82 -30
  71. package/lib/ModuleParseError.js +8 -9
  72. package/lib/ModuleRestoreError.js +1 -1
  73. package/lib/ModuleStoreError.js +1 -1
  74. package/lib/ModuleTemplate.js +33 -1
  75. package/lib/ModuleTypeConstants.js +21 -22
  76. package/lib/ModuleWarning.js +1 -5
  77. package/lib/MultiCompiler.js +24 -26
  78. package/lib/MultiStats.js +73 -31
  79. package/lib/MultiWatching.js +1 -1
  80. package/lib/NormalModule.js +130 -69
  81. package/lib/NormalModuleFactory.js +53 -49
  82. package/lib/OptimizationStages.js +3 -3
  83. package/lib/ProgressPlugin.js +9 -9
  84. package/lib/ProvidePlugin.js +4 -4
  85. package/lib/RuntimeGlobals.js +71 -70
  86. package/lib/RuntimeModule.js +1 -1
  87. package/lib/RuntimePlugin.js +24 -12
  88. package/lib/RuntimeTemplate.js +40 -44
  89. package/lib/SizeFormatHelpers.js +2 -4
  90. package/lib/SourceMapDevToolPlugin.js +42 -34
  91. package/lib/Stats.js +5 -11
  92. package/lib/Template.js +18 -24
  93. package/lib/TemplatedPathPlugin.js +21 -13
  94. package/lib/WarnDeprecatedOptionPlugin.js +0 -1
  95. package/lib/WatchIgnorePlugin.js +26 -9
  96. package/lib/Watching.js +10 -5
  97. package/lib/WebpackOptionsApply.js +84 -62
  98. package/lib/asset/AssetGenerator.js +107 -42
  99. package/lib/asset/AssetModulesPlugin.js +29 -23
  100. package/lib/asset/AssetSourceGenerator.js +2 -7
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
  102. package/lib/buildChunkGraph.js +93 -81
  103. package/lib/cache/IdleFileCachePlugin.js +4 -4
  104. package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
  105. package/lib/cache/PackFileCacheStrategy.js +51 -50
  106. package/lib/cache/ResolverCachePlugin.js +6 -6
  107. package/lib/cache/mergeEtags.js +16 -21
  108. package/lib/cli.js +148 -104
  109. package/lib/config/browserslistTargetHandler.js +16 -13
  110. package/lib/config/defaults.js +32 -28
  111. package/lib/config/normalization.js +335 -344
  112. package/lib/config/target.js +42 -52
  113. package/lib/container/ContainerEntryModule.js +2 -2
  114. package/lib/container/ContainerPlugin.js +1 -1
  115. package/lib/container/RemoteRuntimeModule.js +11 -8
  116. package/lib/container/options.js +18 -4
  117. package/lib/css/CssExportsGenerator.js +26 -24
  118. package/lib/css/CssGenerator.js +9 -4
  119. package/lib/css/CssLoadingRuntimeModule.js +10 -10
  120. package/lib/css/CssModulesPlugin.js +127 -47
  121. package/lib/css/CssParser.js +20 -18
  122. package/lib/css/walkCssTokens.js +80 -95
  123. package/lib/debug/ProfilingPlugin.js +19 -20
  124. package/lib/dependencies/AMDDefineDependency.js +1 -1
  125. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
  126. package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
  127. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
  128. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  129. package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
  130. package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
  131. package/lib/dependencies/CommonJsExportsDependency.js +0 -1
  132. package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
  133. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  134. package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
  135. package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
  136. package/lib/dependencies/ConstDependency.js +1 -1
  137. package/lib/dependencies/ContextDependency.js +7 -2
  138. package/lib/dependencies/ContextDependencyHelpers.js +31 -34
  139. package/lib/dependencies/ContextElementDependency.js +35 -8
  140. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  141. package/lib/dependencies/CssExportDependency.js +7 -7
  142. package/lib/dependencies/CssImportDependency.js +0 -2
  143. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
  144. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  145. package/lib/dependencies/CssUrlDependency.js +4 -5
  146. package/lib/dependencies/DynamicExports.js +5 -5
  147. package/lib/dependencies/ExportsInfoDependency.js +1 -2
  148. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
  149. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
  150. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
  151. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  152. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
  153. package/lib/dependencies/HarmonyExports.js +2 -2
  154. package/lib/dependencies/HarmonyImportDependency.js +2 -4
  155. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
  156. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
  157. package/lib/dependencies/ImportDependency.js +1 -1
  158. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
  159. package/lib/dependencies/ImportMetaPlugin.js +11 -13
  160. package/lib/dependencies/ImportParserPlugin.js +39 -44
  161. package/lib/dependencies/JsonExportsDependency.js +22 -18
  162. package/lib/dependencies/LoaderPlugin.js +47 -36
  163. package/lib/dependencies/LocalModule.js +1 -1
  164. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  165. package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
  166. package/lib/dependencies/ProvidedDependency.js +1 -1
  167. package/lib/dependencies/PureExpressionDependency.js +6 -6
  168. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  170. package/lib/dependencies/SystemPlugin.js +1 -1
  171. package/lib/dependencies/URLDependency.js +3 -3
  172. package/lib/dependencies/URLPlugin.js +66 -12
  173. package/lib/dependencies/WorkerPlugin.js +25 -24
  174. package/lib/dependencies/processExportInfo.js +3 -1
  175. package/lib/electron/ElectronTargetPlugin.js +1 -0
  176. package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
  178. package/lib/formatLocation.js +1 -2
  179. package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
  180. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  181. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
  182. package/lib/hmr/LazyCompilationPlugin.js +27 -12
  183. package/lib/hmr/lazyCompilationBackend.js +64 -40
  184. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
  185. package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
  186. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  187. package/lib/ids/HashedModuleIdsPlugin.js +5 -1
  188. package/lib/ids/IdHelpers.js +29 -39
  189. package/lib/ids/SyncModuleIdsPlugin.js +7 -2
  190. package/lib/index.js +1 -5
  191. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
  192. package/lib/javascript/BasicEvaluatedExpression.js +4 -19
  193. package/lib/javascript/ChunkHelpers.js +1 -1
  194. package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
  195. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
  196. package/lib/javascript/JavascriptGenerator.js +23 -7
  197. package/lib/javascript/JavascriptModulesPlugin.js +133 -86
  198. package/lib/javascript/JavascriptParser.js +179 -200
  199. package/lib/javascript/JavascriptParserHelpers.js +20 -21
  200. package/lib/javascript/StartupHelpers.js +41 -13
  201. package/lib/json/JsonGenerator.js +7 -13
  202. package/lib/json/JsonModulesPlugin.js +1 -4
  203. package/lib/json/JsonParser.js +5 -3
  204. package/lib/library/AmdLibraryPlugin.js +12 -16
  205. package/lib/library/AssignLibraryPlugin.js +8 -10
  206. package/lib/library/EnableLibraryPlugin.js +15 -14
  207. package/lib/library/JsonpLibraryPlugin.js +2 -1
  208. package/lib/library/ModernModuleLibraryPlugin.js +8 -6
  209. package/lib/library/ModuleLibraryPlugin.js +2 -1
  210. package/lib/library/SystemLibraryPlugin.js +2 -1
  211. package/lib/library/UmdLibraryPlugin.js +66 -92
  212. package/lib/logging/Logger.js +32 -4
  213. package/lib/logging/createConsoleLogger.js +12 -13
  214. package/lib/logging/runtime.js +7 -8
  215. package/lib/logging/truncateArgs.js +5 -8
  216. package/lib/node/NodeWatchFileSystem.js +3 -18
  217. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  218. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  219. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  220. package/lib/node/nodeConsole.js +22 -22
  221. package/lib/optimize/AggressiveMergingPlugin.js +2 -4
  222. package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
  223. package/lib/optimize/ConcatenatedModule.js +81 -51
  224. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  225. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
  226. package/lib/optimize/InnerGraph.js +17 -17
  227. package/lib/optimize/InnerGraphPlugin.js +8 -7
  228. package/lib/optimize/LimitChunkCountPlugin.js +2 -3
  229. package/lib/optimize/MangleExportsPlugin.js +1 -0
  230. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  231. package/lib/optimize/MinMaxSizeWarning.js +1 -1
  232. package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
  233. package/lib/optimize/RealContentHashPlugin.js +7 -10
  234. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  235. package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
  236. package/lib/optimize/SplitChunksPlugin.js +34 -30
  237. package/lib/performance/SizeLimitsPlugin.js +2 -2
  238. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  239. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  240. package/lib/rules/BasicEffectRulePlugin.js +3 -1
  241. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  242. package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
  243. package/lib/rules/RuleSetCompiler.js +41 -22
  244. package/lib/rules/UseEffectRulePlugin.js +36 -32
  245. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  246. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  247. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  248. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
  251. package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
  252. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
  253. package/lib/schemes/DataUriPlugin.js +1 -1
  254. package/lib/schemes/HttpUriPlugin.js +241 -126
  255. package/lib/serialization/BinaryMiddleware.js +44 -28
  256. package/lib/serialization/DateObjectSerializer.js +1 -0
  257. package/lib/serialization/ErrorObjectSerializer.js +2 -0
  258. package/lib/serialization/FileMiddleware.js +154 -106
  259. package/lib/serialization/MapObjectSerializer.js +2 -1
  260. package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
  261. package/lib/serialization/ObjectMiddleware.js +52 -56
  262. package/lib/serialization/PlainObjectSerializer.js +32 -6
  263. package/lib/serialization/RegExpObjectSerializer.js +1 -0
  264. package/lib/serialization/Serializer.js +4 -5
  265. package/lib/serialization/SerializerMiddleware.js +6 -6
  266. package/lib/serialization/SetObjectSerializer.js +2 -1
  267. package/lib/sharing/ConsumeSharedPlugin.js +116 -97
  268. package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
  269. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  270. package/lib/sharing/ProvideSharedPlugin.js +2 -2
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  272. package/lib/sharing/utils.js +15 -27
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
  274. package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
  275. package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
  276. package/lib/stats/StatsFactory.js +127 -56
  277. package/lib/stats/StatsPrinter.js +75 -44
  278. package/lib/util/ArrayHelpers.js +8 -4
  279. package/lib/util/ArrayQueue.js +1 -1
  280. package/lib/util/AsyncQueue.js +31 -12
  281. package/lib/util/IterableHelpers.js +3 -4
  282. package/lib/util/LazyBucketSortedSet.js +60 -44
  283. package/lib/util/LazySet.js +13 -0
  284. package/lib/util/MapHelpers.js +1 -3
  285. package/lib/util/ParallelismFactorCalculator.js +1 -1
  286. package/lib/util/Queue.js +1 -1
  287. package/lib/util/Semaphore.js +4 -7
  288. package/lib/util/SetHelpers.js +5 -5
  289. package/lib/util/SortableSet.js +4 -3
  290. package/lib/util/StackedCacheMap.js +4 -6
  291. package/lib/util/StackedMap.js +1 -3
  292. package/lib/util/StringXor.js +0 -5
  293. package/lib/util/TupleQueue.js +1 -1
  294. package/lib/util/TupleSet.js +15 -5
  295. package/lib/util/URLAbsoluteSpecifier.js +7 -7
  296. package/lib/util/WeakTupleMap.js +19 -21
  297. package/lib/util/binarySearchBounds.js +5 -12
  298. package/lib/util/chainedImports.js +1 -1
  299. package/lib/util/cleverMerge.js +21 -19
  300. package/lib/util/comparators.js +57 -52
  301. package/lib/util/compileBooleanMatcher.js +3 -6
  302. package/lib/util/conventions.js +8 -11
  303. package/lib/util/createHash.js +9 -6
  304. package/lib/util/deprecation.js +22 -12
  305. package/lib/util/deterministicGrouping.js +19 -26
  306. package/lib/util/findGraphRoots.js +2 -2
  307. package/lib/util/fs.js +32 -32
  308. package/lib/util/hash/md4.js +2 -2
  309. package/lib/util/hash/wasm-hash.js +7 -7
  310. package/lib/util/hash/xxhash64.js +2 -2
  311. package/lib/util/identifier.js +81 -59
  312. package/lib/util/memoize.js +8 -10
  313. package/lib/util/mergeScope.js +6 -9
  314. package/lib/util/nonNumericOnlyHash.js +2 -2
  315. package/lib/util/numberHash.js +1 -6
  316. package/lib/util/objectToMap.js +0 -1
  317. package/lib/util/propertyAccess.js +2 -5
  318. package/lib/util/propertyName.js +1 -3
  319. package/lib/util/registerExternalSerializer.js +1 -1
  320. package/lib/util/runtime.js +109 -113
  321. package/lib/util/semver.js +29 -27
  322. package/lib/util/serialization.js +16 -1
  323. package/lib/util/smartGrouping.js +5 -5
  324. package/lib/util/source.js +1 -1
  325. package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
  326. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  327. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
  328. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  329. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
  330. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
  331. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  333. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
  334. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  335. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  336. package/package.json +18 -17
  337. package/schemas/WebpackOptions.check.js +1 -1
  338. package/schemas/WebpackOptions.json +5 -0
  339. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  340. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  341. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  342. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  343. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  344. package/types.d.ts +681 -355
@@ -26,6 +26,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
26
26
 
27
27
  /** @typedef {import("webpack-sources").Source} Source */
28
28
  /** @typedef {import("../Chunk")} Chunk */
29
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
29
30
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
30
31
  /** @typedef {import("../ChunkGroup").OriginRecord} OriginRecord */
31
32
  /** @typedef {import("../Compilation")} Compilation */
@@ -33,20 +34,28 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
33
34
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
34
35
  /** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
35
36
  /** @typedef {import("../Compiler")} Compiler */
37
+ /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
36
38
  /** @typedef {import("../Dependency")} Dependency */
37
39
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
38
40
  /** @typedef {import("../Module")} Module */
41
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
39
42
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
40
43
  /** @typedef {import("../ModuleProfile")} ModuleProfile */
41
44
  /** @typedef {import("../RequestShortener")} RequestShortener */
42
45
  /** @typedef {import("../WebpackError")} WebpackError */
43
- /** @template T @typedef {import("../util/comparators").Comparator<T>} Comparator<T> */
46
+ /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
47
+ /**
48
+ * @template T
49
+ * @typedef {import("../util/comparators").Comparator<T>} Comparator<T>
50
+ */
44
51
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
45
- /** @typedef {import("../util/smartGrouping").GroupConfig<any, object>} GroupConfig */
52
+ /**
53
+ * @template T, R
54
+ * @typedef {import("../util/smartGrouping").GroupConfig<T, R>} GroupConfig
55
+ */
46
56
  /** @typedef {import("./StatsFactory")} StatsFactory */
47
57
  /** @typedef {import("./StatsFactory").StatsFactoryContext} StatsFactoryContext */
48
-
49
- /** @typedef {KnownStatsCompilation & Record<string, any>} StatsCompilation */
58
+ /** @typedef {Record<string, any> & KnownStatsCompilation} StatsCompilation */
50
59
  /**
51
60
  * @typedef {object} KnownStatsCompilation
52
61
  * @property {any=} env
@@ -74,7 +83,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
74
83
  * @property {Record<string, StatsLogging>=} logging
75
84
  */
76
85
 
77
- /** @typedef {KnownStatsLogging & Record<string, any>} StatsLogging */
86
+ /** @typedef {Record<string, any> & KnownStatsLogging} StatsLogging */
78
87
  /**
79
88
  * @typedef {object} KnownStatsLogging
80
89
  * @property {StatsLoggingEntry[]} entries
@@ -82,18 +91,18 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
82
91
  * @property {boolean} debug
83
92
  */
84
93
 
85
- /** @typedef {KnownStatsLoggingEntry & Record<string, any>} StatsLoggingEntry */
94
+ /** @typedef {Record<string, any> & KnownStatsLoggingEntry} StatsLoggingEntry */
86
95
  /**
87
96
  * @typedef {object} KnownStatsLoggingEntry
88
97
  * @property {string} type
89
- * @property {string} message
98
+ * @property {string=} message
90
99
  * @property {string[]=} trace
91
100
  * @property {StatsLoggingEntry[]=} children
92
101
  * @property {any[]=} args
93
102
  * @property {number=} time
94
103
  */
95
104
 
96
- /** @typedef {KnownStatsAsset & Record<string, any>} StatsAsset */
105
+ /** @typedef {Record<string, any> & KnownStatsAsset} StatsAsset */
97
106
  /**
98
107
  * @typedef {object} KnownStatsAsset
99
108
  * @property {string} type
@@ -114,7 +123,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
114
123
  * @property {boolean=} isOverSizeLimit
115
124
  */
116
125
 
117
- /** @typedef {KnownStatsChunkGroup & Record<string, any>} StatsChunkGroup */
126
+ /** @typedef {Record<string, any> & KnownStatsChunkGroup} StatsChunkGroup */
118
127
  /**
119
128
  * @typedef {object} KnownStatsChunkGroup
120
129
  * @property {string=} name
@@ -130,21 +139,21 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
130
139
  * @property {boolean=} isOverSizeLimit
131
140
  */
132
141
 
133
- /** @typedef {KnownStatsModule & Record<string, any>} StatsModule */
142
+ /** @typedef {Record<string, any> & KnownStatsModule} StatsModule */
134
143
  /**
135
144
  * @typedef {object} KnownStatsModule
136
145
  * @property {string=} type
137
146
  * @property {string=} moduleType
138
- * @property {string=} layer
147
+ * @property {(string | null)=} layer
139
148
  * @property {string=} identifier
140
149
  * @property {string=} name
141
- * @property {string=} nameForCondition
150
+ * @property {(string | null)=} nameForCondition
142
151
  * @property {number=} index
143
152
  * @property {number=} preOrderIndex
144
153
  * @property {number=} index2
145
154
  * @property {number=} postOrderIndex
146
155
  * @property {number=} size
147
- * @property {{[x: string]: number}=} sizes
156
+ * @property {{ [x: string]: number }=} sizes
148
157
  * @property {boolean=} cacheable
149
158
  * @property {boolean=} built
150
159
  * @property {boolean=} codeGenerated
@@ -152,29 +161,29 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
152
161
  * @property {boolean=} cached
153
162
  * @property {boolean=} optional
154
163
  * @property {boolean=} orphan
155
- * @property {string|number=} id
156
- * @property {string|number=} issuerId
157
- * @property {(string|number)[]=} chunks
158
- * @property {(string|number)[]=} assets
164
+ * @property {string | number=} id
165
+ * @property {string | number | null=} issuerId
166
+ * @property {(string | number)[]=} chunks
167
+ * @property {(string | number)[]=} assets
159
168
  * @property {boolean=} dependent
160
- * @property {string=} issuer
161
- * @property {string=} issuerName
169
+ * @property {(string | null)=} issuer
170
+ * @property {(string | null)=} issuerName
162
171
  * @property {StatsModuleIssuer[]=} issuerPath
163
172
  * @property {boolean=} failed
164
173
  * @property {number=} errors
165
174
  * @property {number=} warnings
166
175
  * @property {StatsProfile=} profile
167
176
  * @property {StatsModuleReason[]=} reasons
168
- * @property {(boolean | string[])=} usedExports
169
- * @property {string[]=} providedExports
177
+ * @property {(boolean | null | string[])=} usedExports
178
+ * @property {(string[] | null)=} providedExports
170
179
  * @property {string[]=} optimizationBailout
171
- * @property {number=} depth
180
+ * @property {(number | null)=} depth
172
181
  * @property {StatsModule[]=} modules
173
182
  * @property {number=} filteredModules
174
183
  * @property {ReturnType<Source["source"]>=} source
175
184
  */
176
185
 
177
- /** @typedef {KnownStatsProfile & Record<string, any>} StatsProfile */
186
+ /** @typedef {Record<string, any> & KnownStatsProfile} StatsProfile */
178
187
  /**
179
188
  * @typedef {object} KnownStatsProfile
180
189
  * @property {number} total
@@ -189,33 +198,33 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
189
198
  * @property {number} dependencies
190
199
  */
191
200
 
192
- /** @typedef {KnownStatsModuleIssuer & Record<string, any>} StatsModuleIssuer */
201
+ /** @typedef {Record<string, any> & KnownStatsModuleIssuer} StatsModuleIssuer */
193
202
  /**
194
203
  * @typedef {object} KnownStatsModuleIssuer
195
- * @property {string=} identifier
196
- * @property {string=} name
204
+ * @property {string} identifier
205
+ * @property {string} name
197
206
  * @property {(string|number)=} id
198
- * @property {StatsProfile=} profile
207
+ * @property {StatsProfile} profile
199
208
  */
200
209
 
201
- /** @typedef {KnownStatsModuleReason & Record<string, any>} StatsModuleReason */
210
+ /** @typedef {Record<string, any> & KnownStatsModuleReason} StatsModuleReason */
202
211
  /**
203
212
  * @typedef {object} KnownStatsModuleReason
204
- * @property {string=} moduleIdentifier
205
- * @property {string=} module
206
- * @property {string=} moduleName
207
- * @property {string=} resolvedModuleIdentifier
208
- * @property {string=} resolvedModule
209
- * @property {string=} type
213
+ * @property {string | null} moduleIdentifier
214
+ * @property {string | null} module
215
+ * @property {string | null} moduleName
216
+ * @property {string | null} resolvedModuleIdentifier
217
+ * @property {string | null} resolvedModule
218
+ * @property {string | null} type
210
219
  * @property {boolean} active
211
- * @property {string=} explanation
212
- * @property {string=} userRequest
213
- * @property {string=} loc
214
- * @property {(string|number)=} moduleId
215
- * @property {(string|number)=} resolvedModuleId
220
+ * @property {string | null} explanation
221
+ * @property {string | null} userRequest
222
+ * @property {(string | null)=} loc
223
+ * @property {(string | number | null)=} moduleId
224
+ * @property {(string | number | null)=} resolvedModuleId
216
225
  */
217
226
 
218
- /** @typedef {KnownStatsChunk & Record<string, any>} StatsChunk */
227
+ /** @typedef {Record<string, any> & KnownStatsChunk} StatsChunk */
219
228
  /**
220
229
  * @typedef {object} KnownStatsChunk
221
230
  * @property {boolean} rendered
@@ -224,14 +233,14 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
224
233
  * @property {boolean} recorded
225
234
  * @property {string=} reason
226
235
  * @property {number} size
227
- * @property {Record<string, number>=} sizes
228
- * @property {string[]=} names
229
- * @property {string[]=} idHints
236
+ * @property {Record<string, number>} sizes
237
+ * @property {string[]} names
238
+ * @property {string[]} idHints
230
239
  * @property {string[]=} runtime
231
- * @property {string[]=} files
232
- * @property {string[]=} auxiliaryFiles
240
+ * @property {string[]} files
241
+ * @property {string[]} auxiliaryFiles
233
242
  * @property {string} hash
234
- * @property {Record<string, (string|number)[]>=} childrenByOrder
243
+ * @property {Record<string, (string|number)[]>} childrenByOrder
235
244
  * @property {(string|number)=} id
236
245
  * @property {(string|number)[]=} siblings
237
246
  * @property {(string|number)[]=} parents
@@ -241,18 +250,18 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
241
250
  * @property {StatsChunkOrigin[]=} origins
242
251
  */
243
252
 
244
- /** @typedef {KnownStatsChunkOrigin & Record<string, any>} StatsChunkOrigin */
253
+ /** @typedef {Record<string, any> & KnownStatsChunkOrigin} StatsChunkOrigin */
245
254
  /**
246
255
  * @typedef {object} KnownStatsChunkOrigin
247
- * @property {string=} module
248
- * @property {string=} moduleIdentifier
249
- * @property {string=} moduleName
250
- * @property {string=} loc
251
- * @property {string=} request
252
- * @property {(string|number)=} moduleId
256
+ * @property {string} module
257
+ * @property {string} moduleIdentifier
258
+ * @property {string} moduleName
259
+ * @property {string} loc
260
+ * @property {string} request
261
+ * @property {(string | number)=} moduleId
253
262
  */
254
263
 
255
- /** @typedef {KnownStatsModuleTraceItem & Record<string, any>} StatsModuleTraceItem */
264
+ /** @typedef { Record<string, any> & KnownStatsModuleTraceItem} StatsModuleTraceItem */
256
265
  /**
257
266
  * @typedef {object} KnownStatsModuleTraceItem
258
267
  * @property {string=} originIdentifier
@@ -264,13 +273,13 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
264
273
  * @property {(string|number)=} moduleId
265
274
  */
266
275
 
267
- /** @typedef {KnownStatsModuleTraceDependency & Record<string, any>} StatsModuleTraceDependency */
276
+ /** @typedef {Record<string, any> & KnownStatsModuleTraceDependency} StatsModuleTraceDependency */
268
277
  /**
269
278
  * @typedef {object} KnownStatsModuleTraceDependency
270
279
  * @property {string=} loc
271
280
  */
272
281
 
273
- /** @typedef {KnownStatsError & Record<string, any>} StatsError */
282
+ /** @typedef {Record<string, any> & KnownStatsError} StatsError */
274
283
  /**
275
284
  * @typedef {object} KnownStatsError
276
285
  * @property {string} message
@@ -281,14 +290,14 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
281
290
  * @property {string=} moduleIdentifier
282
291
  * @property {string=} moduleName
283
292
  * @property {string=} loc
284
- * @property {string|number=} chunkId
293
+ * @property {ChunkId=} chunkId
285
294
  * @property {string|number=} moduleId
286
295
  * @property {StatsModuleTraceItem[]=} moduleTrace
287
296
  * @property {any=} details
288
297
  * @property {string=} stack
289
298
  */
290
299
 
291
- /** @typedef {Asset & { type: string, related: PreprocessedAsset[] }} PreprocessedAsset */
300
+ /** @typedef {Asset & { type: string, related: PreprocessedAsset[] | undefined }} PreprocessedAsset */
292
301
 
293
302
  /**
294
303
  * @template T
@@ -341,15 +350,14 @@ const uniqueArray = (items, selector) => {
341
350
  * @param {Comparator<I>} comparator comparator function
342
351
  * @returns {I[]} array of values
343
352
  */
344
- const uniqueOrderedArray = (items, selector, comparator) => {
345
- return uniqueArray(items, selector).sort(comparator);
346
- };
353
+ const uniqueOrderedArray = (items, selector, comparator) =>
354
+ uniqueArray(items, selector).sort(comparator);
347
355
 
348
356
  /** @template T @template R @typedef {{ [P in keyof T]: R }} MappedValues<T, R> */
349
357
 
350
358
  /**
351
- * @template T
352
- * @template R
359
+ * @template {object} T
360
+ * @template {object} R
353
361
  * @param {T} obj object to be mapped
354
362
  * @param {function(T[keyof T], keyof T): R} fn mapping function
355
363
  * @returns {MappedValues<T, R>} mapped object
@@ -357,7 +365,10 @@ const uniqueOrderedArray = (items, selector, comparator) => {
357
365
  const mapObject = (obj, fn) => {
358
366
  const newObj = Object.create(null);
359
367
  for (const key of Object.keys(obj)) {
360
- newObj[key] = fn(obj[key], /** @type {keyof T} */ (key));
368
+ newObj[key] = fn(
369
+ obj[/** @type {keyof T} */ (key)],
370
+ /** @type {keyof T} */ (key)
371
+ );
361
372
  }
362
373
  return newObj;
363
374
  };
@@ -405,10 +416,12 @@ const EXTRACT_ERROR = {
405
416
  ids: (object, error, { compilation: { chunkGraph } }) => {
406
417
  if (typeof error !== "string") {
407
418
  if (error.chunk) {
408
- object.chunkId = error.chunk.id;
419
+ object.chunkId = /** @type {ChunkId} */ (error.chunk.id);
409
420
  }
410
421
  if (error.module) {
411
- object.moduleId = chunkGraph.getModuleId(error.module);
422
+ object.moduleId =
423
+ /** @type {ModuleId} */
424
+ (chunkGraph.getModuleId(error.module));
412
425
  }
413
426
  }
414
427
  },
@@ -470,25 +483,21 @@ const SIMPLE_EXTRACTORS = {
470
483
  }
471
484
  if (!context.cachedGetErrors) {
472
485
  const map = new WeakMap();
473
- context.cachedGetErrors = compilation => {
474
- return (
475
- map.get(compilation) ||
476
- (errors => (map.set(compilation, errors), errors))(
477
- compilation.getErrors()
478
- )
486
+ context.cachedGetErrors = compilation =>
487
+ map.get(compilation) ||
488
+ // eslint-disable-next-line no-sequences
489
+ (errors => (map.set(compilation, errors), errors))(
490
+ compilation.getErrors()
479
491
  );
480
- };
481
492
  }
482
493
  if (!context.cachedGetWarnings) {
483
494
  const map = new WeakMap();
484
- context.cachedGetWarnings = compilation => {
485
- return (
486
- map.get(compilation) ||
487
- (warnings => (map.set(compilation, warnings), warnings))(
488
- compilation.getWarnings()
489
- )
495
+ context.cachedGetWarnings = compilation =>
496
+ map.get(compilation) ||
497
+ // eslint-disable-next-line no-sequences
498
+ (warnings => (map.set(compilation, warnings), warnings))(
499
+ compilation.getWarnings()
490
500
  );
491
- };
492
501
  }
493
502
  if (compilation.name) {
494
503
  object.name = compilation.name;
@@ -504,9 +513,6 @@ const SIMPLE_EXTRACTORS = {
504
513
  let acceptedTypes;
505
514
  let collapsedGroups = false;
506
515
  switch (logging) {
507
- default:
508
- acceptedTypes = new Set();
509
- break;
510
516
  case "error":
511
517
  acceptedTypes = new Set([LogType.error]);
512
518
  break;
@@ -549,6 +555,9 @@ const SIMPLE_EXTRACTORS = {
549
555
  ]);
550
556
  collapsedGroups = true;
551
557
  break;
558
+ default:
559
+ acceptedTypes = new Set();
560
+ break;
552
561
  }
553
562
  const cachedMakePathsRelative = makePathsRelative.bindContextCache(
554
563
  options.context,
@@ -581,15 +590,16 @@ const SIMPLE_EXTRACTORS = {
581
590
 
582
591
  if (type === LogType.groupEnd) {
583
592
  groupStack.pop();
584
- if (groupStack.length > 0) {
585
- currentList = groupStack[groupStack.length - 1].children;
586
- } else {
587
- currentList = rootList;
588
- }
593
+ currentList =
594
+ groupStack.length > 0
595
+ ? /** @type {KnownStatsLoggingEntry[]} */ (
596
+ groupStack[groupStack.length - 1].children
597
+ )
598
+ : rootList;
589
599
  if (depthInCollapsedGroup > 0) depthInCollapsedGroup--;
590
600
  continue;
591
601
  }
592
- let message = undefined;
602
+ let message;
593
603
  if (entry.type === LogType.time) {
594
604
  message = `${entry.args[0]}: ${
595
605
  entry.args[1] * 1000 + entry.args[2] / 1000000
@@ -636,7 +646,7 @@ const SIMPLE_EXTRACTORS = {
636
646
  }
637
647
  },
638
648
  hash: (object, compilation) => {
639
- object.hash = compilation.hash;
649
+ object.hash = /** @type {string} */ (compilation.hash);
640
650
  },
641
651
  version: object => {
642
652
  object.version = require("../../package.json").version;
@@ -645,18 +655,23 @@ const SIMPLE_EXTRACTORS = {
645
655
  object.env = _env;
646
656
  },
647
657
  timings: (object, compilation) => {
648
- object.time = compilation.endTime - compilation.startTime;
658
+ object.time =
659
+ /** @type {number} */ (compilation.endTime) -
660
+ /** @type {number} */ (compilation.startTime);
649
661
  },
650
662
  builtAt: (object, compilation) => {
651
- object.builtAt = compilation.endTime;
663
+ object.builtAt = /** @type {number} */ (compilation.endTime);
652
664
  },
653
665
  publicPath: (object, compilation) => {
654
666
  object.publicPath = compilation.getPath(
655
- compilation.outputOptions.publicPath
667
+ /** @type {TemplatePath} */
668
+ (compilation.outputOptions.publicPath)
656
669
  );
657
670
  },
658
671
  outputPath: (object, compilation) => {
659
- object.outputPath = compilation.outputOptions.path;
672
+ object.outputPath = /** @type {string} */ (
673
+ compilation.outputOptions.path
674
+ );
660
675
  },
661
676
  assets: (object, compilation, context, options, factory) => {
662
677
  const { type } = context;
@@ -741,7 +756,10 @@ const SIMPLE_EXTRACTORS = {
741
756
  compilationAuxiliaryFileToChunks
742
757
  }
743
758
  );
744
- const limited = spaceLimited(groupedAssets, options.assetsSpace);
759
+ const limited = spaceLimited(
760
+ groupedAssets,
761
+ /** @type {number} */ (options.assetsSpace)
762
+ );
745
763
  object.assets = limited.children;
746
764
  object.filteredAssets = limited.filteredChildren;
747
765
  },
@@ -834,7 +852,8 @@ const SIMPLE_EXTRACTORS = {
834
852
  }
835
853
  const [errors, filteredBySpace] = errorsSpaceLimit(
836
854
  factorizedErrors,
837
- options.errorsSpace
855
+ /** @type {number} */
856
+ (options.errorsSpace)
838
857
  );
839
858
  object.filteredErrorDetailsCount = filtered + filteredBySpace;
840
859
  object.errors = errors;
@@ -867,7 +886,8 @@ const SIMPLE_EXTRACTORS = {
867
886
  }
868
887
  const [warnings, filteredBySpace] = errorsSpaceLimit(
869
888
  rawWarnings,
870
- options.warningsSpace
889
+ /** @type {number} */
890
+ (options.warningsSpace)
871
891
  );
872
892
  object.filteredWarningDetailsCount = filtered + filteredBySpace;
873
893
  object.warnings = warnings;
@@ -881,18 +901,31 @@ const SIMPLE_EXTRACTORS = {
881
901
  ) => {
882
902
  const { type, cachedGetWarnings } = context;
883
903
  object.warningsCount = countWithChildren(compilation, (c, childType) => {
884
- if (!warningsFilter && warningsFilter.length === 0)
904
+ if (
905
+ !warningsFilter &&
906
+ /** @type {((warning: StatsError, textValue: string) => boolean)[]} */
907
+ (warningsFilter).length === 0
908
+ )
885
909
  return cachedGetWarnings(c);
886
910
  return factory
887
911
  .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context)
888
- .filter(warning => {
889
- const warningString = Object.keys(warning)
890
- .map(key => `${warning[key]}`)
891
- .join("\n");
892
- return !warningsFilter.some(filter =>
893
- filter(warning, warningString)
894
- );
895
- });
912
+ .filter(
913
+ /**
914
+ * @param {TODO} warning warning
915
+ * @returns {boolean} result
916
+ */
917
+ warning => {
918
+ const warningString = Object.keys(warning)
919
+ .map(
920
+ key =>
921
+ `${warning[/** @type {keyof KnownStatsError} */ (key)]}`
922
+ )
923
+ .join("\n");
924
+ return !warningsFilter.some(filter =>
925
+ filter(warning, warningString)
926
+ );
927
+ }
928
+ );
896
929
  });
897
930
  },
898
931
  children: (object, compilation, context, options, factory) => {
@@ -960,11 +993,12 @@ const SIMPLE_EXTRACTORS = {
960
993
  const { type } = context;
961
994
  object.related = factory.create(
962
995
  `${type.slice(0, -8)}.related`,
963
- asset.related,
996
+ asset.related || [],
964
997
  context
965
998
  );
966
999
  object.filteredRelated = asset.related
967
- ? asset.related.length - object.related.length
1000
+ ? asset.related.length -
1001
+ /** @type {StatsAsset[]} */ (object.related).length
968
1002
  : undefined;
969
1003
  },
970
1004
  ids: (
@@ -975,10 +1009,14 @@ const SIMPLE_EXTRACTORS = {
975
1009
  const chunks = compilationFileToChunks.get(asset.name) || [];
976
1010
  const auxiliaryChunks =
977
1011
  compilationAuxiliaryFileToChunks.get(asset.name) || [];
978
- object.chunks = uniqueOrderedArray(chunks, c => c.ids, compareIds);
1012
+ object.chunks = uniqueOrderedArray(
1013
+ chunks,
1014
+ c => /** @type {ChunkId[]} */ (c.ids),
1015
+ compareIds
1016
+ );
979
1017
  object.auxiliaryChunks = uniqueOrderedArray(
980
1018
  auxiliaryChunks,
981
- c => c.ids,
1019
+ c => /** @type {ChunkId[]} */ (c.ids),
982
1020
  compareIds
983
1021
  );
984
1022
  },
@@ -1004,7 +1042,7 @@ const SIMPLE_EXTRACTORS = {
1004
1042
  const asset = compilation.getAsset(name);
1005
1043
  return {
1006
1044
  name,
1007
- size: asset ? asset.info.size : -1
1045
+ size: /** @type {number} */ (asset ? asset.info.size : -1)
1008
1046
  };
1009
1047
  };
1010
1048
  /** @type {(total: number, asset: { size: number }) => number} */
@@ -1020,7 +1058,9 @@ const SIMPLE_EXTRACTORS = {
1020
1058
  /** @type {KnownStatsChunkGroup} */
1021
1059
  const statsChunkGroup = {
1022
1060
  name,
1023
- chunks: ids ? chunkGroup.chunks.map(c => c.id) : undefined,
1061
+ chunks: ids
1062
+ ? /** @type {ChunkId[]} */ (chunkGroup.chunks.map(c => c.id))
1063
+ : undefined,
1024
1064
  assets: assets.length <= chunkGroupMaxAssets ? assets : undefined,
1025
1065
  filteredAssets:
1026
1066
  assets.length <= chunkGroupMaxAssets ? 0 : assets.length,
@@ -1049,7 +1089,10 @@ const SIMPLE_EXTRACTORS = {
1049
1089
  /** @type {KnownStatsChunkGroup} */
1050
1090
  const childStatsChunkGroup = {
1051
1091
  name: group.name,
1052
- chunks: ids ? group.chunks.map(c => c.id) : undefined,
1092
+ chunks: ids
1093
+ ? /** @type {ChunkId[]} */
1094
+ (group.chunks.map(c => c.id))
1095
+ : undefined,
1053
1096
  assets:
1054
1097
  assets.length <= chunkGroupMaxAssets ? assets : undefined,
1055
1098
  filteredAssets:
@@ -1093,7 +1136,8 @@ const SIMPLE_EXTRACTORS = {
1093
1136
  },
1094
1137
  module: {
1095
1138
  _: (object, module, context, options, factory) => {
1096
- const { compilation, type } = context;
1139
+ const { type } = context;
1140
+ const compilation = /** @type {Compilation} */ (context.compilation);
1097
1141
  const built = compilation.builtModules.has(module);
1098
1142
  const codeGenerated = compilation.codeGeneratedModules.has(module);
1099
1143
  const buildTimeExecuted =
@@ -1127,7 +1171,8 @@ const SIMPLE_EXTRACTORS = {
1127
1171
  },
1128
1172
  module$visible: {
1129
1173
  _: (object, module, context, { requestShortener }, factory) => {
1130
- const { compilation, type, rootModules } = context;
1174
+ const { type, rootModules } = context;
1175
+ const compilation = /** @type {Compilation} */ (context.compilation);
1131
1176
  const { moduleGraph } = compilation;
1132
1177
  /** @type {Module[]} */
1133
1178
  const path = [];
@@ -1154,11 +1199,15 @@ const SIMPLE_EXTRACTORS = {
1154
1199
  identifier: module.identifier(),
1155
1200
  name: module.readableIdentifier(requestShortener),
1156
1201
  nameForCondition: module.nameForCondition(),
1157
- index: moduleGraph.getPreOrderIndex(module),
1158
- preOrderIndex: moduleGraph.getPreOrderIndex(module),
1159
- index2: moduleGraph.getPostOrderIndex(module),
1160
- postOrderIndex: moduleGraph.getPostOrderIndex(module),
1161
- cacheable: module.buildInfo.cacheable,
1202
+ index: /** @type {number} */ (moduleGraph.getPreOrderIndex(module)),
1203
+ preOrderIndex: /** @type {number} */ (
1204
+ moduleGraph.getPreOrderIndex(module)
1205
+ ),
1206
+ index2: /** @type {number} */ (moduleGraph.getPostOrderIndex(module)),
1207
+ postOrderIndex: /** @type {number} */ (
1208
+ moduleGraph.getPostOrderIndex(module)
1209
+ ),
1210
+ cacheable: /** @type {BuildInfo} */ (module.buildInfo).cacheable,
1162
1211
  optional: module.isOptional(moduleGraph),
1163
1212
  orphan:
1164
1213
  !type.endsWith("module.modules[].module$visible") &&
@@ -1183,17 +1232,24 @@ const SIMPLE_EXTRACTORS = {
1183
1232
  }
1184
1233
  },
1185
1234
  ids: (object, module, { compilation: { chunkGraph, moduleGraph } }) => {
1186
- object.id = chunkGraph.getModuleId(module);
1235
+ object.id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
1187
1236
  const issuer = moduleGraph.getIssuer(module);
1188
1237
  object.issuerId = issuer && chunkGraph.getModuleId(issuer);
1189
- object.chunks = Array.from(
1190
- chunkGraph.getOrderedModuleChunksIterable(module, compareChunksById),
1191
- chunk => chunk.id
1192
- );
1238
+ object.chunks =
1239
+ /** @type {ChunkId[]} */
1240
+ (
1241
+ Array.from(
1242
+ chunkGraph.getOrderedModuleChunksIterable(
1243
+ module,
1244
+ compareChunksById
1245
+ ),
1246
+ chunk => chunk.id
1247
+ )
1248
+ );
1193
1249
  },
1194
1250
  moduleAssets: (object, module) => {
1195
- object.assets = module.buildInfo.assets
1196
- ? Object.keys(module.buildInfo.assets)
1251
+ object.assets = /** @type {BuildInfo} */ (module.buildInfo).assets
1252
+ ? Object.keys(/** @type {BuildInfo} */ (module.buildInfo).assets)
1197
1253
  : [];
1198
1254
  },
1199
1255
  reasons: (object, module, context, options, factory) => {
@@ -1206,7 +1262,11 @@ const SIMPLE_EXTRACTORS = {
1206
1262
  Array.from(moduleGraph.getIncomingConnections(module)),
1207
1263
  context
1208
1264
  );
1209
- const limited = spaceLimited(groupsReasons, options.reasonsSpace);
1265
+ const limited = spaceLimited(
1266
+ groupsReasons,
1267
+ /** @type {number} */
1268
+ (options.reasonsSpace)
1269
+ );
1210
1270
  object.reasons = limited.children;
1211
1271
  object.filteredReasons = limited.filteredChildren;
1212
1272
  },
@@ -1299,10 +1359,11 @@ const SIMPLE_EXTRACTORS = {
1299
1359
  },
1300
1360
  moduleIssuer: {
1301
1361
  _: (object, module, context, { requestShortener }, factory) => {
1302
- const { compilation, type } = context;
1362
+ const { type } = context;
1363
+ const compilation = /** @type {Compilation} */ (context.compilation);
1303
1364
  const { moduleGraph } = compilation;
1304
1365
  const profile = moduleGraph.getProfile(module);
1305
- /** @type {KnownStatsModuleIssuer} */
1366
+ /** @type {Partial<KnownStatsModuleIssuer>} */
1306
1367
  const statsModuleIssuer = {
1307
1368
  identifier: module.identifier(),
1308
1369
  name: module.readableIdentifier(requestShortener)
@@ -1313,7 +1374,7 @@ const SIMPLE_EXTRACTORS = {
1313
1374
  }
1314
1375
  },
1315
1376
  ids: (object, module, { compilation: { chunkGraph } }) => {
1316
- object.id = chunkGraph.getModuleId(module);
1377
+ object.id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
1317
1378
  }
1318
1379
  },
1319
1380
  moduleReason: {
@@ -1383,13 +1444,13 @@ const SIMPLE_EXTRACTORS = {
1383
1444
  : Array.from(chunk.runtime.sort(), makePathsRelative),
1384
1445
  files: Array.from(chunk.files),
1385
1446
  auxiliaryFiles: Array.from(chunk.auxiliaryFiles).sort(compareIds),
1386
- hash: chunk.renderedHash,
1447
+ hash: /** @type {string} */ (chunk.renderedHash),
1387
1448
  childrenByOrder: childIdByOrder
1388
1449
  };
1389
1450
  Object.assign(object, statsChunk);
1390
1451
  },
1391
1452
  ids: (object, chunk) => {
1392
- object.id = chunk.id;
1453
+ object.id = /** @type {ChunkId} */ (chunk.id);
1393
1454
  },
1394
1455
  chunkRelations: (object, chunk, { compilation: { chunkGraph } }) => {
1395
1456
  /** @type {Set<string|number>} */
@@ -1402,16 +1463,17 @@ const SIMPLE_EXTRACTORS = {
1402
1463
  for (const chunkGroup of chunk.groupsIterable) {
1403
1464
  for (const parentGroup of chunkGroup.parentsIterable) {
1404
1465
  for (const chunk of parentGroup.chunks) {
1405
- parents.add(chunk.id);
1466
+ parents.add(/** @type {ChunkId} */ (chunk.id));
1406
1467
  }
1407
1468
  }
1408
1469
  for (const childGroup of chunkGroup.childrenIterable) {
1409
1470
  for (const chunk of childGroup.chunks) {
1410
- children.add(chunk.id);
1471
+ children.add(/** @type {ChunkId} */ (chunk.id));
1411
1472
  }
1412
1473
  }
1413
1474
  for (const sibling of chunkGroup.chunks) {
1414
- if (sibling !== chunk) siblings.add(sibling.id);
1475
+ if (sibling !== chunk)
1476
+ siblings.add(/** @type {ChunkId} */ (sibling.id));
1415
1477
  }
1416
1478
  }
1417
1479
  object.siblings = Array.from(siblings).sort(compareIds);
@@ -1473,7 +1535,7 @@ const SIMPLE_EXTRACTORS = {
1473
1535
  },
1474
1536
  ids: (object, origin, { compilation: { chunkGraph } }) => {
1475
1537
  object.moduleId = origin.module
1476
- ? chunkGraph.getModuleId(origin.module)
1538
+ ? /** @type {ModuleId} */ (chunkGraph.getModuleId(origin.module))
1477
1539
  : undefined;
1478
1540
  }
1479
1541
  },
@@ -1501,8 +1563,12 @@ const SIMPLE_EXTRACTORS = {
1501
1563
  );
1502
1564
  },
1503
1565
  ids: (object, { origin, module }, { compilation: { chunkGraph } }) => {
1504
- object.originId = chunkGraph.getModuleId(origin);
1505
- object.moduleId = chunkGraph.getModuleId(module);
1566
+ object.originId =
1567
+ /** @type {ModuleId} */
1568
+ (chunkGraph.getModuleId(origin));
1569
+ object.moduleId =
1570
+ /** @type {ModuleId} */
1571
+ (chunkGraph.getModuleId(module));
1506
1572
  }
1507
1573
  },
1508
1574
  moduleTraceDependency: {
@@ -1526,13 +1592,13 @@ const FILTER = {
1526
1592
  }
1527
1593
  };
1528
1594
 
1529
- /** @type {Record<string, Record<string, (thing: object, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
1595
+ /** @type {Record<string, Record<string, (thing: KnownStatsError, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
1530
1596
  const FILTER_RESULTS = {
1531
1597
  "compilation.warnings": {
1532
1598
  warningsFilter: util.deprecate(
1533
1599
  (warning, context, { warningsFilter }) => {
1534
1600
  const warningString = Object.keys(warning)
1535
- .map(key => `${warning[key]}`)
1601
+ .map(key => `${warning[/** @type {keyof KnownStatsError} */ (key)]}`)
1536
1602
  .join("\n");
1537
1603
  return !warningsFilter.some(filter => filter(warning, warningString));
1538
1604
  },
@@ -1549,7 +1615,7 @@ const MODULES_SORTER = {
1549
1615
  compareSelect(
1550
1616
  /**
1551
1617
  * @param {Module} m module
1552
- * @returns {number} depth
1618
+ * @returns {number | null} depth
1553
1619
  */
1554
1620
  m => moduleGraph.getDepth(m),
1555
1621
  compareNumbers
@@ -1557,7 +1623,7 @@ const MODULES_SORTER = {
1557
1623
  compareSelect(
1558
1624
  /**
1559
1625
  * @param {Module} m module
1560
- * @returns {number} index
1626
+ * @returns {number | null} index
1561
1627
  */
1562
1628
  m => moduleGraph.getPreOrderIndex(m),
1563
1629
  compareNumbers
@@ -1626,17 +1692,31 @@ const SORTERS = {
1626
1692
  }
1627
1693
  };
1628
1694
 
1629
- const getItemSize = item => {
1695
+ /**
1696
+ * @template T
1697
+ * @typedef {T & { children: Children<T>[] | undefined, filteredChildren?: number }} Children
1698
+ */
1699
+
1700
+ /**
1701
+ * @template T
1702
+ * @param {Children<T>} item item
1703
+ * @returns {number} item size
1704
+ */
1705
+ const getItemSize = item =>
1630
1706
  // Each item takes 1 line
1631
1707
  // + the size of the children
1632
1708
  // + 1 extra line when it has children and filteredChildren
1633
- return !item.children
1709
+ !item.children
1634
1710
  ? 1
1635
1711
  : item.filteredChildren
1636
1712
  ? 2 + getTotalSize(item.children)
1637
1713
  : 1 + getTotalSize(item.children);
1638
- };
1639
1714
 
1715
+ /**
1716
+ * @template T
1717
+ * @param {Children<T>[]} children children
1718
+ * @returns {number} total size
1719
+ */
1640
1720
  const getTotalSize = children => {
1641
1721
  let size = 0;
1642
1722
  for (const child of children) {
@@ -1645,6 +1725,11 @@ const getTotalSize = children => {
1645
1725
  return size;
1646
1726
  };
1647
1727
 
1728
+ /**
1729
+ * @template T
1730
+ * @param {Children<T>[]} children children
1731
+ * @returns {number} total items
1732
+ */
1648
1733
  const getTotalItems = children => {
1649
1734
  let count = 0;
1650
1735
  for (const child of children) {
@@ -1658,6 +1743,11 @@ const getTotalItems = children => {
1658
1743
  return count;
1659
1744
  };
1660
1745
 
1746
+ /**
1747
+ * @template T
1748
+ * @param {Children<T>[]} children children
1749
+ * @returns {Children<T>[]} collapsed children
1750
+ */
1661
1751
  const collapse = children => {
1662
1752
  // After collapse each child must take exactly one line
1663
1753
  const newChildren = [];
@@ -1677,24 +1767,33 @@ const collapse = children => {
1677
1767
  return newChildren;
1678
1768
  };
1679
1769
 
1770
+ /**
1771
+ * @template T
1772
+ * @param {Children<T>[]} itemsAndGroups item and groups
1773
+ * @param {number} max max
1774
+ * @param {boolean=} filteredChildrenLineReserved filtered children line reserved
1775
+ * @returns {Children<T>} result
1776
+ */
1680
1777
  const spaceLimited = (
1681
1778
  itemsAndGroups,
1682
1779
  max,
1683
1780
  filteredChildrenLineReserved = false
1684
1781
  ) => {
1685
1782
  if (max < 1) {
1686
- return {
1783
+ return /** @type {Children<T>} */ ({
1687
1784
  children: undefined,
1688
1785
  filteredChildren: getTotalItems(itemsAndGroups)
1689
- };
1786
+ });
1690
1787
  }
1691
- /** @type {any[] | undefined} */
1692
- let children = undefined;
1788
+ /** @type {Children<T>[] | undefined} */
1789
+ let children;
1693
1790
  /** @type {number | undefined} */
1694
- let filteredChildren = undefined;
1791
+ let filteredChildren;
1695
1792
  // This are the groups, which take 1+ lines each
1793
+ /** @type {Children<T>[] | undefined} */
1696
1794
  const groups = [];
1697
1795
  // The sizes of the groups are stored in groupSizes
1796
+ /** @type {number[]} */
1698
1797
  const groupSizes = [];
1699
1798
  // This are the items, which take 1 line each
1700
1799
  const items = [];
@@ -1757,7 +1856,7 @@ const spaceLimited = (
1757
1856
  // So it should always end up being smaller
1758
1857
  const headerSize = group.filteredChildren ? 2 : 1;
1759
1858
  const limited = spaceLimited(
1760
- group.children,
1859
+ /** @type {Children<T>} */ (group.children),
1761
1860
  maxGroupSize -
1762
1861
  // we should use ceil to always feet in max
1763
1862
  Math.ceil(oversize / groups.length) -
@@ -1792,12 +1891,14 @@ const spaceLimited = (
1792
1891
  }
1793
1892
  }
1794
1893
 
1795
- return {
1796
- children,
1797
- filteredChildren
1798
- };
1894
+ return /** @type {Children<T>} */ ({ children, filteredChildren });
1799
1895
  };
1800
1896
 
1897
+ /**
1898
+ * @param {StatsError[]} errors errors
1899
+ * @param {number} max max
1900
+ * @returns {[StatsError[], number]} error space limit
1901
+ */
1801
1902
  const errorsSpaceLimit = (errors, max) => {
1802
1903
  let filtered = 0;
1803
1904
  // Can not fit into limit
@@ -1853,18 +1954,30 @@ const errorsSpaceLimit = (errors, max) => {
1853
1954
  return [result, filtered];
1854
1955
  };
1855
1956
 
1957
+ /**
1958
+ * @template {{ size: number }} T
1959
+ * @template {{ size: number }} R
1960
+ * @param {(R | T)[]} children children
1961
+ * @param {T[]} assets assets
1962
+ * @returns {{ size: number }} asset size
1963
+ */
1856
1964
  const assetGroup = (children, assets) => {
1857
1965
  let size = 0;
1858
1966
  for (const asset of children) {
1859
1967
  size += asset.size;
1860
1968
  }
1861
- return {
1862
- size
1863
- };
1969
+ return { size };
1864
1970
  };
1865
1971
 
1972
+ /**
1973
+ * @template {{ size: number, sizes: Record<string, number> }} T
1974
+ * @param {Children<T>[]} children children
1975
+ * @param {KnownStatsModule[]} modules modules
1976
+ * @returns {{ size: number, sizes: Record<string, number>}} size and sizes
1977
+ */
1866
1978
  const moduleGroup = (children, modules) => {
1867
1979
  let size = 0;
1980
+ /** @type {Record<string, number>} */
1868
1981
  const sizes = {};
1869
1982
  for (const module of children) {
1870
1983
  size += module.size;
@@ -1878,6 +1991,12 @@ const moduleGroup = (children, modules) => {
1878
1991
  };
1879
1992
  };
1880
1993
 
1994
+ /**
1995
+ * @template {{ active: boolean }} T
1996
+ * @param {Children<T>[]} children children
1997
+ * @param {KnownStatsModuleReason[]} reasons reasons
1998
+ * @returns {{ active: boolean }} reason group
1999
+ */
1881
2000
  const reasonGroup = (children, reasons) => {
1882
2001
  let active = false;
1883
2002
  for (const reason of children) {
@@ -1891,35 +2010,36 @@ const reasonGroup = (children, reasons) => {
1891
2010
  const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/;
1892
2011
  const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/;
1893
2012
 
1894
- /** @type {Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2013
+ /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsAsset, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} AssetsGroupers */
2014
+
2015
+ /** @type {AssetsGroupers} */
1895
2016
  const ASSETS_GROUPERS = {
1896
2017
  _: (groupConfigs, context, options) => {
2018
+ /**
2019
+ * @param {keyof KnownStatsAsset} name name
2020
+ * @param {boolean=} exclude need exclude?
2021
+ */
1897
2022
  const groupByFlag = (name, exclude) => {
1898
2023
  groupConfigs.push({
1899
- getKeys: asset => {
1900
- return asset[name] ? ["1"] : undefined;
1901
- },
1902
- getOptions: () => {
1903
- return {
1904
- groupChildren: !exclude,
1905
- force: exclude
1906
- };
1907
- },
1908
- createGroup: (key, children, assets) => {
1909
- return exclude
2024
+ getKeys: asset => (asset[name] ? ["1"] : undefined),
2025
+ getOptions: () => ({
2026
+ groupChildren: !exclude,
2027
+ force: exclude
2028
+ }),
2029
+ createGroup: (key, children, assets) =>
2030
+ exclude
1910
2031
  ? {
1911
2032
  type: "assets by status",
1912
- [name]: !!key,
2033
+ [name]: Boolean(key),
1913
2034
  filteredChildren: assets.length,
1914
2035
  ...assetGroup(children, assets)
1915
2036
  }
1916
2037
  : {
1917
2038
  type: "assets by status",
1918
- [name]: !!key,
2039
+ [name]: Boolean(key),
1919
2040
  children,
1920
2041
  ...assetGroup(children, assets)
1921
- };
1922
- }
2042
+ }
1923
2043
  });
1924
2044
  };
1925
2045
  const {
@@ -1954,41 +2074,38 @@ const ASSETS_GROUPERS = {
1954
2074
  : `*${extension}`
1955
2075
  );
1956
2076
  while (path.length > 0) {
1957
- keys.push(path.join("/") + "/");
2077
+ keys.push(`${path.join("/")}/`);
1958
2078
  path.pop();
1959
2079
  }
1960
- } else {
1961
- if (extension) keys.push(`*${extension}`);
2080
+ } else if (extension) {
2081
+ keys.push(`*${extension}`);
1962
2082
  }
1963
2083
  return keys;
1964
2084
  },
1965
- createGroup: (key, children, assets) => {
1966
- return {
1967
- type: groupAssetsByPath ? "assets by path" : "assets by extension",
1968
- name: key,
1969
- children,
1970
- ...assetGroup(children, assets)
1971
- };
1972
- }
2085
+ createGroup: (key, children, assets) => ({
2086
+ type: groupAssetsByPath ? "assets by path" : "assets by extension",
2087
+ name: key,
2088
+ children,
2089
+ ...assetGroup(children, assets)
2090
+ })
1973
2091
  });
1974
2092
  }
1975
2093
  },
1976
2094
  groupAssetsByInfo: (groupConfigs, context, options) => {
2095
+ /**
2096
+ * @param {string} name name
2097
+ */
1977
2098
  const groupByAssetInfoFlag = name => {
1978
2099
  groupConfigs.push({
1979
- getKeys: asset => {
1980
- return asset.info && asset.info[name] ? ["1"] : undefined;
1981
- },
1982
- createGroup: (key, children, assets) => {
1983
- return {
1984
- type: "assets by info",
1985
- info: {
1986
- [name]: !!key
1987
- },
1988
- children,
1989
- ...assetGroup(children, assets)
1990
- };
1991
- }
2100
+ getKeys: asset => (asset.info && asset.info[name] ? ["1"] : undefined),
2101
+ createGroup: (key, children, assets) => ({
2102
+ type: "assets by info",
2103
+ info: {
2104
+ [name]: Boolean(key)
2105
+ },
2106
+ children,
2107
+ ...assetGroup(children, assets)
2108
+ })
1992
2109
  });
1993
2110
  };
1994
2111
  groupByAssetInfoFlag("immutable");
@@ -1996,19 +2113,18 @@ const ASSETS_GROUPERS = {
1996
2113
  groupByAssetInfoFlag("hotModuleReplacement");
1997
2114
  },
1998
2115
  groupAssetsByChunk: (groupConfigs, context, options) => {
2116
+ /**
2117
+ * @param {keyof KnownStatsAsset} name name
2118
+ */
1999
2119
  const groupByNames = name => {
2000
2120
  groupConfigs.push({
2001
- getKeys: asset => {
2002
- return asset[name];
2003
- },
2004
- createGroup: (key, children, assets) => {
2005
- return {
2006
- type: "assets by chunk",
2007
- [name]: [key],
2008
- children,
2009
- ...assetGroup(children, assets)
2010
- };
2011
- }
2121
+ getKeys: asset => /** @type {string[]} */ (asset[name]),
2122
+ createGroup: (key, children, assets) => ({
2123
+ type: "assets by chunk",
2124
+ [name]: [key],
2125
+ children,
2126
+ ...assetGroup(children, assets)
2127
+ })
2012
2128
  });
2013
2129
  };
2014
2130
  groupByNames("chunkNames");
@@ -2036,28 +2152,29 @@ const ASSETS_GROUPERS = {
2036
2152
  }
2037
2153
  };
2038
2154
 
2039
- /** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2155
+ /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsModule, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModulesGroupers */
2156
+
2157
+ /** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): ModulesGroupers} */
2040
2158
  const MODULES_GROUPERS = type => ({
2041
2159
  _: (groupConfigs, context, options) => {
2160
+ /**
2161
+ * @param {keyof KnownStatsModule} name name
2162
+ * @param {string} type type
2163
+ * @param {boolean=} exclude need exclude?
2164
+ */
2042
2165
  const groupByFlag = (name, type, exclude) => {
2043
2166
  groupConfigs.push({
2044
- getKeys: module => {
2045
- return module[name] ? ["1"] : undefined;
2046
- },
2047
- getOptions: () => {
2048
- return {
2049
- groupChildren: !exclude,
2050
- force: exclude
2051
- };
2052
- },
2053
- createGroup: (key, children, modules) => {
2054
- return {
2055
- type,
2056
- [name]: !!key,
2057
- ...(exclude ? { filteredChildren: modules.length } : { children }),
2058
- ...moduleGroup(children, modules)
2059
- };
2060
- }
2167
+ getKeys: module => (module[name] ? ["1"] : undefined),
2168
+ getOptions: () => ({
2169
+ groupChildren: !exclude,
2170
+ force: exclude
2171
+ }),
2172
+ createGroup: (key, children, modules) => ({
2173
+ type,
2174
+ [name]: Boolean(key),
2175
+ ...(exclude ? { filteredChildren: modules.length } : { children }),
2176
+ ...moduleGroup(children, modules)
2177
+ })
2061
2178
  });
2062
2179
  };
2063
2180
  const {
@@ -2120,24 +2237,22 @@ const MODULES_GROUPERS = type => ({
2120
2237
  }
2121
2238
  if (groupModulesByLayer) {
2122
2239
  groupConfigs.push({
2123
- getKeys: module => {
2124
- return [module.layer];
2125
- },
2126
- createGroup: (key, children, modules) => {
2127
- return {
2128
- type: "modules by layer",
2129
- layer: key,
2130
- children,
2131
- ...moduleGroup(children, modules)
2132
- };
2133
- }
2240
+ getKeys: module => /** @type {string[]} */ ([module.layer]),
2241
+ createGroup: (key, children, modules) => ({
2242
+ type: "modules by layer",
2243
+ layer: key,
2244
+ children,
2245
+ ...moduleGroup(children, modules)
2246
+ })
2134
2247
  });
2135
2248
  }
2136
2249
  if (groupModulesByPath || groupModulesByExtension) {
2137
2250
  groupConfigs.push({
2138
2251
  getKeys: module => {
2139
2252
  if (!module.name) return;
2140
- const resource = parseResource(module.name.split("!").pop()).path;
2253
+ const resource = parseResource(
2254
+ /** @type {string} */ (module.name.split("!").pop())
2255
+ ).path;
2141
2256
  const dataUrl = /^data:[^,;]+/.exec(resource);
2142
2257
  if (dataUrl) return [dataUrl[0]];
2143
2258
  const extensionMatch =
@@ -2155,11 +2270,11 @@ const MODULES_GROUPERS = type => ({
2155
2270
  : `*${extension}`
2156
2271
  );
2157
2272
  while (path.length > 0) {
2158
- keys.push(path.join("/") + "/");
2273
+ keys.push(`${path.join("/")}/`);
2159
2274
  path.pop();
2160
2275
  }
2161
- } else {
2162
- if (extension) keys.push(`*${extension}`);
2276
+ } else if (extension) {
2277
+ keys.push(`*${extension}`);
2163
2278
  }
2164
2279
  return keys;
2165
2280
  },
@@ -2201,7 +2316,24 @@ const MODULES_GROUPERS = type => ({
2201
2316
  }
2202
2317
  });
2203
2318
 
2204
- /** @type {Record<string, Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2319
+ /** @typedef {Record<string, (groupConfigs: import("../util/smartGrouping").GroupConfig<KnownStatsModuleReason, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModuleReasonsGroupers */
2320
+
2321
+ /** @type {ModuleReasonsGroupers} */
2322
+ const MODULE_REASONS_GROUPERS = {
2323
+ groupReasonsByOrigin: groupConfigs => {
2324
+ groupConfigs.push({
2325
+ getKeys: reason => /** @type {string[]} */ ([reason.module]),
2326
+ createGroup: (key, children, reasons) => ({
2327
+ type: "from origin",
2328
+ module: key,
2329
+ children,
2330
+ ...reasonGroup(children, reasons)
2331
+ })
2332
+ });
2333
+ }
2334
+ };
2335
+
2336
+ /** @type {Record<string, AssetsGroupers | ModulesGroupers | ModuleReasonsGroupers>} */
2205
2337
  const RESULT_GROUPERS = {
2206
2338
  "compilation.assets": ASSETS_GROUPERS,
2207
2339
  "asset.related": ASSETS_GROUPERS,
@@ -2209,26 +2341,14 @@ const RESULT_GROUPERS = {
2209
2341
  "chunk.modules": MODULES_GROUPERS("chunk"),
2210
2342
  "chunk.rootModules": MODULES_GROUPERS("root-of-chunk"),
2211
2343
  "module.modules": MODULES_GROUPERS("nested"),
2212
- "module.reasons": {
2213
- groupReasonsByOrigin: groupConfigs => {
2214
- groupConfigs.push({
2215
- getKeys: reason => {
2216
- return [reason.module];
2217
- },
2218
- createGroup: (key, children, reasons) => {
2219
- return {
2220
- type: "from origin",
2221
- module: key,
2222
- children,
2223
- ...reasonGroup(children, reasons)
2224
- };
2225
- }
2226
- });
2227
- }
2228
- }
2344
+ "module.reasons": MODULE_REASONS_GROUPERS
2229
2345
  };
2230
2346
 
2231
2347
  // remove a prefixed "!" that can be specified to reverse sort order
2348
+ /**
2349
+ * @param {string} field a field name
2350
+ * @returns {field} normalized field
2351
+ */
2232
2352
  const normalizeFieldKey = field => {
2233
2353
  if (field[0] === "!") {
2234
2354
  return field.slice(1);
@@ -2237,6 +2357,10 @@ const normalizeFieldKey = field => {
2237
2357
  };
2238
2358
 
2239
2359
  // if a field is prefixed by a "!" reverse sort order
2360
+ /**
2361
+ * @param {string} field a field name
2362
+ * @returns {boolean} result
2363
+ */
2240
2364
  const sortOrderRegular = field => {
2241
2365
  if (field[0] === "!") {
2242
2366
  return false;
@@ -2246,7 +2370,7 @@ const sortOrderRegular = field => {
2246
2370
 
2247
2371
  /**
2248
2372
  * @param {string} field field name
2249
- * @returns {function(object, object): number} comparators
2373
+ * @returns {function(object, object): 0 | 1 | -1} comparators
2250
2374
  */
2251
2375
  const sortByField = field => {
2252
2376
  if (!field) {
@@ -2274,8 +2398,8 @@ const sortByField = field => {
2274
2398
  return sortFn;
2275
2399
  };
2276
2400
 
2401
+ /** @type {Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2277
2402
  const ASSET_SORTERS = {
2278
- /** @type {(comparators: Function[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void} */
2279
2403
  assetsSort: (comparators, context, { assetsSort }) => {
2280
2404
  comparators.push(sortByField(assetsSort));
2281
2405
  },
@@ -2284,7 +2408,7 @@ const ASSET_SORTERS = {
2284
2408
  }
2285
2409
  };
2286
2410
 
2287
- /** @type {Record<string, Record<string, (comparators: Function[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2411
+ /** @type {Record<string, Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2288
2412
  const RESULT_SORTERS = {
2289
2413
  "compilation.chunks": {
2290
2414
  chunksSort: (comparators, context, { chunksSort }) => {
@@ -2361,8 +2485,14 @@ const ITEM_NAMES = {
2361
2485
  };
2362
2486
 
2363
2487
  /**
2364
- * @param {object[]} items items to be merged
2365
- * @returns {object} an object
2488
+ * @template T
2489
+ * @typedef {{ name: T }} NamedObject
2490
+ */
2491
+
2492
+ /**
2493
+ * @template {{ name: string }} T
2494
+ * @param {T[]} items items to be merged
2495
+ * @returns {NamedObject<T>} an object
2366
2496
  */
2367
2497
  const mergeToObject = items => {
2368
2498
  const obj = Object.create(null);
@@ -2372,7 +2502,10 @@ const mergeToObject = items => {
2372
2502
  return obj;
2373
2503
  };
2374
2504
 
2375
- /** @type {Record<string, (items: object[]) => any>} */
2505
+ /**
2506
+ * @template {{ name: string }} T
2507
+ * @type {Record<string, (items: T[]) => NamedObject<T>>}
2508
+ */
2376
2509
  const MERGER = {
2377
2510
  "compilation.entrypoints": mergeToObject,
2378
2511
  "compilation.namedChunkGroups": mergeToObject
@@ -2388,7 +2521,11 @@ class DefaultStatsFactoryPlugin {
2388
2521
  compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
2389
2522
  compilation.hooks.statsFactory.tap(
2390
2523
  "DefaultStatsFactoryPlugin",
2391
- (stats, options, context) => {
2524
+ /**
2525
+ * @param {StatsFactory} stats stats factory
2526
+ * @param {NormalizedStatsOptions} options stats options
2527
+ */
2528
+ (stats, options) => {
2392
2529
  iterateConfig(SIMPLE_EXTRACTORS, options, (hookFor, fn) => {
2393
2530
  stats.hooks.extract
2394
2531
  .for(hookFor)
@@ -2445,25 +2582,31 @@ class DefaultStatsFactoryPlugin {
2445
2582
  if (Array.isArray(options.children)) {
2446
2583
  stats.hooks.getItemFactory
2447
2584
  .for("compilation.children[].compilation")
2448
- .tap("DefaultStatsFactoryPlugin", (comp, { _index: idx }) => {
2449
- if (idx < options.children.length) {
2450
- return compilation.createStatsFactory(
2451
- compilation.createStatsOptions(
2452
- options.children[idx],
2453
- context
2454
- )
2455
- );
2585
+ .tap(
2586
+ "DefaultStatsFactoryPlugin",
2587
+ /**
2588
+ * @param {Compilation} comp compilation
2589
+ * @param {StatsFactoryContext} options options
2590
+ * @returns {StatsFactory | undefined} stats factory
2591
+ */
2592
+ (comp, { _index: idx }) => {
2593
+ const children =
2594
+ /** @type {TODO} */
2595
+ (options.children);
2596
+ if (idx < children.length) {
2597
+ return compilation.createStatsFactory(
2598
+ compilation.createStatsOptions(children[idx])
2599
+ );
2600
+ }
2456
2601
  }
2457
- });
2602
+ );
2458
2603
  } else if (options.children !== true) {
2459
2604
  const childFactory = compilation.createStatsFactory(
2460
- compilation.createStatsOptions(options.children, context)
2605
+ compilation.createStatsOptions(options.children)
2461
2606
  );
2462
2607
  stats.hooks.getItemFactory
2463
2608
  .for("compilation.children[].compilation")
2464
- .tap("DefaultStatsFactoryPlugin", () => {
2465
- return childFactory;
2466
- });
2609
+ .tap("DefaultStatsFactoryPlugin", () => childFactory);
2467
2610
  }
2468
2611
  }
2469
2612
  }