webpack 5.103.0 → 5.104.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 (177) hide show
  1. package/hot/dev-server.js +18 -3
  2. package/hot/emitter-event-target.js +7 -0
  3. package/hot/lazy-compilation-node.js +45 -29
  4. package/hot/lazy-compilation-universal.js +18 -0
  5. package/hot/lazy-compilation-web.js +15 -5
  6. package/hot/load-http.js +7 -0
  7. package/hot/only-dev-server.js +19 -4
  8. package/lib/APIPlugin.js +6 -0
  9. package/lib/Chunk.js +1 -1
  10. package/lib/ChunkGraph.js +9 -7
  11. package/lib/ChunkGroup.js +8 -5
  12. package/lib/CleanPlugin.js +6 -3
  13. package/lib/CodeGenerationResults.js +2 -1
  14. package/lib/CompatibilityPlugin.js +3 -0
  15. package/lib/Compilation.js +33 -19
  16. package/lib/Compiler.js +3 -3
  17. package/lib/ContextModule.js +6 -3
  18. package/lib/ContextModuleFactory.js +6 -4
  19. package/lib/DefinePlugin.js +34 -3
  20. package/lib/DelegatedModule.js +7 -4
  21. package/lib/DllModule.js +6 -3
  22. package/lib/DotenvPlugin.js +11 -6
  23. package/lib/ExportsInfo.js +5 -5
  24. package/lib/ExternalModule.js +8 -7
  25. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  26. package/lib/FileSystemInfo.js +1 -1
  27. package/lib/Generator.js +10 -7
  28. package/lib/HookWebpackError.js +33 -4
  29. package/lib/HotModuleReplacementPlugin.js +22 -0
  30. package/lib/ManifestPlugin.js +1 -1
  31. package/lib/Module.js +24 -15
  32. package/lib/ModuleBuildError.js +1 -1
  33. package/lib/ModuleError.js +1 -1
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +27 -12
  36. package/lib/ModuleGraphConnection.js +2 -2
  37. package/lib/ModuleSourceTypeConstants.js +189 -0
  38. package/lib/ModuleTypeConstants.js +1 -4
  39. package/lib/ModuleWarning.js +1 -1
  40. package/lib/NodeStuffPlugin.js +52 -42
  41. package/lib/NormalModule.js +6 -4
  42. package/lib/NormalModuleFactory.js +7 -10
  43. package/lib/Parser.js +1 -1
  44. package/lib/RawModule.js +7 -4
  45. package/lib/RuntimeModule.js +1 -1
  46. package/lib/RuntimeTemplate.js +5 -1
  47. package/lib/SizeFormatHelpers.js +1 -1
  48. package/lib/SourceMapDevToolPlugin.js +6 -1
  49. package/lib/Template.js +17 -6
  50. package/lib/TemplatedPathPlugin.js +5 -6
  51. package/lib/WebpackError.js +0 -1
  52. package/lib/WebpackOptionsApply.js +37 -9
  53. package/lib/asset/AssetBytesGenerator.js +15 -11
  54. package/lib/asset/AssetGenerator.js +30 -24
  55. package/lib/asset/AssetSourceGenerator.js +15 -11
  56. package/lib/asset/RawDataUrlModule.js +6 -3
  57. package/lib/buildChunkGraph.js +4 -2
  58. package/lib/cache/PackFileCacheStrategy.js +6 -5
  59. package/lib/cli.js +2 -43
  60. package/lib/config/browserslistTargetHandler.js +19 -0
  61. package/lib/config/defaults.js +128 -43
  62. package/lib/config/normalization.js +2 -2
  63. package/lib/config/target.js +5 -0
  64. package/lib/container/ContainerEntryModule.js +6 -3
  65. package/lib/container/FallbackModule.js +6 -3
  66. package/lib/container/RemoteModule.js +1 -3
  67. package/lib/css/CssGenerator.js +26 -24
  68. package/lib/css/CssLoadingRuntimeModule.js +12 -4
  69. package/lib/css/CssModulesPlugin.js +29 -74
  70. package/lib/css/CssParser.js +828 -341
  71. package/lib/css/walkCssTokens.js +33 -13
  72. package/lib/dependencies/CachedConstDependency.js +24 -10
  73. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  74. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  75. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  76. package/lib/dependencies/CssIcssExportDependency.js +242 -104
  77. package/lib/dependencies/CssIcssImportDependency.js +61 -4
  78. package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
  79. package/lib/dependencies/CssImportDependency.js +2 -1
  80. package/lib/dependencies/CssUrlDependency.js +3 -2
  81. package/lib/dependencies/DynamicExports.js +7 -7
  82. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  83. package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
  84. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
  85. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
  86. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -4
  87. package/lib/dependencies/HarmonyExports.js +4 -4
  88. package/lib/dependencies/HarmonyImportDependency.js +8 -3
  89. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  90. package/lib/dependencies/ImportMetaPlugin.js +57 -0
  91. package/lib/dependencies/ImportParserPlugin.js +2 -2
  92. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  93. package/lib/dependencies/WorkerPlugin.js +2 -2
  94. package/lib/dependencies/getFunctionExpression.js +1 -1
  95. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  96. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  97. package/lib/hmr/LazyCompilationPlugin.js +4 -3
  98. package/lib/ids/IdHelpers.js +16 -7
  99. package/lib/javascript/ChunkHelpers.js +1 -1
  100. package/lib/javascript/JavascriptGenerator.js +4 -3
  101. package/lib/javascript/JavascriptModulesPlugin.js +57 -24
  102. package/lib/javascript/JavascriptParser.js +19 -6
  103. package/lib/json/JsonGenerator.js +5 -4
  104. package/lib/json/JsonParser.js +2 -1
  105. package/lib/library/AbstractLibraryPlugin.js +1 -1
  106. package/lib/library/AmdLibraryPlugin.js +4 -1
  107. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  108. package/lib/library/ModuleLibraryPlugin.js +41 -13
  109. package/lib/library/SystemLibraryPlugin.js +4 -1
  110. package/lib/library/UmdLibraryPlugin.js +1 -1
  111. package/lib/logging/Logger.js +5 -4
  112. package/lib/logging/createConsoleLogger.js +2 -2
  113. package/lib/optimize/ConcatenatedModule.js +47 -32
  114. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  115. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  116. package/lib/optimize/SplitChunksPlugin.js +60 -46
  117. package/lib/rules/RuleSetCompiler.js +1 -1
  118. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  119. package/lib/schemes/HttpUriPlugin.js +97 -10
  120. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  121. package/lib/serialization/ObjectMiddleware.js +0 -2
  122. package/lib/serialization/SingleItemMiddleware.js +1 -1
  123. package/lib/sharing/ConsumeSharedModule.js +1 -1
  124. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  125. package/lib/sharing/ProvideSharedModule.js +1 -1
  126. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  127. package/lib/sharing/utils.js +1 -1
  128. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  129. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  130. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  131. package/lib/util/StringXor.js +1 -1
  132. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  133. package/lib/util/binarySearchBounds.js +2 -2
  134. package/lib/util/comparators.js +53 -76
  135. package/lib/util/compileBooleanMatcher.js +78 -6
  136. package/lib/util/createHash.js +20 -199
  137. package/lib/util/deprecation.js +1 -1
  138. package/lib/util/deterministicGrouping.js +6 -3
  139. package/lib/util/fs.js +75 -75
  140. package/lib/util/hash/BatchedHash.js +10 -9
  141. package/lib/util/hash/BulkUpdateHash.js +138 -0
  142. package/lib/util/hash/DebugHash.js +75 -0
  143. package/lib/util/hash/hash-digest.js +216 -0
  144. package/lib/util/identifier.js +82 -17
  145. package/lib/util/internalSerializables.js +2 -6
  146. package/lib/util/runtime.js +3 -3
  147. package/lib/util/source.js +2 -2
  148. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  149. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
  150. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  151. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
  152. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  153. package/lib/webpack.js +1 -1
  154. package/package.json +30 -25
  155. package/schemas/WebpackOptions.check.js +1 -1
  156. package/schemas/WebpackOptions.json +59 -82
  157. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  158. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  159. package/types.d.ts +225 -158
  160. package/lib/ModuleSourceTypesConstants.js +0 -117
  161. package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
  162. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
  163. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
  164. package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
  165. package/lib/util/jsonParseEvenBetterErrors.js +0 -10
  166. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  167. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  168. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  169. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  170. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  171. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  173. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  174. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  175. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  176. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  177. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -11,6 +11,79 @@
