webpack 5.98.0 → 5.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +7 -3
  2. package/lib/AsyncDependenciesBlock.js +3 -1
  3. package/lib/BannerPlugin.js +1 -1
  4. package/lib/Cache.js +9 -7
  5. package/lib/CacheFacade.js +5 -5
  6. package/lib/Chunk.js +2 -2
  7. package/lib/ChunkGraph.js +21 -16
  8. package/lib/ChunkTemplate.js +6 -6
  9. package/lib/CleanPlugin.js +10 -10
  10. package/lib/CodeGenerationResults.js +4 -3
  11. package/lib/CompatibilityPlugin.js +4 -1
  12. package/lib/Compilation.js +326 -152
  13. package/lib/Compiler.js +13 -18
  14. package/lib/ConditionalInitFragment.js +1 -1
  15. package/lib/ConstPlugin.js +5 -3
  16. package/lib/ContextModule.js +4 -2
  17. package/lib/ContextModuleFactory.js +3 -3
  18. package/lib/ContextReplacementPlugin.js +43 -16
  19. package/lib/DefinePlugin.js +25 -24
  20. package/lib/DelegatedModule.js +4 -2
  21. package/lib/DelegatedModuleFactoryPlugin.js +2 -1
  22. package/lib/Dependency.js +19 -13
  23. package/lib/DependencyTemplates.js +4 -3
  24. package/lib/DllModule.js +4 -2
  25. package/lib/DllModuleFactory.js +2 -2
  26. package/lib/DllReferencePlugin.js +2 -1
  27. package/lib/DynamicEntryPlugin.js +1 -1
  28. package/lib/EnvironmentPlugin.js +4 -2
  29. package/lib/ExportsInfo.js +72 -40
  30. package/lib/ExternalModule.js +14 -5
  31. package/lib/ExternalModuleFactoryPlugin.js +24 -12
  32. package/lib/FileSystemInfo.js +129 -94
  33. package/lib/FlagDependencyExportsPlugin.js +6 -4
  34. package/lib/FlagDependencyUsagePlugin.js +1 -1
  35. package/lib/Generator.js +29 -1
  36. package/lib/HookWebpackError.js +2 -2
  37. package/lib/HotModuleReplacementPlugin.js +3 -9
  38. package/lib/IgnoreErrorModuleFactory.js +2 -2
  39. package/lib/IgnorePlugin.js +0 -5
  40. package/lib/InitFragment.js +1 -1
  41. package/lib/LoaderOptionsPlugin.js +8 -5
  42. package/lib/MainTemplate.js +7 -7
  43. package/lib/Module.js +40 -17
  44. package/lib/ModuleBuildError.js +3 -1
  45. package/lib/ModuleDependencyError.js +4 -3
  46. package/lib/ModuleDependencyWarning.js +4 -3
  47. package/lib/ModuleFactory.js +9 -3
  48. package/lib/ModuleFilenameHelpers.js +13 -13
  49. package/lib/ModuleGraph.js +20 -14
  50. package/lib/ModuleGraphConnection.js +7 -13
  51. package/lib/ModuleNotFoundError.js +1 -1
  52. package/lib/ModuleParseError.js +2 -1
  53. package/lib/ModuleSourceTypesConstants.js +11 -0
  54. package/lib/ModuleTemplate.js +5 -5
  55. package/lib/ModuleTypeConstants.js +15 -0
  56. package/lib/MultiCompiler.js +4 -4
  57. package/lib/MultiStats.js +1 -1
  58. package/lib/NormalModule.js +101 -54
  59. package/lib/NormalModuleFactory.js +38 -33
  60. package/lib/NormalModuleReplacementPlugin.js +3 -2
  61. package/lib/NullFactory.js +2 -2
  62. package/lib/Parser.js +4 -3
  63. package/lib/ProgressPlugin.js +1 -2
  64. package/lib/RawModule.js +4 -2
  65. package/lib/RecordIdsPlugin.js +6 -2
  66. package/lib/RequestShortener.js +3 -1
  67. package/lib/ResolverFactory.js +12 -9
  68. package/lib/RuntimeModule.js +4 -2
  69. package/lib/RuntimeTemplate.js +2 -1
  70. package/lib/SelfModuleFactory.js +2 -2
  71. package/lib/SourceMapDevToolPlugin.js +0 -8
  72. package/lib/Template.js +6 -5
  73. package/lib/TemplatedPathPlugin.js +15 -12
  74. package/lib/WebpackOptionsApply.js +1 -1
  75. package/lib/asset/AssetGenerator.js +237 -170
  76. package/lib/asset/AssetModulesPlugin.js +50 -8
  77. package/lib/asset/AssetSourceGenerator.js +18 -0
  78. package/lib/asset/RawDataUrlModule.js +4 -2
  79. package/lib/buildChunkGraph.js +14 -4
  80. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  81. package/lib/cache/PackFileCacheStrategy.js +137 -121
  82. package/lib/cache/ResolverCachePlugin.js +15 -7
  83. package/lib/cache/getLazyHashedEtag.js +4 -3
  84. package/lib/cli.js +23 -15
  85. package/lib/config/defaults.js +93 -26
  86. package/lib/config/normalization.js +14 -13
  87. package/lib/config/target.js +8 -8
  88. package/lib/container/ContainerEntryModule.js +4 -2
  89. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  90. package/lib/container/FallbackModule.js +4 -2
  91. package/lib/container/FallbackModuleFactory.js +2 -2
  92. package/lib/container/RemoteModule.js +4 -2
  93. package/lib/container/options.js +5 -5
  94. package/lib/css/CssGenerator.js +71 -9
  95. package/lib/css/CssModulesPlugin.js +30 -5
  96. package/lib/css/CssParser.js +37 -17
  97. package/lib/css/walkCssTokens.js +17 -17
  98. package/lib/debug/ProfilingPlugin.js +98 -38
  99. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
  100. package/lib/dependencies/AMDPlugin.js +5 -2
  101. package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
  102. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  103. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
  104. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  105. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
  106. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
  107. package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
  108. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  109. package/lib/dependencies/ContextDependencyHelpers.js +13 -6
  110. package/lib/dependencies/CssIcssExportDependency.js +15 -12
  111. package/lib/dependencies/CssIcssImportDependency.js +4 -1
  112. package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
  113. package/lib/dependencies/ExportsInfoDependency.js +6 -1
  114. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
  115. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
  116. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
  117. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  118. package/lib/dependencies/HarmonyImportDependency.js +8 -6
  119. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
  120. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
  121. package/lib/dependencies/ImportContextDependency.js +2 -1
  122. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
  123. package/lib/dependencies/JsonExportsDependency.js +24 -8
  124. package/lib/dependencies/LoaderPlugin.js +4 -14
  125. package/lib/dependencies/RequireContextDependency.js +2 -1
  126. package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
  127. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
  128. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
  129. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  130. package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
  131. package/lib/dependencies/WorkerDependency.js +6 -3
  132. package/lib/dependencies/WorkerPlugin.js +100 -41
  133. package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
  134. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  136. package/lib/hmr/LazyCompilationPlugin.js +32 -24
  137. package/lib/hmr/lazyCompilationBackend.js +1 -1
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  139. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  140. package/lib/ids/IdHelpers.js +15 -14
  141. package/lib/ids/SyncModuleIdsPlugin.js +9 -5
  142. package/lib/index.js +5 -5
  143. package/lib/javascript/BasicEvaluatedExpression.js +6 -6
  144. package/lib/javascript/JavascriptGenerator.js +11 -1
  145. package/lib/javascript/JavascriptModulesPlugin.js +51 -31
  146. package/lib/javascript/JavascriptParser.js +287 -188
  147. package/lib/javascript/JavascriptParserHelpers.js +10 -9
  148. package/lib/javascript/StartupHelpers.js +4 -1
  149. package/lib/json/JsonData.js +4 -4
  150. package/lib/json/JsonGenerator.js +54 -22
  151. package/lib/json/JsonModulesPlugin.js +16 -2
  152. package/lib/json/JsonParser.js +8 -4
  153. package/lib/library/AbstractLibraryPlugin.js +7 -3
  154. package/lib/library/AssignLibraryPlugin.js +29 -1
  155. package/lib/library/EnableLibraryPlugin.js +7 -10
  156. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  157. package/lib/library/ModuleLibraryPlugin.js +121 -15
  158. package/lib/logging/Logger.js +2 -2
  159. package/lib/logging/createConsoleLogger.js +4 -4
  160. package/lib/node/NodeEnvironmentPlugin.js +6 -2
  161. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
  162. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  163. package/lib/node/nodeConsole.js +3 -1
  164. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  165. package/lib/optimize/ConcatenatedModule.js +19 -12
  166. package/lib/optimize/InnerGraph.js +3 -2
  167. package/lib/optimize/InnerGraphPlugin.js +13 -7
  168. package/lib/optimize/LimitChunkCountPlugin.js +20 -0
  169. package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
  170. package/lib/optimize/RealContentHashPlugin.js +8 -4
  171. package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
  172. package/lib/optimize/SplitChunksPlugin.js +87 -65
  173. package/lib/rules/BasicEffectRulePlugin.js +9 -1
  174. package/lib/rules/BasicMatcherRulePlugin.js +15 -4
  175. package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
  176. package/lib/rules/RuleSetCompiler.js +25 -14
  177. package/lib/rules/UseEffectRulePlugin.js +47 -17
  178. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
  179. package/lib/schemes/HttpUriPlugin.js +38 -17
  180. package/lib/serialization/BinaryMiddleware.js +52 -19
  181. package/lib/serialization/FileMiddleware.js +78 -48
  182. package/lib/serialization/ObjectMiddleware.js +78 -29
  183. package/lib/serialization/PlainObjectSerializer.js +1 -1
  184. package/lib/serialization/Serializer.js +15 -10
  185. package/lib/serialization/SerializerMiddleware.js +80 -41
  186. package/lib/serialization/SingleItemMiddleware.js +10 -7
  187. package/lib/serialization/types.js +1 -1
  188. package/lib/sharing/ConsumeSharedModule.js +4 -2
  189. package/lib/sharing/ProvideSharedModule.js +4 -2
  190. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  191. package/lib/sharing/utils.js +2 -2
  192. package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
  193. package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
  194. package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
  195. package/lib/stats/StatsFactory.js +11 -11
  196. package/lib/stats/StatsPrinter.js +7 -7
  197. package/lib/util/ArrayHelpers.js +2 -4
  198. package/lib/util/ArrayQueue.js +1 -1
  199. package/lib/util/AsyncQueue.js +4 -4
  200. package/lib/util/IterableHelpers.js +1 -1
  201. package/lib/util/LazyBucketSortedSet.js +41 -23
  202. package/lib/util/LazySet.js +3 -2
  203. package/lib/util/MapHelpers.js +1 -1
  204. package/lib/util/ParallelismFactorCalculator.js +1 -1
  205. package/lib/util/Semaphore.js +3 -3
  206. package/lib/util/SetHelpers.js +1 -1
  207. package/lib/util/SortableSet.js +9 -7
  208. package/lib/util/TupleQueue.js +9 -8
  209. package/lib/util/TupleSet.js +2 -2
  210. package/lib/util/WeakTupleMap.js +12 -11
  211. package/lib/util/binarySearchBounds.js +2 -1
  212. package/lib/util/cleverMerge.js +84 -54
  213. package/lib/util/comparators.js +22 -21
  214. package/lib/util/compileBooleanMatcher.js +3 -3
  215. package/lib/util/concatenate.js +6 -4
  216. package/lib/util/create-schema-validation.js +4 -4
  217. package/lib/util/createHash.js +2 -2
  218. package/lib/util/deprecation.js +35 -33
  219. package/lib/util/deterministicGrouping.js +6 -6
  220. package/lib/util/findGraphRoots.js +1 -1
  221. package/lib/util/fs.js +39 -39
  222. package/lib/util/hash/wasm-hash.js +2 -2
  223. package/lib/util/identifier.js +15 -18
  224. package/lib/util/makeSerializable.js +1 -1
  225. package/lib/util/memoize.js +4 -1
  226. package/lib/util/objectToMap.js +3 -2
  227. package/lib/util/processAsyncTree.js +2 -2
  228. package/lib/util/propertyName.js +0 -1
  229. package/lib/util/registerExternalSerializer.js +15 -18
  230. package/lib/util/removeBOM.js +25 -0
  231. package/lib/util/runtime.js +34 -27
  232. package/lib/util/serialization.js +5 -16
  233. package/lib/util/smartGrouping.js +3 -3
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  235. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
  236. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
  237. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
  239. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
  240. package/lib/wasm-sync/WebAssemblyParser.js +9 -4
  241. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
  243. package/package.json +19 -17
  244. package/schemas/WebpackOptions.check.js +1 -1
  245. package/schemas/WebpackOptions.json +48 -13
  246. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
  247. package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
  248. package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
  249. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  250. package/types.d.ts +918 -615
  251. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -12,10 +12,14 @@ const Cache = require("../Cache");
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
  /** @typedef {import("../Module")} Module */
