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
package/lib/ChunkGraph.js CHANGED
@@ -30,6 +30,7 @@ const {
30
30
 
31
31
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
32
32
  /** @typedef {import("./Chunk")} Chunk */
33
+ /** @typedef {import("./Chunk").ChunkId} ChunkId */
33
34
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
34
35
  /** @typedef {import("./Module")} Module */
35
36
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
@@ -73,9 +74,7 @@ class ModuleHashInfo {
73
74
  * @param {SortableSet<T>} set the set
74
75
  * @returns {T[]} set as array
75
76
  */
76
- const getArray = set => {
77
- return Array.from(set);
78
- };
77
+ const getArray = set => Array.from(set);
79
78
 
80
79
  /**
81
80
  * @param {SortableSet<Chunk>} chunks the chunks
@@ -159,7 +158,7 @@ const getModulesSize = modules => {
159
158
  * @returns {Record<string, number>} the sizes of the modules
160
159
  */
161
160
  const getModulesSizes = modules => {
162
- let sizes = Object.create(null);
161
+ const sizes = Object.create(null);
163
162
  for (const module of modules) {
164
163
  for (const type of module.getSourceTypes()) {
165
164
  sizes[type] = (sizes[type] || 0) + module.size(type);
@@ -199,7 +198,7 @@ class ChunkGraphModule {
199
198
  this.runtimeInChunks = undefined;
200
199
  /** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
201
200
  this.hashes = undefined;
202
- /** @type {string | number} */
201
+ /** @type {ModuleId | null} */
203
202
  this.id = null;
204
203
  /** @type {RuntimeSpecMap<Set<string>> | undefined} */
205
204
  this.runtimeRequirements = undefined;
@@ -702,7 +701,7 @@ class ChunkGraph {
702
701
  const modulesWithSourceType = cgc.modules
703
702
  .getFromUnorderedCache(cgc._modulesBySourceType)
704
703
  .get(sourceType);
705
- if (modulesWithSourceType === undefined) return undefined;
704
+ if (modulesWithSourceType === undefined) return;
706
705
  modulesWithSourceType.sortWith(comparator);
707
706
  return modulesWithSourceType;
708
707
  }
@@ -749,9 +748,9 @@ class ChunkGraph {
749
748
  if (filterFn(module)) {
750
749
  if (array === undefined) {
751
750
  array = [];
752
- chunkModuleIdMap[asyncChunk.id] = array;
751
+ chunkModuleIdMap[/** @type {ChunkId} */ (asyncChunk.id)] = array;
753
752
  }
754
- const moduleId = this.getModuleId(module);
753
+ const moduleId = /** @type {ModuleId} */ (this.getModuleId(module));
755
754
  array.push(moduleId);
756
755
  }
757
756
  }
@@ -773,13 +772,15 @@ class ChunkGraph {
773
772
  hashLength = 0,
774
773
  includeAllChunks = false
775
774
  ) {
776
- /** @type {Record<string|number, Record<string|number, string>>} */
775
+ /** @type {Record<ChunkId, Record<string|number, string>>} */
777
776
  const chunkModuleHashMap = Object.create(null);
778
777
 
778
+ /** @typedef {Record<string|number, string>} IdToHashMap */
779
+
779
780
  for (const asyncChunk of includeAllChunks
780
781
  ? chunk.getAllReferencedChunks()
781
782
  : chunk.getAllAsyncChunks()) {
782
- /** @type {Record<string|number, string> | undefined} */
783
+ /** @type {IdToHashMap | undefined} */
783
784
  let idToHashMap;
784
785
  for (const module of this.getOrderedChunkModulesIterable(
785
786
  asyncChunk,
@@ -788,11 +789,15 @@ class ChunkGraph {
788
789
  if (filterFn(module)) {
789
790
  if (idToHashMap === undefined) {
790
791
  idToHashMap = Object.create(null);
791
- chunkModuleHashMap[asyncChunk.id] = idToHashMap;
792
+ chunkModuleHashMap[/** @type {ChunkId} */ (asyncChunk.id)] =
793
+ /** @type {IdToHashMap} */ (idToHashMap);
792
794
  }
793
795
  const moduleId = this.getModuleId(module);
794
796
  const hash = this.getRenderedModuleHash(module, asyncChunk.runtime);
795
- idToHashMap[moduleId] = hashLength ? hash.slice(0, hashLength) : hash;
797
+ /** @type {IdToHashMap} */
798
+ (idToHashMap)[/** @type {ModuleId} */ (moduleId)] = hashLength
799
+ ? hash.slice(0, hashLength)
800
+ : hash;
796
801
  }
797
802
  }
798
803
  }
@@ -808,7 +813,7 @@ class ChunkGraph {
808
813
  getChunkConditionMap(chunk, filterFn) {
809
814
  const map = Object.create(null);
810
815
  for (const c of chunk.getAllReferencedChunks()) {
811
- map[c.id] = filterFn(c, this);
816
+ map[/** @type {ChunkId} */ (c.id)] = filterFn(c, this);
812
817
  }
813
818
  return map;
814
819
  }
@@ -916,7 +921,7 @@ class ChunkGraph {
916
921
  const cgcB = this._getChunkGraphChunk(chunkB);
917
922
  const allModules = new Set(cgcA.modules);
918
923
  for (const m of cgcB.modules) allModules.add(m);
919
- let modulesSize = getModulesSize(allModules);
924
+ const modulesSize = getModulesSize(allModules);
920
925
  const chunkOverhead =
921
926
  typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
922
927
  const entryChunkMultiplicator =
@@ -950,9 +955,9 @@ class ChunkGraph {
950
955
  return isAvailableChunk(chunkA, chunkB);
951
956
  } else if (hasRuntimeB) {
952
957
  return isAvailableChunk(chunkB, chunkA);
953
- } else {
954
- return false;
955
958
  }
959
+
960
+ return false;
956
961
  }
957
962
 
958
963
  if (
@@ -1011,7 +1016,12 @@ class ChunkGraph {
1011
1016
  this.getChunkEntryModulesWithChunkGroupIterable(chunkB)
1012
1017
  )) {
1013
1018
  this.disconnectChunkAndEntryModule(chunkB, module);
1014
- this.connectChunkAndEntryModule(chunkA, module, chunkGroup);
1019
+ this.connectChunkAndEntryModule(
1020
+ chunkA,
1021
+ module,
1022
+ /** @type {Entrypoint} */
1023
+ (chunkGroup)
1024
+ );
1015
1025
  }
1016
1026
 
1017
1027
  for (const chunkGroup of chunkB.groupsIterable) {
@@ -1052,7 +1062,7 @@ class ChunkGraph {
1052
1062
  /**
1053
1063
  * @param {Chunk} chunk the new chunk
1054
1064
  * @param {Module} module the entry module
1055
- * @param {Entrypoint=} entrypoint the chunk group which must be loaded before the module is executed
1065
+ * @param {Entrypoint} entrypoint the chunk group which must be loaded before the module is executed
1056
1066
  * @returns {void}
1057
1067
  */
1058
1068
  connectChunkAndEntryModule(chunk, module, entrypoint) {
@@ -1111,8 +1121,9 @@ class ChunkGraph {
1111
1121
  disconnectChunkAndEntryModule(chunk, module) {
1112
1122
  const cgm = this._getChunkGraphModule(module);
1113
1123
  const cgc = this._getChunkGraphChunk(chunk);
1114
- cgm.entryInChunks.delete(chunk);
1115
- if (cgm.entryInChunks.size === 0) {
1124
+ /** @type {EntryInChunks} */
1125
+ (cgm.entryInChunks).delete(chunk);
1126
+ if (/** @type {EntryInChunks} */ (cgm.entryInChunks).size === 0) {
1116
1127
  cgm.entryInChunks = undefined;
1117
1128
  }
1118
1129
  cgc.entryModules.delete(module);
@@ -1126,8 +1137,9 @@ class ChunkGraph {
1126
1137
  disconnectChunkAndRuntimeModule(chunk, module) {
1127
1138
  const cgm = this._getChunkGraphModule(module);
1128
1139
  const cgc = this._getChunkGraphChunk(chunk);
1129
- cgm.runtimeInChunks.delete(chunk);
1130
- if (cgm.runtimeInChunks.size === 0) {
1140
+ /** @type {RuntimeInChunks} */
1141
+ (cgm.runtimeInChunks).delete(chunk);
1142
+ if (/** @type {RuntimeInChunks} */ (cgm.runtimeInChunks).size === 0) {
1131
1143
  cgm.runtimeInChunks = undefined;
1132
1144
  }
1133
1145
  cgc.runtimeModules.delete(module);
@@ -1154,8 +1166,9 @@ class ChunkGraph {
1154
1166
  const cgc = this._getChunkGraphChunk(chunk);
1155
1167
  for (const module of cgc.entryModules.keys()) {
1156
1168
  const cgm = this._getChunkGraphModule(module);
1157
- cgm.entryInChunks.delete(chunk);
1158
- if (cgm.entryInChunks.size === 0) {
1169
+ /** @type {EntryInChunks} */
1170
+ (cgm.entryInChunks).delete(chunk);
1171
+ if (/** @type {EntryInChunks} */ (cgm.entryInChunks).size === 0) {
1159
1172
  cgm.entryInChunks = undefined;
1160
1173
  }
1161
1174
  }
@@ -1322,7 +1335,7 @@ class ChunkGraph {
1322
1335
 
1323
1336
  /**
1324
1337
  * @param {Module} module the module
1325
- * @returns {ModuleId} the id of the module
1338
+ * @returns {ModuleId | null} the id of the module
1326
1339
  */
1327
1340
  getModuleId(module) {
1328
1341
  const cgm = this._getChunkGraphModule(module);
@@ -1344,7 +1357,7 @@ class ChunkGraph {
1344
1357
  * @returns {string | number} the id of the runtime
1345
1358
  */
1346
1359
  getRuntimeId(runtime) {
1347
- return this._runtimeIds.get(runtime);
1360
+ return /** @type {string | number} */ (this._runtimeIds.get(runtime));
1348
1361
  }
1349
1362
 
1350
1363
  /**
@@ -1474,10 +1487,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1474
1487
  } else if (!transferOwnership || runtimeRequirements.size >= items.size) {
1475
1488
  for (const item of items) runtimeRequirements.add(item);
1476
1489
  return runtimeRequirements;
1477
- } else {
1478
- for (const item of runtimeRequirements) items.add(item);
1479
- return items;
1480
1490
  }
1491
+
1492
+ for (const item of runtimeRequirements) items.add(item);
1493
+ return items;
1481
1494
  });
1482
1495
  }
1483
1496
 
@@ -1593,6 +1606,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1593
1606
  if (cgm.graphHashesWithConnections === undefined) {
1594
1607
  cgm.graphHashesWithConnections = new RuntimeSpecMap();
1595
1608
  }
1609
+
1596
1610
  /**
1597
1611
  * @param {ConnectionState} state state
1598
1612
  * @returns {"F" | "T" | "O"} result
@@ -1615,6 +1629,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1615
1629
  const activeNamespaceModules = new Set();
1616
1630
  /** @type {Map<string, Module | Set<Module>>} */
1617
1631
  const connectedModules = new Map();
1632
+ /**
1633
+ * @param {ModuleGraphConnection} connection connection
1634
+ * @param {string} stateInfo state info
1635
+ */
1618
1636
  const processConnection = (connection, stateInfo) => {
1619
1637
  const module = connection.module;
1620
1638
  stateInfo += module.getExportsType(this.moduleGraph, strict);
@@ -1696,7 +1714,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1696
1714
  hash.update(xor.toString(16));
1697
1715
  };
1698
1716
  if (activeNamespaceModules.size === 1)
1699
- addModuleToHash(activeNamespaceModules.values().next().value);
1717
+ addModuleToHash(
1718
+ /** @type {Module} */ (activeNamespaceModules.values().next().value)
1719
+ );
1700
1720
  else if (activeNamespaceModules.size > 1)
1701
1721
  addModulesToHash(activeNamespaceModules);
1702
1722
  for (const [stateInfo, modules] of connectedModulesInOrder) {
@@ -1740,12 +1760,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1740
1760
  const chunkGraph = chunkGraphForModuleMap.get(module);
1741
1761
  if (!chunkGraph)
1742
1762
  throw new Error(
1743
- deprecateMessage +
1744
- ": There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)"
1763
+ `${
1764
+ deprecateMessage
1765
+ }: There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)`
1745
1766
  );
1746
1767
  return chunkGraph;
1747
1768
  },
1748
- deprecateMessage + ": Use new ChunkGraph API",
1769
+ `${deprecateMessage}: Use new ChunkGraph API`,
1749
1770
  deprecationCode
1750
1771
  );
1751
1772
  deprecateGetChunkGraphForModuleMap.set(deprecateMessage, newFn);
@@ -1790,12 +1811,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1790
1811
  const chunkGraph = chunkGraphForChunkMap.get(chunk);
1791
1812
  if (!chunkGraph)
1792
1813
  throw new Error(
1793
- deprecateMessage +
1794
- "There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)"
1814
+ `${
1815
+ deprecateMessage
1816
+ }There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)`
1795
1817
  );
1796
1818
  return chunkGraph;
1797
1819
  },
1798
- deprecateMessage + ": Use new ChunkGraph API",
1820
+ `${deprecateMessage}: Use new ChunkGraph API`,
1799
1821
  deprecationCode
1800
1822
  );
1801
1823
  deprecateGetChunkGraphForChunkMap.set(deprecateMessage, newFn);
package/lib/ChunkGroup.js CHANGED
@@ -22,7 +22,7 @@ const {
22
22
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
23
23
 
24
24
  /** @typedef {{id: number}} HasId */
25
- /** @typedef {{module: Module, loc: DependencyLocation, request: string}} OriginRecord */
25
+ /** @typedef {{module: Module | null, loc: DependencyLocation, request: string}} OriginRecord */
26
26
 
27
27
  /**
28
28
  * @typedef {object} RawChunkGroupOptions
@@ -404,7 +404,7 @@ class ChunkGroup {
404
404
  }
405
405
 
406
406
  /**
407
- * @param {Module} module origin module
407
+ * @param {Module | null} module origin module
408
408
  * @param {DependencyLocation} loc location of the reference in the origin module
409
409
  * @param {string} request request name of the reference
410
410
  * @returns {void}
@@ -478,7 +478,6 @@ class ChunkGroup {
478
478
  /**
479
479
  * Sorting predicate which allows current ChunkGroup to be compared against another.
480
480
  * Sorting values are based off of number of chunks in ChunkGroup.
481
- *
482
481
  * @param {ChunkGraph} chunkGraph the chunk graph
483
482
  * @param {ChunkGroup} otherGroup the chunkGroup to compare this against
484
483
  * @returns {-1|0|1} sort position for comparison
@@ -8,8 +8,21 @@
8
8
  const util = require("util");
9
9
  const memoize = require("./util/memoize");
10
10
 
11
+ /** @typedef {import("tapable").Tap} Tap */
11
12
  /** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
13
+ /** @typedef {import("./Chunk")} Chunk */
12
14
  /** @typedef {import("./Compilation")} Compilation */
15
+ /** @typedef {import("./Compilation").ChunkHashContext} ChunkHashContext */
16
+ /** @typedef {import("./Compilation").Hash} Hash */
17
+ /** @typedef {import("./Compilation").RenderManifestEntry} RenderManifestEntry */
18
+ /** @typedef {import("./Compilation").RenderManifestOptions} RenderManifestOptions */
19
+ /** @typedef {import("./Compilation").Source} Source */
20
+ /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
21
+ /** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
22
+ /**
23
+ * @template T
24
+ * @typedef {import("tapable").IfSet<T>} IfSet
25
+ */
13
26
 
14
27
  const getJavascriptModulesPlugin = memoize(() =>
15
28
  require("./javascript/JavascriptModulesPlugin")
@@ -26,6 +39,11 @@ class ChunkTemplate {
26
39
  this.hooks = Object.freeze({
27
40
  renderManifest: {
28
41
  tap: util.deprecate(
42
+ /**
43
+ * @template AdditionalOptions
44
+ * @param {string | Tap & IfSet<AdditionalOptions>} options options
45
+ * @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn function
46
+ */
29
47
  (options, fn) => {
30
48
  compilation.hooks.renderManifest.tap(
31
49
  options,
@@ -41,6 +59,11 @@ class ChunkTemplate {
41
59
  },
42
60
  modules: {
43
61
  tap: util.deprecate(
62
+ /**
63
+ * @template AdditionalOptions
64
+ * @param {string | Tap & IfSet<AdditionalOptions>} options options
65
+ * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
66
+ */
44
67
  (options, fn) => {
45
68
  getJavascriptModulesPlugin()
46
69
  .getCompilationHooks(compilation)
@@ -58,6 +81,11 @@ class ChunkTemplate {
58
81
  },
59
82
  render: {
60
83
  tap: util.deprecate(
84
+ /**
85
+ * @template AdditionalOptions
86
+ * @param {string | Tap & IfSet<AdditionalOptions>} options options
87
+ * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
88
+ */
61
89
  (options, fn) => {
62
90
  getJavascriptModulesPlugin()
63
91
  .getCompilationHooks(compilation)
@@ -75,6 +103,11 @@ class ChunkTemplate {
75
103
  },
76
104
  renderWithEntry: {
77
105
  tap: util.deprecate(
106
+ /**
107
+ * @template AdditionalOptions
108
+ * @param {string | Tap & IfSet<AdditionalOptions>} options options
109
+ * @param {function(Source, Chunk): Source} fn function
110
+ */
78
111
  (options, fn) => {
79
112
  getJavascriptModulesPlugin()
80
113
  .getCompilationHooks(compilation)
@@ -96,6 +129,11 @@ class ChunkTemplate {
96
129
  },
97
130
  hash: {
98
131
  tap: util.deprecate(
132
+ /**
133
+ * @template AdditionalOptions
134
+ * @param {string | Tap & IfSet<AdditionalOptions>} options options
135
+ * @param {function(Hash): void} fn function
136
+ */
99
137
  (options, fn) => {
100
138
  compilation.hooks.fullHash.tap(options, fn);
101
139
  },
@@ -105,6 +143,11 @@ class ChunkTemplate {
105
143
  },
106
144
  hashForChunk: {
107
145
  tap: util.deprecate(
146
+ /**
147
+ * @template AdditionalOptions
148
+ * @param {string | Tap & IfSet<AdditionalOptions>} options options
149
+ * @param {function(Hash, Chunk, ChunkHashContext): void} fn function
150
+ */
108
151
  (options, fn) => {
109
152
  getJavascriptModulesPlugin()
110
153
  .getCompilationHooks(compilation)
@@ -7,7 +7,7 @@
7
7
 
8
8
  const asyncLib = require("neo-async");
9
9
  const { SyncBailHook } = require("tapable");
10
- const Compilation = require("../lib/Compilation");
10
+ const Compilation = require("./Compilation");
11
11
  const createSchemaValidation = require("./util/create-schema-validation");
12
12
  const { join } = require("./util/fs");
13
13
  const processAsyncTree = require("./util/processAsyncTree");
@@ -28,6 +28,12 @@ const processAsyncTree = require("./util/processAsyncTree");
28
28
  * @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
29
29
  */
30
30
 
31
+ /**
32
+ * @callback KeepFn
33
+ * @param {string} path path
34
+ * @returns {boolean} true, if the path should be kept
35
+ */
36
+
31
37
  const validate = createSchemaValidation(
32
38
  undefined,
33
39
  () => {
@@ -326,21 +332,14 @@ class CleanPlugin {
326
332
  apply(compiler) {
327
333
  const { dry, keep } = this.options;
328
334
 
335
+ /** @type {KeepFn} */
329
336
  const keepFn =
330
337
  typeof keep === "function"
331
338
  ? keep
332
339
  : typeof keep === "string"
333
- ? /**
334
- * @param {string} path path
335
- * @returns {boolean} true, if the path should be kept
336
- */
337
- path => path.startsWith(keep)
340
+ ? path => path.startsWith(keep)
338
341
  : typeof keep === "object" && keep.test
339
- ? /**
340
- * @param {string} path path
341
- * @returns {boolean} true, if the path should be kept
342
- */
343
- path => keep.test(path)
342
+ ? path => keep.test(path)
344
343
  : () => false;
345
344
 
346
345
  // We assume that no external modification happens while the compiler is active
@@ -42,7 +42,9 @@ class CodeGenerationResults {
42
42
  );
43
43
  }
44
44
  if (runtime === undefined) {
45
- if (entry.size > 1) {
45
+ if (
46
+ /** @type {RuntimeSpecMap<CodeGenerationResult>} */ (entry).size > 1
47
+ ) {
46
48
  const results = new Set(entry.values());
47
49
  if (results.size !== 1) {
48
50
  throw new Error(
@@ -53,9 +55,9 @@ class CodeGenerationResults {
53
55
  Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
54
56
  );
55
57
  }
56
- return first(results);
58
+ return /** @type {CodeGenerationResult} */ (first(results));
57
59
  }
58
- return entry.values().next().value;
60
+ return /** @type {CodeGenerationResult} */ (entry.values().next().value);
59
61
  }
60
62
  const result = entry.get(runtime);
61
63
  if (result === undefined) {
@@ -86,9 +88,8 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
86
88
  } else if (entry.size > 1) {
87
89
  const results = new Set(entry.values());
88
90
  return results.size === 1;
89
- } else {
90
- return entry.size === 1;
91
91
  }
92
+ return entry.size === 1;
92
93
  }
93
94
 
94
95
  /**
@@ -12,7 +12,6 @@ const makeSerializable = require("./util/makeSerializable");
12
12
 
13
13
  class CommentCompilationWarning extends WebpackError {
14
14
  /**
15
- *
16
15
  * @param {string} message warning message
17
16
  * @param {DependencyLocation} loc affected lines of code
18
17
  */