11
11
  */
12
12
  const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
13
13
 
14
+ /**
15
+ * @param {string} char character to escape for use in character class
16
+ * @returns {string} escaped character
17
+ */
18
+ const quoteMetaInCharClass = (char) => {
19
+ // In character class, only these need escaping: ] \ ^ -
20
+ if (char === "]" || char === "\\" || char === "^" || char === "-") {
21
+ return `\\${char}`;
22
+ }
23
+ return char;
24
+ };
25
+
26
+ /**
27
+ * Converts an array of single characters into an optimized character class string
28
+ * using ranges where possible. E.g., ["1","2","3","4","a"] => "1-4a"
29
+ * @param {string[]} chars array of single characters (should be sorted)
30
+ * @returns {string} optimized character class content (without the brackets)
31
+ */
32
+ const charsToCharClassContent = (chars) => {
33
+ if (chars.length === 0) return "";
34
+ if (chars.length === 1) return quoteMetaInCharClass(chars[0]);
35
+
36
+ // Sort by char code
37
+ const sorted = [...chars].sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0));
38
+
39
+ /** @type {string[]} */
40
+ const parts = [];
41
+ let rangeStart = sorted[0];
42
+ let rangeEnd = sorted[0];
43
+
44
+ for (let i = 1; i < sorted.length; i++) {
45
+ const char = sorted[i];
46
+ const prevCode = rangeEnd.charCodeAt(0);
47
+ const currCode = char.charCodeAt(0);
48
+
49
+ if (currCode === prevCode + 1) {
50
+ // Extend the range
51
+ rangeEnd = char;
52
+ } else {
53
+ // Flush the current range
54
+ parts.push(formatRange(rangeStart, rangeEnd));
55
+ rangeStart = char;
56
+ rangeEnd = char;
57
+ }
58
+ }
59
+ // Flush the last range
60
+ parts.push(formatRange(rangeStart, rangeEnd));
61
+
62
+ return parts.join("");
63
+ };
64
+
65
+ /**
66
+ * Formats a range of characters for use in a character class
67
+ * @param {string} start start character
68
+ * @param {string} end end character
69
+ * @returns {string} formatted range
70
+ */
71
+ const formatRange = (start, end) => {
72
+ const startCode = start.charCodeAt(0);
73
+ const endCode = end.charCodeAt(0);
74
+ const length = endCode - startCode + 1;
75
+
76
+ if (length === 1) {
77
+ return quoteMetaInCharClass(start);
78
+ }
79
+ if (length === 2) {
80
+ // For 2 chars, just list them (e.g., "ab" instead of "a-b")
81
+ return quoteMetaInCharClass(start) + quoteMetaInCharClass(end);
82
+ }
83
+ // For 3+ chars, use range notation
84
+ return `${quoteMetaInCharClass(start)}-${quoteMetaInCharClass(end)}`;
85
+ };
86
+
14
87
  /**
15
88
  * @param {string} str string
16
89
  * @returns {string} string
@@ -148,19 +221,20 @@ const itemsToRegexp = (itemsArr) => {
148
221
  }
149
222
  // special case for only single char items
150
223
  if (countOfSingleCharItems === itemsArr.length) {
151
- return `[${quoteMeta(itemsArr.sort().join(""))}]`;
224
+ return `[${charsToCharClassContent(itemsArr)}]`;
152
225
  }
153
226
  /** @type {Set<string>} */
