webpack 5.90.3 → 5.91.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (174) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +262 -93
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +2 -0
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/DefinePlugin.js +4 -2
  18. package/lib/Dependency.js +4 -2
  19. package/lib/DependencyTemplate.js +7 -2
  20. package/lib/DllModule.js +1 -0
  21. package/lib/DllReferencePlugin.js +6 -2
  22. package/lib/EntryOptionPlugin.js +4 -1
  23. package/lib/EntryPlugin.js +6 -1
  24. package/lib/Entrypoint.js +1 -1
  25. package/lib/ExportsInfo.js +1 -4
  26. package/lib/ExternalModule.js +118 -24
  27. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  28. package/lib/FileSystemInfo.js +1 -1
  29. package/lib/Generator.js +2 -1
  30. package/lib/HookWebpackError.js +2 -2
  31. package/lib/InitFragment.js +5 -3
  32. package/lib/LibManifestPlugin.js +15 -7
  33. package/lib/Module.js +30 -2
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +56 -27
  36. package/lib/ModuleGraphConnection.js +2 -1
  37. package/lib/MultiCompiler.js +26 -8
  38. package/lib/NodeStuffPlugin.js +14 -3
  39. package/lib/NormalModule.js +3 -1
  40. package/lib/NormalModuleFactory.js +1 -1
  41. package/lib/NormalModuleReplacementPlugin.js +5 -1
  42. package/lib/ProvidePlugin.js +3 -1
  43. package/lib/RawModule.js +2 -1
  44. package/lib/ResolverFactory.js +3 -1
  45. package/lib/RuntimeModule.js +4 -4
  46. package/lib/RuntimePlugin.js +1 -0
  47. package/lib/RuntimeTemplate.js +102 -34
  48. package/lib/SourceMapDevToolPlugin.js +4 -1
  49. package/lib/Stats.js +10 -3
  50. package/lib/TemplatedPathPlugin.js +32 -6
  51. package/lib/Watching.js +67 -60
  52. package/lib/WebpackError.js +6 -6
  53. package/lib/WebpackOptionsApply.js +18 -5
  54. package/lib/asset/RawDataUrlModule.js +3 -1
  55. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  56. package/lib/buildChunkGraph.js +117 -64
  57. package/lib/cache/IdleFileCachePlugin.js +8 -3
  58. package/lib/cache/MemoryCachePlugin.js +1 -1
  59. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  60. package/lib/cache/PackFileCacheStrategy.js +49 -16
  61. package/lib/cache/ResolverCachePlugin.js +14 -6
  62. package/lib/cache/getLazyHashedEtag.js +1 -1
  63. package/lib/config/defaults.js +24 -1
  64. package/lib/config/normalization.js +3 -1
  65. package/lib/container/ContainerEntryDependency.js +2 -1
  66. package/lib/container/ContainerEntryModule.js +3 -1
  67. package/lib/container/ContainerPlugin.js +14 -10
  68. package/lib/container/FallbackModule.js +1 -1
  69. package/lib/container/RemoteRuntimeModule.js +12 -3
  70. package/lib/css/CssExportsGenerator.js +34 -17
  71. package/lib/css/CssGenerator.js +20 -2
  72. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  73. package/lib/css/CssModulesPlugin.js +47 -13
  74. package/lib/debug/ProfilingPlugin.js +27 -2
  75. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  76. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  77. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  78. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  79. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  80. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  81. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  82. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  83. package/lib/dependencies/ContextElementDependency.js +8 -1
  84. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  85. package/lib/dependencies/CssUrlDependency.js +5 -3
  86. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  87. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  88. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  89. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  90. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  92. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  93. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  94. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  95. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  96. package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
  97. package/lib/dependencies/ImportDependency.js +9 -2
  98. package/lib/dependencies/ImportEagerDependency.js +4 -2
  99. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  100. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  101. package/lib/dependencies/ImportParserPlugin.js +12 -4
  102. package/lib/dependencies/ImportWeakDependency.js +4 -2
  103. package/lib/dependencies/LoaderDependency.js +2 -1
  104. package/lib/dependencies/LoaderImportDependency.js +2 -1
  105. package/lib/dependencies/ModuleDependency.js +4 -5
  106. package/lib/dependencies/PureExpressionDependency.js +4 -1
  107. package/lib/dependencies/RequireContextPlugin.js +1 -1
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  109. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  110. package/lib/dependencies/URLDependency.js +7 -4
  111. package/lib/dependencies/WorkerPlugin.js +2 -1
  112. package/lib/dependencies/getFunctionExpression.js +3 -1
  113. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  114. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  115. package/lib/javascript/ChunkHelpers.js +2 -2
  116. package/lib/javascript/JavascriptParser.js +169 -57
  117. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  118. package/lib/javascript/StartupHelpers.js +22 -5
  119. package/lib/logging/Logger.js +27 -2
  120. package/lib/logging/createConsoleLogger.js +11 -7
  121. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  122. package/lib/node/NodeWatchFileSystem.js +37 -26
  123. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  124. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  125. package/lib/node/nodeConsole.js +24 -1
  126. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  127. package/lib/optimize/ConcatenatedModule.js +138 -54
  128. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  129. package/lib/optimize/InnerGraph.js +7 -2
  130. package/lib/optimize/InnerGraphPlugin.js +36 -13
  131. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  132. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  133. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  134. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  135. package/lib/optimize/SplitChunksPlugin.js +2 -2
  136. package/lib/performance/SizeLimitsPlugin.js +11 -0
  137. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  138. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  139. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  140. package/lib/serialization/FileMiddleware.js +1 -0
  141. package/lib/serialization/ObjectMiddleware.js +2 -0
  142. package/lib/serialization/Serializer.js +19 -0
  143. package/lib/sharing/ConsumeSharedModule.js +1 -1
  144. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  145. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  146. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  147. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  148. package/lib/sharing/utils.js +13 -6
  149. package/lib/util/StackedCacheMap.js +26 -0
  150. package/lib/util/WeakTupleMap.js +57 -13
  151. package/lib/util/cleverMerge.js +24 -11
  152. package/lib/util/comparators.js +34 -14
  153. package/lib/util/conventions.js +129 -0
  154. package/lib/util/fs.js +379 -65
  155. package/lib/util/hash/BatchedHash.js +3 -0
  156. package/lib/util/hash/xxhash64.js +2 -2
  157. package/lib/util/runtime.js +1 -1
  158. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  159. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  161. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  162. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  163. package/lib/webpack.js +7 -3
  164. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  165. package/package.json +25 -26
  166. package/schemas/WebpackOptions.check.js +1 -1
  167. package/schemas/WebpackOptions.json +69 -8
  168. package/schemas/plugins/BannerPlugin.check.js +1 -1
  169. package/schemas/plugins/BannerPlugin.json +5 -1
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +1668 -613
@@ -88,6 +88,7 @@ const { isSourceEqual } = require("./util/source");
88
88
  /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
