webpack 5.104.1 → 5.105.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/bin/webpack.js +6 -3
  2. package/lib/APIPlugin.js +85 -15
  3. package/lib/AbstractMethodError.js +1 -0
  4. package/lib/AsyncDependenciesBlock.js +13 -1
  5. package/lib/AsyncDependencyToInitialChunkError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +2 -0
  8. package/lib/CacheFacade.js +2 -2
  9. package/lib/CaseSensitiveModulesWarning.js +1 -0
  10. package/lib/Chunk.js +8 -4
  11. package/lib/ChunkGraph.js +30 -9
  12. package/lib/ChunkGroup.js +6 -3
  13. package/lib/ChunkRenderError.js +2 -0
  14. package/lib/CleanPlugin.js +4 -1
  15. package/lib/CodeGenerationError.js +7 -1
  16. package/lib/CodeGenerationResults.js +10 -3
  17. package/lib/CommentCompilationWarning.js +2 -1
  18. package/lib/Compilation.js +280 -236
  19. package/lib/Compiler.js +3 -2
  20. package/lib/ConcatenationScope.js +2 -1
  21. package/lib/ConcurrentCompilationError.js +3 -3
  22. package/lib/ContextModule.js +248 -111
  23. package/lib/ContextModuleFactory.js +14 -2
  24. package/lib/DefinePlugin.js +3 -1
  25. package/lib/DelegatedModule.js +6 -0
  26. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  27. package/lib/Dependency.js +6 -1
  28. package/lib/DependencyTemplates.js +3 -2
  29. package/lib/DllModule.js +2 -0
  30. package/lib/DllReferencePlugin.js +1 -0
  31. package/lib/DotenvPlugin.js +11 -5
  32. package/lib/DynamicEntryPlugin.js +1 -0
  33. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  34. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  35. package/lib/ExportsInfo.js +8 -4
  36. package/lib/ExternalModule.js +16 -0
  37. package/lib/FalseIIFEUmdWarning.js +1 -0
  38. package/lib/FileSystemInfo.js +49 -25
  39. package/lib/FlagDependencyExportsPlugin.js +8 -1
  40. package/lib/FlagDependencyUsagePlugin.js +9 -7
  41. package/lib/HarmonyLinkingError.js +1 -0
  42. package/lib/HookWebpackError.js +2 -0
  43. package/lib/HotModuleReplacementPlugin.js +16 -2
  44. package/lib/InitFragment.js +1 -0
  45. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  46. package/lib/LibManifestPlugin.js +1 -0
  47. package/lib/ManifestPlugin.js +4 -1
  48. package/lib/Module.js +7 -4
  49. package/lib/ModuleBuildError.js +3 -1
  50. package/lib/ModuleDependencyError.js +1 -0
  51. package/lib/ModuleDependencyWarning.js +1 -0
  52. package/lib/ModuleError.js +2 -1
  53. package/lib/ModuleFilenameHelpers.js +2 -1
  54. package/lib/ModuleGraph.js +3 -0
  55. package/lib/ModuleGraphConnection.js +10 -1
  56. package/lib/ModuleHashingError.js +2 -0
  57. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  58. package/lib/ModuleNotFoundError.js +1 -0
  59. package/lib/ModuleParseError.js +5 -1
  60. package/lib/ModuleProfile.js +1 -1
  61. package/lib/ModuleRestoreError.js +2 -0
  62. package/lib/ModuleSourceTypeConstants.js +1 -11
  63. package/lib/ModuleStoreError.js +2 -0
  64. package/lib/ModuleWarning.js +3 -1
  65. package/lib/MultiCompiler.js +11 -7
  66. package/lib/MultiWatching.js +2 -2
  67. package/lib/NoModeWarning.js +1 -0
  68. package/lib/NodeStuffInWebError.js +1 -0
  69. package/lib/NormalModule.js +26 -5
  70. package/lib/NormalModuleFactory.js +20 -4
  71. package/lib/OptionsApply.js +3 -1
  72. package/lib/ProgressPlugin.js +4 -0
  73. package/lib/RawModule.js +2 -0
  74. package/lib/RuntimeModule.js +10 -0
  75. package/lib/RuntimePlugin.js +7 -9
  76. package/lib/RuntimeTemplate.js +14 -7
  77. package/lib/SourceMapDevToolPlugin.js +30 -23
  78. package/lib/Template.js +10 -5
  79. package/lib/TemplatedPathPlugin.js +4 -2
  80. package/lib/UnhandledSchemeError.js +1 -0
  81. package/lib/UnsupportedFeatureWarning.js +1 -0
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  83. package/lib/WatchIgnorePlugin.js +1 -1
  84. package/lib/Watching.js +5 -0
  85. package/lib/WebpackError.js +4 -0
  86. package/lib/WebpackOptionsApply.js +60 -40
  87. package/lib/asset/AssetBytesGenerator.js +1 -0
  88. package/lib/asset/AssetGenerator.js +9 -3
  89. package/lib/asset/AssetModulesPlugin.js +33 -2
  90. package/lib/asset/AssetSourceGenerator.js +1 -0
  91. package/lib/asset/RawDataUrlModule.js +4 -0
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +31 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  95. package/lib/cache/PackFileCacheStrategy.js +41 -8
  96. package/lib/cache/getLazyHashedEtag.js +13 -4
  97. package/lib/cache/mergeEtags.js +3 -1
  98. package/lib/cli.js +3 -1
  99. package/lib/config/defaults.js +65 -44
  100. package/lib/config/normalization.js +96 -0
  101. package/lib/container/ContainerEntryModule.js +4 -0
  102. package/lib/container/FallbackModule.js +2 -0
  103. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  104. package/lib/container/RemoteModule.js +19 -0
  105. package/lib/css/CssGenerator.js +31 -4
  106. package/lib/css/CssModulesPlugin.js +26 -30
  107. package/lib/css/CssParser.js +12 -9
  108. package/lib/debug/ProfilingPlugin.js +1 -0
  109. package/lib/dependencies/AMDDefineDependency.js +3 -1
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  111. package/lib/dependencies/AMDPlugin.js +1 -1
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  113. package/lib/dependencies/CachedConstDependency.js +1 -0
  114. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  118. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  120. package/lib/dependencies/ConstDependency.js +1 -0
  121. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  122. package/lib/dependencies/ContextElementDependency.js +1 -0
  123. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  124. package/lib/dependencies/CssIcssExportDependency.js +5 -4
  125. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  126. package/lib/dependencies/CssUrlDependency.js +2 -3
  127. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  128. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  129. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  130. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
  131. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  133. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  134. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  135. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
  136. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  137. package/lib/dependencies/ImportDependency.js +1 -0
  138. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  139. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  140. package/lib/dependencies/ImportParserPlugin.js +7 -12
  141. package/lib/dependencies/LoaderPlugin.js +3 -0
  142. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +1 -0
  144. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  145. package/lib/dependencies/ProvidedDependency.js +1 -0
  146. package/lib/dependencies/RequireContextPlugin.js +1 -0
  147. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  148. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  149. package/lib/dependencies/WorkerDependency.js +9 -3
  150. package/lib/dependencies/WorkerPlugin.js +1 -0
  151. package/lib/dependencies/getFunctionExpression.js +3 -1
  152. package/lib/errors/BuildCycleError.js +4 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  156. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  157. package/lib/hmr/lazyCompilationBackend.js +3 -2
  158. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
  159. package/lib/ids/IdHelpers.js +10 -8
  160. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
  161. package/lib/ids/SyncModuleIdsPlugin.js +5 -1
  162. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  163. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  164. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  165. package/lib/javascript/JavascriptParser.js +47 -14
  166. package/lib/json/JsonParser.js +6 -0
  167. package/lib/library/AbstractLibraryPlugin.js +4 -1
  168. package/lib/library/AmdLibraryPlugin.js +2 -1
  169. package/lib/library/AssignLibraryPlugin.js +6 -2
  170. package/lib/library/EnableLibraryPlugin.js +1 -0
  171. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  172. package/lib/library/JsonpLibraryPlugin.js +1 -1
  173. package/lib/library/ModuleLibraryPlugin.js +130 -13
  174. package/lib/library/SystemLibraryPlugin.js +4 -1
  175. package/lib/library/UmdLibraryPlugin.js +4 -3
  176. package/lib/logging/createConsoleLogger.js +3 -0
  177. package/lib/logging/truncateArgs.js +1 -1
  178. package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
  179. package/lib/node/NodeTargetPlugin.js +1 -0
  180. package/lib/node/NodeWatchFileSystem.js +3 -0
  181. package/lib/node/nodeConsole.js +18 -1
  182. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  183. package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
  184. package/lib/optimize/ConcatenatedModule.js +33 -19
  185. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  186. package/lib/optimize/InnerGraph.js +5 -3
  187. package/lib/optimize/InnerGraphPlugin.js +25 -25
  188. package/lib/optimize/MangleExportsPlugin.js +14 -2
  189. package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
  190. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  191. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  192. package/lib/optimize/RealContentHashPlugin.js +35 -27
  193. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  194. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  195. package/lib/optimize/SplitChunksPlugin.js +14 -3
  196. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  197. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  198. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  199. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  200. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  201. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  202. package/lib/rules/RuleSetCompiler.js +2 -0
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  204. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  205. package/lib/runtime/CompatRuntimeModule.js +1 -0
  206. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  207. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  208. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  209. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  210. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  211. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
  212. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  213. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  214. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  215. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  216. package/lib/schemes/HttpUriPlugin.js +27 -7
  217. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  218. package/lib/serialization/BinaryMiddleware.js +4 -0
  219. package/lib/serialization/FileMiddleware.js +9 -4
  220. package/lib/serialization/ObjectMiddleware.js +34 -11
  221. package/lib/serialization/PlainObjectSerializer.js +2 -0
  222. package/lib/sharing/ConsumeSharedModule.js +60 -0
  223. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  224. package/lib/sharing/ProvideSharedModule.js +4 -0
  225. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  226. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  227. package/lib/sharing/utils.js +8 -6
  228. package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
  229. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  230. package/lib/stats/StatsFactory.js +2 -2
  231. package/lib/url/URLParserPlugin.js +4 -3
  232. package/lib/util/AppendOnlyStackedSet.js +57 -0
  233. package/lib/util/Hash.js +1 -0
  234. package/lib/util/IterableHelpers.js +1 -0
  235. package/lib/util/LazyBucketSortedSet.js +1 -0
  236. package/lib/util/LazySet.js +1 -0
  237. package/lib/util/ParallelismFactorCalculator.js +1 -0
  238. package/lib/util/SortableSet.js +1 -0
  239. package/lib/util/StringXor.js +1 -0
  240. package/lib/util/binarySearchBounds.js +15 -8
  241. package/lib/util/chainedImports.js +1 -1
  242. package/lib/util/cleverMerge.js +6 -1
  243. package/lib/util/comparators.js +21 -1
  244. package/lib/util/compileBooleanMatcher.js +3 -3
  245. package/lib/util/concatenate.js +3 -2
  246. package/lib/util/conventions.js +3 -2
  247. package/lib/util/deterministicGrouping.js +13 -1
  248. package/lib/util/extractSourceMap.js +12 -13
  249. package/lib/util/fs.js +15 -19
  250. package/lib/util/hash/BatchedHash.js +3 -0
  251. package/lib/util/hash/BulkUpdateHash.js +7 -1
  252. package/lib/util/hash/hash-digest.js +1 -0
  253. package/lib/util/hash/wasm-hash.js +16 -1
  254. package/lib/util/identifier.js +7 -2
  255. package/lib/util/magicComment.js +1 -1
  256. package/lib/util/propertyName.js +1 -1
  257. package/lib/util/registerExternalSerializer.js +1 -0
  258. package/lib/util/runtime.js +15 -1
  259. package/lib/util/semver.js +1 -0
  260. package/lib/util/serialization.js +2 -2
  261. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
  262. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  263. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  264. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  265. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  266. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  267. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  268. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  269. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  270. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  271. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  272. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  273. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  274. package/lib/webpack.js +13 -3
  275. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  276. package/package.json +20 -28
  277. package/schemas/WebpackOptions.check.js +1 -1
  278. package/schemas/WebpackOptions.json +71 -5
  279. package/types.d.ts +339 -93
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { getFullModuleName } = require("../ids/IdHelpers");
8
9
  const { compareRuntime } = require("./runtime");
