webpack 5.104.1 → 5.105.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 (279) hide show
  1. package/bin/webpack.js +6 -3
  2. package/lib/APIPlugin.js +85 -15
  3. package/lib/AbstractMethodError.js +1 -0
  4. package/lib/AsyncDependenciesBlock.js +13 -1
  5. package/lib/AsyncDependencyToInitialChunkError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +2 -0
  8. package/lib/CacheFacade.js +2 -2
  9. package/lib/CaseSensitiveModulesWarning.js +1 -0
  10. package/lib/Chunk.js +8 -4
  11. package/lib/ChunkGraph.js +30 -9
  12. package/lib/ChunkGroup.js +6 -3
  13. package/lib/ChunkRenderError.js +2 -0
  14. package/lib/CleanPlugin.js +4 -1
  15. package/lib/CodeGenerationError.js +7 -1
  16. package/lib/CodeGenerationResults.js +10 -3
  17. package/lib/CommentCompilationWarning.js +2 -1
  18. package/lib/Compilation.js +280 -236
  19. package/lib/Compiler.js +3 -2
  20. package/lib/ConcatenationScope.js +2 -1
  21. package/lib/ConcurrentCompilationError.js +3 -3
  22. package/lib/ContextModule.js +248 -111
  23. package/lib/ContextModuleFactory.js +14 -2
  24. package/lib/DefinePlugin.js +3 -1
  25. package/lib/DelegatedModule.js +6 -0
  26. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  27. package/lib/Dependency.js +6 -1
  28. package/lib/DependencyTemplates.js +3 -2
  29. package/lib/DllModule.js +2 -0
  30. package/lib/DllReferencePlugin.js +1 -0
  31. package/lib/DotenvPlugin.js +11 -5
  32. package/lib/DynamicEntryPlugin.js +1 -0
  33. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  34. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  35. package/lib/ExportsInfo.js +8 -4
  36. package/lib/ExternalModule.js +16 -0
  37. package/lib/FalseIIFEUmdWarning.js +1 -0
  38. package/lib/FileSystemInfo.js +49 -25
  39. package/lib/FlagDependencyExportsPlugin.js +8 -1
  40. package/lib/FlagDependencyUsagePlugin.js +9 -7
  41. package/lib/HarmonyLinkingError.js +1 -0
  42. package/lib/HookWebpackError.js +2 -0
  43. package/lib/HotModuleReplacementPlugin.js +16 -2
  44. package/lib/InitFragment.js +1 -0
  45. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  46. package/lib/LibManifestPlugin.js +1 -0
  47. package/lib/ManifestPlugin.js +4 -1
  48. package/lib/Module.js +7 -4
  49. package/lib/ModuleBuildError.js +3 -1
  50. package/lib/ModuleDependencyError.js +1 -0
  51. package/lib/ModuleDependencyWarning.js +1 -0
  52. package/lib/ModuleError.js +2 -1
  53. package/lib/ModuleFilenameHelpers.js +2 -1
  54. package/lib/ModuleGraph.js +3 -0
  55. package/lib/ModuleGraphConnection.js +10 -1
  56. package/lib/ModuleHashingError.js +2 -0
  57. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  58. package/lib/ModuleNotFoundError.js +1 -0
  59. package/lib/ModuleParseError.js +5 -1
  60. package/lib/ModuleProfile.js +1 -1
  61. package/lib/ModuleRestoreError.js +2 -0
  62. package/lib/ModuleSourceTypeConstants.js +1 -11
  63. package/lib/ModuleStoreError.js +2 -0
  64. package/lib/ModuleWarning.js +3 -1
  65. package/lib/MultiCompiler.js +11 -7
  66. package/lib/MultiWatching.js +2 -2
  67. package/lib/NoModeWarning.js +1 -0
  68. package/lib/NodeStuffInWebError.js +1 -0
  69. package/lib/NormalModule.js +26 -5
  70. package/lib/NormalModuleFactory.js +20 -4
  71. package/lib/OptionsApply.js +3 -1
  72. package/lib/ProgressPlugin.js +4 -0
  73. package/lib/RawModule.js +2 -0
  74. package/lib/RuntimeModule.js +10 -0
  75. package/lib/RuntimePlugin.js +7 -9
  76. package/lib/RuntimeTemplate.js +14 -7
  77. package/lib/SourceMapDevToolPlugin.js +30 -23
  78. package/lib/Template.js +10 -5
  79. package/lib/TemplatedPathPlugin.js +4 -2
  80. package/lib/UnhandledSchemeError.js +1 -0
  81. package/lib/UnsupportedFeatureWarning.js +1 -0
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  83. package/lib/WatchIgnorePlugin.js +1 -1
  84. package/lib/Watching.js +5 -0
  85. package/lib/WebpackError.js +4 -0
  86. package/lib/WebpackOptionsApply.js +60 -40
  87. package/lib/asset/AssetBytesGenerator.js +1 -0
  88. package/lib/asset/AssetGenerator.js +9 -3
  89. package/lib/asset/AssetModulesPlugin.js +33 -2
  90. package/lib/asset/AssetSourceGenerator.js +1 -0
  91. package/lib/asset/RawDataUrlModule.js +4 -0
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +31 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  95. package/lib/cache/PackFileCacheStrategy.js +41 -8
  96. package/lib/cache/getLazyHashedEtag.js +13 -4
  97. package/lib/cache/mergeEtags.js +3 -1
  98. package/lib/cli.js +3 -1
  99. package/lib/config/defaults.js +65 -44
  100. package/lib/config/normalization.js +96 -0
  101. package/lib/container/ContainerEntryModule.js +4 -0
  102. package/lib/container/FallbackModule.js +2 -0
  103. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  104. package/lib/container/RemoteModule.js +19 -0
  105. package/lib/css/CssGenerator.js +31 -4
  106. package/lib/css/CssModulesPlugin.js +26 -30
  107. package/lib/css/CssParser.js +12 -9
  108. package/lib/debug/ProfilingPlugin.js +1 -0
  109. package/lib/dependencies/AMDDefineDependency.js +3 -1
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  111. package/lib/dependencies/AMDPlugin.js +1 -1
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  113. package/lib/dependencies/CachedConstDependency.js +1 -0
  114. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  118. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  120. package/lib/dependencies/ConstDependency.js +1 -0
  121. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  122. package/lib/dependencies/ContextElementDependency.js +1 -0
  123. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  124. package/lib/dependencies/CssIcssExportDependency.js +5 -4
  125. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  126. package/lib/dependencies/CssUrlDependency.js +2 -3
  127. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  128. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  129. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  130. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
  131. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  133. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  134. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  135. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
  136. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  137. package/lib/dependencies/ImportDependency.js +1 -0
  138. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  139. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  140. package/lib/dependencies/ImportParserPlugin.js +7 -12
  141. package/lib/dependencies/LoaderPlugin.js +3 -0
  142. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +1 -0
  144. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  145. package/lib/dependencies/ProvidedDependency.js +1 -0
  146. package/lib/dependencies/RequireContextPlugin.js +1 -0
  147. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  148. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  149. package/lib/dependencies/WorkerDependency.js +9 -3
  150. package/lib/dependencies/WorkerPlugin.js +1 -0
  151. package/lib/dependencies/getFunctionExpression.js +3 -1
  152. package/lib/errors/BuildCycleError.js +4 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  156. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  157. package/lib/hmr/lazyCompilationBackend.js +3 -2
  158. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
  159. package/lib/ids/IdHelpers.js +10 -8
  160. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
  161. package/lib/ids/SyncModuleIdsPlugin.js +5 -1
  162. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  163. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  164. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  165. package/lib/javascript/JavascriptParser.js +47 -14
  166. package/lib/json/JsonParser.js +6 -0
  167. package/lib/library/AbstractLibraryPlugin.js +4 -1
  168. package/lib/library/AmdLibraryPlugin.js +2 -1
  169. package/lib/library/AssignLibraryPlugin.js +6 -2
  170. package/lib/library/EnableLibraryPlugin.js +1 -0
  171. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  172. package/lib/library/JsonpLibraryPlugin.js +1 -1
  173. package/lib/library/ModuleLibraryPlugin.js +130 -13
  174. package/lib/library/SystemLibraryPlugin.js +4 -1
  175. package/lib/library/UmdLibraryPlugin.js +4 -3
  176. package/lib/logging/createConsoleLogger.js +3 -0
  177. package/lib/logging/truncateArgs.js +1 -1
  178. package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
  179. package/lib/node/NodeTargetPlugin.js +1 -0
  180. package/lib/node/NodeWatchFileSystem.js +3 -0
  181. package/lib/node/nodeConsole.js +18 -1
  182. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  183. package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
  184. package/lib/optimize/ConcatenatedModule.js +33 -19
  185. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  186. package/lib/optimize/InnerGraph.js +5 -3
  187. package/lib/optimize/InnerGraphPlugin.js +25 -25
  188. package/lib/optimize/MangleExportsPlugin.js +14 -2
  189. package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
  190. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  191. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  192. package/lib/optimize/RealContentHashPlugin.js +35 -27
  193. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  194. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  195. package/lib/optimize/SplitChunksPlugin.js +14 -3
  196. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  197. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  198. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  199. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  200. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  201. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  202. package/lib/rules/RuleSetCompiler.js +2 -0
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  204. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  205. package/lib/runtime/CompatRuntimeModule.js +1 -0
  206. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  207. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  208. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  209. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  210. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  211. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
  212. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  213. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  214. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  215. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  216. package/lib/schemes/HttpUriPlugin.js +27 -7
  217. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  218. package/lib/serialization/BinaryMiddleware.js +4 -0
  219. package/lib/serialization/FileMiddleware.js +9 -4
  220. package/lib/serialization/ObjectMiddleware.js +34 -11
  221. package/lib/serialization/PlainObjectSerializer.js +2 -0
  222. package/lib/sharing/ConsumeSharedModule.js +60 -0
  223. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  224. package/lib/sharing/ProvideSharedModule.js +4 -0
  225. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  226. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  227. package/lib/sharing/utils.js +8 -6
  228. package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
  229. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  230. package/lib/stats/StatsFactory.js +2 -2
  231. package/lib/url/URLParserPlugin.js +4 -3
  232. package/lib/util/AppendOnlyStackedSet.js +57 -0
  233. package/lib/util/Hash.js +1 -0
  234. package/lib/util/IterableHelpers.js +1 -0
  235. package/lib/util/LazyBucketSortedSet.js +1 -0
  236. package/lib/util/LazySet.js +1 -0
  237. package/lib/util/ParallelismFactorCalculator.js +1 -0
  238. package/lib/util/SortableSet.js +1 -0
  239. package/lib/util/StringXor.js +1 -0
  240. package/lib/util/binarySearchBounds.js +15 -8
  241. package/lib/util/chainedImports.js +1 -1
  242. package/lib/util/cleverMerge.js +6 -1
  243. package/lib/util/comparators.js +21 -1
  244. package/lib/util/compileBooleanMatcher.js +3 -3
  245. package/lib/util/concatenate.js +3 -2
  246. package/lib/util/conventions.js +3 -2
  247. package/lib/util/deterministicGrouping.js +13 -1
  248. package/lib/util/extractSourceMap.js +12 -13
  249. package/lib/util/fs.js +15 -19
  250. package/lib/util/hash/BatchedHash.js +3 -0
  251. package/lib/util/hash/BulkUpdateHash.js +7 -1
  252. package/lib/util/hash/hash-digest.js +1 -0
  253. package/lib/util/hash/wasm-hash.js +16 -1
  254. package/lib/util/identifier.js +7 -2
  255. package/lib/util/magicComment.js +1 -1
  256. package/lib/util/propertyName.js +1 -1
  257. package/lib/util/registerExternalSerializer.js +1 -0
  258. package/lib/util/runtime.js +15 -1
  259. package/lib/util/semver.js +1 -0
  260. package/lib/util/serialization.js +2 -2
  261. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
  262. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  263. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  264. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  265. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  266. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  267. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  268. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  269. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  270. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  271. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  272. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  273. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  274. package/lib/webpack.js +13 -3
  275. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  276. package/package.json +20 -28
  277. package/schemas/WebpackOptions.check.js +1 -1
  278. package/schemas/WebpackOptions.json +71 -5
  279. package/types.d.ts +339 -93
