webpack 5.101.3 → 5.102.1

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 (339) hide show
  1. package/README.md +21 -26
  2. package/lib/APIPlugin.js +30 -36
  3. package/lib/AsyncDependenciesBlock.js +1 -4
  4. package/lib/BannerPlugin.js +0 -1
  5. package/lib/Cache.js +7 -6
  6. package/lib/CacheFacade.js +0 -1
  7. package/lib/Chunk.js +49 -31
  8. package/lib/ChunkGraph.js +37 -27
  9. package/lib/ChunkGroup.js +8 -10
  10. package/lib/ChunkTemplate.js +1 -1
  11. package/lib/CleanPlugin.js +3 -3
  12. package/lib/CodeGenerationResults.js +3 -2
  13. package/lib/CompatibilityPlugin.js +29 -12
  14. package/lib/Compilation.js +209 -196
  15. package/lib/Compiler.js +36 -35
  16. package/lib/ConcatenationScope.js +6 -1
  17. package/lib/ConditionalInitFragment.js +1 -1
  18. package/lib/ConstPlugin.js +6 -5
  19. package/lib/ContextExclusionPlugin.js +0 -1
  20. package/lib/ContextModule.js +25 -21
  21. package/lib/ContextModuleFactory.js +30 -11
  22. package/lib/ContextReplacementPlugin.js +38 -15
  23. package/lib/DefinePlugin.js +5 -9
  24. package/lib/DelegatedModule.js +7 -11
  25. package/lib/DependenciesBlock.js +0 -2
  26. package/lib/Dependency.js +9 -11
  27. package/lib/DependencyTemplates.js +2 -4
  28. package/lib/DllModule.js +1 -7
  29. package/lib/DllReferencePlugin.js +2 -4
  30. package/lib/DynamicEntryPlugin.js +0 -2
  31. package/lib/EntryOptionPlugin.js +0 -5
  32. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  33. package/lib/EvalDevToolModulePlugin.js +4 -3
  34. package/lib/EvalSourceMapDevToolPlugin.js +3 -4
  35. package/lib/ExportsInfo.js +50 -49
  36. package/lib/ExternalModule.js +84 -52
  37. package/lib/ExternalModuleFactoryPlugin.js +27 -7
  38. package/lib/ExternalsPlugin.js +24 -17
  39. package/lib/FileSystemInfo.js +105 -90
  40. package/lib/FlagDependencyUsagePlugin.js +3 -4
  41. package/lib/Generator.js +2 -13
  42. package/lib/GraphHelpers.js +0 -3
  43. package/lib/HookWebpackError.js +0 -2
  44. package/lib/HotModuleReplacementPlugin.js +22 -24
  45. package/lib/HotUpdateChunk.js +0 -3
  46. package/lib/IgnorePlugin.js +5 -2
  47. package/lib/InitFragment.js +41 -29
  48. package/lib/InvalidDependenciesModuleWarning.js +0 -1
  49. package/lib/LibManifestPlugin.js +4 -6
  50. package/lib/LoaderOptionsPlugin.js +1 -10
  51. package/lib/MainTemplate.js +8 -19
  52. package/lib/Module.js +32 -20
  53. package/lib/ModuleFactory.js +1 -1
  54. package/lib/ModuleFilenameHelpers.js +42 -25
  55. package/lib/ModuleGraph.js +30 -16
  56. package/lib/ModuleInfoHeaderPlugin.js +0 -1
  57. package/lib/ModuleTemplate.js +0 -2
  58. package/lib/ModuleTypeConstants.js +11 -1
  59. package/lib/MultiCompiler.js +23 -15
  60. package/lib/MultiWatching.js +6 -10
  61. package/lib/NodeStuffPlugin.js +2 -10
  62. package/lib/NormalModule.js +146 -89
  63. package/lib/NormalModuleFactory.js +132 -42
  64. package/lib/OptionsApply.js +1 -1
  65. package/lib/Parser.js +1 -1
  66. package/lib/ProgressPlugin.js +6 -10
  67. package/lib/ProvidePlugin.js +5 -7
  68. package/lib/RawModule.js +1 -6
  69. package/lib/RecordIdsPlugin.js +10 -6
  70. package/lib/ResolverFactory.js +0 -2
  71. package/lib/RuntimeGlobals.js +5 -0
  72. package/lib/RuntimeModule.js +1 -3
  73. package/lib/RuntimePlugin.js +26 -22
  74. package/lib/RuntimeTemplate.js +22 -12
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
  76. package/lib/SourceMapDevToolPlugin.js +11 -18
  77. package/lib/Stats.js +0 -1
  78. package/lib/Template.js +6 -11
  79. package/lib/TemplatedPathPlugin.js +2 -1
  80. package/lib/WatchIgnorePlugin.js +2 -3
  81. package/lib/Watching.js +15 -15
  82. package/lib/WebpackIsIncludedPlugin.js +0 -2
  83. package/lib/WebpackOptionsApply.js +74 -107
  84. package/lib/asset/AssetBytesGenerator.js +167 -0
  85. package/lib/asset/AssetBytesParser.js +37 -0
  86. package/lib/asset/AssetGenerator.js +22 -37
  87. package/lib/asset/AssetModulesPlugin.js +34 -16
  88. package/lib/asset/AssetParser.js +7 -3
  89. package/lib/asset/AssetSourceGenerator.js +1 -1
  90. package/lib/asset/RawDataUrlModule.js +3 -2
  91. package/lib/async-modules/AsyncModuleHelpers.js +6 -4
  92. package/lib/buildChunkGraph.js +0 -1
  93. package/lib/cache/MemoryCachePlugin.js +0 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
  95. package/lib/cache/PackFileCacheStrategy.js +14 -1
  96. package/lib/cache/ResolverCachePlugin.js +9 -15
  97. package/lib/cache/getLazyHashedEtag.js +1 -1
  98. package/lib/config/browserslistTargetHandler.js +77 -76
  99. package/lib/config/defaults.js +162 -23
  100. package/lib/config/normalization.js +18 -3
  101. package/lib/config/target.js +1 -1
  102. package/lib/container/ContainerEntryDependency.js +0 -1
  103. package/lib/container/ContainerEntryModule.js +3 -7
  104. package/lib/container/ContainerPlugin.js +1 -2
  105. package/lib/container/ContainerReferencePlugin.js +0 -1
  106. package/lib/container/FallbackDependency.js +2 -1
  107. package/lib/container/FallbackModule.js +6 -7
  108. package/lib/container/ModuleFederationPlugin.js +0 -1
  109. package/lib/container/RemoteModule.js +8 -8
  110. package/lib/container/RemoteRuntimeModule.js +2 -2
  111. package/lib/css/CssGenerator.js +3 -6
  112. package/lib/css/CssLoadingRuntimeModule.js +6 -9
  113. package/lib/css/CssModulesPlugin.js +13 -19
  114. package/lib/css/CssParser.js +3 -3
  115. package/lib/css/walkCssTokens.js +2 -2
  116. package/lib/debug/ProfilingPlugin.js +35 -8
  117. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
  118. package/lib/dependencies/AMDPlugin.js +2 -2
  119. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
  120. package/lib/dependencies/CachedConstDependency.js +0 -4
  121. package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
  122. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  123. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
  124. package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
  125. package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
  126. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  127. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  128. package/lib/dependencies/ConstDependency.js +2 -2
  129. package/lib/dependencies/ContextDependency.js +9 -4
  130. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  131. package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
  132. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
  133. package/lib/dependencies/ContextElementDependency.js +22 -11
  134. package/lib/dependencies/CssIcssImportDependency.js +0 -2
  135. package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
  136. package/lib/dependencies/CssImportDependency.js +0 -8
  137. package/lib/dependencies/CssLocalIdentifierDependency.js +4 -7
  138. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
  139. package/lib/dependencies/CssUrlDependency.js +0 -6
  140. package/lib/dependencies/ExportsInfoDependency.js +7 -9
  141. package/lib/dependencies/ExternalModuleDependency.js +0 -3
  142. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  143. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  144. package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
  145. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  146. package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
  147. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
  148. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
  149. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
  150. package/lib/dependencies/HarmonyImportDependency.js +33 -14
  151. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -23
  152. package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
  153. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
  154. package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
  155. package/lib/dependencies/ImportContextDependency.js +13 -0
  156. package/lib/dependencies/ImportDependency.js +18 -6
  157. package/lib/dependencies/ImportEagerDependency.js +2 -3
  158. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
  159. package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
  160. package/lib/dependencies/ImportMetaPlugin.js +3 -2
  161. package/lib/dependencies/ImportParserPlugin.js +288 -45
  162. package/lib/dependencies/ImportWeakDependency.js +2 -3
  163. package/lib/dependencies/JsonExportsDependency.js +0 -1
  164. package/lib/dependencies/LoaderDependency.js +0 -3
  165. package/lib/dependencies/LoaderImportDependency.js +0 -3
  166. package/lib/dependencies/LoaderPlugin.js +11 -5
  167. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  168. package/lib/dependencies/ModuleDependency.js +3 -9
  169. package/lib/dependencies/NullDependency.js +2 -0
  170. package/lib/dependencies/ProvidedDependency.js +6 -8
  171. package/lib/dependencies/PureExpressionDependency.js +0 -1
  172. package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
  173. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
  174. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  175. package/lib/dependencies/RequireResolveDependency.js +2 -2
  176. package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
  177. package/lib/dependencies/StaticExportsDependency.js +3 -5
  178. package/lib/dependencies/URLDependency.js +2 -7
  179. package/lib/dependencies/URLPlugin.js +1 -2
  180. package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
  181. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  182. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  183. package/lib/dependencies/WorkerDependency.js +2 -3
  184. package/lib/dependencies/WorkerPlugin.js +4 -12
  185. package/lib/dependencies/processExportInfo.js +2 -3
  186. package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
  187. package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
  188. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
  189. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  190. package/lib/hmr/lazyCompilationBackend.js +13 -10
  191. package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
  192. package/lib/ids/HashedModuleIdsPlugin.js +5 -7
  193. package/lib/ids/IdHelpers.js +1 -1
  194. package/lib/ids/NamedChunkIdsPlugin.js +1 -6
  195. package/lib/ids/NamedModuleIdsPlugin.js +1 -5
  196. package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
  197. package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
  198. package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
  199. package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
  200. package/lib/ids/SyncModuleIdsPlugin.js +4 -3
  201. package/lib/index.js +8 -7
  202. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
  203. package/lib/javascript/BasicEvaluatedExpression.js +13 -6
  204. package/lib/javascript/ChunkFormatHelpers.js +1 -1
  205. package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
  206. package/lib/javascript/JavascriptGenerator.js +2 -3
  207. package/lib/javascript/JavascriptModulesPlugin.js +46 -24
  208. package/lib/javascript/JavascriptParser.js +120 -55
  209. package/lib/javascript/JavascriptParserHelpers.js +2 -2
  210. package/lib/javascript/StartupHelpers.js +2 -4
  211. package/lib/json/JsonData.js +1 -1
  212. package/lib/json/JsonGenerator.js +4 -5
  213. package/lib/json/JsonModulesPlugin.js +0 -3
  214. package/lib/json/JsonParser.js +4 -2
  215. package/lib/library/AbstractLibraryPlugin.js +2 -2
  216. package/lib/library/AmdLibraryPlugin.js +0 -1
  217. package/lib/library/AssignLibraryPlugin.js +23 -12
  218. package/lib/library/EnableLibraryPlugin.js +7 -11
  219. package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
  220. package/lib/library/JsonpLibraryPlugin.js +5 -2
  221. package/lib/library/ModuleLibraryPlugin.js +88 -43
  222. package/lib/library/SystemLibraryPlugin.js +15 -6
  223. package/lib/library/UmdLibraryPlugin.js +12 -18
  224. package/lib/logging/Logger.js +12 -10
  225. package/lib/logging/createConsoleLogger.js +15 -14
  226. package/lib/logging/truncateArgs.js +1 -1
  227. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  228. package/lib/node/NodeWatchFileSystem.js +4 -4
  229. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  230. package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
  231. package/lib/node/nodeConsole.js +2 -2
  232. package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
  233. package/lib/optimize/ConcatenatedModule.js +142 -100
  234. package/lib/optimize/InnerGraph.js +17 -11
  235. package/lib/optimize/InnerGraphPlugin.js +0 -3
  236. package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
  237. package/lib/optimize/RealContentHashPlugin.js +5 -3
  238. package/lib/optimize/RuntimeChunkPlugin.js +0 -1
  239. package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
  240. package/lib/optimize/SplitChunksPlugin.js +46 -40
  241. package/lib/performance/SizeLimitsPlugin.js +2 -1
  242. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  243. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
  244. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
  245. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  246. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  247. package/lib/rules/BasicMatcherRulePlugin.js +0 -2
  248. package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
  249. package/lib/rules/RuleSetCompiler.js +8 -6
  250. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  251. package/lib/runtime/CompatRuntimeModule.js +0 -1
  252. package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
  253. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  254. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
  255. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  256. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  257. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  258. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  259. package/lib/schemes/DataUriPlugin.js +2 -28
  260. package/lib/schemes/FileUriPlugin.js +5 -2
  261. package/lib/schemes/HttpUriPlugin.js +4 -2
  262. package/lib/schemes/VirtualUrlPlugin.js +11 -11
  263. package/lib/serialization/FileMiddleware.js +1 -1
  264. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  265. package/lib/serialization/ObjectMiddleware.js +31 -20
  266. package/lib/serialization/SerializerMiddleware.js +1 -3
  267. package/lib/serialization/types.js +1 -1
  268. package/lib/sharing/ConsumeSharedModule.js +3 -5
  269. package/lib/sharing/ConsumeSharedPlugin.js +2 -4
  270. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
  271. package/lib/sharing/ProvideSharedModule.js +3 -7
  272. package/lib/sharing/SharePlugin.js +0 -2
  273. package/lib/sharing/ShareRuntimeModule.js +4 -1
  274. package/lib/sharing/resolveMatchedConfigs.js +14 -6
  275. package/lib/sharing/utils.js +0 -6
  276. package/lib/stats/DefaultStatsFactoryPlugin.js +179 -95
  277. package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
  278. package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
  279. package/lib/stats/StatsFactory.js +14 -11
  280. package/lib/url/URLParserPlugin.js +2 -4
  281. package/lib/util/ArrayHelpers.js +4 -4
  282. package/lib/util/AsyncQueue.js +1 -0
  283. package/lib/util/Hash.js +35 -5
  284. package/lib/util/LazySet.js +2 -2
  285. package/lib/util/StackedCacheMap.js +0 -2
  286. package/lib/util/TupleSet.js +9 -4
  287. package/lib/util/URLAbsoluteSpecifier.js +0 -1
  288. package/lib/util/WeakTupleMap.js +1 -1
  289. package/lib/util/chainedImports.js +3 -1
  290. package/lib/util/cleverMerge.js +15 -18
  291. package/lib/util/comparators.js +2 -4
  292. package/lib/util/compileBooleanMatcher.js +11 -9
  293. package/lib/util/concatenate.js +1 -2
  294. package/lib/util/create-schema-validation.js +1 -2
  295. package/lib/util/createHash.js +85 -15
  296. package/lib/util/dataURL.js +39 -0
  297. package/lib/util/deprecation.js +29 -31
  298. package/lib/util/deterministicGrouping.js +34 -30
  299. package/lib/util/extractSourceMap.js +319 -0
  300. package/lib/util/findGraphRoots.js +15 -5
  301. package/lib/util/fs.js +29 -8
  302. package/lib/util/hash/BatchedHash.js +47 -8
  303. package/lib/util/hash/wasm-hash.js +53 -13
  304. package/lib/util/semver.js +9 -8
  305. package/lib/util/smartGrouping.js +41 -26
  306. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  307. package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
  308. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  309. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
  310. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
  311. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -10
  312. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
  313. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
  314. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
  315. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
  316. package/lib/wasm-sync/WebAssemblyParser.js +1 -13
  317. package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
  318. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  319. package/lib/web/JsonpTemplatePlugin.js +0 -1
  320. package/lib/webpack.js +21 -8
  321. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
  322. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  323. package/package.json +21 -21
  324. package/schemas/WebpackOptions.check.js +1 -1
  325. package/schemas/WebpackOptions.json +93 -96
  326. package/schemas/plugins/BannerPlugin.check.js +1 -1
  327. package/schemas/plugins/BannerPlugin.json +4 -0
  328. package/schemas/plugins/IgnorePlugin.json +1 -1
  329. package/schemas/plugins/ProgressPlugin.json +1 -1
  330. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  331. package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
  332. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  333. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  334. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  335. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  336. package/types.d.ts +1699 -706
  337. package/SECURITY.md +0 -9
  338. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +0 -7
  339. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