154
227
  const items = new Set(itemsArr.sort());
155
228
  if (countOfSingleCharItems > 2) {
156
- let singleCharItems = "";
229
+ /** @type {string[]} */
230
+ const singleCharItems = [];
157
231
  for (const item of items) {
158
232
  if (item.length === 1) {
159
- singleCharItems += item;
233
+ singleCharItems.push(item);
160
234
  items.delete(item);
161
235
  }
162
236
  }
163
- finishedItems.push(`[${quoteMeta(singleCharItems)}]`);
237
+ finishedItems.push(`[${charsToCharClassContent(singleCharItems)}]`);
164
238
  }
165
239
 
166
240
  // special case for 2 items with common prefix/suffix
@@ -227,8 +301,6 @@ const itemsToRegexp = (itemsArr) => {
227
301
  );
228
302
  }
229
303
 
230
- // TODO further optimize regexp, i. e.
231
- // use ranges: (1|2|3|4|a) => [1-4a]
232
304
  /** @type {string[]} */
233
305
  const conditional = [...finishedItems, ...Array.from(items, quoteMeta)];
234
306
  if (conditional.length === 1) return conditional[0];
@@ -5,212 +5,21 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const Hash = require("./Hash");
9
-
10
- /** @typedef {import("../../declarations/WebpackOptions").HashDigest} Encoding */
8
+ /** @typedef {import("./Hash")} Hash */
11
9
  /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