@@ -286,7 +286,7 @@ const { isSourceEqual } = require("./util/source");
286
286
 
287
287
  /**
288
288
  * @typedef {object} LogEntry
289
- * @property {string} type
289
+ * @property {keyof LogType} type
290
290
  * @property {EXPECTED_ANY[]=} args
291
291
  * @property {number} time
292
292
  * @property {string[]=} trace
@@ -403,11 +403,11 @@ const { isSourceEqual } = require("./util/source");
403
403
 
404
404
  /** @typedef {KnownCreateStatsOptionsContext & Record<string, EXPECTED_ANY>} CreateStatsOptionsContext */
405
405
 
406
- /** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}} CodeGenerationJob */
406
+ /** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[] }} CodeGenerationJob */
407
407
 
408
408
  /** @typedef {CodeGenerationJob[]} CodeGenerationJobs */
409
409
 
410
- /** @typedef {{javascript: ModuleTemplate}} ModuleTemplates */
410
+ /** @typedef {{ javascript: ModuleTemplate }} ModuleTemplates */
411
411
 
412
412
  /** @typedef {Set<Module>} NotCodeGeneratedModules */
413
413
 
@@ -514,22 +514,25 @@ class Compilation {
514
514
  /** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
515
515
  const processAssetsHook = new AsyncSeriesHook(["assets"]);
516
516
 
517
+ /** @type {Set<string>} */
517
518
  let savedAssets = new Set();
518
519
  /**
519
520
  * @param {CompilationAssets} assets assets
520
521
  * @returns {CompilationAssets} new assets
521
522
  */
522
523
  const popNewAssets = (assets) => {
524
+ /** @type {undefined | CompilationAssets} */
523
525
  let newAssets;
524
526
  for (const file of Object.keys(assets)) {
525
527
  if (savedAssets.has(file)) continue;
526
528
  if (newAssets === undefined) {
527
529
  newAssets = Object.create(null);
528
530
  }
529
- newAssets[file] = assets[file];
531
+ /** @type {CompilationAssets} */
532
+ (newAssets)[file] = assets[file];
530
533
  savedAssets.add(file);
531
534
  }
532
- return newAssets;
535
+ return /** @type {CompilationAssets} */ (newAssets);
533
536
  };
534
537
  processAssetsHook.intercept({
535
538
  name: "Compilation",
@@ -1347,6 +1350,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1347
1350
  );
1348
1351
  }
1349
1352
  }