89
89
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
90
90
  /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
91
+ /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
91
92
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
92
93
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
93
94
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
@@ -101,8 +102,11 @@ const { isSourceEqual } = require("./util/source");
101
102
  /** @typedef {import("./Dependency").ReferencedExport} ReferencedExport */
102
103
  /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
103
104
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
105
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
106
+ /** @typedef {import("./NormalModule").NormalModuleCompilationHooks} NormalModuleCompilationHooks */
104
107
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
105
108
  /** @typedef {import("./ModuleFactory")} ModuleFactory */
109
+ /** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
106
110
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */
107
111
  /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
108
112
  /** @typedef {import("./RequestShortener")} RequestShortener */
@@ -113,9 +117,13 @@ const { isSourceEqual } = require("./util/source");
113
117
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsError} StatsError */
114
118
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
115
119
  /** @typedef {import("./util/Hash")} Hash */
116
- /** @template T @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T> */
120
+ /**
121
+ * @template T
122
+ * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
123
+ */
117
124
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
118
-
125
+ /** @typedef {WeakMap<Dependency, Module>} References */
126
+ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
119
127
  /**
120
128
  * @callback Callback
121
129
  * @param {(WebpackError | null)=} err
@@ -344,12 +352,23 @@ const { isSourceEqual } = require("./util/source");
344
352
 
345
353
  /** @typedef {KnownCreateStatsOptionsContext & Record<string, any>} CreateStatsOptionsContext */
346
354
 
355
+ /** @typedef {{module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}[]} CodeGenerationJobs */
356
+
357
+ /** @typedef {{javascript: ModuleTemplate}} ModuleTemplates */
358
+
359
+ /** @typedef {Set<Module>} NotCodeGeneratedModules */
360
+
347
361
  /** @type {AssetInfo} */
348
362
  const EMPTY_ASSET_INFO = Object.freeze({});
349
363
 
350
364
  const esmDependencyCategory = "esm";
365
+
351
366
  // TODO webpack 6: remove
352
367
  const deprecatedNormalModuleLoaderHook = util.deprecate(
368
+ /**
369
+ * @param {Compilation} compilation compilation
370
+ * @returns {NormalModuleCompilationHooks["loader"]} hooks
371
+ */
353
372
  compilation => {
354
373
  return require("./NormalModule").getCompilationHooks(compilation).loader;
355
374
  },
@@ -358,6 +377,9 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
358
377
  );
359
378
 
360
379
  // TODO webpack 6: remove
380
+ /**
381
+ * @param {ModuleTemplates | undefined} moduleTemplates module templates
382
+ */
361
383
  const defineRemovedModuleTemplates = moduleTemplates => {
362
384
  Object.defineProperties(moduleTemplates, {
363
385
  asset: {
@@ -382,30 +404,11 @@ const defineRemovedModuleTemplates = moduleTemplates => {
382
404
  moduleTemplates = undefined;
383
405
  };
384
406
 
385
- const byId = compareSelect(
386
- /**
387
- * @param {Chunk} c chunk
388
- * @returns {number | string} id
389
- */ c => c.id,
390
- compareIds
391
- );
407
+ const byId = compareSelect(c => c.id, compareIds);
392
408
 
393
409
  const byNameOrHash = concatComparators(
394
- compareSelect(
395
- /**
396
- * @param {Compilation} c compilation
397
- * @returns {string} name
398
- */
399
- c => c.name,
400
- compareIds
401
- ),
402
- compareSelect(
403
- /**
404
- * @param {Compilation} c compilation
405
- * @returns {string} hash
406
- */ c => c.fullHash,
407
- compareIds
408
- )
410
+ compareSelect(c => c.name, compareIds),
411
+ compareSelect(c => c.fullHash, compareIds)
409
412
  );
410
413
 
411
414
  const byMessage = compareSelect(err => `${err.message}`, compareStringsNumeric);
@@ -440,6 +443,10 @@ class Compilation {
440
443
  const processAssetsHook = new AsyncSeriesHook(["assets"]);
441
444
 
442
445
  let savedAssets = new Set();
446
+ /**
447
+ * @param {CompilationAssets} assets assets
448
+ * @returns {CompilationAssets} new assets
449
+ */
443
450
  const popNewAssets = assets => {
444
451
  let newAssets = undefined;
445
452
  for (const file of Object.keys(assets)) {
@@ -667,7 +674,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
667
674
  /** @type {SyncHook<[Iterable<Module>]>} */
668
675
  afterOptimizeModules: new SyncHook(["modules"]),
669
676
 
670
- /** @type {SyncBailHook<[Iterable<Chunk>, ChunkGroup[]]>} */
677
+ /** @type {SyncBailHook<[Iterable<Chunk>, ChunkGroup[]], boolean | void>} */
671
678
  optimizeChunks: new SyncBailHook(["chunks", "chunkGroups"]),
672
679
  /** @type {SyncHook<[Iterable<Chunk>, ChunkGroup[]]>} */
673
680
  afterOptimizeChunks: new SyncHook(["chunks", "chunkGroups"]),
@@ -677,7 +684,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
677
684
  /** @type {SyncHook<[Iterable<Chunk>, Iterable<Module>]>} */
678
685
  afterOptimizeTree: new SyncHook(["chunks", "modules"]),
679
686
 
680
- /** @type {AsyncSeriesBailHook<[Iterable<Chunk>, Iterable<Module>]>} */
687
+ /** @type {AsyncSeriesBailHook<[Iterable<Chunk>, Iterable<Module>], void>} */
681
688
  optimizeChunkModules: new AsyncSeriesBailHook(["chunks", "modules"]),
682
689
  /** @type {SyncHook<[Iterable<Chunk>, Iterable<Module>]>} */
683
690
  afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]),
@@ -690,7 +697,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
690
697
  "runtimeRequirements",
691
698
  "context"
692
699
  ]),
693
- /** @type {HookMap<SyncBailHook<[Chunk, Set<string>, RuntimeRequirementsContext]>>} */
700
+ /** @type {HookMap<SyncBailHook<[Chunk, Set<string>, RuntimeRequirementsContext], void>>} */
694
701
  runtimeRequirementInChunk: new HookMap(
695
702
  () => new SyncBailHook(["chunk", "runtimeRequirements", "context"])
696
703
  ),
@@ -824,7 +831,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
824
831
  /** @type {AsyncSeriesHook<[CompilationAssets]>} */
825
832
  processAdditionalAssets: new AsyncSeriesHook(["assets"]),
826
833
 
827
- /** @type {SyncBailHook<[], boolean>} */
834
+ /** @type {SyncBailHook<[], boolean | undefined>} */
828
835
  needAdditionalSeal: new SyncBailHook([]),
829
836
  /** @type {AsyncSeriesHook<[]>} */
830
837
  afterSeal: new AsyncSeriesHook([]),
@@ -878,12 +885,17 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
878
885
  });
879
886
  /** @type {string=} */
880
887
  this.name = undefined;
888
+ /** @type {number | undefined} */
881
889
  this.startTime = undefined;
890
+ /** @type {number | undefined} */
882
891
  this.endTime = undefined;
883
892
  /** @type {Compiler} */
884
893
  this.compiler = compiler;
885
894
  this.resolverFactory = compiler.resolverFactory;
886
- this.inputFileSystem = compiler.inputFileSystem;
895
+ /** @type {InputFileSystem} */
896
+ this.inputFileSystem =
897
+ /** @type {InputFileSystem} */
898
+ (compiler.inputFileSystem);
887
899
  this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
888
900
  unmanagedPaths: compiler.unmanagedPaths,
889
901
  managedPaths: compiler.managedPaths,
@@ -907,7 +919,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
907
919
 
908
920
  this.logger = this.getLogger("webpack.Compilation");
909
921
 
910
- const options = compiler.options;
922
+ const options = /** @type {WebpackOptions} */ (compiler.options);
911
923
  this.options = options;
912
924
  this.outputOptions = options && options.output;
913
925
  /** @type {boolean} */
@@ -923,7 +935,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
923
935
  this.outputOptions,
924
936
  this.requestShortener
925
937
  );