@@ -18,7 +18,6 @@ const makeSerializable = require("./util/makeSerializable");
18
18
  const memoize = require("./util/memoize");
19
19
  const processAsyncTree = require("./util/processAsyncTree");
20
20
 
21
- /** @typedef {import("enhanced-resolve").Resolver} Resolver */
22
21
  /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
23
22
  /** @typedef {import("enhanced-resolve").ResolveFunctionAsync} ResolveFunctionAsync */
24
23
  /** @typedef {import("./WebpackError")} WebpackError */
@@ -28,8 +27,6 @@ const processAsyncTree = require("./util/processAsyncTree");
28
27
  /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
29
28
  /** @typedef {import("./util/fs").IStats} IStats */
30
29
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
31
- /** @typedef {import("./util/fs").PathLike} PathLike */
32
- /** @typedef {import("./util/fs").StringCallback} StringCallback */
33
30
  /**
34
31
  * @template T
35
32
  * @typedef {import("./util/AsyncQueue").Callback<T>} ProcessorCallback
@@ -48,8 +45,8 @@ let FS_ACCURACY = 2000;
48
45
 
49
46
  const EMPTY_SET = new Set();
50
47
 
51
- const RBDT_RESOLVE_CJS = 0;
52
- const RBDT_RESOLVE_ESM = 1;
48
+ const RBDT_RESOLVE_INITIAL = 0;
49
+ const RBDT_RESOLVE_FILE = 1;
53
50
  const RBDT_RESOLVE_DIRECTORY = 2;
54
51
  const RBDT_RESOLVE_CJS_FILE = 3;
55
52
  const RBDT_RESOLVE_CJS_FILE_AS_CHILD = 4;
@@ -59,7 +56,7 @@ const RBDT_FILE = 7;
59
56
  const RBDT_DIRECTORY_DEPENDENCIES = 8;
60
57
  const RBDT_FILE_DEPENDENCIES = 9;
61
58
 
62
- /** @typedef {RBDT_RESOLVE_CJS | RBDT_RESOLVE_ESM | RBDT_RESOLVE_DIRECTORY | RBDT_RESOLVE_CJS_FILE | RBDT_RESOLVE_CJS_FILE_AS_CHILD | RBDT_RESOLVE_ESM_FILE | RBDT_DIRECTORY | RBDT_FILE | RBDT_DIRECTORY_DEPENDENCIES | RBDT_FILE_DEPENDENCIES} JobType */
59
+ /** @typedef {RBDT_RESOLVE_INITIAL | RBDT_RESOLVE_FILE | RBDT_RESOLVE_DIRECTORY | RBDT_RESOLVE_CJS_FILE | RBDT_RESOLVE_CJS_FILE_AS_CHILD | RBDT_RESOLVE_ESM_FILE | RBDT_DIRECTORY | RBDT_FILE | RBDT_DIRECTORY_DEPENDENCIES | RBDT_FILE_DEPENDENCIES} JobType */
63
60
 
