webpack 5.104.1 → 5.105.4

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 (333) hide show
  1. package/README.md +2 -2
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +85 -15
  4. package/lib/AbstractMethodError.js +1 -0
  5. package/lib/AsyncDependenciesBlock.js +17 -2
  6. package/lib/AsyncDependencyToInitialChunkError.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +1 -1
  8. package/lib/BannerPlugin.js +5 -1
  9. package/lib/CacheFacade.js +2 -2
  10. package/lib/CaseSensitiveModulesWarning.js +1 -0
  11. package/lib/Chunk.js +9 -5
  12. package/lib/ChunkGraph.js +30 -9
  13. package/lib/ChunkGroup.js +6 -3
  14. package/lib/ChunkRenderError.js +9 -2
  15. package/lib/CleanPlugin.js +5 -1
  16. package/lib/CodeGenerationError.js +7 -1
  17. package/lib/CodeGenerationResults.js +10 -3
  18. package/lib/CommentCompilationWarning.js +2 -1
  19. package/lib/Compilation.js +294 -244
  20. package/lib/Compiler.js +4 -3
  21. package/lib/ConcatenationScope.js +2 -1
  22. package/lib/ConcurrentCompilationError.js +3 -3
  23. package/lib/ContextModule.js +255 -112
  24. package/lib/ContextModuleFactory.js +14 -2
  25. package/lib/DefinePlugin.js +15 -8
  26. package/lib/DelegatedModule.js +6 -0
  27. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  28. package/lib/Dependency.js +7 -2
  29. package/lib/DependencyTemplates.js +3 -2
  30. package/lib/DllModule.js +2 -0
  31. package/lib/DllReferencePlugin.js +1 -0
  32. package/lib/DotenvPlugin.js +11 -5
  33. package/lib/DynamicEntryPlugin.js +8 -1
  34. package/lib/EnvironmentNotSupportAsyncWarning.js +2 -0
  35. package/lib/EvalDevToolModulePlugin.js +3 -0
  36. package/lib/EvalSourceMapDevToolPlugin.js +25 -14
  37. package/lib/ExportsInfo.js +8 -34
  38. package/lib/ExternalModule.js +18 -2
  39. package/lib/ExternalModuleFactoryPlugin.js +9 -2
  40. package/lib/ExternalsPlugin.js +2 -1
  41. package/lib/FalseIIFEUmdWarning.js +1 -0
  42. package/lib/FileSystemInfo.js +49 -25
  43. package/lib/FlagDependencyExportsPlugin.js +8 -1
  44. package/lib/FlagDependencyUsagePlugin.js +9 -7
  45. package/lib/HarmonyLinkingError.js +1 -0
  46. package/lib/HookWebpackError.js +2 -0
  47. package/lib/HotModuleReplacementPlugin.js +16 -2
  48. package/lib/IgnoreWarningsPlugin.js +5 -2
  49. package/lib/InitFragment.js +1 -0
  50. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  51. package/lib/LibManifestPlugin.js +1 -0
  52. package/lib/ManifestPlugin.js +8 -1
  53. package/lib/Module.js +51 -8
  54. package/lib/ModuleBuildError.js +3 -1
  55. package/lib/ModuleDependencyError.js +1 -0
  56. package/lib/ModuleDependencyWarning.js +1 -0
  57. package/lib/ModuleError.js +4 -1
  58. package/lib/ModuleFilenameHelpers.js +4 -2
  59. package/lib/ModuleGraph.js +3 -0
  60. package/lib/ModuleGraphConnection.js +10 -10
  61. package/lib/ModuleHashingError.js +2 -0
  62. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  63. package/lib/ModuleNotFoundError.js +1 -0
  64. package/lib/ModuleParseError.js +5 -1
  65. package/lib/ModuleProfile.js +1 -1
  66. package/lib/ModuleRestoreError.js +2 -0
  67. package/lib/ModuleSourceTypeConstants.js +1 -11
  68. package/lib/ModuleStoreError.js +2 -0
  69. package/lib/ModuleWarning.js +3 -1
  70. package/lib/MultiCompiler.js +11 -7
  71. package/lib/MultiStats.js +5 -5
  72. package/lib/MultiWatching.js +2 -2
  73. package/lib/NoModeWarning.js +1 -0
  74. package/lib/NodeStuffInWebError.js +1 -0
  75. package/lib/NormalModule.js +28 -5
  76. package/lib/NormalModuleFactory.js +20 -4
  77. package/lib/OptionsApply.js +3 -1
  78. package/lib/ProgressPlugin.js +4 -0
  79. package/lib/RawModule.js +2 -0
  80. package/lib/RuntimeModule.js +28 -1
  81. package/lib/RuntimePlugin.js +7 -9
  82. package/lib/RuntimeTemplate.js +14 -7
  83. package/lib/SourceMapDevToolModuleOptionsPlugin.js +1 -0
  84. package/lib/SourceMapDevToolPlugin.js +40 -25
  85. package/lib/Stats.js +3 -2
  86. package/lib/Template.js +10 -5
  87. package/lib/TemplatedPathPlugin.js +4 -2
  88. package/lib/UnhandledSchemeError.js +1 -0
  89. package/lib/UnsupportedFeatureWarning.js +3 -0
  90. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  91. package/lib/WatchIgnorePlugin.js +1 -1
  92. package/lib/Watching.js +5 -0
  93. package/lib/WebpackError.js +4 -0
  94. package/lib/WebpackOptionsApply.js +74 -44
  95. package/lib/asset/AssetBytesGenerator.js +1 -0
  96. package/lib/asset/AssetGenerator.js +18 -3
  97. package/lib/asset/AssetModulesPlugin.js +48 -2
  98. package/lib/asset/AssetParser.js +4 -0
  99. package/lib/asset/AssetSourceGenerator.js +1 -0
  100. package/lib/asset/RawDataUrlModule.js +9 -1
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  102. package/lib/buildChunkGraph.js +31 -2
  103. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  104. package/lib/cache/PackFileCacheStrategy.js +41 -8
  105. package/lib/cache/getLazyHashedEtag.js +13 -4
  106. package/lib/cache/mergeEtags.js +3 -1
  107. package/lib/cli.js +3 -1
  108. package/lib/config/defaults.js +65 -44
  109. package/lib/config/normalization.js +96 -0
  110. package/lib/container/ContainerEntryDependency.js +3 -0
  111. package/lib/container/ContainerEntryModule.js +7 -0
  112. package/lib/container/ContainerExposedDependency.js +1 -0
  113. package/lib/container/FallbackDependency.js +1 -0
  114. package/lib/container/FallbackItemDependency.js +1 -0
  115. package/lib/container/FallbackModule.js +4 -0
  116. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  117. package/lib/container/ModuleFederationPlugin.js +1 -1
  118. package/lib/container/RemoteModule.js +42 -1
  119. package/lib/css/CssGenerator.js +38 -4
  120. package/lib/css/CssModulesPlugin.js +33 -30
  121. package/lib/css/CssParser.js +12 -9
  122. package/lib/debug/ProfilingPlugin.js +1 -0
  123. package/lib/dependencies/AMDDefineDependency.js +3 -1
  124. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  125. package/lib/dependencies/AMDPlugin.js +1 -1
  126. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  127. package/lib/dependencies/CachedConstDependency.js +1 -0
  128. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  129. package/lib/dependencies/CommonJsExportRequireDependency.js +5 -0
  130. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  131. package/lib/dependencies/CommonJsImportsParserPlugin.js +315 -506
  132. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  133. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  134. package/lib/dependencies/ConstDependency.js +1 -0
  135. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  136. package/lib/dependencies/ContextElementDependency.js +1 -0
  137. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  138. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  139. package/lib/dependencies/CssIcssExportDependency.js +7 -4
  140. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  141. package/lib/dependencies/CssUrlDependency.js +2 -3
  142. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  143. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  144. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  145. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
  146. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -8
  147. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  148. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  149. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  150. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  151. package/lib/dependencies/HarmonyImportDependency.js +31 -1
  152. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -49
  153. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  154. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  155. package/lib/dependencies/HarmonyModulesPlugin.js +4 -0
  156. package/lib/dependencies/ImportDependency.js +1 -0
  157. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  158. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  159. package/lib/dependencies/ImportParserPlugin.js +8 -23
  160. package/lib/dependencies/ImportPhase.js +4 -0
  161. package/lib/dependencies/LoaderPlugin.js +3 -0
  162. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  163. package/lib/dependencies/ModuleDependency.js +1 -0
  164. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  165. package/lib/dependencies/ProvidedDependency.js +1 -0
  166. package/lib/dependencies/RequireContextPlugin.js +1 -0
  167. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
  168. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  170. package/lib/dependencies/WorkerDependency.js +9 -3
  171. package/lib/dependencies/WorkerPlugin.js +1 -0
  172. package/lib/dependencies/getFunctionExpression.js +3 -1
  173. package/lib/electron/ElectronTargetPlugin.js +3 -1
  174. package/lib/errors/BuildCycleError.js +4 -1
  175. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  176. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  178. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  179. package/lib/hmr/lazyCompilationBackend.js +3 -2
  180. package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
  181. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
  182. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
  183. package/lib/ids/HashedModuleIdsPlugin.js +3 -8
  184. package/lib/ids/IdHelpers.js +10 -8
  185. package/lib/ids/NamedChunkIdsPlugin.js +7 -5
  186. package/lib/ids/NamedModuleIdsPlugin.js +1 -0
  187. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  188. package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
  189. package/lib/ids/SyncModuleIdsPlugin.js +30 -20
  190. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  191. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  192. package/lib/javascript/JavascriptModulesPlugin.js +104 -30
  193. package/lib/javascript/JavascriptParser.js +48 -15
  194. package/lib/json/JsonGenerator.js +1 -0
  195. package/lib/json/JsonParser.js +9 -2
  196. package/lib/library/AbstractLibraryPlugin.js +4 -1
  197. package/lib/library/AmdLibraryPlugin.js +2 -1
  198. package/lib/library/AssignLibraryPlugin.js +6 -2
  199. package/lib/library/EnableLibraryPlugin.js +1 -0
  200. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  201. package/lib/library/JsonpLibraryPlugin.js +1 -1
  202. package/lib/library/ModuleLibraryPlugin.js +130 -13
  203. package/lib/library/SystemLibraryPlugin.js +4 -1
  204. package/lib/library/UmdLibraryPlugin.js +4 -3
  205. package/lib/logging/Logger.js +9 -5
  206. package/lib/logging/createConsoleLogger.js +4 -0
  207. package/lib/logging/truncateArgs.js +1 -1
  208. package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
  209. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  210. package/lib/node/NodeTargetPlugin.js +10 -1
  211. package/lib/node/NodeTemplatePlugin.js +1 -0
  212. package/lib/node/NodeWatchFileSystem.js +6 -0
  213. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
  214. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  215. package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
  216. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
  217. package/lib/node/nodeConsole.js +18 -1
  218. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  219. package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
  220. package/lib/optimize/ConcatenatedModule.js +36 -19
  221. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  222. package/lib/optimize/InnerGraph.js +5 -3
  223. package/lib/optimize/InnerGraphPlugin.js +25 -25
  224. package/lib/optimize/LimitChunkCountPlugin.js +3 -2
  225. package/lib/optimize/MangleExportsPlugin.js +14 -2
  226. package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
  227. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  228. package/lib/optimize/ModuleConcatenationPlugin.js +23 -5
  229. package/lib/optimize/RealContentHashPlugin.js +37 -27
  230. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  231. package/lib/optimize/RuntimeChunkPlugin.js +3 -5
  232. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  233. package/lib/optimize/SplitChunksPlugin.js +23 -5
  234. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -2
  235. package/lib/performance/EntrypointsOverSizeLimitWarning.js +7 -2
  236. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  237. package/lib/performance/SizeLimitsPlugin.js +7 -6
  238. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
  239. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
  240. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
  241. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  242. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  243. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  244. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  245. package/lib/rules/RuleSetCompiler.js +6 -0
  246. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  247. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  248. package/lib/runtime/CompatRuntimeModule.js +1 -0
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
  251. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  252. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  253. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  254. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  255. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
  256. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  257. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  258. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  259. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  260. package/lib/runtime/ToBinaryRuntimeModule.js +14 -6
  261. package/lib/schemes/HttpUriPlugin.js +39 -20
  262. package/lib/schemes/VirtualUrlPlugin.js +28 -2
  263. package/lib/serialization/BinaryMiddleware.js +4 -0
  264. package/lib/serialization/FileMiddleware.js +9 -4
  265. package/lib/serialization/ObjectMiddleware.js +34 -11
  266. package/lib/serialization/PlainObjectSerializer.js +2 -0
  267. package/lib/sharing/ConsumeSharedModule.js +78 -1
  268. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  269. package/lib/sharing/ProvideSharedModule.js +4 -0
  270. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  272. package/lib/sharing/utils.js +8 -6
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
  274. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  275. package/lib/stats/StatsFactory.js +2 -2
  276. package/lib/url/URLParserPlugin.js +5 -3
  277. package/lib/util/AppendOnlyStackedSet.js +78 -0
  278. package/lib/util/Hash.js +1 -0
  279. package/lib/util/IterableHelpers.js +1 -0
  280. package/lib/util/LazyBucketSortedSet.js +1 -0
  281. package/lib/util/LazySet.js +1 -0
  282. package/lib/util/ParallelismFactorCalculator.js +1 -0
  283. package/lib/util/SortableSet.js +1 -0
  284. package/lib/util/StringXor.js +1 -0
  285. package/lib/util/binarySearchBounds.js +15 -8
  286. package/lib/util/chainedImports.js +1 -1
  287. package/lib/util/cleverMerge.js +6 -1
  288. package/lib/util/comparators.js +21 -1
  289. package/lib/util/compileBooleanMatcher.js +3 -3
  290. package/lib/util/concatenate.js +3 -2
  291. package/lib/util/conventions.js +3 -2
  292. package/lib/util/deterministicGrouping.js +13 -1
  293. package/lib/util/extractSourceMap.js +12 -13
  294. package/lib/util/findGraphRoots.js +79 -109
  295. package/lib/util/fs.js +15 -19
  296. package/lib/util/hash/BatchedHash.js +4 -0
  297. package/lib/util/hash/BulkUpdateHash.js +8 -1
  298. package/lib/util/hash/hash-digest.js +1 -0
  299. package/lib/util/hash/wasm-hash.js +18 -2
  300. package/lib/util/identifier.js +7 -2
  301. package/lib/util/magicComment.js +1 -1
  302. package/lib/util/propertyName.js +1 -1
  303. package/lib/util/registerExternalSerializer.js +1 -0
  304. package/lib/util/runtime.js +15 -1
  305. package/lib/util/semver.js +1 -0
  306. package/lib/util/serialization.js +2 -2
  307. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
  308. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  309. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  310. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  311. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  312. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  313. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  314. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  315. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  316. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  317. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  318. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  319. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  320. package/lib/webpack.js +16 -4
  321. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  322. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
  323. package/package.json +40 -40
  324. package/schemas/WebpackOptions.check.js +1 -1
  325. package/schemas/WebpackOptions.json +121 -55
  326. package/schemas/plugins/BannerPlugin.json +2 -2
  327. package/schemas/plugins/IgnorePlugin.json +1 -1
  328. package/schemas/plugins/ManifestPlugin.json +3 -3
  329. package/schemas/plugins/ProgressPlugin.json +1 -1
  330. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  331. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  332. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  333. package/types.d.ts +677 -230