12
10
 
13
- const BULK_SIZE = 3;
14
-
15
- // We are using an object instead of a Map as this will stay static during the runtime
16
- // so access to it can be optimized by v8
17
- /** @type {{[key: string]: Map<string, string>}} */
18
- const digestCaches = {};
19
-
20
- /** @typedef {() => Hash} HashFactory */
21
-
22
- class BulkUpdateDecorator extends Hash {
23
- /**
24
- * @param {Hash | HashFactory} hashOrFactory function to create a hash
25
- * @param {string=} hashKey key for caching
26
- */
27
- constructor(hashOrFactory, hashKey) {
28
- super();
29
- this.hashKey = hashKey;
30
- if (typeof hashOrFactory === "function") {
31
- this.hashFactory = hashOrFactory;
32
- this.hash = undefined;
33
- } else {
34
- this.hashFactory = undefined;
35
- this.hash = hashOrFactory;
36
- }
37
- this.buffer = "";
38
- }
39
-
40
- /**
41
- * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
42
- * @overload
43
- * @param {string | Buffer} data data
44
- * @returns {Hash} updated hash
45
- */
46
- /**
47
- * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
48
- * @overload
49
- * @param {string} data data
50
- * @param {Encoding} inputEncoding data encoding
51
- * @returns {Hash} updated hash
52
- */
53
- /**
54
- * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
55
- * @param {string | Buffer} data data
56
- * @param {Encoding=} inputEncoding data encoding
57
- * @returns {Hash} updated hash
58
- */
59
- update(data, inputEncoding) {
60
- if (
61
- inputEncoding !== undefined ||
62
- typeof data !== "string" ||
63
- data.length > BULK_SIZE
64
- ) {
65
- if (this.hash === undefined) {
66
- this.hash = /** @type {HashFactory} */ (this.hashFactory)();
67
- }
68
- if (this.buffer.length > 0) {
69
- this.hash.update(this.buffer);
70
- this.buffer = "";
71
- }
72
- if (typeof data === "string" && inputEncoding) {
73
- this.hash.update(data, inputEncoding);
74
- } else {
75
- this.hash.update(data);
76
- }
77
- } else {
78
- this.buffer += data;
79
- if (this.buffer.length > BULK_SIZE) {
80
- if (this.hash === undefined) {
81
- this.hash = /** @type {HashFactory} */ (this.hashFactory)();
82
- }
83
- this.hash.update(this.buffer);
84
- this.buffer = "";
85
- }
86
- }
87
- return this;
88
- }
89
-
90
- /**
91
- * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
92
- * @overload
93
- * @returns {Buffer} digest
94
- */
95
- /**
96
- * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
97
- * @overload
98
- * @param {Encoding} encoding encoding of the return value
99
- * @returns {string} digest
100
- */
101
- /**
102
- * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
103
- * @param {Encoding=} encoding encoding of the return value
104
- * @returns {string | Buffer} digest
105
- */
106
- digest(encoding) {
107
- let digestCache;
108
- const buffer = this.buffer;
109
- if (this.hash === undefined) {
110
- // short data for hash, we can use caching
111
- const cacheKey = `${this.hashKey}-${encoding}`;
112
- digestCache = digestCaches[cacheKey];
113
- if (digestCache === undefined) {
114
- digestCache = digestCaches[cacheKey] = new Map();
115
- }
116
- const cacheEntry = digestCache.get(buffer);
117
- if (cacheEntry !== undefined) return cacheEntry;
118
- this.hash = /** @type {HashFactory} */ (this.hashFactory)();
119
- }
120
- if (buffer.length > 0) {
121
- this.hash.update(buffer);
122
- }
123
- if (!encoding) {
124
- const result = this.hash.digest();
125
- if (digestCache !== undefined) {
126
- digestCache.set(buffer, result);
127
- }
128
- return result;
129
- }
130
- const digestResult = this.hash.digest(encoding);
131
- // Compatibility with the old hash library
132
- const result =
133
- typeof digestResult === "string"
134
- ? digestResult
135
- : /** @type {NodeJS.TypedArray} */ (digestResult).toString();
136
- if (digestCache !== undefined) {
137
- digestCache.set(buffer, result);
138
- }
139
- return result;
140
- }
141
- }
142
-
143
- /* istanbul ignore next */
144
- class DebugHash extends Hash {
145
- constructor() {
146
- super();
147
- this.string = "";
148
- }
149
-
150
- /**
151
- * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
152
- * @overload
153
- * @param {string | Buffer} data data
154
- * @returns {Hash} updated hash
155
- */
156
- /**
157
- * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
158
- * @overload
159
- * @param {string} data data
160
- * @param {Encoding} inputEncoding data encoding
161
- * @returns {Hash} updated hash
162
- */
163
- /**
164
- * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
165
- * @param {string | Buffer} data data
166
- * @param {Encoding=} inputEncoding data encoding
167
- * @returns {Hash} updated hash
168
- */
169
- update(data, inputEncoding) {
170
- if (typeof data !== "string") data = data.toString("utf8");
171
- const prefix = Buffer.from("@webpack-debug-digest@").toString("hex");
172
- if (data.startsWith(prefix)) {
173
- data = Buffer.from(data.slice(prefix.length), "hex").toString();
174
- }
175
- this.string += `[${data}](${
176
- /** @type {string} */
177
- (
178
- // eslint-disable-next-line unicorn/error-message
179
- new Error().stack
180
- ).split("\n", 3)[2]
181
- })\n`;
182
- return this;
183
- }
184
-
185
- /**
186
- * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
187
- * @overload
188
- * @returns {Buffer} digest
189
- */
190
- /**
191
- * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
192
- * @overload
193
- * @param {Encoding} encoding encoding of the return value
194
- * @returns {string} digest
195
- */
196
- /**
197
- * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
198
- * @param {Encoding=} encoding encoding of the return value
199
- * @returns {string | Buffer} digest
200
- */
201
- digest(encoding) {
202
- return Buffer.from(`@webpack-debug-digest@${this.string}`).toString("hex");
203
- }
204
- }
205
-
206
11
  /** @type {typeof import("crypto") | undefined} */