926
- /** @type {{javascript: ModuleTemplate}} */
938
+ /** @type {ModuleTemplates} */
927
939
  this.moduleTemplates = {
928
940
  javascript: new ModuleTemplate(this.runtimeTemplate, this)
929
941
  };
@@ -1066,6 +1078,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1066
1078
  // TODO webpack 6 remove
1067
1079
  this.compilationDependencies = {
1068
1080
  add: util.deprecate(
1081
+ /**
1082
+ * @param {string} item item
1083
+ * @returns {LazySet<string>} file dependencies
1084
+ */
1069
1085
  item => this.fileDependencies.add(item),
1070
1086
  "Compilation.compilationDependencies is deprecated (used Compilation.fileDependencies instead)",
1071
1087
  "DEP_WEBPACK_COMPILATION_COMPILATION_DEPENDENCIES"
@@ -1119,12 +1135,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1119
1135
  }
1120
1136
  }
1121
1137
 
1138
+ /**
1139
+ * @param {NormalizedStatsOptions} options options
1140
+ * @returns {StatsFactory} the stats factory
1141
+ */
1122
1142
  createStatsFactory(options) {
1123
1143
  const statsFactory = new StatsFactory();
1124
1144
  this.hooks.statsFactory.call(statsFactory, options);
1125
1145
  return statsFactory;
1126
1146
  }
1127
1147
 