64
61
  const INVALID = Symbol("invalid");
65
62
 
@@ -168,13 +165,18 @@ class SnapshotIterator {
168
165
  }
169
166
  }
170
167
 
171
- /** @typedef {Map<string, TODO> | Set<string> | undefined} SnapshotMap */
172
- /** @typedef {(snapshot: Snapshot) => SnapshotMap[]} GetMapsFunction */
168
+ /**
169
+ * @template T
170
+ * @typedef {(snapshot: Snapshot) => T[]} GetMapsFunction
171
+ */
173
172
 
173
+ /**
174
+ * @template T
175
+ */
174
176
  class SnapshotIterable {
175
177
  /**
176
178
  * @param {Snapshot} snapshot snapshot
177
- * @param {GetMapsFunction} getMaps get maps function
179
+ * @param {GetMapsFunction<T>} getMaps get maps function
178
180
  */
179
181
  constructor(snapshot, getMaps) {
180
182
  this.snapshot = snapshot;
@@ -185,9 +187,9 @@ class SnapshotIterable {
185
187
  let state = 0;
186
188
  /** @type {IterableIterator<string>} */
187
189
  let it;
188
- /** @type {GetMapsFunction} */
190
+ /** @type {GetMapsFunction<T>} */
189
191
  let getMaps;
190
- /** @type {SnapshotMap[]} */
192
+ /** @type {T[]} */
191
193
  let maps;
192
194
  /** @type {Snapshot} */
193
195
  let snapshot;
@@ -206,7 +208,9 @@ class SnapshotIterable {
206
208
  if (maps.length > 0) {
207
209
  const map = maps.pop();
208
210
  if (map !== undefined) {
209
- it = map.keys();
211
+ it =
212
+ /** @type {Set<EXPECTED_ANY> | Map<string, EXPECTED_ANY>} */
213
+ (map).keys();
210
214
  state = 2;
211
215
  } else {
212
216
  break;
@@ -539,8 +543,9 @@ class Snapshot {
539
543
  }
540
544
 
541
545
  /**
542
- * @param {GetMapsFunction} getMaps first
543
- * @returns {Iterable<string>} iterable
546
+ * @template T
547
+ * @param {GetMapsFunction<T>} getMaps first
548
+ * @returns {SnapshotIterable<T>} iterable
544
549
  */
545
550
  _createIterable(getMaps) {
546
551
  return new SnapshotIterable(this, getMaps);
@@ -658,6 +663,9 @@ class SnapshotOptimization {
658
663
  * @returns {void}
659
664
  */
660
665
  optimize(newSnapshot, capturedFiles) {
666
+ if (capturedFiles.size === 0) {
667
+ return;
668
+ }
661
669
  /**
662
670
  * @param {SnapshotOptimizationEntry} entry optimization entry
663
671
  * @returns {void}
@@ -727,6 +735,7 @@ class SnapshotOptimization {
727
735
  ) {
728
736
  continue;
729
737
  }
738
+ /** @type {Set<string>} */
730
739
  const nonSharedFiles = new Set();
731
740
  const snapshotContent =
732
741
  /** @type {NonNullable<SnapshotOptimizationEntry["snapshotContent"]>} */
@@ -1203,34 +1212,34 @@ class FileSystemInfo {
1203
1212
  processor: this._getManagedItemDirectoryInfo.bind(this)
1204
1213
  });
1205
1214
  const _unmanagedPaths = [...unmanagedPaths];
1206
- this.unmanagedPathsWithSlash =
1207
- /** @type {string[]} */
1208
- (_unmanagedPaths.filter((p) => typeof p === "string")).map((p) =>
1209
- join(fs, p, "_").slice(0, -1)
1210
- );
1211
- this.unmanagedPathsRegExps =
1212
- /** @type {RegExp[]} */
1213
- (_unmanagedPaths.filter((p) => typeof p !== "string"));
1215
+ /** @type {string[]} */
1216
+ this.unmanagedPathsWithSlash = _unmanagedPaths
1217
+ .filter((p) => typeof p === "string")
1218
+ .map((p) => join(fs, p, "_").slice(0, -1));
1219
+ /** @type {RegExp[]} */
1220
+ this.unmanagedPathsRegExps = _unmanagedPaths.filter(
1221
+ (p) => typeof p !== "string"
1222
+ );
1214
1223
 
1215
1224
  this.managedPaths = [...managedPaths];
1216
- this.managedPathsWithSlash =
1217
- /** @type {string[]} */
1218
- (this.managedPaths.filter((p) => typeof p === "string")).map((p) =>
1219
- join(fs, p, "_").slice(0, -1)
1220
- );
1225
+ /** @type {string[]} */
1226
+ this.managedPathsWithSlash = this.managedPaths
1227
+ .filter((p) => typeof p === "string")
1228
+ .map((p) => join(fs, p, "_").slice(0, -1));
1229
+ /** @type {RegExp[]} */
1230
+ this.managedPathsRegExps = this.managedPaths.filter(
1231
+ (p) => typeof p !== "string"
1232
+ );
1221
1233
 
1222
- this.managedPathsRegExps =
1223
- /** @type {RegExp[]} */
1224
- (this.managedPaths.filter((p) => typeof p !== "string"));
1225
1234
  this.immutablePaths = [...immutablePaths];
1226
- this.immutablePathsWithSlash =
1227
- /** @type {string[]} */
1228
- (this.immutablePaths.filter((p) => typeof p === "string")).map((p) =>
1229
- join(fs, p, "_").slice(0, -1)
1230
- );
1231
- this.immutablePathsRegExps =
1232
- /** @type {RegExp[]} */
1233
- (this.immutablePaths.filter((p) => typeof p !== "string"));
1235
+ /** @type {string[]} */
1236
+ this.immutablePathsWithSlash = this.immutablePaths
1237
+ .filter((p) => typeof p === "string")
1238
+ .map((p) => join(fs, p, "_").slice(0, -1));
1239
+ /** @type {RegExp[]} */
1240
+ this.immutablePathsRegExps = this.immutablePaths.filter(
1241
+ (p) => typeof p !== "string"
1242
+ );
1234
1243
 
1235
1244
  this._cachedDeprecatedFileTimestamps = undefined;
1236
1245
  this._cachedDeprecatedContextTimestamps = undefined;
@@ -1614,16 +1623,12 @@ class FileSystemInfo {
1614
1623
 
1615
1624
  /**
1616
1625
  * @param {Job} job job
1617
- * @returns {`resolve commonjs file ${string}${string}`|`resolve esm file ${string}${string}`|`resolve esm ${string}${string}`|`resolve directory ${string}`|`file ${string}`|`unknown ${string} ${string}`|`resolve commonjs ${string}${string}`|`directory ${string}`|`file dependencies ${string}`|`directory dependencies ${string}`} result
1626
+ * @returns {string} result
1618
1627
  */
1619
1628
  const jobToString = (job) => {
1620
1629
  switch (job.type) {
1621
- case RBDT_RESOLVE_CJS:
1622
- return `resolve commonjs ${job.path}${expectedToString(
1623
- job.expected
1624
- )}`;
1625
- case RBDT_RESOLVE_ESM:
1626
- return `resolve esm ${job.path}${expectedToString(job.expected)}`;
1630
+ case RBDT_RESOLVE_FILE:
1631
+ return `resolve file ${job.path}${expectedToString(job.expected)}`;
1627
1632
  case RBDT_RESOLVE_DIRECTORY:
1628
1633
  return `resolve directory ${job.path}`;
1629
1634
  case RBDT_RESOLVE_CJS_FILE:
@@ -1665,7 +1670,7 @@ class FileSystemInfo {
1665
1670
  deps,
1666
1671
  (dep) =>
1667
1672
  /** @type {Job} */ ({
1668
- type: RBDT_RESOLVE_CJS,
1673
+ type: RBDT_RESOLVE_INITIAL,
1669
1674
  context,
1670
1675
  path: dep,
1671
1676
  expected: undefined,
@@ -1769,27 +1774,23 @@ class FileSystemInfo {
1769
1774
  }
1770
1775
  );
1771
1776
  };
1772
- switch (type) {
1773
- case RBDT_RESOLVE_CJS: {
1774
- const isDirectory = /[\\/]$/.test(path);
1775
- if (isDirectory) {
1776
- resolveDirectory(path.slice(0, -1));
1777
- } else {
1778
- resolveFile(path, "f", resolveCjs);
1779
- }
1780
- break;
1781
- }
1782
- case RBDT_RESOLVE_ESM: {
1783
- const isDirectory = /[\\/]$/.test(path);
1784
- if (isDirectory) {
1785
- resolveDirectory(path.slice(0, -1));
1786
- } else {
1787
- resolveFile(path);
1788
- }
1777
+ const resolvedType =
1778
+ type === RBDT_RESOLVE_INITIAL
1779
+ ? /[\\/]$/.test(path)
1780
+ ? RBDT_RESOLVE_DIRECTORY
1781
+ : RBDT_RESOLVE_FILE
1782
+ : type;
1783
+ switch (resolvedType) {
1784
+ case RBDT_RESOLVE_FILE: {
1785
+ resolveFile(
1786
+ path,
1787
+ "f",
1788
+ /\.mjs$/.test(path) ? resolveEsm : resolveCjs
1789
+ );
1789
1790
  break;
1790
1791
  }
1791
1792
  case RBDT_RESOLVE_DIRECTORY: {
1792
- resolveDirectory(path);
1793
+ resolveDirectory(RBDT_RESOLVE_INITIAL ? path.slice(0, -1) : path);
1793
1794
  break;
1794
1795
  }
1795
1796
  case RBDT_RESOLVE_CJS_FILE: {
@@ -1867,7 +1868,13 @@ class FileSystemInfo {
1867
1868
  // Check commonjs cache for the module
1868
1869
  /** @type {NodeModule | undefined} */
1869
1870
  const module = require.cache[path];
1870
- if (module && Array.isArray(module.children)) {
1871
+ if (
1872
+ module &&
1873
+ Array.isArray(module.children) &&
1874
+ // https://github.com/nodejs/node/issues/59868
1875
+ // Force use `es-module-lexer` for mjs
1876
+ !/\.mjs$/.test(path)
1877
+ ) {
1871
1878
  children: for (const child of module.children) {
1872
1879
  const childPath = child.filename;
1873
1880
  if (childPath) {
@@ -1947,6 +1954,7 @@ class FileSystemInfo {
1947
1954
  const context = dirname(this.fs, path);
1948
1955
  const source = /** @type {Buffer} */ (content).toString();
1949
1956
  const [imports] = lexer.parse(source);
1957
+ const added = new Set();
1950
1958
  for (const imp of imports) {
1951
1959
  try {
1952
1960
  let dependency;
@@ -1964,9 +1972,11 @@ class FileSystemInfo {
1964
1972
  continue;
1965
1973
  }
1966
1974
 
1967
- // we should not track Node.js build dependencies
1975
+ // We should not track Node.js build dependencies
1968
1976
  if (dependency.startsWith("node:")) continue;
1969
1977
  if (builtinModules.has(dependency)) continue;
1978
+ // Avoid extra jobs for identical imports
1979
+ if (added.has(dependency)) continue;
1970
1980
 
1971
1981
  push({
1972
1982
  type: RBDT_RESOLVE_ESM_FILE,
@@ -1975,6 +1985,7 @@ class FileSystemInfo {
1975
1985
  expected: imp.d > -1 ? false : undefined,
1976
1986
  issuer: job
1977
1987
  });
1988
+ added.add(dependency);
1978
1989
  } catch (err1) {
1979
1990
  logger.warn(
1980
1991
  `Parsing of ${path} for build dependencies failed at 'import(${source.slice(
@@ -2336,6 +2347,9 @@ class FileSystemInfo {
2336
2347
  * @param {ManagedFiles} capturedFiles captured files
2337
2348
  */
2338
2349
  const processCapturedFiles = (capturedFiles) => {
2350
+ if (capturedFiles.size === 0) {
2351
+ return;
2352
+ }
2339
2353
  switch (mode) {
2340
2354
  case 3:
2341
2355
  this._fileTshsOptimization.optimize(snapshot, capturedFiles);
@@ -2424,6 +2438,9 @@ class FileSystemInfo {
2424
2438
  * @param {ManagedContexts} capturedDirectories captured directories
2425
2439
  */
2426
2440
  const processCapturedDirectories = (capturedDirectories) => {
2441
+ if (capturedDirectories.size === 0) {
2442
+ return;
2443
+ }
2427
2444
  switch (mode) {
2428
2445
  case 3:
2429
2446
  this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
@@ -2569,6 +2586,9 @@ class FileSystemInfo {
2569
2586
  * @param {ManagedMissing} capturedMissing captured missing
2570
2587
  */
2571
2588
  const processCapturedMissing = (capturedMissing) => {
2589
+ if (capturedMissing.size === 0) {
2590
+ return;
2591
+ }
2572
2592
  this._missingExistenceOptimization.optimize(snapshot, capturedMissing);
2573
2593
  for (const path of capturedMissing) {
2574
2594
  const cache = this._fileTimestamps.get(path);
@@ -3330,7 +3350,7 @@ class FileSystemInfo {
3330
3350
 
3331
3351
  hash.update(/** @type {string | Buffer} */ (content));
3332
3352
 
3333
- const digest = /** @type {string} */ (hash.digest("hex"));
3353
+ const digest = hash.digest("hex");
3334
3354
 
3335
3355
  this._fileHashes.set(path, digest);
3336
3356
 
@@ -3341,7 +3361,7 @@ class FileSystemInfo {
3341
3361
  /**
3342
3362
  * @private
3343
3363
  * @param {string} path path
3344
- * @param {(err: WebpackError | null, timestampAndHash?: TimestampAndHash) => void} callback callback
3364
+ * @param {(err: WebpackError | null, timestampAndHash?: TimestampAndHash | string) => void} callback callback
3345
3365
  */
3346
3366
  _getFileTimestampAndHash(path, callback) {
3347
3367
  /**
@@ -3361,7 +3381,7 @@ class FileSystemInfo {
3361
3381
  return callback(null, result);
3362
3382
  }
3363
3383
  this._fileTshs.set(path, hash);
3364
- return callback(null, /** @type {TODO} */ (hash));
3384
+ return callback(null, hash);
3365
3385
  }
3366
3386
  this.fileTimestampQueue.add(path, (err, entry) => {
3367
3387
  if (err) {
@@ -3598,7 +3618,7 @@ class FileSystemInfo {
3598
3618
  }
3599
3619
  }
3600
3620
 
3601
- const digest = /** @type {string} */ (hash.digest("hex"));
3621
+ const digest = hash.digest("hex");
3602
3622
  /** @type {ContextFileSystemInfoEntry} */
3603
3623
  const result = {
3604
3624
  safeTime,
@@ -3661,7 +3681,7 @@ class FileSystemInfo {
3661
3681
  null,
3662
3682
  (entry.resolved = {
3663
3683
  safeTime,
3664
- timestampHash: /** @type {string} */ (hash.digest("hex"))
3684
+ timestampHash: hash.digest("hex")
3665
3685
  })
3666
3686
  );
3667
3687
  }
@@ -3723,7 +3743,7 @@ class FileSystemInfo {
3723
3743
 
3724
3744
  /** @type {ContextHash} */
3725
3745
  const result = {
3726
- hash: /** @type {string} */ (hash.digest("hex"))
3746
+ hash: hash.digest("hex")
3727
3747
  };
3728
3748
  if (symlinks) result.symlinks = symlinks;
3729
3749
  return result;
@@ -3770,10 +3790,7 @@ class FileSystemInfo {
3770
3790
  for (const h of hashes) {
3771
3791
  hash.update(h);
3772
3792
  }
3773
- callback(
3774
- null,
3775
- (entry.resolved = /** @type {string} */ (hash.digest("hex")))
3776
- );
3793
+ callback(null, (entry.resolved = hash.digest("hex")));
3777
3794
  }
3778
3795
  );
3779
3796
  }
@@ -3819,22 +3836,20 @@ class FileSystemInfo {
3819
3836
  {
3820
3837
  path,
3821
3838
  fromImmutablePath: () =>
3822
- /** @type {ContextTimestampAndHash | null} */ (null),
3839
+ /** @type {ContextTimestampAndHash | Omit<ContextTimestampAndHash, "safeTime"> | string | null} */ (
3840
+ null
3841
+ ),
3823
3842
  fromManagedItem: (info) => ({
3824
3843
  safeTime: 0,
3825
3844
  timestampHash: info,
3826
3845
  hash: info || ""
3827
3846
  }),
3828
3847
  fromSymlink: (file, target, callback) => {
3829
- callback(
3830
- null,
3831
- /** @type {TODO} */
3832
- ({
3833
- timestampHash: target,
3834
- hash: target,
3835
- symlinks: new Set([target])
3836
- })
3837
- );
3848
+ callback(null, {
3849
+ timestampHash: target,
3850
+ hash: target,
3851
+ symlinks: new Set([target])
3852
+ });
3838
3853
  },
3839
3854
  fromFile: (file, stat, callback) => {
3840
3855
  this._getFileTimestampAndHash(file, callback);
@@ -3892,8 +3907,8 @@ class FileSystemInfo {
3892
3907
  /** @type {ContextTimestampAndHash} */
3893
3908
  const result = {
3894
3909
  safeTime,
3895
- timestampHash: /** @type {string} */ (tsHash.digest("hex")),
3896
- hash: /** @type {string} */ (hash.digest("hex"))
3910
+ timestampHash: tsHash.digest("hex"),
3911
+ hash: hash.digest("hex")
3897
3912
  };
3898
3913
  if (symlinks) result.symlinks = symlinks;
3899
3914
  return result;
@@ -3961,8 +3976,8 @@ class FileSystemInfo {
3961
3976
  null,
3962
3977
  (entry.resolved = {
3963
3978
  safeTime,
3964
- timestampHash: /** @type {string} */ (tsHash.digest("hex")),
3965
- hash: /** @type {string} */ (hash.digest("hex"))
3979
+ timestampHash: tsHash.digest("hex"),
3980
+ hash: hash.digest("hex")
3966
3981
  })
3967
3982
  );
3968
3983
  }
@@ -13,11 +13,10 @@ const ArrayQueue = require("./util/ArrayQueue");
13
13
  const TupleQueue = require("./util/TupleQueue");
14
14
  const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
15
15
 
16
- /** @typedef {import("./Chunk")} Chunk */
17
- /** @typedef {import("./ChunkGroup")} ChunkGroup */
18
16
  /** @typedef {import("./Compiler")} Compiler */
19
17
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
20
18
  /** @typedef {import("./Dependency").ReferencedExport} ReferencedExport */
19
+ /** @typedef {import("./Dependency").ReferencedExports} ReferencedExports */
21
20
  /** @typedef {import("./ExportsInfo")} ExportsInfo */
22
21
  /** @typedef {import("./Module")} Module */
23
22
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
@@ -61,7 +60,7 @@ class FlagDependencyUsagePlugin {
61
60
 
62
61
  /**
63
62
  * @param {Module} module module to process
64
- * @param {(string[] | ReferencedExport)[]} usedExports list of used exports
63
+ * @param {ReferencedExports} usedExports list of used exports
65
64
  * @param {RuntimeSpec} runtime part of which runtime
66
65
  * @param {boolean} forceSideEffects always apply side effects
67
66
  * @returns {void}
@@ -168,7 +167,7 @@ class FlagDependencyUsagePlugin {
168
167
  * @returns {void}
169
168
  */
170
169
  const processModule = (module, runtime, forceSideEffects) => {
171
- /** @type {Map<Module, (string[] | ReferencedExport)[] | Map<string, string[] | ReferencedExport>>} */
170
+ /** @type {Map<Module, ReferencedExports | Map<string, string[] | ReferencedExport>>} */
172
171
  const map = new Map();
173
172
 
174
173
  /** @type {ArrayQueue<DependenciesBlock>} */
package/lib/Generator.js CHANGED
@@ -8,11 +8,9 @@
8
8
  /** @typedef {import("webpack-sources").Source} Source */
9
9
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
10
10
  /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
11
- /** @typedef {import("./Compilation")} Compilation */
12
- /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
13
11
  /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
14
- /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
15
12
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
13
+ /** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */
16
14
  /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
17
15
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
18
16
  /** @typedef {import("./Module").SourceTypes} SourceTypes */
@@ -22,15 +20,6 @@
22
20
  /** @typedef {import("./util/Hash")} Hash */
23
21
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
24
22
 
25
- /**
26
- * @template T
27
- * @typedef {import("./InitFragment")<T>} InitFragment
28
- */
29
-
30
- /** @typedef {Map<"url", { [key: string]: string }> & Map<"fullContentHash", string> & Map<"contentHash", string> & Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"chunkInitFragments", InitFragment<GenerateContext>[]>} KnownGenerateContextData */
31
-
32
- /** @typedef {KnownGenerateContextData & Record<string, EXPECTED_ANY>} GenerateContextData */
33
-
34
23
  /**
35
24
  * @typedef {object} GenerateContext
36
25
  * @property {DependencyTemplates} dependencyTemplates mapping from dependencies to templates
@@ -42,7 +31,7 @@
42
31
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
43
32
  * @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
44
33
  * @property {string} type which kind of code should be generated
45
- * @property {() => GenerateContextData=} getData get access to the code generation data
34
+ * @property {() => CodeGenerationResultData=} getData get access to the code generation data
46
35
  */
47
36
 
48
37
  /**
@@ -5,11 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
9
8
  /** @typedef {import("./Chunk")} Chunk */
10
9
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
11
- /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
12
- /** @typedef {import("./Module")} Module */
13
10
  /** @typedef {import(".").Entrypoint} Entrypoint */
14
11
 
15
12
  /**
@@ -7,8 +7,6 @@
7
7
 
8
8
  const WebpackError = require("./WebpackError");
9
9
 
10
- /** @typedef {import("./Module")} Module */
11
-
12
10
  /**
13
11
  * @template T
14
12
  * @callback Callback
@@ -44,13 +44,13 @@ const {
44
44
  /** @typedef {import("estree").CallExpression} CallExpression */
45
45
  /** @typedef {import("estree").Expression} Expression */
46
46
  /** @typedef {import("estree").SpreadElement} SpreadElement */
47
- /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
48
47
  /** @typedef {import("./Chunk")} Chunk */
49
48
  /** @typedef {import("./Chunk").ChunkId} ChunkId */
50
49
  /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
51
50
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
52
51
  /** @typedef {import("./Compilation").Records} Records */
53
52
  /** @typedef {import("./Compiler")} Compiler */
53
+ /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
54
54
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
55
55
  /** @typedef {import("./Module")} Module */
56
56
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
@@ -59,10 +59,12 @@ const {
59
59
  /** @typedef {import("./javascript/JavascriptParserHelpers").Range} Range */
60
60
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
61
61
 
62
+ /** @typedef {string[]} Requests */
63
+
62
64
  /**
63
65
  * @typedef {object} HMRJavascriptParserHooks
64
- * @property {SyncBailHook<[Expression | SpreadElement, string[]], void>} hotAcceptCallback
65
- * @property {SyncBailHook<[CallExpression, string[]], void>} hotAcceptWithoutCallback
66
+ * @property {SyncBailHook<[Expression | SpreadElement, Requests], void>} hotAcceptCallback
67
+ * @property {SyncBailHook<[CallExpression, Requests], void>} hotAcceptWithoutCallback
66
68
  */
67
69
 
68
70
  /** @typedef {number} HotIndex */
@@ -147,7 +149,7 @@ class HotModuleReplacementPlugin {
147
149
  /** @type {BasicEvaluatedExpression[]} */
148
150
  (arg.items).filter((param) => param.isString());
149
151
  }
150
- /** @type {string[]} */
152
+ /** @type {Requests} */
151
153
  const requests = [];
152
154
  if (params.length > 0) {
153
155
  for (const [idx, param] of params.entries()) {
@@ -400,13 +402,11 @@ class HotModuleReplacementPlugin {
400
402
  * @returns {string} module hash
401
403
  */
402
404
  const getModuleHash = (module) => {
403
- if (
404
- compilation.codeGenerationResults.has(module, chunk.runtime)
405
- ) {
406
- return compilation.codeGenerationResults.getHash(
407
- module,
408
- chunk.runtime
409
- );
405
+ const codeGenerationResults =
406
+ /** @type {CodeGenerationResults} */
407
+ (compilation.codeGenerationResults);
408
+ if (codeGenerationResults.has(module, chunk.runtime)) {
409
+ return codeGenerationResults.getHash(module, chunk.runtime);
410
410
  }
411
411
  nonCodeGeneratedModules.add(module, chunk.runtime);
412
412
  return chunkGraph.getModuleHash(module, chunk.runtime);
@@ -500,14 +500,14 @@ class HotModuleReplacementPlugin {
500
500
  ) {
501
501
  return;
502
502
  }
503
+ const codeGenerationResults =
504
+ /** @type {CodeGenerationResults} */
505
+ (compilation.codeGenerationResults);
503
506
  for (const [module, chunk] of fullHashModules) {
504
507
  const key = `${chunk.id}|${module.identifier()}`;
505
508
  const hash = nonCodeGeneratedModules.has(module, chunk.runtime)
506
509
  ? chunkGraph.getModuleHash(module, chunk.runtime)
507
- : compilation.codeGenerationResults.getHash(
508
- module,
509
- chunk.runtime
510
- );
510
+ : codeGenerationResults.getHash(module, chunk.runtime);
511
511
  if (records.chunkModuleHashes[key] !== hash) {
512
512
  updatedModules.add(module, chunk);
513
513
  }
@@ -527,8 +527,7 @@ class HotModuleReplacementPlugin {
527
527
  forEachRuntime(allOldRuntime, (runtime) => {
528
528
  const { path: filename, info: assetInfo } =
529
529
  compilation.getPathWithInfo(
530
- /** @type {NonNullable<OutputNormalized["hotUpdateMainFilename"]>} */
531
- (compilation.outputOptions.hotUpdateMainFilename),
530
+ compilation.outputOptions.hotUpdateMainFilename,
532
531
  {
533
532
  hash: records.hash,
534
533
  runtime
@@ -548,7 +547,7 @@ class HotModuleReplacementPlugin {
548
547
  if (hotUpdateMainContentByRuntime.size === 0) return;
549
548
 
550
549
  // Create a list of all active modules to verify which modules are removed completely
551
- /** @type {Map<number | string, Module>} */
550
+ /** @type {Map<ModuleId, Module>} */
552
551
  const allModules = new Map();
553
552
  for (const module of compilation.modules) {
554
553
  const id =
@@ -558,7 +557,7 @@ class HotModuleReplacementPlugin {
558
557
  }
559
558
 
560
559
  // List of completely removed modules
561
- /** @type {Set<string | number>} */
560
+ /** @type {Set<ModuleId>} */
562
561
  const completelyRemovedModules = new Set();
563
562
 
564
563
  for (const key of Object.keys(records.chunkHashes)) {
@@ -646,10 +645,7 @@ class HotModuleReplacementPlugin {
646
645
  // Module is still in the same runtime combination
647
646
  const hash = nonCodeGeneratedModules.has(module, newRuntime)
648
647
  ? chunkGraph.getModuleHash(module, newRuntime)
649
- : compilation.codeGenerationResults.getHash(
650
- module,
651
- newRuntime
652
- );
648
+ : codeGenerationResults.getHash(module, newRuntime);
653
649
  if (hash !== oldHash) {
654
650
  if (module.type === WEBPACK_MODULE_TYPE_RUNTIME) {
655
651
  newRuntimeModules = newRuntimeModules || [];
@@ -733,7 +729,9 @@ class HotModuleReplacementPlugin {
733
729
  outputOptions: compilation.outputOptions,
734
730
  moduleTemplates: compilation.moduleTemplates,
735
731
  dependencyTemplates: compilation.dependencyTemplates,
736
- codeGenerationResults: compilation.codeGenerationResults,
732
+ codeGenerationResults: /** @type {CodeGenerationResults} */ (
733
+ compilation.codeGenerationResults
734
+ ),
737
735
  runtimeTemplate: compilation.runtimeTemplate,
738
736
  moduleGraph: compilation.moduleGraph,
739
737
  chunkGraph
@@ -7,9 +7,6 @@
7
7
 
8
8
  const Chunk = require("./Chunk");
9
9
 
10
- /** @typedef {import("./ChunkGraph")} ChunkGraph */
11
- /** @typedef {import("./util/Hash")} Hash */
12
-
13
10
  class HotUpdateChunk extends Chunk {
14
11
  constructor() {
15
12
  super();