207
12
  let crypto;
208
13
  /** @type {typeof import("./hash/xxhash64") | undefined} */
209
14
  let createXXHash64;
210
15
  /** @type {typeof import("./hash/md4") | undefined} */
211
16
  let createMd4;
17
+ /** @type {typeof import("./hash/DebugHash") | undefined} */
18
+ let DebugHash;
212
19
  /** @type {typeof import("./hash/BatchedHash") | undefined} */
213
20
  let BatchedHash;
21
+ /** @type {typeof import("./hash/BulkUpdateHash") | undefined} */
22
+ let BulkUpdateHash;
214
23
 
215
24
  /**
216
25
  * Creates a hash by name or function
@@ -219,12 +28,18 @@ let BatchedHash;
219
28
  */
220
29
  module.exports = (algorithm) => {
221
30
  if (typeof algorithm === "function") {
31
+ if (BulkUpdateHash === undefined) {
32
+ BulkUpdateHash = require("./hash/BulkUpdateHash");
33
+ }
222
34
  // eslint-disable-next-line new-cap
223
- return new BulkUpdateDecorator(() => new algorithm());
35
+ return new BulkUpdateHash(() => new algorithm());
224
36
  }
225
37
  switch (algorithm) {
226
38
  // TODO add non-cryptographic algorithm here
227
39
  case "debug":
40
+ if (DebugHash === undefined) {
41
+ DebugHash = require("./hash/DebugHash");
42
+ }
228
43
  return new DebugHash();
229
44
  case "xxhash64":
230
45
  if (createXXHash64 === undefined) {
@@ -248,7 +63,10 @@ module.exports = (algorithm) => {
248
63
  )(createMd4());
249
64
  case "native-md4":
250
65
  if (crypto === undefined) crypto = require("crypto");
251
- return new BulkUpdateDecorator(
66
+ if (BulkUpdateHash === undefined) {
67
+ BulkUpdateHash = require("./hash/BulkUpdateHash");
68
+ }
69
+ return new BulkUpdateHash(
252
70
  () =>
253
71
  /** @type {Hash} */ (
254
72
  /** @type {typeof import("crypto")} */
@@ -258,7 +76,10 @@ module.exports = (algorithm) => {
258
76
  );
259
77
  default:
260
78
  if (crypto === undefined) crypto = require("crypto");
261
- return new BulkUpdateDecorator(
79
+ if (BulkUpdateHash === undefined) {
80
+ BulkUpdateHash = require("./hash/BulkUpdateHash");
81
+ }
82
+ return new BulkUpdateHash(
262
83
  () =>
263
84
  /** @type {Hash} */ (
264
85
  /** @type {typeof import("crypto")} */
@@ -194,7 +194,7 @@ module.exports.arrayToSetDeprecation = (set, name) => {
194
194
  /**
195
195
  * @template T
196
196
  * @param {string} name name
197
- * @returns {{ new <T = any>(values?: ReadonlyArray<T> | null): SetDeprecatedArray<T> }} SetDeprecatedArray
197
+ * @returns {{ new <T = EXPECTED_ANY>(values?: ReadonlyArray<T> | null): SetDeprecatedArray<T> }} SetDeprecatedArray
198
198
  */
199
199
  module.exports.createArrayToSetDeprecationSet = (name) => {
200
200
  let initialized = false;
@@ -137,12 +137,15 @@ const isTooSmall = (size, minSize) => {
137
137
  return false;
138
138
  };
139
139
 
140
+ /** @typedef {Set<string>} Types */
141
+
140
142
  /**
141
143
  * @param {Sizes} size size
142
144
  * @param {Sizes} minSize minimum size
143
- * @returns {Set<string>} set of types that are too small
145
+ * @returns {Types} set of types that are too small
144
146
  */
145
147
  const getTooSmallTypes = (size, minSize) => {
148
+ /** @typedef {Types} */
146
149
  const types = new Set();
147
150
  for (const key of Object.keys(size)) {
148
151
  const s = size[key];
@@ -156,7 +159,7 @@ const getTooSmallTypes = (size, minSize) => {
156
159
  /**
157
160
  * @template {object} T
158
161
  * @param {T} size size
159
- * @param {Set<string>} types types
162
+ * @param {Types} types types
160
163
  * @returns {number} number of matching size types
161
164
  */
162
165
  const getNumberOfMatchingSizeTypes = (size, types) => {
@@ -169,7 +172,7 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
169
172
 
170
173
  /**
171
174
  * @param {Sizes} size size
172
- * @param {Set<string>} types types
175
+ * @param {Types} types types
173
176
  * @returns {number} selective size sum
174
177
  */
175
178
  const selectiveSizeSum = (size, types) => {