1148
+ /**
1149
+ * @param {NormalizedStatsOptions} options options
1150
+ * @returns {StatsPrinter} the stats printer
1151
+ */
1128
1152
  createStatsPrinter(options) {
1129
1153
  const statsPrinter = new StatsPrinter();
1130
1154
  this.hooks.statsPrinter.call(statsPrinter, options);
@@ -1164,7 +1188,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1164
1188
  case LogType.warn:
1165
1189
  case LogType.error:
1166
1190
  case LogType.trace:
1167
- trace = ErrorHelpers.cutOffLoaderExecution(new Error("Trace").stack)
1191
+ trace = ErrorHelpers.cutOffLoaderExecution(
1192
+ /** @type {string} */ (new Error("Trace").stack)
1193
+ )
1168
1194
  .split("\n")
1169
1195
  .slice(3);
1170
1196
  break;
@@ -1314,7 +1340,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1314
1340
  */
1315
1341
  getModule(module) {
1316
1342
  const identifier = module.identifier();
1317
- return this._modules.get(identifier);
1343
+ return /** @type {Module} */ (this._modules.get(identifier));
1318
1344
  }
1319
1345
 
1320
1346
  /**
@@ -1375,7 +1401,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1375
1401
  this.options,
1376
1402
  this,
1377
1403
  this.resolverFactory.get("normal", module.resolveOptions),
1378
- this.inputFileSystem,
1404
+ /** @type {InputFileSystem} */ (this.inputFileSystem),
1379
1405
  err => {
1380
1406
  if (currentProfile !== undefined) {
1381
1407
  currentProfile.markBuildingEnd();
@@ -1392,7 +1418,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1392
1418
  currentProfile.markStoringEnd();
1393
1419
  }
1394
1420
  if (err) {
1395
- this.hooks.failedModule.call(module, err);
1421
+ this.hooks.failedModule.call(
1422
+ module,
1423
+ /** @type {WebpackError} */ (err)
1424
+ );
1396
1425
  return callback(new ModuleStoreError(module, err));
1397
1426
  }
1398
1427
  this.hooks.succeedModule.call(module);
@@ -1418,6 +1447,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1418
1447
  * @returns {void}
1419
1448
  */
1420
1449
  processModuleDependenciesNonRecursive(module) {
1450
+ /**
1451
+ * @param {DependenciesBlock} block block
1452
+ */
1421
1453
  const processDependenciesBlock = block => {
1422
1454
  if (block.dependencies) {
1423
1455
  let i = 0;
@@ -1463,6 +1495,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1463
1495
  let inProgressSorting = 1;
1464
1496
  let inProgressTransitive = 1;
1465
1497
 
1498
+ /**
1499
+ * @param {WebpackError=} err error
1500
+ * @returns {void}
1501
+ */
1466
1502
  const onDependenciesSorted = err => {
1467
1503
  if (err) return callback(err);
1468
1504
 
@@ -1494,6 +1530,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1494
1530
  if (--inProgressTransitive === 0) onTransitiveTasksFinished();
1495
1531
  };
1496
1532
 
1533
+ /**
1534
+ * @param {WebpackError=} err error
1535
+ * @returns {void}
1536
+ */
1497
1537
  const onTransitiveTasksFinished = err => {
1498
1538
  if (err) return callback(err);
1499
1539
  this.processDependenciesQueue.decreaseParallelism();
@@ -1541,7 +1581,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1541
1581
  if (err) {
1542
1582
  if (inProgressSorting <= 0) return;
1543
1583
  inProgressSorting = -1;
1544
- onDependenciesSorted(err);
1584
+ onDependenciesSorted(/** @type {WebpackError} */ (err));
1545
1585
  return;
1546
1586
  }
1547
1587
  try {
@@ -1596,7 +1636,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1596
1636
  } catch (err) {
1597
1637
  if (inProgressSorting <= 0) return;
1598
1638
  inProgressSorting = -1;
1599
- onDependenciesSorted(err);
1639
+ onDependenciesSorted(/** @type {WebpackError} */ (err));
1600
1640
  return;
1601
1641
  }
1602
1642
  if (--inProgressSorting === 0) onDependenciesSorted();
@@ -1686,7 +1726,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1686
1726
  /** @type {DependenciesBlock[]} */
1687
1727
  const queue = [module];
1688
1728
  do {
1689
- const block = queue.pop();
1729
+ const block = /** @type {DependenciesBlock} */ (queue.pop());
1690
1730
  if (block.dependencies) {
1691
1731
  currentBlock = block;
1692
1732
  let i = 0;
@@ -1703,6 +1743,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1703
1743
  if (--inProgressSorting === 0) onDependenciesSorted();
1704
1744
  }
1705
1745
 
1746
+ /**
1747
+ * @private
1748
+ * @param {Module} originModule original module
1749
+ * @param {Dependency} dependency dependency
1750
+ * @param {Module} module cached module
1751
+ * @param {Callback} callback callback
1752
+ */
1706
1753
  _handleNewModuleFromUnsafeCache(originModule, dependency, module, callback) {
1707
1754
  const moduleGraph = this.moduleGraph;
1708
1755
 
@@ -1727,6 +1774,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1727
1774
  );
1728
1775
  }
1729
1776
 
1777
+ /**
1778
+ * @private
1779
+ * @param {Module} originModule original modules
1780
+ * @param {Dependency} dependency dependency
1781
+ * @param {Module} module cached module
1782
+ */
1730
1783
  _handleExistingModuleFromUnsafeCache(originModule, dependency, module) {
1731
1784
  const moduleGraph = this.moduleGraph;
1732
1785
 
@@ -1813,27 +1866,30 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1813
1866
  moduleGraph.setProfile(newModule, currentProfile);
1814
1867
  }
1815
1868
 
1816
- this.addModule(newModule, (err, module) => {
1869
+ this.addModule(newModule, (err, _module) => {
1817
1870
  if (err) {
1818
1871
  applyFactoryResultDependencies();
1819
1872
  if (!err.module) {
1820
- err.module = module;
1873
+ err.module = _module;
1821
1874
  }
1822
1875
  this.errors.push(err);
1823
1876
 
1824
1877
  return callback(err);
1825
1878
  }
1826
1879
 
1880
+ const module =
1881
+ /** @type {Module & { restoreFromUnsafeCache?: Function }} */
1882
+ (_module);
1883
+
1827
1884
  if (
1828
1885
  this._unsafeCache &&
1829
1886
  factoryResult.cacheable !== false &&
1830
- /** @type {any} */ (module).restoreFromUnsafeCache &&
1887
+ module.restoreFromUnsafeCache &&
1831
1888
  this._unsafeCachePredicate(module)
1832
1889
  ) {
1833
1890
  const unsafeCacheableModule =
1834
- /** @type {Module & { restoreFromUnsafeCache: Function }} */ (
1835
- module
1836
- );
1891
+ /** @type {Module & { restoreFromUnsafeCache: Function }} */
1892
+ (module);
1837
1893
  for (let i = 0; i < dependencies.length; i++) {
1838
1894
  const dependency = dependencies[i];
1839
1895
  moduleGraph.setResolvedModule(
@@ -1888,6 +1944,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1888
1944
  );
1889
1945
  }
1890
1946
 
1947
+ /**
1948
+ * @private
1949
+ * @param {Module} originModule original module
1950
+ * @param {Module} module module
1951
+ * @param {boolean} recursive true if make it recursive, otherwise false
1952
+ * @param {boolean} checkCycle true if need to check cycle, otherwise false
1953
+ * @param {ModuleCallback} callback callback
1954
+ * @returns {void}
1955
+ */
1891
1956
  _handleModuleBuildAndDependencies(
1892
1957
  originModule,
1893
1958
  module,
@@ -2164,7 +2229,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2164
2229
  }
2165
2230
  };
2166
2231
  entryData[target].push(entry);
2167
- this.entries.set(name, entryData);
2232
+ this.entries.set(
2233
+ /** @type {NonNullable<EntryOptions["name"]>} */ (name),
2234
+ entryData
2235
+ );
2168
2236
  } else {
2169
2237
  entryData[target].push(entry);
2170
2238
  for (const key of Object.keys(options)) {
@@ -2204,7 +2272,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2204
2272
  this.hooks.failedEntry.call(entry, options, err);
2205
2273
  return callback(err);
2206
2274
  }
2207
- this.hooks.succeedEntry.call(entry, options, module);
2275
+ this.hooks.succeedEntry.call(
2276
+ entry,
2277
+ options,
2278
+ /** @type {Module} */ (module)
2279
+ );
2208
2280
  return callback(null, module);
2209
2281
  }
2210
2282
  );
@@ -2264,6 +2336,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2264
2336
  });
2265
2337
  }
2266
2338
 
2339
+ /**
2340
+ * @private
2341
+ * @param {Set<Module>} modules modules
2342
+ */
2267
2343
  _computeAffectedModules(modules) {
2268
2344
  const moduleMemCacheCache = this.compiler.moduleMemCaches;
2269
2345
  if (!moduleMemCacheCache) return;
@@ -2280,8 +2356,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2280
2356
  let statReferencesChanged = 0;
2281
2357
  let statWithoutBuild = 0;
2282
2358
 
2359
+ /**
2360
+ * @param {Module} module module
2361
+ * @returns {References | undefined} references
2362
+ */
2283
2363
  const computeReferences = module => {
2284
- /** @type {WeakMap<Dependency, Module>} */
2364
+ /** @type {References | undefined} */
2285
2365
  let references = undefined;
2286
2366
  for (const connection of moduleGraph.getOutgoingConnections(module)) {
2287
2367
  const d = connection.dependency;
@@ -2295,7 +2375,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2295
2375
 
2296
2376
  /**
2297
2377
  * @param {Module} module the module
2298
- * @param {WeakMap<Dependency, Module>} references references
2378
+ * @param {References | undefined} references references
2299
2379
  * @returns {boolean} true, when the references differ
2300
2380
  */
2301
2381
  const compareReferences = (module, references) => {
@@ -2367,6 +2447,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2367
2447
  }
2368
2448
  }
2369
2449
 
2450
+ /**
2451
+ * @param {readonly ModuleGraphConnection[]} connections connections
2452
+ * @returns {symbol|boolean} result
2453
+ */
2370
2454
  const reduceAffectType = connections => {
2371
2455
  let affected = false;
2372
2456
  for (const { dependency } of connections) {
@@ -2442,13 +2526,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2442
2526
  let statNew = 0;
2443
2527
  /**
2444
2528
  * @param {Module} module module
2445
- * @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
2529
+ * @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[] }} references
2446
2530
  */
2447
2531
  const computeReferences = module => {
2448
2532
  const id = chunkGraph.getModuleId(module);
2449
- /** @type {Map<Module, string | number | undefined>} */
2533
+ /** @type {Map<Module, string | number | undefined> | undefined} */
2450
2534
  let modules = undefined;
2451
- /** @type {(string | number)[] | undefined} */
2535
+ /** @type {(string | number | null)[] | undefined} */
2452
2536
  let blocks = undefined;
2453
2537
  const outgoing = moduleGraph.getOutgoingConnectionsByModule(module);
2454
2538
  if (outgoing !== undefined) {
@@ -2479,8 +2563,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2479
2563
  * @param {Module} module module
2480
2564
  * @param {Object} references references
2481
2565
  * @param {string | number} references.id id
2482
- * @param {Map<Module, string | number>=} references.modules modules
2483
- * @param {(string | number)[]=} references.blocks blocks
2566
+ * @param {Map<Module, string | number | undefined>=} references.modules modules
2567
+ * @param {(string | number | null)[]=} references.blocks blocks
2484
2568
  * @returns {boolean} ok?
2485
2569
  */
2486
2570
  const compareReferences = (module, { id, modules, blocks }) => {
@@ -2510,7 +2594,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2510
2594
  };
2511
2595
 
2512
2596
  for (const [module, memCache] of moduleMemCaches) {
2513
- /** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
2597
+ /** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[]}, memCache: WeakTupleMap<any[], any> }} */
2514
2598
  const cache = memCache.get(key);
2515
2599
  if (cache === undefined) {
2516
2600
  const memCache2 = new WeakTupleMap();
@@ -2539,6 +2623,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2539
2623
  );
2540
2624
  }
2541
2625
 
2626
+ /**
2627
+ * @param {Callback} callback callback
2628
+ */
2542
2629
  finish(callback) {
2543
2630
  this.factorizeQueue.clear();
2544
2631
  if (this.profile) {
@@ -2546,6 +2633,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2546
2633
  const ParallelismFactorCalculator = require("./util/ParallelismFactorCalculator");
2547
2634
  const p = new ParallelismFactorCalculator();
2548
2635
  const moduleGraph = this.moduleGraph;
2636
+ /** @type {Map<Module, ModuleProfile>} */
2549
2637
  const modulesWithProfiles = new Map();
2550
2638
  for (const module of this.modules) {
2551
2639
  const profile = moduleGraph.getProfile(module);
@@ -2606,6 +2694,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2606
2694
  logger.debug(msg);
2607
2695
  }
2608
2696
  };
2697
+ /**
2698
+ * @param {string} category a category
2699
+ * @param {(profile: ModuleProfile) => number} getDuration get duration callback
2700
+ * @param {(profile: ModuleProfile) => number} getParallelism get parallelism callback
2701
+ */
2609
2702
  const logNormalSummary = (category, getDuration, getParallelism) => {
2610
2703
  let sum = 0;
2611
2704
  let max = 0;
@@ -2630,6 +2723,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2630
2723
  `${Math.round(sum)} ms ${category}`
2631
2724
  );
2632
2725
  };
2726
+ /**
2727
+ * @param {string} category a category
2728
+ * @param {(profile: ModuleProfile) => number} getDuration get duration callback
2729
+ * @param {(profile: ModuleProfile) => number} getParallelism get parallelism callback
2730
+ */
2633
2731
  const logByLoadersSummary = (category, getDuration, getParallelism) => {
2634
2732
  const map = new Map();
2635
2733
  for (const [module, profile] of modulesWithProfiles) {
@@ -2728,7 +2826,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2728
2826
  const { modules, moduleMemCaches } = this;
2729
2827
  this.hooks.finishModules.callAsync(modules, err => {
2730
2828
  this.logger.timeEnd("finish modules");
2731
- if (err) return callback(err);
2829
+ if (err) return callback(/** @type {WebpackError} */ (err));
2732
2830
 
2733
2831
  // extract warnings and errors from modules
2734
2832
  this.moduleGraph.freeze("dependency errors");
@@ -2894,12 +2992,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2894
2992
  Entrypoints that depend on other entrypoints do not have their own runtime.
2895
2993
  They will use the runtime(s) from referenced entrypoints instead.
2896
2994
  Remove the 'runtime' option from the entrypoint.`);
2897
- const entry = this.entrypoints.get(name);
2995
+ const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
2898
2996
  err.chunk = entry.getEntrypointChunk();
2899
2997
  this.errors.push(err);
2900
2998
  }
2901
2999
  if (dependOn) {
2902
- const entry = this.entrypoints.get(name);
3000
+ const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
2903
3001
  const referencedChunks = entry
2904
3002
  .getEntrypointChunk()
2905
3003
  .getAllReferencedChunks();
@@ -2927,7 +3025,7 @@ Remove the 'runtime' option from the entrypoint.`);
2927
3025
  connectChunkGroupParentAndChild(dependency, entry);
2928
3026
  }
2929
3027
  } else if (runtime) {
2930
- const entry = this.entrypoints.get(name);
3028
+ const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
2931
3029
  let chunk = this.namedChunks.get(runtime);
2932
3030
  if (chunk) {
2933
3031
  if (!runtimeChunks.has(chunk)) {
@@ -2938,7 +3036,9 @@ Did you mean to use 'dependOn: ${JSON.stringify(
2938
3036
  runtime
2939
3037
  )}' instead to allow using entrypoint '${name}' within the runtime of entrypoint '${runtime}'? For this '${runtime}' must always be loaded when '${name}' is used.
2940
3038
  Or do you want to use the entrypoints '${name}' and '${runtime}' independently on the same page with a shared runtime? In this case give them both the same value for the 'runtime' option. It must be a name not already used by an entrypoint.`);
2941
- const entryChunk = entry.getEntrypointChunk();
3039
+ const entryChunk =
3040
+ /** @type {Chunk} */
3041
+ (entry.getEntrypointChunk());
2942
3042
  err.chunk = entryChunk;
2943
3043
  this.errors.push(err);
2944
3044
  entry.setRuntimeChunk(entryChunk);
@@ -3077,16 +3177,18 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3077
3177
  }
3078
3178
  this.hooks.afterProcessAssets.call(this.assets);
3079
3179
  this.logger.timeEnd("process assets");
3080
- this.assets = this._backCompat
3081
- ? soonFrozenObjectDeprecation(
3082
- this.assets,
3083
- "Compilation.assets",
3084
- "DEP_WEBPACK_COMPILATION_ASSETS",
3085
- `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3180
+ this.assets = /** @type {CompilationAssets} */ (
3181
+ this._backCompat
3182
+ ? soonFrozenObjectDeprecation(
3183
+ this.assets,
3184
+ "Compilation.assets",
3185
+ "DEP_WEBPACK_COMPILATION_ASSETS",
3186
+ `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3086
3187
  Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
3087
3188
  Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
3088
- )
3089
- : Object.freeze(this.assets);
3189
+ )
3190
+ : Object.freeze(this.assets)
3191
+ );
3090
3192
 
3091
3193
  this.summarizeDependencies();
3092
3194
  if (shouldRecord) {
@@ -3172,12 +3274,15 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3172
3274
  return hasProblems;
3173
3275
  }
3174
3276
 
3277
+ /**
3278
+ * @param {Callback} callback callback
3279
+ */
3175
3280
  codeGeneration(callback) {
3176
3281
  const { chunkGraph } = this;
3177
3282
  this.codeGenerationResults = new CodeGenerationResults(
3178
3283
  this.outputOptions.hashFunction
3179
3284
  );
3180
- /** @type {{module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}[]} */
3285
+ /** @type {CodeGenerationJobs} */
3181
3286
  const jobs = [];
3182
3287
  for (const module of this.modules) {
3183
3288
  const runtimes = chunkGraph.getModuleRuntimes(module);
@@ -3206,6 +3311,12 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3206
3311
  this._runCodeGenerationJobs(jobs, callback);
3207
3312
  }
3208
3313
 
3314
+ /**
3315
+ * @private
3316
+ * @param {CodeGenerationJobs} jobs code generation jobs
3317
+ * @param {Callback} callback callback
3318
+ * @returns {void}
3319
+ */
3209
3320
  _runCodeGenerationJobs(jobs, callback) {
3210
3321
  if (jobs.length === 0) {
3211
3322
  return callback();
@@ -3217,9 +3328,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3217
3328
  const results = this.codeGenerationResults;
3218
3329
  /** @type {WebpackError[]} */
3219
3330
  const errors = [];
3220
- /** @type {Set<Module> | undefined} */
3331
+ /** @type {NotCodeGeneratedModules | undefined} */
3221
3332
  let notCodeGeneratedModules = undefined;
3222
3333
  const runIteration = () => {
3334
+ /** @type {CodeGenerationJobs} */
3223
3335
  let delayedJobs = [];
3224
3336
  let delayedModules = new Set();
3225
3337
  asyncLib.eachLimit(
@@ -3232,8 +3344,12 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3232
3344
  if (
3233
3345
  notCodeGeneratedModules === undefined ||
3234
3346
  codeGenerationDependencies.some(dep => {
3235
- const referencedModule = moduleGraph.getModule(dep);
3236
- return notCodeGeneratedModules.has(referencedModule);
3347
+ const referencedModule = /** @type {Module} */ (
3348
+ moduleGraph.getModule(dep)
3349
+ );
3350
+ return /** @type {NotCodeGeneratedModules} */ (
3351
+ notCodeGeneratedModules
3352
+ ).has(referencedModule);
3237
3353
  })
3238
3354
  ) {
3239
3355
  delayedJobs.push(job);
@@ -3265,11 +3381,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3265
3381
  if (delayedJobs.length > 0) {
3266
3382
  if (delayedJobs.length === jobs.length) {
3267
3383
  return callback(
3268
- new Error(
3269
- `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3270
- delayedModules,
3271
- m => m.identifier()
3272
- ).join(", ")}`
3384
+ /** @type {WebpackError} */ (
3385
+ new Error(
3386
+ `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3387
+ delayedModules,
3388
+ m => m.identifier()
3389
+ ).join(", ")}`
3390
+ )
3273
3391
  )
3274
3392
  );
3275
3393
  }
@@ -3336,7 +3454,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3336
3454
  )
3337
3455
  );
3338
3456
  cache.get((err, cachedResult) => {
3339
- if (err) return callback(err);
3457
+ if (err) return callback(/** @type {WebpackError} */ (err));
3340
3458
  let result;
3341
3459
  if (!cachedResult) {
3342
3460
  try {
@@ -3353,7 +3471,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3353
3471
  compilation: this
3354
3472
  });
3355
3473
  } catch (err) {
3356
- errors.push(new CodeGenerationError(module, err));
3474
+ errors.push(
3475
+ new CodeGenerationError(module, /** @type {Error} */ (err))
3476
+ );
3357
3477
  result = cachedResult = {
3358
3478
  sources: new Map(),
3359
3479
  runtimeRequirements: null
@@ -3366,7 +3486,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3366
3486
  results.add(module, runtime, result);
3367
3487
  }
3368
3488
  if (!cachedResult) {
3369
- cache.store(result, err => callback(err, codeGenerated));
3489
+ cache.store(result, err =>
3490
+ callback(/** @type {WebpackError} */ (err), codeGenerated)
3491
+ );
3370
3492
  } else {
3371
3493
  callback(null, codeGenerated);
3372
3494
  }
@@ -3835,7 +3957,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3835
3957
  const blocks = block.blocks;
3836
3958
  for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
3837
3959
  const asyncBlock = blocks[indexBlock];
3838
- const chunkGroup = this.chunkGraph.getBlockChunkGroup(asyncBlock);
3960
+ const chunkGroup =
3961
+ /** @type {ChunkGroup} */
3962
+ (this.chunkGraph.getBlockChunkGroup(asyncBlock));
3839
3963
  // Grab all chunks from the first Block's AsyncDepBlock
3840
3964
  const chunks = chunkGroup.chunks;
3841
3965
  // For each chunk in chunkGroup
@@ -3906,6 +4030,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3906
4030
  let statModulesFromCache = 0;
3907
4031
  const { chunkGraph, runtimeTemplate, moduleMemCaches2 } = this;
3908
4032
  const { hashFunction, hashDigest, hashDigestLength } = this.outputOptions;
4033
+ /** @type {WebpackError[]} */
3909
4034
  const errors = [];
3910
4035
  for (const module of this.modules) {
3911
4036
  const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
@@ -3954,6 +4079,18 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3954
4079
  );
3955
4080
  }
3956
4081
 
4082
+ /**
4083
+ * @private
4084
+ * @param {Module} module module
4085
+ * @param {ChunkGraph} chunkGraph the chunk graph
4086
+ * @param {RuntimeSpec} runtime runtime
4087
+ * @param {OutputOptions["hashFunction"]} hashFunction hash function
4088
+ * @param {RuntimeTemplate} runtimeTemplate runtime template
4089
+ * @param {OutputOptions["hashDigest"]} hashDigest hash digest
4090
+ * @param {OutputOptions["hashDigestLength"]} hashDigestLength hash digest length
4091
+ * @param {WebpackError[]} errors errors
4092
+ * @returns {string} module hash digest
4093
+ */
3957
4094
  _createModuleHash(
3958
4095
  module,
3959
4096
  chunkGraph,
@@ -3974,7 +4111,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3974
4111
  });
3975
4112
  moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
3976
4113
  } catch (err) {
3977
- errors.push(new ModuleHashingError(module, err));
4114
+ errors.push(new ModuleHashingError(module, /** @type {Error} */ (err)));
3978
4115
  moduleHashDigest = "XXXXXX";
3979
4116
  }
3980
4117
  chunkGraph.setModuleHashes(
@@ -3988,7 +4125,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3988
4125
 
3989
4126
  createHash() {
3990
4127
  this.logger.time("hashing: initialize hash");
3991
- const chunkGraph = this.chunkGraph;
4128
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
3992
4129
  const runtimeTemplate = this.runtimeTemplate;
3993
4130
  const outputOptions = this.outputOptions;
3994
4131
  const hashFunction = outputOptions.hashFunction;
@@ -4083,7 +4220,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4083
4220
  for (const chunk of runtimeChunks) {
4084
4221
  const hasFullHashModules =
4085
4222
  chunkGraph.getNumberOfChunkFullHashModules(chunk) !== 0;
4086
- const info = runtimeChunksMap.get(chunk);
4223
+ const info =
4224
+ /** @type {RuntimeChunkInfo} */
4225
+ (runtimeChunksMap.get(chunk));
4087
4226
  for (const otherInfo of info.referencedBy) {
4088
4227
  if (hasFullHashModules) {
4089
4228
  chunkGraph.upgradeDependentToFullHashModules(otherInfo.chunk);
@@ -4127,8 +4266,12 @@ This prevents using hashes of each other and should be avoided.`);
4127
4266
  const codeGenerationJobs = [];
4128
4267
  /** @type {Map<string, Map<Module, {module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}>>} */
4129
4268
  const codeGenerationJobsMap = new Map();
4269
+ /** @type {WebpackError[]} */
4130
4270
  const errors = [];
4131
4271
 
4272
+ /**
4273
+ * @param {Chunk} chunk chunk
4274
+ */
4132
4275
  const processChunk = chunk => {
4133
4276
  // Last minute module hash generation for modules that depend on chunk hashes
4134
4277
  this.logger.time("hashing: hash runtime modules");
@@ -4217,7 +4360,9 @@ This prevents using hashes of each other and should be avoided.`);
4217
4360
 
4218
4361
  this.logger.time("hashing: process full hash modules");
4219
4362
  for (const chunk of fullHashChunks) {
4220
- for (const module of chunkGraph.getChunkFullHashModulesIterable(chunk)) {
4363
+ for (const module of /** @type {Iterable<RuntimeModule>} */ (
4364
+ chunkGraph.getChunkFullHashModulesIterable(chunk)
4365
+ )) {
4221
4366
  const moduleHash = createHash(hashFunction);
4222
4367
  module.updateHash(moduleHash, {
4223
4368
  chunkGraph,
@@ -4291,6 +4436,9 @@ This prevents using hashes of each other and should be avoided.`);
4291
4436
  const newRelated = newInfo && newInfo.related;
4292
4437
  if (oldRelated) {
4293
4438
  for (const key of Object.keys(oldRelated)) {
4439
+ /**
4440
+ * @param {string} name name
4441
+ */
4294
4442
  const remove = name => {
4295
4443
  const relatedIn = this._assetsRelatedIn.get(name);
4296
4444
  if (relatedIn === undefined) return;
@@ -4311,6 +4459,9 @@ This prevents using hashes of each other and should be avoided.`);
4311
4459
  }
4312
4460
  if (newRelated) {
4313
4461
  for (const key of Object.keys(newRelated)) {
4462
+ /**
4463
+ * @param {string} name name
4464
+ */
4314
4465
  const add = name => {
4315
4466
  let relatedIn = this._assetsRelatedIn.get(name);
4316
4467
  if (relatedIn === undefined) {
@@ -4335,7 +4486,7 @@ This prevents using hashes of each other and should be avoided.`);
4335
4486
  /**
4336
4487
  * @param {string} file file name
4337
4488
  * @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new
4338
- * @param {AssetInfo | function(AssetInfo | undefined): AssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new
4489
+ * @param {(AssetInfo | function(AssetInfo | undefined): AssetInfo) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
4339
4490
  */
4340
4491
  updateAsset(
4341
4492
  file,
@@ -4366,6 +4517,10 @@ This prevents using hashes of each other and should be avoided.`);
4366
4517
  }
4367
4518
  }
4368
4519
 
4520
+ /**
4521
+ * @param {string} file file name
4522
+ * @param {string} newFile the new name of file
4523
+ */
4369
4524
  renameAsset(file, newFile) {
4370
4525
  const source = this.assets[file];
4371
4526
  if (!source) {
@@ -4504,9 +4659,10 @@ This prevents using hashes of each other and should be avoided.`);
4504
4659
  createModuleAssets() {
4505
4660
  const { chunkGraph } = this;
4506
4661
  for (const module of this.modules) {
4507
- if (module.buildInfo.assets) {
4508
- const assetsInfo = module.buildInfo.assetsInfo;
4509
- for (const assetName of Object.keys(module.buildInfo.assets)) {
4662
+ const buildInfo = /** @type {BuildInfo} */ (module.buildInfo);
4663
+ if (buildInfo.assets) {
4664
+ const assetsInfo = buildInfo.assetsInfo;
4665
+ for (const assetName of Object.keys(buildInfo.assets)) {
4510
4666
  const fileName = this.getPath(assetName, {
4511
4667
  chunkGraph: this.chunkGraph,
4512
4668
  module
@@ -4516,7 +4672,7 @@ This prevents using hashes of each other and should be avoided.`);
4516
4672
  }
4517
4673
  this.emitAsset(
4518
4674
  fileName,
4519
- module.buildInfo.assets[assetName],
4675
+ buildInfo.assets[assetName],
4520
4676
  assetsInfo ? assetsInfo.get(assetName) : undefined
4521
4677
  );
4522
4678
  this.hooks.moduleAsset.call(module, fileName);
@@ -4563,7 +4719,9 @@ This prevents using hashes of each other and should be avoided.`);
4563
4719
  runtimeTemplate: this.runtimeTemplate
4564
4720
  });
4565
4721
  } catch (err) {
4566
- this.errors.push(new ChunkRenderError(chunk, "", err));
4722
+ this.errors.push(
4723
+ new ChunkRenderError(chunk, "", /** @type {Error} */ (err))
4724
+ );
4567
4725
  return callback();
4568
4726
  }
4569
4727
  asyncLib.forEach(
@@ -4586,6 +4744,10 @@ This prevents using hashes of each other and should be avoided.`);
4586
4744
  let assetInfo;
4587
4745
 
4588
4746
  let inTry = true;
4747
+ /**
4748
+ * @param {Error} err error
4749
+ * @returns {void}
4750
+ */
4589
4751
  const errorAndCallback = err => {
4590
4752
  const filename =
4591
4753
  file ||
@@ -4813,7 +4975,7 @@ This prevents using hashes of each other and should be avoided.`);
4813
4975
  });
4814
4976
  },
4815
4977
  err => {
4816
- if (err) return callback(err);
4978
+ if (err) return callback(/** @type {WebpackError} */ (err));
4817
4979
 
4818
4980
  // Create new chunk graph, chunk and entrypoint for the build time execution
4819
4981
  const chunkGraph = new ChunkGraph(
@@ -4996,7 +5158,10 @@ This prevents using hashes of each other and should be avoided.`);
4996
5158
  missingDependencies,
4997
5159
  buildDependencies
4998
5160
  );
4999
- if (module.buildInfo.cacheable === false) {
5161
+ if (
5162
+ /** @type {BuildInfo} */ (module.buildInfo).cacheable ===
5163
+ false
5164
+ ) {
5000
5165
  cacheable = false;
5001
5166
  }
5002
5167
  if (module.buildInfo && module.buildInfo.assets) {
@@ -5098,7 +5263,8 @@ This prevents using hashes of each other and should be avoided.`);
5098
5263
  chunk
5099
5264
  )) {
5100
5265
  __webpack_require_module__(
5101
- moduleArgumentsMap.get(runtimeModule)
5266
+ /** @type {ExecuteModuleArgument} */
5267
+ (moduleArgumentsMap.get(runtimeModule))
5102
5268
  );
5103
5269
  }
5104
5270
  exports = __webpack_require__(module.identifier());
@@ -5229,6 +5395,9 @@ Object.defineProperty(compilationPrototype, "cache", {
5229
5395
  "DEP_WEBPACK_COMPILATION_CACHE"
5230
5396
  ),
5231
5397
  set: util.deprecate(
5398
+ /**
5399
+ * @param {any} v value
5400
+ */
5232
5401
  v => {},
5233
5402
  "Compilation.cache was removed in favor of Compilation.getCache()",
5234
5403
  "DEP_WEBPACK_COMPILATION_CACHE"