webpack 5.85.0 → 5.88.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.

Potentially problematic release.


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

Files changed (249) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/BannerPlugin.js +2 -1
  5. package/lib/CaseSensitiveModulesWarning.js +3 -1
  6. package/lib/Chunk.js +35 -17
  7. package/lib/ChunkGraph.js +4 -4
  8. package/lib/ChunkGroup.js +20 -9
  9. package/lib/CompatibilityPlugin.js +50 -30
  10. package/lib/Compilation.js +2 -1
  11. package/lib/Compiler.js +10 -9
  12. package/lib/ConcatenationScope.js +2 -2
  13. package/lib/ConditionalInitFragment.js +11 -1
  14. package/lib/ConstPlugin.js +73 -32
  15. package/lib/ContextModule.js +8 -3
  16. package/lib/ContextModuleFactory.js +1 -0
  17. package/lib/ContextReplacementPlugin.js +13 -0
  18. package/lib/DelegatedModule.js +15 -3
  19. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  20. package/lib/DependenciesBlock.js +1 -1
  21. package/lib/Dependency.js +11 -5
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllEntryPlugin.js +11 -1
  24. package/lib/DllModule.js +6 -0
  25. package/lib/DllReferencePlugin.js +13 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ErrorHelpers.js +1 -0
  28. package/lib/EvalSourceMapDevToolPlugin.js +6 -1
  29. package/lib/ExportsInfo.js +22 -4
  30. package/lib/ExportsInfoApiPlugin.js +14 -5
  31. package/lib/ExternalModule.js +20 -8
  32. package/lib/FileSystemInfo.js +52 -24
  33. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  34. package/lib/FlagDependencyUsagePlugin.js +3 -1
  35. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  36. package/lib/Generator.js +7 -0
  37. package/lib/HotModuleReplacementPlugin.js +8 -0
  38. package/lib/InitFragment.js +28 -5
  39. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  40. package/lib/LibManifestPlugin.js +20 -4
  41. package/lib/Module.js +14 -3
  42. package/lib/ModuleDependencyError.js +4 -2
  43. package/lib/ModuleDependencyWarning.js +4 -2
  44. package/lib/ModuleGraph.js +31 -24
  45. package/lib/ModuleGraphConnection.js +19 -6
  46. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  47. package/lib/ModuleNotFoundError.js +5 -2
  48. package/lib/ModuleProfile.js +1 -0
  49. package/lib/ModuleRestoreError.js +2 -0
  50. package/lib/ModuleStoreError.js +2 -1
  51. package/lib/ModuleTypeConstants.js +7 -0
  52. package/lib/MultiWatching.js +4 -0
  53. package/lib/NodeStuffPlugin.js +32 -6
  54. package/lib/ProgressPlugin.js +71 -15
  55. package/lib/ProvidePlugin.js +13 -4
  56. package/lib/RawModule.js +3 -1
  57. package/lib/RequireJsStuffPlugin.js +7 -0
  58. package/lib/RuntimeGlobals.js +5 -0
  59. package/lib/RuntimeModule.js +3 -3
  60. package/lib/RuntimePlugin.js +6 -3
  61. package/lib/RuntimeTemplate.js +22 -4
  62. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  63. package/lib/SourceMapDevToolPlugin.js +7 -2
  64. package/lib/UseStrictPlugin.js +10 -3
  65. package/lib/Watching.js +62 -25
  66. package/lib/WebpackError.js +6 -5
  67. package/lib/WebpackIsIncludedPlugin.js +6 -4
  68. package/lib/WebpackOptionsApply.js +4 -2
  69. package/lib/WebpackOptionsDefaulter.js +10 -3
  70. package/lib/asset/AssetGenerator.js +2 -1
  71. package/lib/asset/AssetParser.js +11 -6
  72. package/lib/asset/AssetSourceParser.js +8 -3
  73. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  74. package/lib/buildChunkGraph.js +37 -21
  75. package/lib/cache/IdleFileCachePlugin.js +2 -1
  76. package/lib/cache/PackFileCacheStrategy.js +53 -22
  77. package/lib/config/browserslistTargetHandler.js +7 -7
  78. package/lib/config/defaults.js +43 -26
  79. package/lib/container/RemoteRuntimeModule.js +1 -1
  80. package/lib/css/CssExportsGenerator.js +9 -0
  81. package/lib/css/CssGenerator.js +1 -1
  82. package/lib/css/CssLoadingRuntimeModule.js +43 -19
  83. package/lib/css/CssModulesPlugin.js +42 -14
  84. package/lib/css/CssParser.js +22 -0
  85. package/lib/dependencies/AMDDefineDependency.js +34 -4
  86. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  87. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  88. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  89. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  90. package/lib/dependencies/CommonJsPlugin.js +13 -8
  91. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  92. package/lib/dependencies/ConstDependency.js +2 -2
  93. package/lib/dependencies/ContextDependency.js +7 -2
  94. package/lib/dependencies/CssImportDependency.js +1 -1
  95. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  96. package/lib/dependencies/CssUrlDependency.js +3 -3
  97. package/lib/dependencies/DllEntryDependency.js +5 -0
  98. package/lib/dependencies/DynamicExports.js +10 -6
  99. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  100. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  101. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  102. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  103. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  104. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  105. package/lib/dependencies/HarmonyExports.js +9 -5
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
  109. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  110. package/lib/dependencies/ImportDependency.js +5 -3
  111. package/lib/dependencies/ImportEagerDependency.js +5 -3
  112. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  113. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  114. package/lib/dependencies/ImportParserPlugin.js +62 -25
  115. package/lib/dependencies/ImportWeakDependency.js +5 -3
  116. package/lib/dependencies/JsonExportsDependency.js +1 -1
  117. package/lib/dependencies/ModuleDependency.js +1 -1
  118. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  119. package/lib/dependencies/ProvidedDependency.js +4 -1
  120. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  121. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  122. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  123. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  124. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  125. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  126. package/lib/dependencies/SystemPlugin.js +17 -5
  127. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  128. package/lib/dependencies/URLDependency.js +2 -2
  129. package/lib/dependencies/URLPlugin.js +9 -4
  130. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  131. package/lib/dependencies/WorkerPlugin.js +59 -22
  132. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  134. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  135. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  136. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  137. package/lib/javascript/BasicEvaluatedExpression.js +28 -19
  138. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  139. package/lib/javascript/JavascriptModulesPlugin.js +25 -5
  140. package/lib/javascript/JavascriptParser.js +157 -85
  141. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  142. package/lib/json/JsonData.js +2 -2
  143. package/lib/json/JsonParser.js +25 -12
  144. package/lib/library/AmdLibraryPlugin.js +2 -2
  145. package/lib/library/AssignLibraryPlugin.js +13 -1
  146. package/lib/library/EnableLibraryPlugin.js +4 -0
  147. package/lib/library/SystemLibraryPlugin.js +1 -1
  148. package/lib/library/UmdLibraryPlugin.js +20 -2
  149. package/lib/logging/runtime.js +1 -1
  150. package/lib/logging/truncateArgs.js +4 -0
  151. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  152. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  153. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  154. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  155. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  156. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  157. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  158. package/lib/optimize/InnerGraph.js +5 -5
  159. package/lib/optimize/InnerGraphPlugin.js +2 -1
  160. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  161. package/lib/optimize/MangleExportsPlugin.js +1 -1
  162. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  163. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  164. package/lib/optimize/RealContentHashPlugin.js +80 -30
  165. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  166. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  167. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  168. package/lib/optimize/SplitChunksPlugin.js +71 -31
  169. package/lib/performance/SizeLimitsPlugin.js +7 -4
  170. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  171. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  172. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  173. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  174. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  175. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  176. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  177. package/lib/rules/RuleSetCompiler.js +3 -3
  178. package/lib/rules/UseEffectRulePlugin.js +6 -4
  179. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  180. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  181. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  182. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  183. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  184. package/lib/runtime/CompatRuntimeModule.js +7 -2
  185. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  186. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  187. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  188. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  189. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  190. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  191. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  192. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  193. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  194. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  195. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  196. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  197. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  198. package/lib/runtime/NonceRuntimeModule.js +1 -1
  199. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  200. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  201. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  202. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  203. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  204. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  205. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  206. package/lib/serialization/BinaryMiddleware.js +143 -1
  207. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  208. package/lib/serialization/ObjectMiddleware.js +9 -3
  209. package/lib/serialization/types.js +1 -1
  210. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  211. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  212. package/lib/sharing/ProvideSharedDependency.js +11 -0
  213. package/lib/sharing/ProvideSharedModule.js +4 -0
  214. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  215. package/lib/sharing/ShareRuntimeModule.js +12 -5
  216. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  217. package/lib/sharing/utils.js +32 -5
  218. package/lib/util/AsyncQueue.js +4 -2
  219. package/lib/util/ParallelismFactorCalculator.js +10 -0
  220. package/lib/util/Semaphore.js +1 -1
  221. package/lib/util/StackedCacheMap.js +1 -1
  222. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  223. package/lib/util/createHash.js +30 -9
  224. package/lib/util/deprecation.js +10 -3
  225. package/lib/util/deterministicGrouping.js +50 -11
  226. package/lib/util/findGraphRoots.js +4 -2
  227. package/lib/util/memoize.js +3 -3
  228. package/lib/util/processAsyncTree.js +7 -1
  229. package/lib/util/registerExternalSerializer.js +1 -1
  230. package/lib/util/runtime.js +84 -21
  231. package/lib/util/semver.js +1 -0
  232. package/lib/util/smartGrouping.js +1 -1
  233. package/lib/validateSchema.js +6 -2
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  235. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  236. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  237. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  239. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  240. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  241. package/lib/webpack.js +11 -2
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  243. package/module.d.ts +1 -0
  244. package/package.json +5 -4
  245. package/schemas/WebpackOptions.check.js +1 -1
  246. package/schemas/WebpackOptions.json +52 -6
  247. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  248. package/schemas/plugins/css/CssParserOptions.json +1 -1
  249. package/types.d.ts +606 -292