9
10
 
10
11
  /** @typedef {import("../Chunk")} Chunk */
@@ -13,6 +14,7 @@ const { compareRuntime } = require("./runtime");
13
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
15
  /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
15
16
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
17
+ /** @typedef {import("../Compiler")} Compiler */
16
18
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
17
19
  /** @typedef {import("../Dependency")} Dependency */
18
20
  /** @typedef {import("../dependencies/HarmonyImportSideEffectDependency")} HarmonyImportSideEffectDependency */
@@ -316,6 +318,19 @@ const compareModulesByIdOrIdentifier = (chunkGraph, a, b) => {
316
318
  return compareIds(a.identifier(), b.identifier());
317
319
  };
318
320
 
321
+ /**
322
+ * Compare modules by their full name. This differs from comparing by identifier in that the values have been normalized to be relative to the compiler context.
323
+ * @param {{ context: string, root: object }} compiler the compiler, used for context and cache
324
+ * @param {Module} a module
325
+ * @param {Module} b module
326
+ * @returns {-1 | 0 | 1} compare result
327
+ */
328
+ const compareModulesByFullName = (compiler, a, b) => {
329
+ const aName = getFullModuleName(a, compiler.context, compiler.root);
330
+ const bName = getFullModuleName(b, compiler.context, compiler.root);
331
+ return compareIds(aName, bName);
332
+ };
333
+
319
334
  /**
320
335
  * @param {ChunkGraph} chunkGraph the chunk graph
321
336
  * @param {Chunk} a chunk
@@ -519,7 +534,7 @@ const sortWithSourceOrder = (
519
534
  dependencySourceOrderMap,
520
535
  onDependencyReSort
521
536
  ) => {
522
- /** @type {{dep: Dependency, main: number, sub: number}[]} */
537
+ /** @type {{ dep: Dependency, main: number, sub: number }[]} */
523
538
  const withSourceOrder = [];