14
14
 
15
+ /**
16
+ * @typedef {object} MemoryWithGcCachePluginOptions
17
+ * @property {number} maxGenerations max generations
18
+ */
19
+
15
20
  class MemoryWithGcCachePlugin {
16
21
  /**
17
- * @param {object} options Options
18
- * @param {number} options.maxGenerations max generations
22
+ * @param {MemoryWithGcCachePluginOptions} options options
19
23
  */
20
24
  constructor({ maxGenerations }) {
21
25
  this._maxGenerations = maxGenerations;
@@ -21,20 +21,21 @@ const {
21
21
  /** @typedef {import("../Cache").Etag} Etag */
22
22
  /** @typedef {import("../Compiler")} Compiler */
23
23
  /** @typedef {import("../FileSystemInfo").ResolveBuildDependenciesResult} ResolveBuildDependenciesResult */
24
+ /** @typedef {import("../FileSystemInfo").ResolveResults} ResolveResults */
24
25
  /** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
25
26
  /** @typedef {import("../logging/Logger").Logger} Logger */
26
27
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
27
28
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
29
+ /** @typedef {typeof import("../util/Hash")} Hash */
28
30
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
29
31
 
30
- /** @typedef {Map<string, string | false>} ResolveResults */
31
32
  /** @typedef {Set<string>} Items */
32
33
  /** @typedef {Set<string>} BuildDependencies */
33
34
  /** @typedef {Map<string, PackItemInfo>} ItemInfo */
34
35
 
35
36
  class PackContainer {
36
37
  /**
37
- * @param {object} data stored data
38
+ * @param {Pack} data stored data
38
39
  * @param {string} version version identifier
39
40
  * @param {Snapshot} buildSnapshot snapshot of all build dependencies
40
41
  * @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured
@@ -95,11 +96,14 @@ const MIN_ITEMS_IN_FRESH_PACK = 100;
95
96
  const MAX_ITEMS_IN_FRESH_PACK = 50000;
96
97
  const MAX_TIME_IN_FRESH_PACK = 1 * 60 * 1000; // 1 min
97
98
 
99
+ /** @typedef {TODO | undefined} Value */
100
+ /** @typedef {TODO | undefined} LazyValue */
101
+
98
102
  class PackItemInfo {
99
103
  /**
100
104
  * @param {string} identifier identifier of item
101
105
  * @param {string | null | undefined} etag etag of item
102
- * @param {any} value fresh value of item
106
+ * @param {Value} value fresh value of item
103
107
  */
104
108
  constructor(identifier, etag, value) {
105
109
  this.identifier = identifier;
@@ -154,7 +158,7 @@ class Pack {
154
158
  /**
155
159
  * @param {string} identifier unique name for the resource
156
160
  * @param {string | null} etag etag of the resource
157
- * @returns {any} cached content
161
+ * @returns {Value} cached content
158
162
  */
159
163
  get(identifier, etag) {
160
164
  const info = this.itemInfo.get(identifier);
@@ -177,7 +181,7 @@ class Pack {
177
181
  /**
178
182
  * @param {string} identifier unique name for the resource
179
183
  * @param {string | null} etag etag of the resource
180
- * @param {any} data cached content
184
+ * @param {Value} data cached content
181
185
  * @returns {void}
182
186
  */
183
187
  set(identifier, etag, data) {
@@ -268,7 +272,7 @@ class Pack {
268
272
  }
269
273
 
270
274
  _persistFreshContent() {
271
- /** @typedef {{ items: Items, map: Map<string, any>, loc: number }} PackItem */
275
+ /** @typedef {{ items: Items, map: Content, loc: number }} PackItem */
272
276
  const itemsCount = this.freshContent.size;
273
277
  if (itemsCount > 0) {
274
278
  const packCount = Math.ceil(itemsCount / MAX_ITEMS_IN_FRESH_PACK);
@@ -393,7 +397,7 @@ class Pack {
393
397
  const mergedItems = new Set();
394
398
  /** @type {Items} */
395
399
  const mergedUsedItems = new Set();
396
- /** @type {(function(Map<string, any>): Promise<void>)[]} */
400
+ /** @type {((map: Content) => Promise<void>)[]} */
397
401
  const addToMergedMap = [];
398
402
  for (const content of mergedContent) {
399
403
  for (const identifier of content.items) {
@@ -472,6 +476,7 @@ class Pack {
472
476
  await content.unpack(
473
477
  "it should be splitted into used and unused items"
474
478
  );
479
+ /** @type {Content} */
475
480
  const map = new Map();
476
481
  for (const identifier of usedItems) {
477
482
  map.set(
@@ -597,7 +602,10 @@ class Pack {
597
602
  const content = this.content[i];
598
603
  if (content !== undefined) {
599
604
  write(content.items);
600
- content.writeLazy(lazy => writeSeparate(lazy, { name: `${i}` }));
605
+ content.writeLazy(lazy =>
606
+ /** @type {NonNullable<ObjectSerializerContext["writeSeparate"]>} */
607
+ (writeSeparate)(lazy, { name: `${i}` })
608
+ );
601
609
  } else {
602
610
  write(undefined); // undefined marks an empty content slot
603
611
  }
@@ -659,7 +667,7 @@ class Pack {
659
667
 
660
668
  makeSerializable(Pack, "webpack/lib/cache/PackFileCacheStrategy", "Pack");
661
669
 
662
- /** @typedef {Map<string, any>} Content */
670
+ /** @typedef {Map<string, Value>} Content */
663
671
 
664
672
  class PackContentItems {
665
673
  /**
@@ -670,7 +678,7 @@ class PackContentItems {
670
678
  }
671
679
 
672
680
  /**
673
- * @param {ObjectSerializerContext & { snapshot: TODO, rollback: TODO, logger: Logger, profile: boolean | undefined }} context context
681
+ * @param {ObjectSerializerContext & { logger: Logger, profile: boolean | undefined }} context context
674
682
  */
675
683
  serialize({ write, snapshot, rollback, logger, profile }) {
676
684
  if (profile) {
@@ -791,7 +799,7 @@ makeSerializable(
791
799
  "PackContentItems"
792
800
  );
793
801
 
794
- /** @typedef {(function(): Promise<PackContentItems> | PackContentItems)} LazyFn */
802
+ /** @typedef {(() => Promise<PackContentItems> | PackContentItems)} LazyFunction */
795
803
 
796
804
  class PackContent {
797
805
  /*
@@ -816,13 +824,13 @@ class PackContent {
816
824
  /**
817
825
  * @param {Items} items keys
818
826
  * @param {Items} usedItems used keys
819
- * @param {PackContentItems | function(): Promise<PackContentItems>} dataOrFn sync or async content
827
+ * @param {PackContentItems | (() => Promise<PackContentItems>)} dataOrFn sync or async content
820
828
  * @param {Logger=} logger logger for logging
821
829
  * @param {string=} lazyName name of dataOrFn for logging
822
830
  */
823
831
  constructor(items, usedItems, dataOrFn, logger, lazyName) {
824
832
  this.items = items;
825
- /** @type {LazyFn | undefined} */
833
+ /** @type {LazyValue} */
826
834
  this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
827
835
  /** @type {Content | undefined} */
828
836
  this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
@@ -860,7 +868,7 @@ class PackContent {
860
868
  );
861
869
  logger.time(timeMessage);
862
870
  }
863
- const value = /** @type {LazyFn} */ (this.lazy)();
871
+ const value = /** @type {LazyFunction} */ (this.lazy)();
864
872
  if ("then" in value) {
865
873
  return value.then(data => {
866
874
  const map = data.map;
@@ -870,7 +878,7 @@ class PackContent {
870
878
  // Move to state C
871
879
  this.content = map;
872
880
  this.lazy = SerializerMiddleware.unMemoizeLazy(
873
- /** @type {LazyFn} */
881
+ /** @type {LazyFunction} */
874
882
  (this.lazy)
875
883
  );
876
884
  return map.get(identifier);
@@ -884,7 +892,7 @@ class PackContent {
884
892
  // Move to state C
885
893
  this.content = map;
886
894
  this.lazy = SerializerMiddleware.unMemoizeLazy(
887
- /** @type {LazyFn} */
895
+ /** @type {LazyFunction} */
888
896
  (this.lazy)
889
897
  );
890
898
  return map.get(identifier);
@@ -916,7 +924,9 @@ class PackContent {
916
924
  );
917
925
  logger.time(timeMessage);
918
926
  }
919
- const value = this.lazy();
927
+ const value =
928
+ /** @type {PackContentItems | Promise<PackContentItems>} */
929
+ (this.lazy());
920
930
  if ("then" in value) {
921
931
  return value.then(data => {
922
932
  if (timeMessage) {
@@ -937,7 +947,9 @@ class PackContent {
937
947
  */
938
948
  getSize() {
939
949
  if (!this.lazy) return -1;
940
- const options = /** @type {any} */ (this.lazy).options;
950
+ const options =
951
+ /** @type {{ options: { size?: number } }} */
952
+ (this.lazy).options;
941
953
  if (!options) return -1;
942
954
  const size = options.size;
943
955
  if (typeof size !== "number") return -1;
@@ -955,7 +967,7 @@ class PackContent {
955
967
 
956
968
  /**
957
969
  * @template T
958
- * @param {function(any): function(): Promise<PackContentItems> | PackContentItems} write write function
970
+ * @param {(item?: LazyValue) => (() => Promise<PackContentItems> | PackContentItems)} write write function
959
971
  * @returns {void}
960
972
  */
961
973
  writeLazy(write) {
@@ -1007,7 +1019,7 @@ class PackContent {
1007
1019
  );
1008
1020
  logger.time(timeMessage);
1009
1021
  }
1010
- const value = /** @type {LazyFn} */ (this.lazy)();
1022
+ const value = /** @type {LazyFunction} */ (this.lazy)();
1011
1023
  this.outdated = false;
1012
1024
  if ("then" in value) {
1013
1025
  // Move to state B1
@@ -1024,10 +1036,7 @@ class PackContent {
1024
1036
  }
1025
1037
  // Move to state C1 (or maybe C2)
1026
1038
  this.content = map;
1027
- this.lazy = SerializerMiddleware.unMemoizeLazy(
1028
- /** @type {LazyFn} */
1029
- (this.lazy)
1030
- );
1039
+ this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
1031
1040
 
1032
1041
  return new PackContentItems(map);
1033
1042
  })
@@ -1093,7 +1102,8 @@ class PackFileCacheStrategy {
1093
1102
  }) {
1094
1103
  this.fileSerializer = createFileSerializer(
1095
1104
  fs,
1096
- compiler.options.output.hashFunction
1105
+ /** @type {string | Hash} */
1106
+ (compiler.options.output.hashFunction)
1097
1107
  );
1098
1108
  this.fileSystemInfo = new FileSystemInfo(fs, {
1099
1109
  managedPaths: snapshot.managedPaths,
@@ -1276,7 +1286,7 @@ class PackFileCacheStrategy {
1276
1286
  logger.timeEnd("check build dependencies");
1277
1287
  if (buildSnapshotValid && resolveValid) {
1278
1288
  logger.time("restore cache content metadata");
1279
- const d = packContainer.data();
1289
+ const d = /** @type {TODO} */ (packContainer).data();
1280
1290
  logger.timeEnd("restore cache content metadata");
1281
1291
  return d;
1282
1292
  }
@@ -1309,7 +1319,7 @@ class PackFileCacheStrategy {
1309
1319
  /**
1310
1320
  * @param {string} identifier unique name for the resource
1311
1321
  * @param {Etag | null} etag etag of the resource
1312
- * @param {any} data cached content
1322
+ * @param {Value} data cached content
1313
1323
  * @returns {Promise<void>} promise
1314
1324
  */
1315
1325
  store(identifier, etag, data) {
@@ -1323,7 +1333,7 @@ class PackFileCacheStrategy {
1323
1333
  /**
1324
1334
  * @param {string} identifier unique name for the resource
1325
1335
  * @param {Etag | null} etag etag of the resource
1326
- * @returns {Promise<any>} promise to the cached content
1336
+ * @returns {Promise<Value>} promise to the cached content
1327
1337
  */
1328
1338
  restore(identifier, etag) {
1329
1339
  return this._getPack()
@@ -1372,104 +1382,110 @@ class PackFileCacheStrategy {
1372
1382
  newBuildDependencies
1373
1383
  ).join(", ")})`
1374
1384
  );
1375
- promise = new Promise((resolve, reject) => {
1376
- this.logger.time("resolve build dependencies");
1377
- this.fileSystemInfo.resolveBuildDependencies(
1378
- this.context,
1379
- newBuildDependencies,
1380
- (err, result) => {
1381
- this.logger.timeEnd("resolve build dependencies");
1382
- if (err) return reject(err);
1383
-
1384
- this.logger.time("snapshot build dependencies");
1385
- const {
1386
- files,
1387
- directories,
1388
- missing,
1389
- resolveResults,
1390
- resolveDependencies
1391
- } = /** @type {ResolveBuildDependenciesResult} */ (result);
1392
- if (this.resolveResults) {
1393
- for (const [key, value] of resolveResults) {
1394
- this.resolveResults.set(key, value);
1395
- }
1396
- } else {
1397
- this.resolveResults = resolveResults;
1398
- }
1399
- if (reportProgress) {
1400
- reportProgress(
1401
- 0.6,
1402
- "snapshot build dependencies",
1403
- "resolving"
1404
- );
1405
- }
1406
- this.fileSystemInfo.createSnapshot(
1407
- undefined,
1408
- resolveDependencies.files,
1409
- resolveDependencies.directories,
1410
- resolveDependencies.missing,
1411
- this.snapshot.resolveBuildDependencies,
1412
- (err, snapshot) => {
1413
- if (err) {
1414
- this.logger.timeEnd("snapshot build dependencies");
1415
- return reject(err);
1385
+ promise = new Promise(
1386
+ /**
1387
+ * @param {(value?: undefined) => void} resolve resolve
1388
+ * @param {(reason?: Error) => void} reject reject
1389
+ */
1390
+ (resolve, reject) => {
1391
+ this.logger.time("resolve build dependencies");
1392
+ this.fileSystemInfo.resolveBuildDependencies(
1393
+ this.context,
1394
+ newBuildDependencies,
1395
+ (err, result) => {
1396
+ this.logger.timeEnd("resolve build dependencies");
1397
+ if (err) return reject(err);
1398
+
1399
+ this.logger.time("snapshot build dependencies");
1400
+ const {
1401
+ files,
1402
+ directories,
1403
+ missing,
1404
+ resolveResults,
1405
+ resolveDependencies
1406
+ } = /** @type {ResolveBuildDependenciesResult} */ (result);
1407
+ if (this.resolveResults) {
1408
+ for (const [key, value] of resolveResults) {
1409
+ this.resolveResults.set(key, value);
1416
1410
  }
1417
- if (!snapshot) {
1418
- this.logger.timeEnd("snapshot build dependencies");
1419
- return reject(
1420
- new Error("Unable to snapshot resolve dependencies")
1421
- );
1422
- }
1423
- if (this.resolveBuildDependenciesSnapshot) {
1424
- this.resolveBuildDependenciesSnapshot =
1425
- this.fileSystemInfo.mergeSnapshots(
1426
- this.resolveBuildDependenciesSnapshot,
1427
- snapshot
1428
- );
1429
- } else {
1430
- this.resolveBuildDependenciesSnapshot = snapshot;
1431
- }
1432
- if (reportProgress) {
1433
- reportProgress(
1434
- 0.7,
1435
- "snapshot build dependencies",
1436
- "modules"
1437
- );
1438
- }
1439
- this.fileSystemInfo.createSnapshot(
1440
- undefined,
1441
- files,
1442
- directories,
1443
- missing,
1444
- this.snapshot.buildDependencies,
1445
- (err, snapshot) => {
1411
+ } else {
1412
+ this.resolveResults = resolveResults;
1413
+ }
1414
+ if (reportProgress) {
1415
+ reportProgress(
1416
+ 0.6,
1417
+ "snapshot build dependencies",
1418
+ "resolving"
1419
+ );
1420
+ }
1421
+ this.fileSystemInfo.createSnapshot(
1422
+ undefined,
1423
+ resolveDependencies.files,
1424
+ resolveDependencies.directories,
1425
+ resolveDependencies.missing,
1426
+ this.snapshot.resolveBuildDependencies,
1427
+ (err, snapshot) => {
1428
+ if (err) {
1429
+ this.logger.timeEnd("snapshot build dependencies");
1430
+ return reject(err);
1431
+ }
1432
+ if (!snapshot) {
1446
1433
  this.logger.timeEnd("snapshot build dependencies");
1447
- if (err) return reject(err);
1448
- if (!snapshot) {
1449
- return reject(
1450
- new Error("Unable to snapshot build dependencies")
1434
+ return reject(
1435
+ new Error("Unable to snapshot resolve dependencies")
1436
+ );
1437
+ }
1438
+ if (this.resolveBuildDependenciesSnapshot) {
1439
+ this.resolveBuildDependenciesSnapshot =
1440
+ this.fileSystemInfo.mergeSnapshots(
1441
+ this.resolveBuildDependenciesSnapshot,
1442
+ snapshot
1451
1443
  );
1452
- }
1453
- this.logger.debug("Captured build dependencies");
1454
-
1455
- if (this.buildSnapshot) {
1456
- this.buildSnapshot =
1457
- this.fileSystemInfo.mergeSnapshots(
1458
- this.buildSnapshot,
1459
- snapshot
1444
+ } else {
1445
+ this.resolveBuildDependenciesSnapshot = snapshot;
1446
+ }
1447
+ if (reportProgress) {
1448
+ reportProgress(
1449
+ 0.7,
1450
+ "snapshot build dependencies",
1451
+ "modules"
1452
+ );
1453
+ }
1454
+ this.fileSystemInfo.createSnapshot(
1455
+ undefined,
1456
+ files,
1457
+ directories,
1458
+ missing,
1459
+ this.snapshot.buildDependencies,
1460
+ (err, snapshot) => {
1461
+ this.logger.timeEnd("snapshot build dependencies");
1462
+ if (err) return reject(err);
1463
+ if (!snapshot) {
1464
+ return reject(
1465
+ new Error("Unable to snapshot build dependencies")
1460
1466
  );
1461
- } else {
1462
- this.buildSnapshot = snapshot;
1467
+ }
1468
+ this.logger.debug("Captured build dependencies");
1469
+
1470
+ if (this.buildSnapshot) {
1471
+ this.buildSnapshot =
1472
+ this.fileSystemInfo.mergeSnapshots(
1473
+ this.buildSnapshot,
1474
+ snapshot
1475
+ );
1476
+ } else {
1477
+ this.buildSnapshot = snapshot;
1478
+ }
1479
+
1480
+ resolve();
1463
1481
  }
1464
-
1465
- resolve();
1466
- }
1467
- );
1468
- }
1469
- );
1470
- }
1471
- );
1472
- });
1482
+ );
1483
+ }
1484
+ );
1485
+ }
1486
+ );
1487
+ }
1488
+ );
1473
1489
  } else {
1474
1490
  promise = Promise.resolve();
1475
1491
  }
@@ -26,6 +26,11 @@ const makeSerializable = require("../util/makeSerializable");
26
26
  * @typedef {import("tapable").SyncHook<T>} SyncHook
27
27
  */
28
28
 
29
+ /**
30
+ * @template H
31
+ * @typedef {import("tapable").HookMapInterceptor<H>} HookMapInterceptor
32
+ */
33
+
29
34
  class CacheEntry {
30
35
  /**
31
36
  * @param {ResolveRequest} result result
@@ -125,7 +130,7 @@ class ResolverCachePlugin {
125
130
  });
126
131
  });
127
132
 
128
- /** @typedef {function((Error | null)=, ResolveRequest=): void} Callback */
133
+ /** @typedef {(err?: Error | null, resolveRequest?: ResolveRequest | null) => void} Callback */
129
134
  /** @typedef {ResolveRequest & { _ResolverCachePluginCacheMiss: true }} ResolveRequestWithCacheMiss */
130
135
 
131
136
  /**
@@ -244,13 +249,16 @@ class ResolverCachePlugin {
244
249
  );
245
250
  };
246
251
  compiler.resolverFactory.hooks.resolver.intercept({
247
- factory(type, hook) {
248
- /** @type {Map<string, (function(Error=, ResolveRequest=): void)[]>} */
252
+ factory(type, _hook) {
253
+ /** @typedef {(err?: Error, resolveRequest?: ResolveRequest) => void} ActiveRequest */
254
+ /** @type {Map<string, ActiveRequest[]>} */
249
255
  const activeRequests = new Map();
250
- /** @type {Map<string, [function(Error=, ResolveRequest=): void, NonNullable<ResolveContext["yield"]>][]>} */
256
+ /** @type {Map<string, [ActiveRequest, NonNullable<ResolveContext["yield"]>][]>} */
251
257
  const activeRequestsWithYield = new Map();
252
- /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
253
- (hook).tap("ResolverCachePlugin", (resolver, options, userOptions) => {
258
+ const hook =
259
+ /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
260
+ (_hook);
261
+ hook.tap("ResolverCachePlugin", (resolver, options, userOptions) => {
254
262
  if (/** @type {TODO} */ (options).cache !== true) return;
255
263
  const optionsIdent = objectToString(userOptions, false);
256
264
  const cacheWithContext =
@@ -299,7 +307,7 @@ class ResolverCachePlugin {
299
307
  let yields;
300
308
 
301
309
  /**
302
- * @type {function((Error | null)=, ResolveRequest | ResolveRequest[]=): void}
310
+ * @type {(err?: Error | null, result?: ResolveRequest | ResolveRequest[] | null) => void}
303
311
  */
304
312
  const done = withYield
305
313
  ? (err, result) => {
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { DEFAULTS } = require("../config/defaults");
8
9
  const createHash = require("../util/createHash");
9
10
 
10
11
  /** @typedef {import("../util/Hash")} Hash */
@@ -12,7 +13,7 @@ const createHash = require("../util/createHash");
12
13
 
13
14
  /**
14
15
  * @typedef {object} HashableObject
15
- * @property {function(Hash): void} updateHash
16
+ * @property {(hash: Hash) => void} updateHash
16
17
  */
17
18
 
18
19
  class LazyHashedEtag {
@@ -20,7 +21,7 @@ class LazyHashedEtag {
20
21
  * @param {HashableObject} obj object with updateHash method
21
22
  * @param {string | HashConstructor} hashFunction the hash function to use
22
23
  */
23
- constructor(obj, hashFunction = "md4") {
24
+ constructor(obj, hashFunction = DEFAULTS.HASH_FUNCTION) {
24
25
  this._obj = obj;
25
26
  this._hash = undefined;
26
27
  this._hashFunction = hashFunction;
@@ -50,7 +51,7 @@ const mapObjects = new WeakMap();
50
51
  * @param {(string | HashConstructor)=} hashFunction the hash function to use
51
52
  * @returns {LazyHashedEtag} etag
52
53
  */
53
- const getter = (obj, hashFunction = "md4") => {
54
+ const getter = (obj, hashFunction = DEFAULTS.HASH_FUNCTION) => {
54
55
  let innerMap;
55
56
  if (typeof hashFunction === "string") {
56
57
  innerMap = mapStrings.get(hashFunction);