1353
+ /** @type {LogEntry["trace"]} */
1350
1354
  let trace;
1351
1355
  switch (type) {
1352
1356
  case LogType.warn:
@@ -1519,7 +1523,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1519
1523
  /**
1520
1524
  * Attempts to search for a module by its identifier
1521
1525
  * @param {string} identifier identifier (usually path) for module
1522
- * @returns {Module|undefined} attempt to search for module and return it, else undefined
1526
+ * @returns {Module | undefined} attempt to search for module and return it, else undefined
1523
1527
  */
1524
1528
  findModule(identifier) {
1525
1529
  return this._modules.get(identifier);
@@ -2292,6 +2296,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2292
2296
  (originModule)
2293
2297
  );
2294
2298
  if (creatingModuleDuringBuildSet === undefined) {
2299
+ /** @type {Set<Module>} */
2295
2300
  creatingModuleDuringBuildSet = new Set();
2296
2301
  this.creatingModuleDuringBuild.set(
2297
2302
  /** @type {Module} */
@@ -2598,7 +2603,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2598
2603
  this.moduleGraph.setModuleMemCaches(this.moduleMemCaches);
2599
2604
  }
2600
2605
  const { moduleGraph, moduleMemCaches } = this;
2606
+ /** @type {Set<Module>} */
2601
2607
  const affectedModules = new Set();
2608
+ /** @type {Set<Module>} */
2602
2609
  const infectedModules = new Set();
2603
2610
  let statNew = 0;
2604
2611
  let statChanged = 0;
@@ -2714,6 +2721,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2714
2721
  }
2715
2722
  return affected;
2716
2723
  };