@@ -313,6 +313,7 @@ class BinaryMiddleware extends SerializerMiddleware {
313
313
  /** @type {number[]} */
314
314
  const lengths = [];
315
315
  for (const item of serializedData) {
316
+ /** @type {undefined | number} */
316
317
  let last;
317
318
  if (typeof item === "function") {
318
319
  lengths.push(0);
@@ -490,8 +491,10 @@ class BinaryMiddleware extends SerializerMiddleware {
490
491
  }
491
492
  case "boolean": {
492
493
  let lastByte = thing === true ? 1 : 0;
494
+ /** @type {number[]} */
493
495
  const bytes = [];
494
496
  let count = 1;
497
+ /** @type {undefined | number} */
495
498
  let n;
496
499
  for (n = 1; n < 0xffffffff && i + n < data.length; n++) {
497
500
  const item = data[i + n];
@@ -541,6 +544,7 @@ class BinaryMiddleware extends SerializerMiddleware {
541
544
  }
542
545
  case "object": {
543
546
  if (thing === null) {
547
+ /** @type {number} */
544
548
  let n;
545
549
  for (n = 1; n < 0x100000104 && i + n < data.length; n++) {
546
550
  const item = data[i + n];
@@ -21,7 +21,7 @@ const { dirname, join, mkdirp } = require("../util/fs");
21
21
  const memoize = require("../util/memoize");
22
22
  const SerializerMiddleware = require("./SerializerMiddleware");
23
23
 
24
- /** @typedef {typeof import("../util/Hash")} Hash */
24
+ /** @typedef {import("../util/Hash").HashFunction} HashFunction */
25
25
  /** @typedef {import("../util/fs").IStats} IStats */
26
26
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
27
27
  /** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
@@ -49,7 +49,7 @@ const WRITE_LIMIT_CHUNK = 511 * 1024 * 1024;
49
49
 
50
50
  /**
51
51
  * @param {Buffer[]} buffers buffers
52
- * @param {string | Hash} hashFunction hash function to use
52
+ * @param {HashFunction} hashFunction hash function to use
53
53
  * @returns {string} hash
54
54
  */
55
55
  const hashForName = (buffers, hashFunction) => {
@@ -101,7 +101,7 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE
101
101
  * @param {(BufferSerializableType | LazyFunction)[]} data data to be serialized
102
102
  * @param {string | boolean} name file base name
103
103
  * @param {(name: string | false, buffers: Buffer[], size: number) => Promise<void>} writeFile writes a file
104
- * @param {string | Hash} hashFunction hash function to use
104
+ * @param {HashFunction=} hashFunction hash function to use
105
105
  * @returns {Promise<SerializeResult>} resulting file pointer and promise
106
106
  */
107
107
  const serialize = async (
@@ -336,6 +336,7 @@ const deserialize = async (middleware, name, readFile) => {
336
336
  throw new Error("Invalid file version");
337
337
  }
338
338
  const sectionCount = readUInt32LE();
339
+ /** @type {number[]} */
339
340
  const lengths = [];
340
341
  let lastLengthPositive = false;
341
342
  for (let i = 0; i < sectionCount; i++) {
@@ -433,11 +434,13 @@ const deserialize = async (middleware, name, readFile) => {
433
434
  class FileMiddleware extends SerializerMiddleware {
434
435
  /**
435
436
  * @param {IntermediateFileSystem} fs filesystem
436
- * @param {string | Hash} hashFunction hash function to use
437
+ * @param {HashFunction} hashFunction hash function to use
437
438
  */
438
439
  constructor(fs, hashFunction = DEFAULTS.HASH_FUNCTION) {
439
440
  super();
441
+ /** @type {IntermediateFileSystem} */
440
442
  this.fs = fs;
443
+ /** @type {HashFunction} */
441
444
  this._hashFunction = hashFunction;
442
445
  }
443
446
 
@@ -454,6 +457,7 @@ class FileMiddleware extends SerializerMiddleware {
454
457
 
455
458
  // It's important that we don't touch existing files during serialization
456
459
  // because serialize may read existing files (when deserializing)
460
+ /** @type {Set<string>} */
457
461
  const allWrittenFiles = new Set();
458
462
  /**
459
463
  * @param {string | false} name name
@@ -472,6 +476,7 @@ class FileMiddleware extends SerializerMiddleware {
472
476
  */
473
477
  (resolve, reject) => {
474
478
  let stream = this.fs.createWriteStream(`${file}_`);
479
+ /** @type {undefined | import("zlib").Gzip | import("zlib").BrotliCompress} */
475
480
  let compression;
476
481
  if (file.endsWith(".gz")) {
477
482
  compression = createGzip({
@@ -18,7 +18,7 @@ const SerializerMiddleware = require("./SerializerMiddleware");
18
18
  const SetObjectSerializer = require("./SetObjectSerializer");
19
19
 
20
20
  /** @typedef {import("../logging/Logger").Logger} Logger */
21
- /** @typedef {typeof import("../util/Hash")} Hash */
21
+ /** @typedef {import("../util/Hash").HashFunction} HashFunction */
22
22
  /** @typedef {import("./SerializerMiddleware").LazyOptions} LazyOptions */
23
23
  /** @typedef {import("./types").ComplexSerializableType} ComplexSerializableType */
24
24
  /** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
@@ -111,7 +111,7 @@ const setMapSize = (map, size) => {
111
111
 
112
112
  /**
113
113
  * @param {Buffer} buffer buffer
114
- * @param {string | Hash} hashFunction hash function to use
114
+ * @param {HashFunction} hashFunction hash function to use
115
115
  * @returns {string} hash
116
116
  */
117
117
  const toHash = (buffer, hashFunction) => {
@@ -207,17 +207,21 @@ const loaders = new Map();
207
207
  /** @typedef {PrimitiveSerializableType[]} SerializedType */
208
208
  /** @typedef {{ logger: Logger }} Context */
209
209
 
210
+ /** @typedef {(context: ObjectSerializerContext | ObjectDeserializerContext) => void} ExtendContext */
211
+
210
212
  /**
211
213
  * @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
212
214
  */
213
215
  class ObjectMiddleware extends SerializerMiddleware {
214
216
  /**
215
- * @param {(context: ObjectSerializerContext | ObjectDeserializerContext) => void} extendContext context extensions
216
- * @param {string | Hash} hashFunction hash function to use
217
+ * @param {ExtendContext} extendContext context extensions
218
+ * @param {HashFunction} hashFunction hash function to use
217
219
  */
218
220
  constructor(extendContext, hashFunction = DEFAULTS.HASH_FUNCTION) {
219
221
  super();
222
+ /** @type {ExtendContext} */
220
223
  this.extendContext = extendContext;
224
+ /** @type {HashFunction} */
221
225
  this._hashFunction = hashFunction;
222
226
  }
223
227
 
@@ -276,11 +280,12 @@ class ObjectMiddleware extends SerializerMiddleware {
276
280
  }
277
281
 
278
282
  /**
279
- * @param {Constructor} object for serialization
283
+ * @param {EXPECTED_ANY} object for serialization
280
284
  * @returns {SerializerConfigWithSerializer} Serializer config
281
285
  */
282
286
  static getSerializerFor(object) {
283
287
  const proto = Object.getPrototypeOf(object);
288
+ /** @type {null | Constructor} */
284
289
  let c;
285
290
  if (proto === null) {
286
291
  // Object created with Object.create(null)
@@ -295,7 +300,11 @@ class ObjectMiddleware extends SerializerMiddleware {
295
300
  }
296
301
  const config = serializers.get(c);
297
302
 
298
- if (!config) throw new Error(`No serializer registered for ${c.name}`);
303
+ if (!config) {
304
+ throw new Error(
305
+ `No serializer registered for ${/** @type {Constructor} */ (c).name}`
306
+ );
307
+ }
299
308
  if (config === NOT_SERIALIZABLE) throw NOT_SERIALIZABLE;
300
309
 
301
310
  return /** @type {SerializerConfigWithSerializer} */ (config);
@@ -345,6 +354,7 @@ class ObjectMiddleware extends SerializerMiddleware {
345
354
  const addReferenceable = (item) => {
346
355
  referenceable.set(item, currentPos++);
347
356
  };
357
+ /** @type {Map<number, Buffer | [Buffer, Buffer] | Map<string, Buffer>>} */
348
358
  let bufferDedupeMap = new Map();
349
359
  /**
350
360
  * @param {Buffer} buf buffer
@@ -366,6 +376,7 @@ class ObjectMiddleware extends SerializerMiddleware {
366
376
  return buf;
367
377
  }
368
378
  const hash = toHash(entry, this._hashFunction);
379
+ /** @type {Map<string, Buffer>} */
369
380
  const newMap = new Map();
370
381
  newMap.set(hash, entry);
371
382
  bufferDedupeMap.set(len, newMap);
@@ -384,8 +395,10 @@ class ObjectMiddleware extends SerializerMiddleware {
384
395
  entry.push(buf);
385
396
  return buf;
386
397
  }
398
+ /** @type {Map<string, Buffer>} */
387
399
  const newMap = new Map();
388
400
  const hash = toHash(buf, this._hashFunction);
401
+ /** @type {undefined | Buffer} */
389
402
  let found;
390
403
  for (const item of entry) {
391
404
  const itemHash = toHash(item, this._hashFunction);
@@ -408,7 +421,9 @@ class ObjectMiddleware extends SerializerMiddleware {
408
421
  return buf;
409
422
  };
410
423
  let currentPosTypeLookup = 0;
424
+ /** @type {Map<ComplexSerializableType, number>} */
411
425
  let objectTypeLookup = new Map();
426
+ /** @type {Set<ComplexSerializableType>} */
412
427
  const cycleStack = new Set();
413
428
  /**
414
429
  * @param {ComplexSerializableType} item item to stack
@@ -441,12 +456,18 @@ class ObjectMiddleware extends SerializerMiddleware {
441
456
  if (item.constructor === Object) {
442
457
  return `Object { ${Object.keys(item).join(", ")} }`;
443
458
  }
444
- if (item.constructor === Map) return `Map { ${item.size} items }`;
459
+ if (item.constructor === Map) {
460
+ return `Map { ${/** @type {Map<EXPECTED_ANY, EXPECTED_ANY>} */ (item).size} items }`;
461
+ }
445
462
  if (item.constructor === Array) {
446
- return `Array { ${item.length} items }`;
463
+ return `Array { ${/** @type {EXPECTED_ANY[]} */ (item).length} items }`;
464
+ }
465
+ if (item.constructor === Set) {
466
+ return `Set { ${/** @type {Set<EXPECTED_ANY>} */ (item).size} items }`;
467
+ }
468
+ if (item.constructor === RegExp) {
469
+ return /** @type {RegExp} */ (item).toString();
447
470
  }
448
- if (item.constructor === Set) return `Set { ${item.size} items }`;
449
- if (item.constructor === RegExp) return item.toString();
450
471
  return `${item.constructor.name}`;
451
472
  }
452
473
  return `Object [null prototype] { ${Object.keys(item).join(
@@ -464,7 +485,7 @@ class ObjectMiddleware extends SerializerMiddleware {
464
485
  })
465
486
  .join(" -> ");
466
487
  };
467
- /** @type {WeakSet<Error>} */
488
+ /** @type {undefined | WeakSet<Error>} */
468
489
  let hasDebugInfoAttached;
469
490
  /** @type {ObjectSerializerContext} */
470
491
  let ctx = {
@@ -723,6 +744,7 @@ class ObjectMiddleware extends SerializerMiddleware {
723
744
  );
724
745
  } else {
725
746
  const request = nextItem;
747
+ /** @type {undefined | ObjectSerializer} */
726
748
  let serializer;
727
749
 
728
750
  if (typeof request === "number") {
@@ -788,6 +810,7 @@ class ObjectMiddleware extends SerializerMiddleware {
788
810
  // As this is only for error handling, we omit creating a Map for
789
811
  // faster access to this information, as this would affect performance
790
812
  // in the good case
813
+ /** @type {undefined | [Constructor | null, SerializerConfig]} */
791
814
  let serializerEntry;
792
815
  for (const entry of serializers) {
793
816
  if (entry[1].serializer === serializer) {
@@ -20,7 +20,9 @@ const cache = new WeakMap();
20
20
  */
21
21
  class ObjectStructure {
22
22
  constructor() {
23
+ /** @type {undefined | keyof T[]} */
23
24
  this.keys = undefined;
25
+ /** @type {undefined | Map<keyof T, ObjectStructure<T>>} */
24
26
  this.children = undefined;
25
27
  }
26
28
 
@@ -8,7 +8,10 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const Module = require("../Module");
11
- const { CONSUME_SHARED_TYPES } = require("../ModuleSourceTypeConstants");
11
+ const {
12
+ CONSUME_SHARED_TYPES,
13
+ JAVASCRIPT_TYPES
14
+ } = require("../ModuleSourceTypeConstants");
12
15
  const {
13
16
  WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE
14
17
  } = require("../ModuleTypeConstants");
@@ -17,6 +20,9 @@ const makeSerializable = require("../util/makeSerializable");
17
20
  const { rangeToString, stringifyHoley } = require("../util/semver");
18
21
  const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependency");
19
22
 
23
+ /** @type {WeakMap<ModuleGraph, WeakMap<ConsumeSharedModule, Module | null>>} */
24
+ const fallbackModuleCache = new WeakMap();
25
+
20
26
  /** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
21
27
  /** @typedef {import("../Compilation")} Compilation */
22
28
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
@@ -27,7 +33,10 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
27
33
  /** @typedef {import("../Module").LibIdent} LibIdent */
28
34
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
29
35
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
36
+ /** @typedef {import("../Module").Sources} Sources */
30
37
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
38
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
39
+ /** @typedef {import("../Module").ExportsType} ExportsType */
31
40
  /** @typedef {import("../RequestShortener")} RequestShortener */
32
41
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
33
42
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -35,6 +44,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
35
44
  /** @typedef {import("../util/Hash")} Hash */
36
45
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
37
46
  /** @typedef {import("../util/semver").SemVerRange} SemVerRange */
47
+ /** @typedef {import("../Module").BasicSourceTypes} BasicSourceTypes */
38
48
 
39
49
  /**
40
50
  * @typedef {object} ConsumeOptions
@@ -153,6 +163,70 @@ class ConsumeSharedModule extends Module {
153
163
  return CONSUME_SHARED_TYPES;
154
164
  }
155
165
 
166
+ /**
167
+ * Basic source types are high-level categories like javascript, css, webassembly, etc.
168
+ * We only have built-in knowledge about the javascript basic type here; other basic types may be
169
+ * added or changed over time by generators and do not need to be handled or detected here.
170
+ *
171
+ * Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
172
+ * from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
173
+ * @returns {BasicSourceTypes} types available (do not mutate)
174
+ */
175
+ getSourceBasicTypes() {
176
+ return JAVASCRIPT_TYPES;
177
+ }
178
+
179
+ /**
180
+ * @param {ModuleGraph} moduleGraph the module graph
181
+ * @returns {Module | null} fallback module
182
+ */
183
+ _getFallbackModule(moduleGraph) {
184
+ let moduleCache = fallbackModuleCache.get(moduleGraph);
185
+ if (!moduleCache) {
186
+ moduleCache = new WeakMap();
187
+ fallbackModuleCache.set(moduleGraph, moduleCache);
188
+ }
189
+ const cached = moduleCache.get(this);
190
+ if (cached !== undefined) {
191
+ return cached;
192
+ }
193
+
194
+ /** @type {undefined | null | Module} */
195
+ let fallbackModule = null;
196
+
197
+ if (this.options.import) {
198
+ if (this.options.eager) {
199
+ const dep = this.dependencies[0];
200
+ if (dep) {
201
+ fallbackModule = moduleGraph.getModule(dep);
202
+ }
203
+ } else {
204
+ const block = this.blocks[0];
205
+ if (block && block.dependencies.length > 0) {
206
+ fallbackModule = moduleGraph.getModule(block.dependencies[0]);
207
+ }
208
+ }
209
+ }
210
+
211
+ moduleCache.set(this, fallbackModule);
212
+ return fallbackModule;
213
+ }
214
+
215
+ /**
216
+ * @param {ModuleGraph} moduleGraph the module graph
217
+ * @param {boolean | undefined} strict the importing module is strict
218
+ * @returns {ExportsType} export type
219
+ * "namespace": Exports is already a namespace object. namespace = exports.
220
+ * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
221
+ * "default-only": Provide a namespace object with only default export. namespace = { default: exports }
222
+ * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
223
+ */
224
+ getExportsType(moduleGraph, strict) {
225
+ const fallbackModule = this._getFallbackModule(moduleGraph);
226
+ if (!fallbackModule) return "dynamic";
227
+ return fallbackModule.getExportsType(moduleGraph, strict);
228
+ }
229
+
156
230
  /**
157
231
  * @param {string=} type the source type for which the size should be estimated
158
232
  * @returns {number} the estimated size of the module (must be non-zero)
@@ -186,6 +260,7 @@ class ConsumeSharedModule extends Module {
186
260
  singleton,
187
261
  eager
188
262
  } = this.options;
263
+ /** @type {undefined | string} */
189
264
  let fallbackCode;
190
265
  if (request) {
191
266
  if (eager) {
@@ -219,6 +294,7 @@ class ConsumeSharedModule extends Module {
219
294
  args.push(fallbackCode);
220
295
  }
221
296
 
297
+ /** @type {string} */
222
298
  let fn;
223
299
 
224
300
  if (requiredVersion) {
@@ -232,6 +308,7 @@ class ConsumeSharedModule extends Module {
232
308
  }
233
309
 
234
310
  const code = runtimeTemplate.returningFunction(`${fn}(${args.join(", ")})`);
311
+ /** @type {Sources} */
235
312
  const sources = new Map();
236
313
  sources.set("consume-shared", new RawSource(code));
237
314
  return {
@@ -26,6 +26,7 @@ const {
26
26
  /** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
27
27
  /** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumeSharedPluginOptions} ConsumeSharedPluginOptions */
28
28
  /** @typedef {import("../Compiler")} Compiler */
29
+ /** @typedef {import("../Compilation").FileSystemDependencies} FileSystemDependencies */
29
30
  /** @typedef {import("../ResolverFactory").ResolveOptionsWithDependencyType} ResolveOptionsWithDependencyType */
30
31
  /** @typedef {import("../util/semver").SemVerRange} SemVerRange */
31
32
  /** @typedef {import("./ConsumeSharedModule").ConsumeOptions} ConsumeOptions */
@@ -159,7 +160,7 @@ class ConsumeSharedPlugin {
159
160
  };
160
161
  const directFallback =
161
162
  config.import &&
162
- /^(\.\.?(\/|$)|\/|[A-Za-z]:|\\\\)/.test(config.import);
163
+ /^(?:\.\.?(?:\/|$)|\/|[A-Z]:|\\\\)/i.test(config.import);
163
164
  return Promise.all([
164
165
  new Promise(
165
166
  /**
@@ -170,7 +171,7 @@ class ConsumeSharedPlugin {
170
171
  resolve();
171
172
  return;
172
173
  }
173
- /** @typedef {ResolveContext} */
174
+ /** @type {ResolveContext & { fileDependencies: FileSystemDependencies, contextDependencies: FileSystemDependencies, missingDependencies: FileSystemDependencies }} */
174
175
  const resolveContext = {
175
176
  fileDependencies: new LazySet(),
176
177
  contextDependencies: new LazySet(),
@@ -215,13 +216,13 @@ class ConsumeSharedPlugin {
215
216
  }
216
217
  let packageName = config.packageName;
217
218
  if (packageName === undefined) {
218
- if (/^(\/|[A-Za-z]:|\\\\)/.test(request)) {
219
+ if (/^(?:\/|[A-Z]:|\\\\)/i.test(request)) {
219
220
  // For relative or absolute requests we don't automatically use a packageName.
220
221
  // If wished one can specify one with the packageName option.
221
222
  resolve();
222
223
  return;
223
224
  }
224
- const match = /^((?:@[^\\/]+[\\/])?[^\\/]+)/.exec(request);
225
+ const match = /^(?:@[^\\/]+[\\/])?[^\\/]+/.exec(request);
225
226
  if (!match) {
226
227
  requiredVersionWarning(
227
228
  "Unable to extract the package name from request."
@@ -22,7 +22,9 @@ const ProvideForSharedDependency = require("./ProvideForSharedDependency");
22
22
  /** @typedef {import("../Module").LibIdent} LibIdent */
23
23
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
24
24
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
25
+ /** @typedef {import("../Module").Sources} Sources */
25
26
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
27
+ /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
26
28
  /** @typedef {import("../RequestShortener")} RequestShortener */
27
29
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
28
30
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -147,7 +149,9 @@ class ProvideSharedModule extends Module {
147
149
  runtimeRequirements
148
150
  })
149
151
  }${this._eager ? ", 1" : ""});`;
152
+ /** @type {Sources} */
150
153
  const sources = new Map();
154
+ /** @type {CodeGenerationResultData} */
151
155
  const data = new Map();
152
156
  data.set("share-init", [
153
157
  {
@@ -45,29 +45,28 @@ class ProvideSharedPlugin {
45
45
  constructor(options) {
46
46
  validate(options);
47
47
 
48
- this._provides = /** @type {[string, ProvideOptions][]} */ (
49
- parseOptions(
50
- options.provides,
51
- (item) => {
52
- if (Array.isArray(item)) {
53
- throw new Error("Unexpected array of provides");
54
- }
55
- /** @type {ProvideOptions} */
56
- const result = {
57
- shareKey: item,
58
- version: undefined,
59
- shareScope: options.shareScope || "default",
60
- eager: false
61
- };
62
- return result;
63
- },
64
- (item) => ({
65
- shareKey: item.shareKey,
66
- version: item.version,
67
- shareScope: item.shareScope || options.shareScope || "default",
68
- eager: Boolean(item.eager)
69
- })
70
- )
48
+ /** @type {[string, ProvideOptions][]} */
49
+ this._provides = parseOptions(
50
+ options.provides,
51
+ (item) => {
52
+ if (Array.isArray(item)) {
53
+ throw new Error("Unexpected array of provides");
54
+ }
55
+ /** @type {ProvideOptions} */
56
+ const result = {
57
+ shareKey: item,
58
+ version: undefined,
59
+ shareScope: options.shareScope || "default",
60
+ eager: false
61
+ };
62
+ return result;
63
+ },
64
+ (item) => ({
65
+ shareKey: /** @type {string} */ (item.shareKey),
66
+ version: item.version,
67
+ shareScope: item.shareScope || options.shareScope || "default",
68
+ eager: Boolean(item.eager)
69
+ })
71
70
  );
72
71
  this._provides.sort(([a], [b]) => {
73
72
  if (a < b) return -1;
@@ -95,13 +94,13 @@ class ProvideSharedPlugin {
95
94
  /** @type {Map<string, ProvideOptions>} */
96
95
  const prefixMatchProvides = new Map();
97
96
  for (const [request, config] of this._provides) {
98
- if (/^(\/|[A-Za-z]:\\|\\\\|\.\.?(\/|$))/.test(request)) {
97
+ if (/^(?:\/|[A-Z]:\\|\\\\|\.\.?(?:\/|$))/i.test(request)) {
99
98
  // relative request
100
99
  resolvedProvideMap.set(request, {
101
100
  config,
102
101
  version: config.version
103
102
  });
104
- } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) {
103
+ } else if (/^(?:\/|[A-Z]:\\|\\\\)/i.test(request)) {
105
104
  // absolute path
106
105
  resolvedProvideMap.set(request, {
107
106
  config,
@@ -54,7 +54,7 @@ module.exports.resolveMatchedConfigs = (compilation, configs) => {
54
54
  return Promise.all(
55
55
  // eslint-disable-next-line array-callback-return
56
56
  configs.map(([request, config]) => {
57
- if (/^\.\.?(\/|$)/.test(request)) {
57
+ if (/^\.\.?(?:\/|$)/.test(request)) {
58
58
  // relative request
59
59
  return new Promise((resolve) => {
60
60
  resolver.resolve(
@@ -77,7 +77,7 @@ module.exports.resolveMatchedConfigs = (compilation, configs) => {
77
77
  }
78
78
  );
79
79
  });
80
- } else if (/^(\/|[A-Za-z]:\\|\\\\)/.test(request)) {
80
+ } else if (/^(?:\/|[a-z]:\\|\\\\)/i.test(request)) {
81
81
  // absolute path
82
82
  resolved.set(request, config);
83
83
  } else if (request.endsWith("/")) {
@@ -15,30 +15,30 @@ const { dirname, join, readJson } = require("../util/fs");
15
15
  const RE_URL_GITHUB_EXTREME_SHORT = /^[^/@:.\s][^/@:\s]*\/[^@:\s]*[^/@:\s]#\S+/;
16
16
 
17
17
  // Short url with specific protocol. eg: github:foo/bar
18
- const RE_GIT_URL_SHORT = /^(github|gitlab|bitbucket|gist):\/?[^/.]+\/?/i;
18
+ const RE_GIT_URL_SHORT = /^(?:github|gitlab|bitbucket|gist):\/?[^/.]+\/?/i;
19
19
 
20
20
  // Currently supported protocols
21
21
  const RE_PROTOCOL =
22
- /^((git\+)?(ssh|https?|file)|git|github|gitlab|bitbucket|gist):$/i;
22
+ /^(?:(?:git\+)?(?:ssh|https?|file)|git|github|gitlab|bitbucket|gist):$/i;
23
23
 
24
24
  // Has custom protocol
25
- const RE_CUSTOM_PROTOCOL = /^((git\+)?(ssh|https?|file)|git):\/\//i;
25
+ const RE_CUSTOM_PROTOCOL = /^(?:(?:git\+)?(?:ssh|https?|file)|git):\/\//i;
26
26
 
27
27
  // Valid hash format for npm / yarn ...
28
28
  const RE_URL_HASH_VERSION = /#(?:semver:)?(.+)/;
29
29
 
30
30
  // Simple hostname validate
31
- const RE_HOSTNAME = /^(?:[^/.]+(\.[^/]+)+|localhost)$/;
31
+ const RE_HOSTNAME = /^(?:[^/.]+(?:\.[^/]+)+|localhost)$/;
32
32
 
33
33
  // For hostname with colon. eg: ssh://user@github.com:foo/bar
34
34
  const RE_HOSTNAME_WITH_COLON =
35
35
  /([^/@#:.]+(?:\.[^/@#:.]+)+|localhost):([^#/0-9]+)/;
36
36
 
37
37
  // Reg for url without protocol
38
- const RE_NO_PROTOCOL = /^([^/@#:.]+(?:\.[^/@#:.]+)+)/;
38
+ const RE_NO_PROTOCOL = /^[^/@#:.]+(?:\.[^/@#:.]+)+/;
39
39
 
40
40
  // RegExp for version string
41
- const VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
41
+ const VERSION_PATTERN_REGEXP = /^(?:[\d^=v<>~]|[*xX]$)/;
42
42
 
43
43
  // Specific protocol for short url without normal hostname
44
44
  const PROTOCOLS_FOR_SHORT = [
@@ -248,7 +248,9 @@ function getGitUrlVersion(gitUrl) {
248
248
 
249
249
  gitUrl = correctUrl(gitUrl);
250
250
 
251
+ /** @type {undefined | URL} */
251
252
  let parsed;
253
+
252
254
  try {
253
255
  parsed = new URL(gitUrl);
254
256
  // eslint-disable-next-line no-empty