@@ -11,11 +11,14 @@ const BULK_SIZE = 2000;
11
11
 
12
12
  // We are using an object instead of a Map as this will stay static during the runtime
13
13
  // so access to it can be optimized by v8
14
+ /** @type {Object<string, Map<string, string>>} */
14
15
  const digestCaches = {};
15
16
 
17
+ /** @typedef {function(): Hash} HashFactory */
18
+
16
19
  class BulkUpdateDecorator extends Hash {
17
20
  /**
18
- * @param {Hash | function(): Hash} hashOrFactory function to create a hash
21
+ * @param {Hash | HashFactory} hashOrFactory function to create a hash
19
22
  * @param {string=} hashKey key for caching
20
23
  */
21
24
  constructor(hashOrFactory, hashKey) {
@@ -43,7 +46,8 @@ class BulkUpdateDecorator extends Hash {
43
46
  typeof data !== "string" ||
44
47
  data.length > BULK_SIZE
45
48
  ) {
46
- if (this.hash === undefined) this.hash = this.hashFactory();
49
+ if (this.hash === undefined)
50
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
47
51
  if (this.buffer.length > 0) {
48
52
  this.hash.update(this.buffer);
49
53
  this.buffer = "";
@@ -52,7 +56,8 @@ class BulkUpdateDecorator extends Hash {
52
56
  } else {
53
57
  this.buffer += data;
54
58
  if (this.buffer.length > BULK_SIZE) {
55
- if (this.hash === undefined) this.hash = this.hashFactory();
59
+ if (this.hash === undefined)
60
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
56
61
  this.hash.update(this.buffer);
57
62
  this.buffer = "";
58
63
  }
@@ -77,7 +82,7 @@ class BulkUpdateDecorator extends Hash {
77
82
  }
78
83
  const cacheEntry = digestCache.get(buffer);
79
84
  if (cacheEntry !== undefined) return cacheEntry;
80
- this.hash = this.hashFactory();
85
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
81
86
  }
82
87
  if (buffer.length > 0) {
83
88
  this.hash.update(buffer);
@@ -111,7 +116,9 @@ class DebugHash extends Hash {
111
116
  if (data.startsWith(prefix)) {
112
117
  data = Buffer.from(data.slice(prefix.length), "hex").toString();
113
118
  }
114
- this.string += `[${data}](${new Error().stack.split("\n", 3)[2]})\n`;
119
+ this.string += `[${data}](${
120
+ /** @type {string} */ (new Error().stack).split("\n", 3)[2]
121
+ })\n`;
115
122
  return this;
116
123
  }
117
124
 
@@ -125,9 +132,13 @@ class DebugHash extends Hash {
125
132
  }
126
133
  }
127
134
 
135
+ /** @type {typeof import("crypto") | undefined} */
128
136
  let crypto = undefined;
137
+ /** @type {typeof import("./hash/xxhash64") | undefined} */
129
138
  let createXXHash64 = undefined;
139
+ /** @type {typeof import("./hash/md4") | undefined} */
130
140
  let createMd4 = undefined;
141
+ /** @type {typeof import("./hash/BatchedHash") | undefined} */
131
142
  let BatchedHash = undefined;
132
143
 
133
144
  /**
@@ -150,7 +161,9 @@ module.exports = algorithm => {
150
161
  BatchedHash = require("./hash/BatchedHash");
151
162
  }
152
163
  }
153
- return new BatchedHash(createXXHash64());
164
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (
165
+ BatchedHash
166
+ )(createXXHash64());
154
167
  case "md4":
155
168
  if (createMd4 === undefined) {
156
169
  createMd4 = require("./hash/md4");
@@ -158,14 +171,22 @@ module.exports = algorithm => {
158
171
  BatchedHash = require("./hash/BatchedHash");
159
172
  }
160
173
  }
161
- return new BatchedHash(createMd4());
174
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (
175
+ BatchedHash
176
+ )(createMd4());
162
177
  case "native-md4":
163
178
  if (crypto === undefined) crypto = require("crypto");
164
- return new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
179
+ return new BulkUpdateDecorator(
180
+ () => /** @type {typeof import("crypto")} */ (crypto).createHash("md4"),
181
+ "md4"
182
+ );
165
183
  default:
166
184
  if (crypto === undefined) crypto = require("crypto");
167
185
  return new BulkUpdateDecorator(
168
- () => crypto.createHash(algorithm),
186
+ () =>
187
+ /** @type {typeof import("crypto")} */ (crypto).createHash(
188
+ /** @type {string} */ (algorithm)
189
+ ),
169
190
  algorithm
170
191
  );
171
192
  }
@@ -78,7 +78,7 @@ exports.arrayToSetDeprecation = (set, name) => {
78
78
  );
79
79
  /**
80
80
  * @deprecated
81
- * @this {Set}
81
+ * @this {Set<any>}
82
82
  * @returns {number} count
83
83
  */
84
84
  set[method] = function () {
@@ -101,7 +101,7 @@ exports.arrayToSetDeprecation = (set, name) => {
101
101
  );
102
102
  /**
103
103
  * @deprecated
104
- * @this {Set}
104
+ * @this {Set<any>}
105
105
  * @returns {number} count
106
106
  */
107
107
  set.push = function () {
@@ -119,9 +119,13 @@ exports.arrayToSetDeprecation = (set, name) => {
119
119
  );
120
120
  };
121
121
  }
122
+ /**
123
+ * @param {number} index index
124
+ * @returns {any} value
125
+ */
122
126
  const createIndexGetter = index => {
123
127
  /**
124
- * @this {Set} a Set
128
+ * @this {Set<any>} a Set
125
129
  * @returns {any} the value at this location
126
130
  */
127
131
  const fn = function () {
@@ -134,6 +138,9 @@ exports.arrayToSetDeprecation = (set, name) => {
134
138
  };
135
139
  return fn;
136
140
  };
141
+ /**
142
+ * @param {number} index index
143
+ */
137
144
  const defineIndexGetter = index => {
138
145
  Object.defineProperty(set, index, {
139
146
  get: createIndexGetter(index),
@@ -94,7 +94,8 @@ const subtractSizeFrom = (total, size) => {
94
94
  };
95
95
 
96
96
  /**
97
- * @param {Iterable<Node>} nodes some nodes
97
+ * @template T
98
+ * @param {Iterable<Node<T>>} nodes some nodes
98
99
  * @returns {Record<string, number>} total size
99
100
  */
100
101
  const sumSize = nodes => {
@@ -105,6 +106,11 @@ const sumSize = nodes => {
105
106
  return sum;
106
107
  };
107
108
 
109
+ /**
110
+ * @param {Record<string, number>} size size
111
+ * @param {Record<string, number>} maxSize minimum size
112
+ * @returns {boolean} true, when size is too big
113
+ */
108
114
  const isTooBig = (size, maxSize) => {
109
115
  for (const key of Object.keys(size)) {
110
116
  const s = size[key];
@@ -117,6 +123,11 @@ const isTooBig = (size, maxSize) => {
117
123
  return false;
118
124
  };
119
125
 
126
+ /**
127
+ * @param {Record<string, number>} size size
128
+ * @param {Record<string, number>} minSize minimum size
129
+ * @returns {boolean} true, when size is too small
130
+ */
120
131
  const isTooSmall = (size, minSize) => {
121
132
  for (const key of Object.keys(size)) {
122
133
  const s = size[key];
@@ -129,6 +140,11 @@ const isTooSmall = (size, minSize) => {
129
140
  return false;
130
141
  };
131
142
 
143
+ /**
144
+ * @param {Record<string, number>} size size
145
+ * @param {Record<string, number>} minSize minimum size
146
+ * @returns {Set<string>} set of types that are too small
147
+ */
132
148
  const getTooSmallTypes = (size, minSize) => {
133
149
  const types = new Set();
134
150
  for (const key of Object.keys(size)) {
@@ -142,6 +158,12 @@ const getTooSmallTypes = (size, minSize) => {
142
158
  return types;
143
159
  };
144
160
 
161
+ /**
162
+ * @template T
163
+ * @param {TODO} size size
164
+ * @param {Set<string>} types types
165
+ * @returns {number} number of matching size types
166
+ */
145
167
  const getNumberOfMatchingSizeTypes = (size, types) => {
146
168
  let i = 0;
147
169
  for (const key of Object.keys(size)) {
@@ -150,6 +172,11 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
150
172
  return i;
151
173
  };
152
174
 
175
+ /**
176
+ * @param {Record<string, number>} size size
177
+ * @param {Set<string>} types types
178
+ * @returns {number} selective size sum
179
+ */
153
180
  const selectiveSizeSum = (size, types) => {
154
181
  let sum = 0;
155
182
  for (const key of Object.keys(size)) {
@@ -180,20 +207,20 @@ class Node {
180
207
  class Group {
181
208
  /**
182
209
  * @param {Node<T>[]} nodes nodes
183
- * @param {number[]} similarities similarities between the nodes (length = nodes.length - 1)
210
+ * @param {number[] | null} similarities similarities between the nodes (length = nodes.length - 1)
184
211
  * @param {Record<string, number>=} size size of the group
185
212
  */
186
213
  constructor(nodes, similarities, size) {
187
214
  this.nodes = nodes;
188
215
  this.similarities = similarities;
189
216
  this.size = size || sumSize(nodes);
190
- /** @type {string} */
217
+ /** @type {string | undefined} */
191
218
  this.key = undefined;
192
219
  }
193
220
 
194
221
  /**
195
- * @param {function(Node): boolean} filter filter function
196
- * @returns {Node[]} removed nodes
222
+ * @param {function(Node<T>): boolean} filter filter function
223
+ * @returns {Node<T>[] | undefined} removed nodes
197
224
  */
198
225
  popNodes(filter) {
199
226
  const newNodes = [];
@@ -208,7 +235,7 @@ class Group {
208
235
  if (newNodes.length > 0) {
209
236
  newSimilarities.push(
210
237
  lastNode === this.nodes[i - 1]
211
- ? this.similarities[i - 1]
238
+ ? /** @type {number[]} */ (this.similarities)[i - 1]
212
239
  : similarity(lastNode.key, node.key)
213
240
  );
214
241
  }
@@ -225,7 +252,8 @@ class Group {
225
252
  }
226
253
 
227
254
  /**
228
- * @param {Iterable<Node>} nodes nodes
255
+ * @template T
256
+ * @param {Iterable<Node<T>>} nodes nodes
229
257
  * @returns {number[]} similarities
230
258
  */
231
259
  const getSimilarities = nodes => {
@@ -297,6 +325,11 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
297
325
  if (initialNodes.length > 0) {
298
326
  const initialGroup = new Group(initialNodes, getSimilarities(initialNodes));
299
327
 
328
+ /**
329
+ * @param {Group<T>} group group
330
+ * @param {Record<string, number>} consideredSize size of the group to consider
331
+ * @returns {boolean} true, if the group was modified
332
+ */
300
333
  const removeProblematicNodes = (group, consideredSize = group.size) => {
301
334
  const problemTypes = getTooSmallTypes(consideredSize, minSize);
302
335
  if (problemTypes.size > 0) {
@@ -347,7 +380,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
347
380
  const queue = [initialGroup];
348
381
 
349
382
  while (queue.length) {
350
- const group = queue.pop();
383
+ const group = /** @type {Group<T>} */ (queue.pop());
351
384
  // only groups bigger than maxSize need to be splitted
352
385
  if (!isTooBig(group.size, maxSize)) {
353
386
  result.push(group);
@@ -428,7 +461,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
428
461
  // rightSize ^^^^^^^^^^^^^^^
429
462
 
430
463
  while (pos <= right + 1) {
431
- const similarity = group.similarities[pos - 1];
464
+ const similarity = /** @type {number[]} */ (group.similarities)[
465
+ pos - 1
466
+ ];
432
467
  if (
433
468
  similarity < bestSimilarity &&
434
469
  !isTooSmall(leftSize, minSize) &&
@@ -458,7 +493,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
458
493
  /** @type {number[]} */
459
494
  const rightSimilarities = [];
460
495
  for (let i = right + 2; i < group.nodes.length; i++) {
461
- rightSimilarities.push(group.similarities[i - 1]);
496
+ rightSimilarities.push(
497
+ /** @type {number[]} */ (group.similarities)[i - 1]
498
+ );
462
499
  rightNodes.push(group.nodes[i]);
463
500
  }
464
501
  queue.push(new Group(rightNodes, rightSimilarities));
@@ -467,7 +504,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
467
504
  /** @type {number[]} */
468
505
  const leftSimilarities = [];
469
506
  for (let i = 1; i < left; i++) {
470
- leftSimilarities.push(group.similarities[i - 1]);
507
+ leftSimilarities.push(
508
+ /** @type {number[]} */ (group.similarities)[i - 1]
509
+ );
471
510
  leftNodes.push(group.nodes[i]);
472
511
  }
473
512
  queue.push(new Group(leftNodes, leftSimilarities));
@@ -109,7 +109,9 @@ module.exports = (items, getDependencies) => {
109
109
  // Are there still edges unprocessed in the current node?
110
110
  if (topOfStack.openEdges.length > 0) {
111
111
  // Process one dependency
112
- const dependency = topOfStack.openEdges.pop();
112
+ const dependency =
113
+ /** @type {Node<T>} */
114
+ (topOfStack.openEdges.pop());
113
115
  switch (dependency.marker) {
114
116
  case NO_MARKER:
115
117
  // dependency has not be visited yet
@@ -169,7 +171,7 @@ module.exports = (items, getDependencies) => {
169
171
  // so it's not really a root cycle
170
172
  // remove the cycle from the root cycles
171
173
  // and convert it to a normal node
172
- rootCycles.delete(dependency.cycle);
174
+ rootCycles.delete(/** @type {Cycle<T>} */ (dependency.cycle));
173
175
  dependency.marker = DONE_MARKER;
174
176
  break;
175
177
  // DONE_MARKER: nothing to do, don't recurse into dependencies
@@ -13,18 +13,18 @@
13
13
  */
14
14
  const memoize = fn => {
15
15
  let cache = false;
16
- /** @type {T} */
16
+ /** @type {T | undefined} */
17
17
  let result = undefined;
18
18
  return () => {
19
19
  if (cache) {
20
- return result;
20
+ return /** @type {T} */ (result);
21
21
  } else {
22
22
  result = fn();
23
23
  cache = true;
24
24
  // Allow to clean up memory for fn
25
25
  // and all dependent resources
26
26
  fn = undefined;
27
- return result;
27
+ return /** @type {T} */ (result);
28
28
  }
29
29
  };
30
30
  };
@@ -21,6 +21,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
21
21
  let finished = false;
22
22
  let processScheduled = true;
23
23
 
24
+ /**
25
+ * @param {T} item item
26
+ */
24
27
  const push = item => {
25
28
  queue.push(item);
26
29
  if (!processScheduled && processing < concurrency) {
@@ -29,6 +32,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
29
32
  }
30
33
  };
31
34
 
35
+ /**
36
+ * @param {E | null | undefined} err error
37
+ */
32
38
  const processorCallback = err => {
33
39
  processing--;
34
40
  if (err && !finished) {
@@ -46,7 +52,7 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
46
52
  if (finished) return;
47
53
  while (processing < concurrency && queue.length > 0) {
48
54
  processing++;
49
- const item = queue.pop();
55
+ const item = /** @type {T} */ (queue.pop());
50
56
  processor(item, push, processorCallback);
51
57
  }
52
58
  processScheduled = false;
@@ -26,7 +26,7 @@ const {
26
26
  /** @typedef {import("./serialization").ObjectDeserializerContext} ObjectDeserializerContext */
27
27
  /** @typedef {import("./serialization").ObjectSerializerContext} ObjectSerializerContext */
28
28
 
29
- /** @typedef {ObjectSerializerContext & { writeLazy?: (any) => void }} WebpackObjectSerializerContext */
29
+ /** @typedef {ObjectSerializerContext & { writeLazy?: (value: any) => void }} WebpackObjectSerializerContext */
30
30
 
31
31
  const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer";
32
32
 
@@ -53,7 +53,7 @@ exports.getEntryRuntime = (compilation, name, options) => {
53
53
 
54
54
  /**
55
55
  * @param {RuntimeSpec} runtime runtime
56
- * @param {function(string): void} fn functor
56
+ * @param {function(string | undefined): void} fn functor
57
57
  * @param {boolean} deterministicOrder enforce a deterministic order
58
58
  * @returns {void}
59
59
  */
@@ -70,6 +70,11 @@ exports.forEachRuntime = (runtime, fn, deterministicOrder = false) => {
70
70
  }
71
71
  };
72
72
 
73
+ /**
74
+ * @template T
75
+ * @param {SortableSet<T>} set set
76
+ * @returns {string} runtime key
77
+ */
73
78
  const getRuntimesKey = set => {
74
79
  set.sort();
75
80
  return Array.from(set).join("\n");
@@ -98,6 +103,11 @@ const keyToRuntime = key => {
98
103
  };
99
104
  exports.keyToRuntime = keyToRuntime;
100
105
 
106
+ /**
107
+ * @template T
108
+ * @param {SortableSet<T>} set set
109
+ * @returns {string} runtime string
110
+ */
101
111
  const getRuntimesString = set => {
102
112
  set.sort();
103
113
  return Array.from(set).join("+");
@@ -415,6 +425,11 @@ exports.filterRuntime = (runtime, filter) => {
415
425
  return result;
416
426
  };
417
427
 
428
+ /**
429
+ * @template T
430
+ * @typedef {Map<string, T>} RuntimeSpecMapInnerMap
431
+ * */
432
+
418
433
  /**
419
434
  * @template T
420
435
  */
@@ -426,15 +441,15 @@ class RuntimeSpecMap {
426
441
  this._mode = clone ? clone._mode : 0; // 0 = empty, 1 = single entry, 2 = map
427
442
  /** @type {RuntimeSpec} */
428
443
  this._singleRuntime = clone ? clone._singleRuntime : undefined;
429
- /** @type {T} */
444
+ /** @type {T | undefined} */
430
445
  this._singleValue = clone ? clone._singleValue : undefined;
431
- /** @type {Map<string, T> | undefined} */
446
+ /** @type {RuntimeSpecMapInnerMap<T> | undefined} */
432
447
  this._map = clone && clone._map ? new Map(clone._map) : undefined;
433
448
  }
434
449
 
435
450
  /**
436
451
  * @param {RuntimeSpec} runtime the runtimes
437
- * @returns {T} value
452
+ * @returns {T | undefined} value
438
453
  */
439
454
  get(runtime) {
440
455
  switch (this._mode) {
@@ -445,7 +460,9 @@ class RuntimeSpecMap {
445
460
  ? this._singleValue
446
461
  : undefined;
447
462
  default:
448
- return this._map.get(getRuntimeKey(runtime));
463
+ return /** @type {RuntimeSpecMapInnerMap<T>} */ (this._map).get(
464
+ getRuntimeKey(runtime)
465
+ );
449
466
  }
450
467
  }
451
468
 
@@ -460,10 +477,16 @@ class RuntimeSpecMap {
460
477
  case 1:
461
478
  return runtimeEqual(this._singleRuntime, runtime);
462
479
  default:
463
- return this._map.has(getRuntimeKey(runtime));
480
+ return /** @type {RuntimeSpecMapInnerMap<T>} */ (this._map).has(
481
+ getRuntimeKey(runtime)
482
+ );
464
483
  }
465
484
  }
466
485
 
486
+ /**
487
+ * @param {RuntimeSpec} runtime the runtimes
488
+ * @param {T} value the value
489
+ */
467
490
  set(runtime, value) {
468
491
  switch (this._mode) {
469
492
  case 0:
@@ -478,15 +501,24 @@ class RuntimeSpecMap {
478
501
  }
479
502
  this._mode = 2;
480
503
  this._map = new Map();
481
- this._map.set(getRuntimeKey(this._singleRuntime), this._singleValue);
504
+ this._map.set(
505
+ getRuntimeKey(this._singleRuntime),
506
+ /** @type {T} */ (this._singleValue)
507
+ );
482
508
  this._singleRuntime = undefined;
483
509
  this._singleValue = undefined;
484
510
  /* falls through */
485
511
  default:
486
- this._map.set(getRuntimeKey(runtime), value);
512
+ /** @type {RuntimeSpecMapInnerMap<T>} */
513
+ (this._map).set(getRuntimeKey(runtime), value);
487
514
  }
488
515
  }
489
516
 
517
+ /**
518
+ * @param {RuntimeSpec} runtime the runtimes
519
+ * @param {() => TODO} computer function to compute the value
520
+ * @returns {TODO} true, when the runtime was deleted
521
+ */
490
522
  provide(runtime, computer) {
491
523
  switch (this._mode) {
492
524
  case 0:
@@ -495,11 +527,14 @@ class RuntimeSpecMap {
495
527
  return (this._singleValue = computer());
496
528
  case 1: {
497
529
  if (runtimeEqual(this._singleRuntime, runtime)) {
498
- return this._singleValue;
530
+ return /** @type {T} */ (this._singleValue);
499
531
  }
500
532
  this._mode = 2;
501
533
  this._map = new Map();
502
- this._map.set(getRuntimeKey(this._singleRuntime), this._singleValue);
534
+ this._map.set(
535
+ getRuntimeKey(this._singleRuntime),
536
+ /** @type {T} */ (this._singleValue)
537
+ );
503
538
  this._singleRuntime = undefined;
504
539
  this._singleValue = undefined;
505
540
  const newValue = computer();
@@ -508,15 +543,19 @@ class RuntimeSpecMap {
508
543
  }
509
544
  default: {
510
545
  const key = getRuntimeKey(runtime);
511
- const value = this._map.get(key);
546
+ const value = /** @type {Map<string, T>} */ (this._map).get(key);
512
547
  if (value !== undefined) return value;
513
548
  const newValue = computer();
514
- this._map.set(key, newValue);
549
+ /** @type {Map<string, T>} */
550
+ (this._map).set(key, newValue);
515
551
  return newValue;
516
552
  }
517
553
  }
518
554
  }
519
555
 
556
+ /**
557
+ * @param {RuntimeSpec} runtime the runtimes
558
+ */
520
559
  delete(runtime) {
521
560
  switch (this._mode) {
522
561
  case 0:
@@ -529,10 +568,15 @@ class RuntimeSpecMap {
529
568
  }
530
569
  return;
531
570
  default:
532
- this._map.delete(getRuntimeKey(runtime));
571
+ /** @type {RuntimeSpecMapInnerMap<T>} */
572
+ (this._map).delete(getRuntimeKey(runtime));
533
573
  }
534
574
  }
535
575
 
576
+ /**
577
+ * @param {RuntimeSpec} runtime the runtimes
578
+ * @param {function(T | undefined): T} fn function to update the value
579
+ */
536
580
  update(runtime, fn) {
537
581
  switch (this._mode) {
538
582
  case 0:
@@ -546,7 +590,10 @@ class RuntimeSpecMap {
546
590
  if (newValue !== undefined) {
547
591
  this._mode = 2;
548
592
  this._map = new Map();
549
- this._map.set(getRuntimeKey(this._singleRuntime), this._singleValue);
593
+ this._map.set(
594
+ getRuntimeKey(this._singleRuntime),
595
+ /** @type {T} */ (this._singleValue)
596
+ );
550
597
  this._singleRuntime = undefined;
551
598
  this._singleValue = undefined;
552
599
  this._map.set(getRuntimeKey(runtime), newValue);
@@ -555,9 +602,11 @@ class RuntimeSpecMap {
555
602
  }
556
603
  default: {
557
604
  const key = getRuntimeKey(runtime);
558
- const oldValue = this._map.get(key);
605
+ const oldValue = /** @type {Map<string, T>} */ (this._map).get(key);
559
606
  const newValue = fn(oldValue);
560
- if (newValue !== oldValue) this._map.set(key, newValue);
607
+ if (newValue !== oldValue)
608
+ /** @type {RuntimeSpecMapInnerMap<T>} */
609
+ (this._map).set(key, newValue);
561
610
  }
562
611
  }
563
612
  }
@@ -569,7 +618,11 @@ class RuntimeSpecMap {
569
618
  case 1:
570
619
  return [this._singleRuntime];
571
620
  default:
572
- return Array.from(this._map.keys(), keyToRuntime);
621
+ return Array.from(
622
+ /** @type {RuntimeSpecMapInnerMap<T>} */
623
+ (this._map).keys(),
624
+ keyToRuntime
625
+ );
573
626
  }
574
627
  }
575
628
 
@@ -578,21 +631,24 @@ class RuntimeSpecMap {
578
631
  case 0:
579
632
  return [][Symbol.iterator]();
580
633
  case 1:
581
- return [this._singleValue][Symbol.iterator]();
634
+ return [/** @type {T} */ (this._singleValue)][Symbol.iterator]();
582
635
  default:
583
- return this._map.values();
636
+ return /** @type {Map<string, T>} */ (this._map).values();
584
637
  }
585
638
  }
586
639
 
587
640
  get size() {
588
- if (this._mode <= 1) return this._mode;
589
- return this._map.size;
641
+ if (/** @type {number} */ (this._mode) <= 1) return this._mode;
642
+ return /** @type {Map<string, T>} */ (this._map).size;
590
643
  }
591
644
  }
592
645
 
593
646
  exports.RuntimeSpecMap = RuntimeSpecMap;
594
647
 
595
648
  class RuntimeSpecSet {
649
+ /**
650
+ * @param {Iterable<RuntimeSpec>=} iterable iterable
651
+ */
596
652
  constructor(iterable) {
597
653
  /** @type {Map<string, RuntimeSpec>} */
598
654
  this._map = new Map();
@@ -603,10 +659,17 @@ class RuntimeSpecSet {
603
659
  }
604
660
  }
605
661
 
662
+ /**
663
+ * @param {RuntimeSpec} runtime runtime
664
+ */
606
665
  add(runtime) {
607
666
  this._map.set(getRuntimeKey(runtime), runtime);
608
667
  }
609
668
 
669
+ /**
670
+ * @param {RuntimeSpec} runtime runtime
671
+ * @returns {boolean} true, when the runtime exists
672
+ */
610
673
  has(runtime) {
611
674
  return this._map.has(getRuntimeKey(runtime));
612
675
  }
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
8
9
  /** @typedef {(string|number|undefined|[])[]} SemVerRange */
9
10
 
10
11
  /**
@@ -110,7 +110,7 @@ const smartGrouping = (items, groupConfigs) => {
110
110
  /** @type {(T | R)[]} */
111
111
  const results = [];
112
112
  for (;;) {
113
- /** @type {Group<T, R>} */
113
+ /** @type {Group<T, R> | undefined} */
114
114
  let bestGroup = undefined;
115
115
  let bestGroupSize = -1;
116
116
  let bestGroupItems = undefined;
@@ -119,7 +119,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
119
119
  )
120
120
  ) {
121
121
  return `${formattedError}\nDid you mean ${
122
- DID_YOU_MEAN[params.additionalProperty]
122
+ DID_YOU_MEAN[
123
+ /** @type {keyof DID_YOU_MEAN} */ (params.additionalProperty)
124
+ ]
123
125
  }?`;
124
126
  }
125
127
 
@@ -129,7 +131,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
129
131
  params.additionalProperty
130
132
  )
131
133
  ) {
132
- return `${formattedError}\n${REMOVED[params.additionalProperty]}?`;
134
+ return `${formattedError}\n${
135
+ REMOVED[/** @type {keyof REMOVED} */ (params.additionalProperty)]
136
+ }?`;
133
137
  }
134
138
 
135
139
  if (!error.dataPath) {