524
539
  /** @type {number[]} */
525
540
  const positions = [];
@@ -590,6 +605,11 @@ module.exports.compareIterables = compareIterables;
590
605
 
591
606
  module.exports.compareLocations = compareLocations;
592
607
 
608
+ /** @type {ParameterizedComparator<Compiler, Module>} */
609
+ module.exports.compareModulesByFullName = createCachedParameterizedComparator(
610
+ compareModulesByFullName
611
+ );
612
+
593
613
  /** @type {ParameterizedComparator<ChunkGraph, Module>} */
594
614
  module.exports.compareModulesById =
595
615
  createCachedParameterizedComparator(compareModulesById);
@@ -252,10 +252,10 @@ const itemsToRegexp = (itemsArr) => {
252
252
 
253
253
  // special case for 2 items with common suffix
254
254
  if (finishedItems.length === 0 && items.size === 2) {
255
- /** @type {Iterator<string>} */
255
+ /** @type {SetIterator<string>} */
256
256
  const it = items[Symbol.iterator]();
257
- const a = it.next().value;
258
- const b = it.next().value;
257
+ const a = /** @type {string} */ (it.next().value);
258
+ const b = /** @type {string} */ (it.next().value);
259
259
  if (a.length > 0 && b.length > 0 && a.slice(-1) === b.slice(-1)) {
260
260
  return `${itemsToRegexp([a.slice(0, -1), b.slice(0, -1)])}${quoteMeta(
261
261
  a.slice(-1)
@@ -110,7 +110,7 @@ function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
110
110
 
111
111
  // Remove uncool stuff
112
112
  extraInfo = extraInfo.replace(
113
- /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
113
+ /\.+\/|(?:\/index)?\.[a-zA-Z0-9]{1,4}(?:$|\s|\?)|\s*\+\s*\d+\s*modules/g,
114
114
  ""
115
115
  );
116
116
 
@@ -199,9 +199,10 @@ const RESERVED_NAMES = new Set(
199
199
  );
200
200
 
201
201
  /** @typedef {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} ScopeInfo */
202
+ /** @typedef {Map<string, ScopeInfo>} UsedNamesInScopeInfo */
202
203
 
203
204
  /**
204
- * @param {Map<string, ScopeInfo>} usedNamesInScopeInfo used names in scope info
205
+ * @param {UsedNamesInScopeInfo} usedNamesInScopeInfo used names in scope info
205
206
  * @param {string} module module identifier
206
207
  * @param {string} id export id
207
208
  * @returns {ScopeInfo} info
@@ -20,7 +20,7 @@ const preserveCamelCase = (string) => {
20
20
  for (let i = 0; i < result.length; i++) {
21
21
  const character = result[i];
22
22
 
23
- if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
23
+ if (isLastCharLower && /\p{Lu}/u.test(character)) {
24
24
  result = `${result.slice(0, i)}-${result.slice(i)}`;
25
25
  isLastCharLower = false;
26
26
  isLastLastCharUpper = isLastCharUpper;
@@ -29,7 +29,7 @@ const preserveCamelCase = (string) => {
29
29
  } else if (
30
30
  isLastCharUpper &&
31
31
  isLastLastCharUpper &&
32
- /[\p{Ll}]/u.test(character)
32
+ /\p{Ll}/u.test(character)
33
33
  ) {
34
34
  result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
35
35
  isLastLastCharUpper = isLastCharUpper;
@@ -84,6 +84,7 @@ module.exports.camelCase = (input) => {
84
84
  * @returns {string[]} results
85
85
  */
86
86
  module.exports.cssExportConvention = (input, convention) => {
87
+ /** @type {Set<string>} */
87
88
  const set = new Set();
88
89
  if (typeof convention === "function") {
89
90
  set.add(convention(input));
@@ -100,6 +100,7 @@ const subtractSizeFrom = (total, size) => {
100
100
  * @returns {Sizes} total size
101
101
  */
102
102
  const sumSize = (nodes) => {
103
+ /** @type {Sizes} */
103
104
  const sum = Object.create(null);
104
105
  for (const node of nodes) {
105
106
  addSizeTo(sum, node.size);
@@ -145,7 +146,7 @@ const isTooSmall = (size, minSize) => {
145
146
  * @returns {Types} set of types that are too small
146
147
  */
147
148
  const getTooSmallTypes = (size, minSize) => {
148
- /** @typedef {Types} */
149
+ /** @type {Types} */
149
150
  const types = new Set();
150
151
  for (const key of Object.keys(size)) {
151
152
  const s = size[key];
@@ -223,9 +224,13 @@ class Group {
223
224
  * @returns {Node<T>[] | undefined} removed nodes
224
225
  */
225
226
  popNodes(filter) {
227
+ /** @type {Node<T>[]} */
226
228
  const newNodes = [];
229
+ /** @type {Similarities} */
227
230
  const newSimilarities = [];
231
+ /** @type {Node<T>[]} */
228
232
  const resultNodes = [];
233
+ /** @type {undefined | Node<T>} */
229
234
  let lastNode;
230
235
  for (let i = 0; i < this.nodes.length; i++) {
231
236
  const node = this.nodes[i];
@@ -260,6 +265,7 @@ const getSimilarities = (nodes) => {
260
265
  // calculate similarities between lexically adjacent nodes
261
266
  /** @type {Similarities} */
262
267
  const similarities = [];
268
+ /** @type {undefined | Node<T>} */
263
269
  let last;
264
270
  for (const node of nodes) {
265
271
  if (last !== undefined) {
@@ -399,6 +405,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
399
405
  // going minSize from left and right
400
406
  // at least one node need to be included otherwise we get stuck
401
407
  let left = 1;
408
+ /** @type {Sizes} */
402
409
  const leftSize = Object.create(null);
403
410
  addSizeTo(leftSize, group.nodes[0].size);
404
411
  while (left < group.nodes.length && isTooSmall(leftSize, minSize)) {
@@ -406,6 +413,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
406
413
  left++;
407
414
  }
408
415
  let right = group.nodes.length - 2;
416
+ /** @type {Sizes} */
409
417
  const rightSize = Object.create(null);
410
418
  addSizeTo(rightSize, group.nodes[group.nodes.length - 1].size);
411
419
  while (right >= 0 && isTooSmall(rightSize, minSize)) {
@@ -425,6 +433,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
425
433
 
426
434
  if (left - 1 > right) {
427
435
  // We try to remove some problematic nodes to "fix" that
436
+ /** @type {Sizes} */
428
437
  let prevSize;
429
438
  if (right < group.nodes.length - left) {
430
439
  subtractSizeFrom(rightSize, group.nodes[right + 1].size);
@@ -490,6 +499,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
490
499
 
491
500
  // create two new groups for left and right area
492
501
  // and queue them up
502
+ /** @type {Node<T>[]} */
493
503
  const rightNodes = [group.nodes[right + 1]];
494
504
  /** @type {Similarities} */
495
505
  const rightSimilarities = [];
@@ -501,6 +511,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
501
511
  }
502
512
  queue.push(new Group(rightNodes, rightSimilarities));
503
513
 
514
+ /** @type {Node<T>[]} */
504
515
  const leftNodes = [group.nodes[0]];
505
516
  /** @type {Similarities} */
506
517
  const leftSimilarities = [];
@@ -523,6 +534,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
523
534
  });
524
535
 
525
536
  // give every group a name
537
+ /** @type {Set<string>} */
526
538
  const usedNames = new Set();
527
539
  for (let i = 0; i < result.length; i++) {
528
540
  const group = result[i];
@@ -10,16 +10,10 @@ const urlUtils = require("url");
10
10
  const { isAbsolute, join } = require("./fs");
11
11
 
12
12
  /** @typedef {import("./fs").InputFileSystem} InputFileSystem */
13
-
14
- /**
15
- * @typedef {(input: string | Buffer<ArrayBufferLike>, resourcePath: string, fs: InputFileSystem) => Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[]}>} SourceMapExtractorFunction
16
- */
17
-
13
+ /** @typedef {string | Buffer<ArrayBufferLike>} StringOrBuffer */
14
+ /** @typedef {(input: StringOrBuffer, resourcePath: string, fs: InputFileSystem) => Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[] }>} SourceMapExtractorFunction */
18
15
  /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
19
-
20
- /**
21
- * @typedef {(resourcePath: string) => Promise<string | Buffer<ArrayBufferLike>>} ReadResource
22
- */
16
+ /** @typedef {(resourcePath: string) => Promise<StringOrBuffer>} ReadResource */
23
17
 
24
18
  /**
25
19
  * @typedef {object} SourceMappingURL
@@ -52,6 +46,7 @@ const sourceMappingURLRegex = new RegExp(
52
46
  */
53
47
  function getSourceMappingURL(code) {
54
48
  const lines = code.split(/^/m);
49
+ /** @type {RegExpMatchArray | null | undefined} */
55
50
  let match;
56
51
 
57
52
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -104,13 +99,14 @@ function isURL(value) {
104
99
  * @param {ReadResource} readResource read resource function
105
100
  * @param {string[]} possibleRequests array of possible file paths
106
101
  * @param {string} errorsAccumulator accumulated error messages
107
- * @returns {Promise<{path: string, data?: string}>} source content promise
102
+ * @returns {Promise<{ path: string, data?: string }>} source content promise
108
103
  */
109
104
  async function fetchPathsFromURL(
110
105
  readResource,
111
106
  possibleRequests,
112
107
  errorsAccumulator = ""
113
108
  ) {
109
+ /** @type {StringOrBuffer} */
114
110
  let result;
115
111
 
116
112
  try {
@@ -146,7 +142,7 @@ async function fetchPathsFromURL(
146
142
  * @param {string} url source URL
147
143
  * @param {string=} sourceRoot source root directory
148
144
  * @param {boolean=} skipReading whether to skip reading file content
149
- * @returns {Promise<{sourceURL: string, sourceContent?: string | Buffer<ArrayBufferLike>}>} source content promise
145
+ * @returns {Promise<{ sourceURL: string, sourceContent?: StringOrBuffer }>} source content promise
150
146
  */
151
147
  async function fetchFromURL(
152
148
  readResource,
@@ -181,9 +177,11 @@ async function fetchFromURL(
181
177
  if (isAbsolute(url)) {
182
178
  let sourceURL = path.normalize(url);
183
179
 
180
+ /** @type {undefined | StringOrBuffer} */
184
181
  let sourceContent;
185
182
 
186
183
  if (!skipReading) {
184
+ /** @type {string[]} */
187
185
  const possibleRequests = [sourceURL];
188
186
 
189
187
  if (url.startsWith("/")) {
@@ -203,6 +201,7 @@ async function fetchFromURL(
203
201
 
204
202
  // 4. Relative path
205
203
  const sourceURL = getAbsolutePath(context, url, sourceRoot || "");
204
+ /** @type {undefined | StringOrBuffer} */
206
205
  let sourceContent;
207
206
 
208
207
  if (!skipReading) {
@@ -214,10 +213,10 @@ async function fetchFromURL(
214
213
 
215
214
  /**
216
215
  * Extract source map from code content
217
- * @param {string | Buffer<ArrayBufferLike>} stringOrBuffer The input code content as string or buffer
216
+ * @param {StringOrBuffer} stringOrBuffer The input code content as string or buffer
218
217
  * @param {string} resourcePath The path to the resource file
219
218
  * @param {ReadResource} readResource The read resource function
220
- * @returns {Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined}>} Promise resolving to extracted source map information
219
+ * @returns {Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined }>} Promise resolving to extracted source map information
221
220
  */
222
221
  async function extractSourceMap(stringOrBuffer, resourcePath, readResource) {
223
222
  const input =
package/lib/util/fs.js CHANGED
@@ -8,7 +8,9 @@
8
8
  const path = require("path");
9
9
 
10
10
  /** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
11
- /** @typedef {import("../FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
11
+ /** @typedef {import("watchpack").Entry} Entry */
12
+ /** @typedef {import("watchpack").OnlySafeTimeEntry} OnlySafeTimeEntry */
13
+ /** @typedef {import("watchpack").ExistenceOnlyTimeEntry} ExistenceOnlyTimeEntry */
12
14
 
13
15
  /**
14
16
  * @template T
@@ -83,7 +85,7 @@ const path = require("path");
83
85
  /** @typedef {(err: NodeJS.ErrnoException | null, result?: number) => void} NumberCallback */
84
86
  /** @typedef {(err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void} ReadJsonCallback */
85
87
 
86
- /** @typedef {Map<string, FileSystemInfoEntry | "ignore">} TimeInfoEntries */
88
+ /** @typedef {Map<string, Entry | OnlySafeTimeEntry | ExistenceOnlyTimeEntry | null | "ignore">} TimeInfoEntries */
87
89
 
88
90
  /** @typedef {Set<string>} Changes */
89
91
  /** @typedef {Set<string>} Removals */
@@ -201,7 +203,7 @@ const path = require("path");
201
203
 
202
204
  /**
203
205
  * @typedef {{
204
- * (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined; } | BufferEncoding | null): string[],
206
+ * (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | null): string[],
205
207
  * (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer"): Buffer[],
206
208
  * (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[],
207
209
  * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[],
@@ -225,8 +227,8 @@ const path = require("path");
225
227
  * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
226
228
  * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
227
229
  * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
228
- * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
229
- * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
230
+ * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
231
+ * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
230
232
  * }} StatSync
231
233
  */
232
234
 
@@ -246,8 +248,8 @@ const path = require("path");
246
248
  * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
247
249
  * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
248
250
  * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
249
- * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
250
- * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
251
+ * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
252
+ * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
251
253
  * }} LStatSync
252
254
  */
253
255
 
@@ -256,7 +258,7 @@ const path = require("path");
256
258
  * (path: PathLike, options: EncodingOption, callback: StringCallback): void,
257
259
  * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void,
258
260
  * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void,
259
- * (path: PathLike, callback: StringCallback): void;
261
+ * (path: PathLike, callback: StringCallback): void,
260
262
  * }} RealPath
261
263
  */
262
264
 
@@ -324,21 +326,14 @@ const path = require("path");
324
326
  /**
325
327
  * @typedef {{
326
328
  * (file: PathLike, options: MakeDirectoryOptions & { recursive: true }, callback: StringCallback): void,
327
- * (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined; }) | null | undefined, callback: NoParamCallback): void,
329
+ * (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined }) | null | undefined, callback: NoParamCallback): void,
328
330
  * (file: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: StringCallback): void,
329
331
  * (file: PathLike, callback: NoParamCallback): void,
330
332
  * }} Mkdir
331
333
  */
332
334
 
333
335
  /**
334
- * @typedef {{ maxRetries?: number | undefined, recursive?: boolean | undefined, retryDelay?: number | undefined }} RmDirOptions
335
- */
336
-
337
- /**
338
- * @typedef {{
339
- * (file: PathLike, callback: NoParamCallback): void,
340
- * (file: PathLike, options: RmDirOptions, callback: NoParamCallback): void,
341
- * }} Rmdir
336
+ * @typedef {{ (file: PathLike, callback: NoParamCallback): void }} Rmdir
342
337
  */
343
338
 
344
339
  /**
@@ -405,7 +400,7 @@ const path = require("path");
405
400
  */
406
401
 
407
402
  /**
408
- * @typedef {FSImplementation & { write: (...args: EXPECTED_ANY[]) => EXPECTED_ANY; close?: (...args: EXPECTED_ANY[]) => EXPECTED_ANY }} CreateWriteStreamFSImplementation
403
+ * @typedef {FSImplementation & { write: (...args: EXPECTED_ANY[]) => EXPECTED_ANY, close?: (...args: EXPECTED_ANY[]) => EXPECTED_ANY }} CreateWriteStreamFSImplementation
409
404
  */
410
405
 
411
406
  /**
@@ -422,7 +417,7 @@ const path = require("path");
422
417
 
423
418
  /**
424
419
  * @typedef {{
425
- * (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void,
420
+ * (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void,
426
421
  * (file: PathLike, flags: OpenMode | undefined, callback: NumberCallback): void,
427
422
  * (file: PathLike, callback: NumberCallback): void,
428
423
  * }} Open
@@ -613,6 +608,7 @@ const readJson = (fs, p, callback) => {
613
608
  }
614
609
  fs.readFile(p, (err, buf) => {
615
610
  if (err) return callback(err);
611
+ /** @type {JsonObject} */
616
612
  let data;
617
613
  try {
618
614
  data = JSON.parse(/** @type {Buffer} */ (buf).toString("utf8"));
@@ -17,8 +17,11 @@ class BatchedHash extends Hash {
17
17
  */
18
18
  constructor(hash) {
19
19
  super();
20
+ /** @type {undefined | string} */
20
21
  this.string = undefined;
22
+ /** @type {undefined | Encoding} */
21
23
  this.encoding = undefined;
24
+ /** @type {Hash} */
22
25
  this.hash = hash;
23
26
  }
24
27
 
@@ -15,7 +15,7 @@ const BULK_SIZE = 3;
15
15
 
16
16
  // We are using an object instead of a Map as this will stay static during the runtime
17
17
  // so access to it can be optimized by v8
18
- /** @type {{[key: string]: Map<string, string>}} */
18
+ /** @type {{ [key: string]: Map<string, string> }} */
19
19
  const digestCaches = {};
20
20
 
21
21
  class BulkUpdateHash extends Hash {
@@ -25,12 +25,17 @@ class BulkUpdateHash extends Hash {
25
25
  */
26
26
  constructor(hashOrFactory, hashKey) {
27
27
  super();
28
+ /** @type {undefined | string} */
28
29
  this.hashKey = hashKey;
29
30
  if (typeof hashOrFactory === "function") {
31
+ /** @type {undefined | HashFactory} */
30
32
  this.hashFactory = hashOrFactory;
33
+ /** @type {undefined | Hash} */
31
34
  this.hash = undefined;
32
35
  } else {
36
+ /** @type {undefined | HashFactory} */
33
37
  this.hashFactory = undefined;
38
+ /** @type {undefined | Hash} */
34
39
  this.hash = hashOrFactory;
35
40
  }
36
41
  this.buffer = "";
@@ -103,6 +108,7 @@ class BulkUpdateHash extends Hash {
103
108
  * @returns {string | Buffer} digest
104
109
  */
105
110
  digest(encoding) {
111
+ /** @type {undefined | Map<string, string | Buffer>} */
106
112
  let digestCache;
107
113
  const buffer = this.buffer;
108
114
  if (this.hash === undefined) {
@@ -49,6 +49,7 @@ const encode = (buffer, base) => {
49
49
  value = (value << EIGHT) | BigInt(buffer[i]);
50
50
  }
51
51
  // Convert to baseX string efficiently using array
52
+ /** @type {string[]} */
52
53
  const digits = [];
53
54
  if (value === ZERO) return ENCODE_TABLE[base][0];
54
55
  while (value > ZERO) {
@@ -13,6 +13,14 @@ const Hash = require("../Hash");
13
13
  // ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
14
14
  const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
15
15
 
16
+ /**
17
+ * @typedef {object} WasmExports
18
+ * @property {WebAssembly.Memory} memory
19
+ * @property {() => void} init
20
+ * @property {(length: number) => void} update
21
+ * @property {(length: number) => void} final
22
+ */
23
+
16
24
  class WasmHash extends Hash {
17
25
  /**
18
26
  * @param {WebAssembly.Instance} instance wasm instance
@@ -23,13 +31,19 @@ class WasmHash extends Hash {
23
31
  constructor(instance, instancesPool, chunkSize, digestSize) {
24
32
  super();
25
33
 
26
- const exports = /** @type {EXPECTED_ANY} */ (instance.exports);
34
+ const exports = /** @type {WasmExports} */ (instance.exports);
27
35
  exports.init();
36
+ /** @type {WasmExports} */
28
37
  this.exports = exports;
38
+ /** @type {Buffer} */
29
39
  this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
40
+ /** @type {number} */
30
41
  this.buffered = 0;
42
+ /** @type {WebAssembly.Instance[]} */
31
43
  this.instancesPool = instancesPool;
44
+ /** @type {number} */
32
45
  this.chunkSize = chunkSize;
46
+ /** @type {number} */
33
47
  this.digestSize = digestSize;
34
48
  }
35
49
 
@@ -85,6 +99,7 @@ class WasmHash extends Hash {
85
99
  */
86
100
  _updateWithShortString(data, encoding) {
87
101
  const { exports, buffered, mem, chunkSize } = this;
102
+ /** @type {number} */
88
103
  let endPos;
89
104
  if (data.length < 70) {
90
105
  // eslint-disable-next-line unicorn/text-encoding-identifier-case
@@ -6,7 +6,7 @@
6
6
 
7
7
  const path = require("path");
8
8
 
9
- const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
9
+ const WINDOWS_ABS_PATH_REGEXP = /^[a-z]:[\\/]/i;
10
10
  const SEGMENTS_SPLIT_REGEXP = /([|!])/;
11
11
  const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
12
12
 
@@ -165,7 +165,8 @@ const makeCacheable = (realFn) => {
165
165
  * @returns {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} cacheable function with context
166
166
  */
167
167
  const makeCacheableWithContext = (fn) => {
168
- /** @type {WeakMap<AssociatedObjectForCache, Map<string, Map<string, string>>>} */
168
+ /** @typedef {Map<string, Map<string, string>>} InnerCache */
169
+ /** @type {WeakMap<AssociatedObjectForCache, InnerCache>} */
169
170
  const cache = new WeakMap();
170
171
 
171
172
  /** @type {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} */
@@ -178,6 +179,7 @@ const makeCacheableWithContext = (fn) => {
178
179
  cache.set(associatedObjectForCache, innerCache);
179
180
  }
180
181
 
182
+ /** @type {undefined | string} */
181
183
  let cachedResult;
182
184
  let innerSubCache = innerCache.get(context);
183
185
  if (innerSubCache === undefined) {
@@ -196,6 +198,7 @@ const makeCacheableWithContext = (fn) => {
196
198
 
197
199
  /** @type {BindCacheForContext} */
198
200
  cachedFn.bindCache = (associatedObjectForCache) => {
201
+ /** @type {undefined | InnerCache} */
199
202
  let innerCache;
200
203
  if (associatedObjectForCache) {
201
204
  innerCache = cache.get(associatedObjectForCache);
@@ -213,6 +216,7 @@ const makeCacheableWithContext = (fn) => {
213
216
  * @returns {string} the returned relative path
214
217
  */
215
218
  const boundFn = (context, identifier) => {
219
+ /** @type {undefined | string} */
216
220
  let cachedResult;
217
221
  let innerSubCache = innerCache.get(context);
218
222
  if (innerSubCache === undefined) {
@@ -234,6 +238,7 @@ const makeCacheableWithContext = (fn) => {
234
238
 
235
239
  /** @type {BindContextCacheForContext} */
236
240
  cachedFn.bindContextCache = (context, associatedObjectForCache) => {
241
+ /** @type {undefined | Map<string, string>} */
237
242
  let innerSubCache;
238
243
  if (associatedObjectForCache) {
239
244
  let innerCache = cache.get(associatedObjectForCache);
@@ -16,7 +16,7 @@ module.exports.createMagicCommentContext = () =>
16
16
  codeGeneration: { strings: false, wasm: false }
17
17
  });
18
18
  module.exports.webpackCommentRegExp = new RegExp(
19
- /(^|\W)webpack[A-Z]{1,}[A-Za-z]{1,}:/
19
+ /(^|\W)webpack[A-Z][A-Za-z]+:/
20
20
  );
21
21
 
22
22
  // regexp to match at least one "magic comment"
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const SAFE_IDENTIFIER = /^[_a-zA-Z$][_a-zA-Z$0-9]*$/;
8
+ const SAFE_IDENTIFIER = /^[_a-z$][_a-z$0-9]*$/i;
9
9
  const RESERVED_IDENTIFIER = new Set([
10
10
  "break",
11
11
  "case",
@@ -168,6 +168,7 @@ register(
168
168
  deserialize({ read }) {
169
169
  const source = new ReplaceSource(read(), read());
170
170
  const len = read();
171
+ /** @type {number[]} */
171
172
  const startEndBuffer = [];
172
173
  for (let i = 0; i < len; i++) {
173
174
  startEndBuffer.push(read(), read());
@@ -10,7 +10,8 @@ const SortableSet = require("./SortableSet");
10
10
  /** @typedef {import("../Compilation")} Compilation */
11
11
  /** @typedef {import("../Entrypoint").EntryOptions} EntryOptions */
12
12
 
13
- /** @typedef {string | SortableSet<string> | undefined} RuntimeSpec */
13
+ /** @typedef {SortableSet<string>} RuntimeSpecSortableSet */
14
+ /** @typedef {string | RuntimeSpecSortableSet | undefined} RuntimeSpec */
14
15
  /** @typedef {RuntimeSpec | boolean} RuntimeCondition */
15
16
 
16
17
  /**
@@ -20,7 +21,9 @@ const SortableSet = require("./SortableSet");
20
21
  * @returns {RuntimeSpec} runtime
21
22
  */
22
23
  const getEntryRuntime = (compilation, name, options) => {
24
+ /** @type {EntryOptions["dependOn"]} */
23
25
  let dependOn;
26
+ /** @type {EntryOptions["runtime"]} */
24
27
  let runtime;
25
28
  if (options) {
26
29
  ({ dependOn, runtime } = options);
@@ -194,6 +197,7 @@ const mergeRuntime = (a, b) => {
194
197
  return a;
195
198
  } else if (typeof a === "string") {
196
199
  if (typeof b === "string") {
200
+ /** @type {RuntimeSpecSortableSet} */
197
201
  const set = new SortableSet();
198
202
  set.add(a);
199
203
  set.add(b);
@@ -201,16 +205,19 @@ const mergeRuntime = (a, b) => {
201
205
  } else if (b.has(a)) {
202
206
  return b;
203
207
  }
208
+ /** @type {RuntimeSpecSortableSet} */
204
209
  const set = new SortableSet(b);
205
210
  set.add(a);
206
211
  return set;
207
212
  }
208
213
  if (typeof b === "string") {
209
214
  if (a.has(b)) return a;
215
+ /** @type {RuntimeSpecSortableSet} */
210
216
  const set = new SortableSet(a);
211
217
  set.add(b);
212
218
  return set;
213
219
  }
220
+ /** @type {RuntimeSpecSortableSet} */
214
221
  const set = new SortableSet(a);
215
222
  for (const item of b) set.add(item);
216
223
  if (set.size === a.size) return a;
@@ -271,14 +278,17 @@ const mergeRuntimeOwned = (a, b) => {
271
278
  if (typeof b === "string") {
272
279
  return b;
273
280
  }
281
+ /** @type {RuntimeSpecSortableSet} */
274
282
  return new SortableSet(b);
275
283
  } else if (typeof a === "string") {
276
284
  if (typeof b === "string") {
285
+ /** @type {RuntimeSpecSortableSet} */
277
286
  const set = new SortableSet();
278
287
  set.add(a);
279
288
  set.add(b);
280
289
  return set;
281
290
  }
291
+ /** @type {RuntimeSpecSortableSet} */
282
292
  const set = new SortableSet(b);
283
293
  set.add(a);
284
294
  return set;
@@ -315,6 +325,7 @@ const intersectRuntime = (a, b) => {
315
325
  if (a.has(b)) return b;
316
326
  return;
317
327
  }
328
+ /** @type {RuntimeSpecSortableSet} */
318
329
  const set = new SortableSet();
319
330
  for (const item of b) {
320
331
  if (a.has(item)) set.add(item);
@@ -354,10 +365,12 @@ const subtractRuntime = (a, b) => {
354
365
  if (item !== b) return item;
355
366
  }
356
367
  }
368
+ /** @type {RuntimeSpecSortableSet} */
357
369
  const set = new SortableSet(a);
358
370
  set.delete(b);
359
371
  return set;
360
372
  }
373
+ /** @type {RuntimeSpecSortableSet} */
361
374
  const set = new SortableSet();
362
375
  for (const item of a) {
363
376
  if (!b.has(item)) set.add(item);
@@ -394,6 +407,7 @@ const filterRuntime = (runtime, filter) => {
394
407
  if (typeof runtime === "string") return filter(runtime);
395
408
  let some = false;
396
409
  let every = true;
410
+ /** @type {RuntimeSpec} */
397
411
  let result;
398
412
  for (const r of runtime) {
399
413
  const v = filter(r);