2724
+ /** @type {Set<Module>} */
2717
2725
  const directOnlyInfectedModules = new Set();
2718
2726
  for (const module of infectedModules) {
2719
2727
  for (const [
@@ -2732,6 +2740,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2732
2740
  }
2733
2741
  }
2734
2742
  for (const module of directOnlyInfectedModules) infectedModules.add(module);
2743
+ /** @type {Set<Module>} */
2735
2744
  const directOnlyAffectModules = new Set();
2736
2745
  for (const module of affectedModules) {
2737
2746
  for (const [
@@ -2994,6 +3003,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2994
3003
  * @param {(profile: ModuleProfile) => number} getParallelism get parallelism callback
2995
3004
  */
2996
3005
  const logByLoadersSummary = (category, getDuration, getParallelism) => {
3006
+ /** @type {Map<string, { module: Module, profile: ModuleProfile }[]>} */
2997
3007
  const map = new Map();
2998
3008
  for (const [module, profile] of modulesWithProfiles) {
2999
3009
  const list = getOrInsert(
@@ -3205,6 +3215,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3205
3215
  this.chunkGroups.push(entrypoint);
3206
3216
  connectChunkGroupAndChunk(entrypoint, chunk);
3207
3217
 
3218
+ /** @type {Set<Module>} */
3208
3219
  const entryModules = new Set();
3209
3220
  for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
3210
3221
  entrypoint.addOrigin(
@@ -3252,6 +3263,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3252
3263
  modulesList.push(module);
3253
3264
  }
3254
3265
  }
3266
+ /** @type {Set<Chunk>} */
3255
3267
  const runtimeChunks = new Set();
3256
3268
  outer: for (const [
3257
3269
  name,
@@ -3625,6 +3637,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3625
3637
  const runIteration = () => {
3626
3638
  /** @type {CodeGenerationJobs} */
3627
3639
  let delayedJobs = [];
3640
+ /** @type {Set<Module>} */
3628
3641
  let delayedModules = new Set();
3629
3642
  asyncLib.eachLimit(
3630
3643
  jobs,
@@ -3668,7 +3681,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3668
3681
  );
3669
3682
  },
3670
3683
  (err) => {
3671
- if (err) return callback(err);
3684
+ if (err) return callback(/** @type {WebpackError} */ (err));
3672
3685
  if (delayedJobs.length > 0) {
3673
3686
  if (delayedJobs.length === jobs.length) {
3674
3687
  return callback(
@@ -3746,6 +3759,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3746
3759
  );
3747
3760
  cache.get((err, cachedResult) => {
3748
3761
  if (err) return callback(/** @type {WebpackError} */ (err));
3762
+ /** @type {CodeGenerationResult} */
3749
3763
  let result;
3750
3764
  if (!cachedResult) {
3751
3765
  try {
@@ -3845,6 +3859,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3845
3859
  continue;
3846
3860
  }
3847
3861
  }
3862
+ /** @type {RuntimeRequirements} */
3848
3863
  let set;
3849
3864
  const runtimeRequirements =
3850
3865
  codeGenerationResults.getRuntimeRequirements(module, runtime);
@@ -4407,6 +4422,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4407
4422
  hashDigestLength,
4408
4423
  errors
4409
4424
  ) {
4425
+ /** @type {string} */
4410
4426
  let moduleHashDigest;
4411
4427
  try {
4412
4428
  const moduleHash = createHash(hashFunction);
@@ -4529,6 +4545,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4529
4545
  // If there are any references between chunks
4530
4546
  // make sure to follow these chains
4531
4547
  if (remaining > 0) {
4548
+ /** @type {Chunk[]} */
4532
4549
  const readyChunks = [];
4533
4550
  for (const chunk of runtimeChunks) {
4534
4551
  const hasFullHashModules =
@@ -4555,6 +4572,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4555
4572
  }
4556
4573
  // If there are still remaining references we have cycles and want to create a warning
4557
4574
  if (remaining > 0) {
4575
+ /** @type {RuntimeChunkInfo[]} */
4558
4576
  const circularRuntimeChunkInfo = [];
4559
4577
  for (const info of runtimeChunksMap.values()) {
4560
4578
  if (info.remaining !== 0) {
@@ -4574,6 +4592,7 @@ This prevents using hashes of each other and should be avoided.`);
4574
4592
  }
4575
4593
  this.logger.timeEnd("hashing: sort chunks");
4576
4594
 
4595
+ /** @type {Set<Chunk>} */
4577
4596
  const fullHashChunks = new Set();
4578
4597
  /** @type {CodeGenerationJobs} */
4579
4598
  const codeGenerationJobs = [];
@@ -4702,7 +4721,7 @@ This prevents using hashes of each other and should be avoided.`);
4702
4721
  ).hash = moduleHashDigest;
4703
4722
  }
4704
4723
  const chunkHash = createHash(hashFunction);
4705
- chunkHash.update(chunk.hash);
4724
+ chunkHash.update(/** @type {string} */ (chunk.hash));
4706
4725
  chunkHash.update(this.hash);
4707
4726
  const chunkHashDigest = chunkHash.digest(hashDigest);
4708
4727
  chunk.hash = chunkHashDigest;
@@ -4873,6 +4892,7 @@ This prevents using hashes of each other and should be avoided.`);
4873
4892
  const related = info.related;
4874
4893
  if (!related) continue;
4875
4894
  const entry = related[key];
4895
+ /** @type {string | string[]} */
4876
4896
  let newEntry;
4877
4897
  if (Array.isArray(entry)) {
4878
4898
  newEntry = entry.map((x) => (x === file ? newFile : x));
@@ -5026,8 +5046,9 @@ This prevents using hashes of each other and should be avoided.`);
5026
5046
  */
5027
5047
  createChunkAssets(callback) {
5028
5048
  const outputOptions = this.outputOptions;
5049
+ /** @type {WeakMap<Source, CachedSource>} */
5029
5050
  const cachedSourceMap = new WeakMap();
5030
- /** @type {Map<string, {hash: string, source: Source, chunk: Chunk}>} */
5051
+ /** @type {Map<string, { hash: string, source: Source, chunk: Chunk }>} */
5031
5052
  const alreadyWrittenFiles = new Map();
5032
5053
 
5033
5054
  asyncLib.forEachLimit(
@@ -5392,254 +5413,277 @@ This prevents using hashes of each other and should be avoided.`);
5392
5413
  };
5393
5414
 
5394
5415
  // Generate code for all aggregated modules
5395
- asyncLib.eachLimit(modules, 10, codeGen, (err) => {
5396
- if (err) return callback(err);
5397
- reportErrors();
5398
-
5399
- // for backward-compat temporary set the chunk graph
5400
- // TODO webpack 6
5401
- const old = this.chunkGraph;
5402
- this.chunkGraph = chunkGraph;
5403
- this.processRuntimeRequirements({
5404
- chunkGraph,
5405
- modules,
5406
- chunks,
5407
- codeGenerationResults,
5408
- chunkGraphEntries: chunks
5409
- });
5410
- this.chunkGraph = old;
5411
-
5412
- const runtimeModules =
5413
- chunkGraph.getChunkRuntimeModulesIterable(chunk);
5416
+ asyncLib.eachLimit(
5417
+ /** @type {import("neo-async").IterableCollection<Module>} */ (
5418
+ /** @type {unknown} */ (modules)
5419
+ ),
5420
+ 10,
5421
+ codeGen,
5422
+ (err) => {
5423
+ if (err) return callback(err);
5424
+ reportErrors();
5414
5425
 
5415
- // Hash runtime modules
5416
- for (const module of runtimeModules) {
5417
- modules.add(module);
5418
- this._createModuleHash(
5419
- module,
5426
+ // for backward-compat temporary set the chunk graph
5427
+ // TODO webpack 6
5428
+ const old = this.chunkGraph;
5429
+ this.chunkGraph = chunkGraph;
5430
+ this.processRuntimeRequirements({
5420
5431
  chunkGraph,
5421
- runtime,
5422
- hashFunction,
5423
- runtimeTemplate,
5424
- hashDigest,
5425
- hashDigestLength,
5426
- errors
5427
- );
5428
- }
5432
+ modules,
5433
+ chunks,
5434
+ codeGenerationResults,
5435
+ chunkGraphEntries: chunks
5436
+ });
5437
+ this.chunkGraph = old;
5429
5438
 
5430
- // Generate code for all runtime modules
5431
- asyncLib.eachLimit(runtimeModules, 10, codeGen, (err) => {
5432
- if (err) return callback(err);
5433
- reportErrors();
5439
+ const runtimeModules =
5440
+ chunkGraph.getChunkRuntimeModulesIterable(chunk);
5434
5441
 
5435
- /** @type {Map<Module, ExecuteModuleArgument>} */
5436
- const moduleArgumentsMap = new Map();
5437
- /** @type {Map<string, ExecuteModuleArgument>} */
5438
- const moduleArgumentsById = new Map();
5439
-
5440
- /** @type {ExecuteModuleResult["fileDependencies"]} */
5441
- const fileDependencies = new LazySet();
5442
- /** @type {ExecuteModuleResult["contextDependencies"]} */
5443
- const contextDependencies = new LazySet();
5444
- /** @type {ExecuteModuleResult["missingDependencies"]} */
5445
- const missingDependencies = new LazySet();
5446
- /** @type {ExecuteModuleResult["buildDependencies"]} */
5447
- const buildDependencies = new LazySet();
5448
-
5449
- /** @type {ExecuteModuleResult["assets"]} */
5450
- const assets = new Map();
5451
-
5452
- let cacheable = true;
5453
-
5454
- /** @type {ExecuteModuleContext} */
5455
- const context = {
5456
- assets,
5457
- __webpack_require__: undefined,
5458
- chunk,
5459
- chunkGraph
5460
- };
5442
+ // Hash runtime modules
5443
+ for (const module of runtimeModules) {
5444
+ modules.add(module);
5445
+ this._createModuleHash(
5446
+ module,
5447
+ chunkGraph,
5448
+ runtime,
5449
+ hashFunction,
5450
+ runtimeTemplate,
5451
+ hashDigest,
5452
+ hashDigestLength,
5453
+ errors
5454
+ );
5455
+ }
5461
5456
 
5462
- // Prepare execution
5457
+ // Generate code for all runtime modules
5463
5458
  asyncLib.eachLimit(
5464
- modules,
5459
+ /** @type {import("neo-async").IterableCollection<RuntimeModule>} */ (
5460
+ runtimeModules
5461
+ ),
5465
5462
  10,
5466
- (module, callback) => {
5467
- const codeGenerationResult = codeGenerationResults.get(
5468
- module,
5469
- runtime
5470
- );
5471
- /** @type {ExecuteModuleArgument} */
5472
- const moduleArgument = {
5473
- module,
5474
- codeGenerationResult,
5475
- moduleObject: undefined
5476
- };
5477
- moduleArgumentsMap.set(module, moduleArgument);
5478
- moduleArgumentsById.set(module.identifier(), moduleArgument);
5479
- module.addCacheDependencies(
5480
- fileDependencies,
5481
- contextDependencies,
5482
- missingDependencies,
5483
- buildDependencies
5484
- );
5485
- if (
5486
- /** @type {BuildInfo} */ (module.buildInfo).cacheable ===
5487
- false
5488
- ) {
5489
- cacheable = false;
5490
- }
5491
- if (module.buildInfo && module.buildInfo.assets) {
5492
- const { assets: moduleAssets, assetsInfo } = module.buildInfo;
5493
- for (const assetName of Object.keys(moduleAssets)) {
5494
- assets.set(assetName, {
5495
- source: moduleAssets[assetName],
5496
- info: assetsInfo ? assetsInfo.get(assetName) : undefined
5497
- });
5498
- }
5499
- }
5500
- this.hooks.prepareModuleExecution.callAsync(
5501
- moduleArgument,
5502
- context,
5503
- callback
5504
- );
5505
- },
5463
+ codeGen,
5506
5464
  (err) => {
5507
5465
  if (err) return callback(err);
5466
+ reportErrors();
5508
5467
 
5509
- /** @type {ExecuteModuleExports | undefined} */
5510
- let exports;
5511
- try {
5512
- const {
5513
- strictModuleErrorHandling,
5514
- strictModuleExceptionHandling
5515
- } = this.outputOptions;
5516
-
5517
- /** @type {WebpackRequire} */
5518
- const __webpack_require__ = (id) => {
5519
- const cached = moduleCache[id];
5520
- if (cached !== undefined) {
5521
- if (cached.error) throw cached.error;
5522
- return cached.exports;
5523
- }
5524
- const moduleArgument = moduleArgumentsById.get(id);
5525
- return __webpack_require_module__(
5526
- /** @type {ExecuteModuleArgument} */
5527
- (moduleArgument),
5528
- id
5529
- );
5530
- };
5531
- const interceptModuleExecution = (__webpack_require__[
5532
- /** @type {"i"} */
5533
- (
5534
- RuntimeGlobals.interceptModuleExecution.replace(
5535
- `${RuntimeGlobals.require}.`,
5536
- ""
5537
- )
5538
- )
5539
- ] = /** @type {NonNullable<WebpackRequire["i"]>} */ ([]));
5540
- const moduleCache = (__webpack_require__[
5541
- /** @type {"c"} */ (
5542
- RuntimeGlobals.moduleCache.replace(
5543
- `${RuntimeGlobals.require}.`,
5544
- ""
5545
- )
5546
- )
5547
- ] = /** @type {NonNullable<WebpackRequire["c"]>} */ ({}));
5468
+ /** @type {Map<Module, ExecuteModuleArgument>} */
5469
+ const moduleArgumentsMap = new Map();
5470
+ /** @type {Map<string, ExecuteModuleArgument>} */
5471
+ const moduleArgumentsById = new Map();
5548
5472
 
5549
- context.__webpack_require__ = __webpack_require__;
5473
+ /** @type {ExecuteModuleResult["fileDependencies"]} */
5474
+ const fileDependencies = new LazySet();
5475
+ /** @type {ExecuteModuleResult["contextDependencies"]} */
5476
+ const contextDependencies = new LazySet();
5477
+ /** @type {ExecuteModuleResult["missingDependencies"]} */
5478
+ const missingDependencies = new LazySet();
5479
+ /** @type {ExecuteModuleResult["buildDependencies"]} */
5480
+ const buildDependencies = new LazySet();
5550
5481
 
5551
- /**
5552
- * @param {ExecuteModuleArgument} moduleArgument the module argument
5553
- * @param {string=} id id
5554
- * @returns {ExecuteModuleExports} exports
5555
- */
5556
- const __webpack_require_module__ = (moduleArgument, id) => {
5557
- /** @type {ExecuteOptions} */
5558
- const execOptions = {
5559
- id,
5560
- module: {
5561
- id,
5562
- exports: {},
5563
- loaded: false,
5564
- error: undefined
5565
- },
5566
- require: __webpack_require__
5482
+ /** @type {ExecuteModuleResult["assets"]} */
5483
+ const assets = new Map();
5484
+
5485
+ let cacheable = true;
5486
+
5487
+ /** @type {ExecuteModuleContext} */
5488
+ const context = {
5489
+ assets,
5490
+ __webpack_require__: undefined,
5491
+ chunk,
5492
+ chunkGraph
5493
+ };
5494
+
5495
+ // Prepare execution
5496
+ asyncLib.eachLimit(
5497
+ modules,
5498
+ 10,
5499
+ (module, callback) => {
5500
+ const codeGenerationResult = codeGenerationResults.get(
5501
+ module,
5502
+ runtime
5503
+ );
5504
+ /** @type {ExecuteModuleArgument} */
5505
+ const moduleArgument = {
5506
+ module,
5507
+ codeGenerationResult,
5508
+ moduleObject: undefined
5567
5509
  };
5568
- for (const handler of interceptModuleExecution) {
5569
- handler(execOptions);
5510
+ moduleArgumentsMap.set(module, moduleArgument);
5511
+ moduleArgumentsById.set(
5512
+ module.identifier(),
5513
+ moduleArgument
5514
+ );
5515
+ module.addCacheDependencies(
5516
+ fileDependencies,
5517
+ contextDependencies,
5518
+ missingDependencies,
5519
+ buildDependencies
5520
+ );
5521
+ if (
5522
+ /** @type {BuildInfo} */ (module.buildInfo).cacheable ===
5523
+ false
5524
+ ) {
5525
+ cacheable = false;
5570
5526
  }
5571
- const module = moduleArgument.module;
5572
- this.buildTimeExecutedModules.add(module);
5573
- const moduleObject = execOptions.module;
5574
- moduleArgument.moduleObject = moduleObject;
5575
- try {
5576
- if (id) moduleCache[id] = moduleObject;
5577
-
5578
- tryRunOrWebpackError(
5579
- () =>
5580
- this.hooks.executeModule.call(
5581
- moduleArgument,
5582
- context
5583
- ),
5584
- "Compilation.hooks.executeModule"
5585
- );
5586
- moduleObject.loaded = true;
5587
- return moduleObject.exports;
5588
- } catch (execErr) {
5589
- if (strictModuleExceptionHandling) {
5590
- if (id) delete moduleCache[id];
5591
- } else if (strictModuleErrorHandling) {
5592
- moduleObject.error =
5593
- /** @type {WebpackError} */
5594
- (execErr);
5527
+ if (module.buildInfo && module.buildInfo.assets) {
5528
+ const { assets: moduleAssets, assetsInfo } =
5529
+ module.buildInfo;
5530
+ for (const assetName of Object.keys(moduleAssets)) {
5531
+ assets.set(assetName, {
5532
+ source: moduleAssets[assetName],
5533
+ info: assetsInfo
5534
+ ? assetsInfo.get(assetName)
5535
+ : undefined
5536
+ });
5595
5537
  }
5596
- if (!(/** @type {WebpackError} */ (execErr).module)) {
5597
- /** @type {WebpackError} */
5598
- (execErr).module = module;
5599
- }
5600
- throw execErr;
5601
5538
  }
5602
- };
5603
-
5604
- for (const runtimeModule of chunkGraph.getChunkRuntimeModulesInOrder(
5605
- chunk
5606
- )) {
5607
- __webpack_require_module__(
5608
- /** @type {ExecuteModuleArgument} */
5609
- (moduleArgumentsMap.get(runtimeModule))
5539
+ this.hooks.prepareModuleExecution.callAsync(
5540
+ moduleArgument,
5541
+ context,
5542
+ callback
5610
5543
  );
5611
- }
5544
+ },
5545
+ (err) => {
5546
+ if (err) return callback(/** @type {WebpackError} */ (err));
5612
5547
 
5613
- exports = __webpack_require__(module.identifier());
5614
- } catch (execErr) {
5615
- const { message, stack, module } =
5616
- /** @type {WebpackError} */
5617
- (execErr);
5618
- const err = new WebpackError(
5619
- `Execution of module code from module graph (${
5620
- /** @type {Module} */
5621
- (module).readableIdentifier(this.requestShortener)
5622
- }) failed: ${message}`,
5623
- { cause: execErr }
5624
- );
5625
- err.stack = stack;
5626
- err.module = module;
5627
- return callback(err);
5628
- }
5548
+ /** @type {ExecuteModuleExports | undefined} */
5549
+ let exports;
5550
+ try {
5551
+ const {
5552
+ strictModuleErrorHandling,
5553
+ strictModuleExceptionHandling
5554
+ } = this.outputOptions;
5555
+
5556
+ /** @type {WebpackRequire} */
5557
+ const __webpack_require__ = (id) => {
5558
+ const cached = moduleCache[id];
5559
+ if (cached !== undefined) {
5560
+ if (cached.error) throw cached.error;
5561
+ return cached.exports;
5562
+ }
5563
+ const moduleArgument = moduleArgumentsById.get(id);
5564
+ return __webpack_require_module__(
5565
+ /** @type {ExecuteModuleArgument} */
5566
+ (moduleArgument),
5567
+ id
5568
+ );
5569
+ };
5570
+ const interceptModuleExecution = (__webpack_require__[
5571
+ /** @type {"i"} */
5572
+ (
5573
+ RuntimeGlobals.interceptModuleExecution.replace(
5574
+ `${RuntimeGlobals.require}.`,
5575
+ ""
5576
+ )
5577
+ )
5578
+ ] = /** @type {NonNullable<WebpackRequire["i"]>} */ ([]));
5579
+ const moduleCache = (__webpack_require__[
5580
+ /** @type {"c"} */ (
5581
+ RuntimeGlobals.moduleCache.replace(
5582
+ `${RuntimeGlobals.require}.`,
5583
+ ""
5584
+ )
5585
+ )
5586
+ ] = /** @type {NonNullable<WebpackRequire["c"]>} */ ({}));
5587
+
5588
+ context.__webpack_require__ = __webpack_require__;
5589
+
5590
+ /**
5591
+ * @param {ExecuteModuleArgument} moduleArgument the module argument
5592
+ * @param {string=} id id
5593
+ * @returns {ExecuteModuleExports} exports
5594
+ */
5595
+ const __webpack_require_module__ = (
5596
+ moduleArgument,
5597
+ id
5598
+ ) => {
5599
+ /** @type {ExecuteOptions} */
5600
+ const execOptions = {
5601
+ id,
5602
+ module: {
5603
+ id,
5604
+ exports: {},
5605
+ loaded: false,
5606
+ error: undefined
5607
+ },
5608
+ require: __webpack_require__
5609
+ };
5610
+ for (const handler of interceptModuleExecution) {
5611
+ handler(execOptions);
5612
+ }
5613
+ const module = moduleArgument.module;
5614
+ this.buildTimeExecutedModules.add(module);
5615
+ const moduleObject = execOptions.module;
5616
+ moduleArgument.moduleObject = moduleObject;
5617
+ try {
5618
+ if (id) moduleCache[id] = moduleObject;
5619
+
5620
+ tryRunOrWebpackError(
5621
+ () =>
5622
+ this.hooks.executeModule.call(
5623
+ moduleArgument,
5624
+ context
5625
+ ),
5626
+ "Compilation.hooks.executeModule"
5627
+ );
5628
+ moduleObject.loaded = true;
5629
+ return moduleObject.exports;
5630
+ } catch (execErr) {
5631
+ if (strictModuleExceptionHandling) {
5632
+ if (id) delete moduleCache[id];
5633
+ } else if (strictModuleErrorHandling) {
5634
+ moduleObject.error =
5635
+ /** @type {WebpackError} */
5636
+ (execErr);
5637
+ }
5638
+ if (!(/** @type {WebpackError} */ (execErr).module)) {
5639
+ /** @type {WebpackError} */
5640
+ (execErr).module = module;
5641
+ }
5642
+ throw execErr;
5643
+ }
5644
+ };
5645
+
5646
+ for (const runtimeModule of chunkGraph.getChunkRuntimeModulesInOrder(
5647
+ chunk
5648
+ )) {
5649
+ __webpack_require_module__(
5650
+ /** @type {ExecuteModuleArgument} */
5651
+ (moduleArgumentsMap.get(runtimeModule))
5652
+ );
5653
+ }
5629
5654
 
5630
- callback(null, {
5631
- exports,
5632
- assets,
5633
- cacheable,
5634
- fileDependencies,
5635
- contextDependencies,
5636
- missingDependencies,
5637
- buildDependencies
5638
- });
5655
+ exports = __webpack_require__(module.identifier());
5656
+ } catch (execErr) {
5657
+ const { message, stack, module } =
5658
+ /** @type {WebpackError} */
5659
+ (execErr);
5660
+ const err = new WebpackError(
5661
+ `Execution of module code from module graph (${
5662
+ /** @type {Module} */
5663
+ (module).readableIdentifier(this.requestShortener)
5664
+ }) failed: ${message}`,
5665
+ { cause: execErr }
5666
+ );
5667
+ err.stack = stack;
5668
+ err.module = module;
5669
+ return callback(err);
5670
+ }
5671
+
5672
+ callback(null, {
5673
+ exports,
5674
+ assets,
5675
+ cacheable,
5676
+ fileDependencies,
5677
+ contextDependencies,
5678
+ missingDependencies,
5679
+ buildDependencies
5680
+ });
5681
+ }
5682
+ );
5639
5683
  }
5640
5684
  );
5641
- });
5642
- });
5685
+ }
5686
+ );
5643
5687
  }
5644
5688
  );
5645
5689
  }