webpack 5.104.1 → 5.105.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 (323) 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 +4 -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 +284 -236
  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 +248 -111
  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 +6 -1
  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 +1 -0
  35. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  36. package/lib/ExportsInfo.js +8 -4
  37. package/lib/ExternalModule.js +16 -0
  38. package/lib/ExternalModuleFactoryPlugin.js +9 -2
  39. package/lib/ExternalsPlugin.js +2 -1
  40. package/lib/FalseIIFEUmdWarning.js +1 -0
  41. package/lib/FileSystemInfo.js +49 -25
  42. package/lib/FlagDependencyExportsPlugin.js +8 -1
  43. package/lib/FlagDependencyUsagePlugin.js +9 -7
  44. package/lib/HarmonyLinkingError.js +1 -0
  45. package/lib/HookWebpackError.js +2 -0
  46. package/lib/HotModuleReplacementPlugin.js +16 -2
  47. package/lib/IgnoreWarningsPlugin.js +5 -2
  48. package/lib/InitFragment.js +1 -0
  49. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  50. package/lib/LibManifestPlugin.js +1 -0
  51. package/lib/ManifestPlugin.js +8 -1
  52. package/lib/Module.js +7 -4
  53. package/lib/ModuleBuildError.js +3 -1
  54. package/lib/ModuleDependencyError.js +1 -0
  55. package/lib/ModuleDependencyWarning.js +1 -0
  56. package/lib/ModuleError.js +4 -1
  57. package/lib/ModuleFilenameHelpers.js +4 -2
  58. package/lib/ModuleGraph.js +3 -0
  59. package/lib/ModuleGraphConnection.js +10 -1
  60. package/lib/ModuleHashingError.js +2 -0
  61. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  62. package/lib/ModuleNotFoundError.js +1 -0
  63. package/lib/ModuleParseError.js +5 -1
  64. package/lib/ModuleProfile.js +1 -1
  65. package/lib/ModuleRestoreError.js +2 -0
  66. package/lib/ModuleSourceTypeConstants.js +1 -11
  67. package/lib/ModuleStoreError.js +2 -0
  68. package/lib/ModuleWarning.js +3 -1
  69. package/lib/MultiCompiler.js +11 -7
  70. package/lib/MultiWatching.js +2 -2
  71. package/lib/NoModeWarning.js +1 -0
  72. package/lib/NodeStuffInWebError.js +1 -0
  73. package/lib/NormalModule.js +28 -5
  74. package/lib/NormalModuleFactory.js +20 -4
  75. package/lib/OptionsApply.js +3 -1
  76. package/lib/ProgressPlugin.js +4 -0
  77. package/lib/RawModule.js +2 -0
  78. package/lib/RuntimeModule.js +10 -0
  79. package/lib/RuntimePlugin.js +7 -9
  80. package/lib/RuntimeTemplate.js +14 -7
  81. package/lib/SourceMapDevToolPlugin.js +30 -23
  82. package/lib/Template.js +10 -5
  83. package/lib/TemplatedPathPlugin.js +4 -2
  84. package/lib/UnhandledSchemeError.js +1 -0
  85. package/lib/UnsupportedFeatureWarning.js +3 -0
  86. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  87. package/lib/WatchIgnorePlugin.js +1 -1
  88. package/lib/Watching.js +5 -0
  89. package/lib/WebpackError.js +4 -0
  90. package/lib/WebpackOptionsApply.js +61 -41
  91. package/lib/asset/AssetBytesGenerator.js +1 -0
  92. package/lib/asset/AssetGenerator.js +18 -3
  93. package/lib/asset/AssetModulesPlugin.js +33 -2
  94. package/lib/asset/AssetParser.js +4 -0
  95. package/lib/asset/AssetSourceGenerator.js +1 -0
  96. package/lib/asset/RawDataUrlModule.js +4 -0
  97. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  98. package/lib/buildChunkGraph.js +31 -2
  99. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  100. package/lib/cache/PackFileCacheStrategy.js +41 -8
  101. package/lib/cache/getLazyHashedEtag.js +13 -4
  102. package/lib/cache/mergeEtags.js +3 -1
  103. package/lib/cli.js +3 -1
  104. package/lib/config/defaults.js +65 -44
  105. package/lib/config/normalization.js +96 -0
  106. package/lib/container/ContainerEntryDependency.js +3 -0
  107. package/lib/container/ContainerEntryModule.js +7 -0
  108. package/lib/container/ContainerExposedDependency.js +1 -0
  109. package/lib/container/FallbackDependency.js +1 -0
  110. package/lib/container/FallbackItemDependency.js +1 -0
  111. package/lib/container/FallbackModule.js +4 -0
  112. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  113. package/lib/container/ModuleFederationPlugin.js +1 -1
  114. package/lib/container/RemoteModule.js +24 -0
  115. package/lib/css/CssGenerator.js +31 -4
  116. package/lib/css/CssModulesPlugin.js +26 -30
  117. package/lib/css/CssParser.js +12 -9
  118. package/lib/debug/ProfilingPlugin.js +1 -0
  119. package/lib/dependencies/AMDDefineDependency.js +3 -1
  120. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  121. package/lib/dependencies/AMDPlugin.js +1 -1
  122. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  123. package/lib/dependencies/CachedConstDependency.js +1 -0
  124. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  125. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  126. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  127. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  128. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  129. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  130. package/lib/dependencies/ConstDependency.js +1 -0
  131. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  132. package/lib/dependencies/ContextElementDependency.js +1 -0
  133. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  134. package/lib/dependencies/CssIcssExportDependency.js +7 -4
  135. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  136. package/lib/dependencies/CssUrlDependency.js +2 -3
  137. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  138. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  139. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  140. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
  141. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  142. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  143. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  144. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  145. package/lib/dependencies/HarmonyImportDependency.js +1 -1
  146. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +269 -5
  147. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  148. package/lib/dependencies/ImportDependency.js +1 -0
  149. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  150. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  151. package/lib/dependencies/ImportParserPlugin.js +7 -12
  152. package/lib/dependencies/LoaderPlugin.js +3 -0
  153. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  154. package/lib/dependencies/ModuleDependency.js +1 -0
  155. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  156. package/lib/dependencies/ProvidedDependency.js +1 -0
  157. package/lib/dependencies/RequireContextPlugin.js +1 -0
  158. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
  159. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  160. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  161. package/lib/dependencies/WorkerDependency.js +9 -3
  162. package/lib/dependencies/WorkerPlugin.js +1 -0
  163. package/lib/dependencies/getFunctionExpression.js +3 -1
  164. package/lib/electron/ElectronTargetPlugin.js +3 -1
  165. package/lib/errors/BuildCycleError.js +4 -1
  166. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  167. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  168. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  169. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  170. package/lib/hmr/lazyCompilationBackend.js +3 -2
  171. package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
  172. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
  173. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
  174. package/lib/ids/HashedModuleIdsPlugin.js +3 -8
  175. package/lib/ids/IdHelpers.js +10 -8
  176. package/lib/ids/NamedChunkIdsPlugin.js +7 -5
  177. package/lib/ids/NamedModuleIdsPlugin.js +1 -0
  178. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  179. package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
  180. package/lib/ids/SyncModuleIdsPlugin.js +30 -20
  181. package/lib/index.js +2 -2
  182. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  183. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  184. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  185. package/lib/javascript/JavascriptParser.js +47 -14
  186. package/lib/json/JsonGenerator.js +1 -0
  187. package/lib/json/JsonParser.js +9 -2
  188. package/lib/library/AbstractLibraryPlugin.js +4 -1
  189. package/lib/library/AmdLibraryPlugin.js +2 -1
  190. package/lib/library/AssignLibraryPlugin.js +6 -2
  191. package/lib/library/EnableLibraryPlugin.js +1 -0
  192. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  193. package/lib/library/JsonpLibraryPlugin.js +1 -1
  194. package/lib/library/ModuleLibraryPlugin.js +130 -13
  195. package/lib/library/SystemLibraryPlugin.js +4 -1
  196. package/lib/library/UmdLibraryPlugin.js +4 -3
  197. package/lib/logging/Logger.js +9 -5
  198. package/lib/logging/createConsoleLogger.js +4 -0
  199. package/lib/logging/truncateArgs.js +1 -1
  200. package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
  201. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  202. package/lib/node/NodeTargetPlugin.js +10 -1
  203. package/lib/node/NodeTemplatePlugin.js +1 -0
  204. package/lib/node/NodeWatchFileSystem.js +6 -0
  205. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
  206. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  207. package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
  208. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
  209. package/lib/node/nodeConsole.js +18 -1
  210. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  211. package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
  212. package/lib/optimize/ConcatenatedModule.js +33 -19
  213. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  214. package/lib/optimize/InnerGraph.js +5 -3
  215. package/lib/optimize/InnerGraphPlugin.js +25 -25
  216. package/lib/optimize/LimitChunkCountPlugin.js +3 -2
  217. package/lib/optimize/MangleExportsPlugin.js +14 -2
  218. package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
  219. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  220. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  221. package/lib/optimize/RealContentHashPlugin.js +37 -27
  222. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  223. package/lib/optimize/RuntimeChunkPlugin.js +3 -5
  224. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  225. package/lib/optimize/SplitChunksPlugin.js +23 -5
  226. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  227. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  228. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  229. package/lib/performance/SizeLimitsPlugin.js +6 -6
  230. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
  231. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
  232. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
  233. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  234. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  235. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  236. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  237. package/lib/rules/RuleSetCompiler.js +6 -0
  238. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  239. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  240. package/lib/runtime/CompatRuntimeModule.js +1 -0
  241. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  242. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
  243. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  244. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  245. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  246. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  247. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
  248. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  249. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  250. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  251. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  252. package/lib/schemes/HttpUriPlugin.js +39 -20
  253. package/lib/schemes/VirtualUrlPlugin.js +28 -2
  254. package/lib/serialization/BinaryMiddleware.js +4 -0
  255. package/lib/serialization/FileMiddleware.js +9 -4
  256. package/lib/serialization/ObjectMiddleware.js +34 -11
  257. package/lib/serialization/PlainObjectSerializer.js +2 -0
  258. package/lib/sharing/ConsumeSharedModule.js +60 -0
  259. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  260. package/lib/sharing/ProvideSharedModule.js +4 -0
  261. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  262. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  263. package/lib/sharing/utils.js +8 -6
  264. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
  265. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  266. package/lib/stats/StatsFactory.js +2 -2
  267. package/lib/url/URLParserPlugin.js +5 -3
  268. package/lib/util/AppendOnlyStackedSet.js +57 -0
  269. package/lib/util/Hash.js +1 -0
  270. package/lib/util/IterableHelpers.js +1 -0
  271. package/lib/util/LazyBucketSortedSet.js +1 -0
  272. package/lib/util/LazySet.js +1 -0
  273. package/lib/util/ParallelismFactorCalculator.js +1 -0
  274. package/lib/util/SortableSet.js +1 -0
  275. package/lib/util/StringXor.js +1 -0
  276. package/lib/util/binarySearchBounds.js +15 -8
  277. package/lib/util/chainedImports.js +1 -1
  278. package/lib/util/cleverMerge.js +6 -1
  279. package/lib/util/comparators.js +21 -1
  280. package/lib/util/compileBooleanMatcher.js +3 -3
  281. package/lib/util/concatenate.js +3 -2
  282. package/lib/util/conventions.js +3 -2
  283. package/lib/util/deterministicGrouping.js +13 -1
  284. package/lib/util/extractSourceMap.js +12 -13
  285. package/lib/util/fs.js +15 -19
  286. package/lib/util/hash/BatchedHash.js +4 -0
  287. package/lib/util/hash/BulkUpdateHash.js +8 -1
  288. package/lib/util/hash/hash-digest.js +1 -0
  289. package/lib/util/hash/wasm-hash.js +18 -2
  290. package/lib/util/identifier.js +7 -2
  291. package/lib/util/magicComment.js +1 -1
  292. package/lib/util/propertyName.js +1 -1
  293. package/lib/util/registerExternalSerializer.js +1 -0
  294. package/lib/util/runtime.js +15 -1
  295. package/lib/util/semver.js +1 -0
  296. package/lib/util/serialization.js +2 -2
  297. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
  298. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  299. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  300. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  301. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  302. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  303. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  304. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  305. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  306. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  307. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  308. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  309. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  310. package/lib/webpack.js +16 -4
  311. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  312. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
  313. package/package.json +33 -36
  314. package/schemas/WebpackOptions.check.js +1 -1
  315. package/schemas/WebpackOptions.json +121 -55
  316. package/schemas/plugins/BannerPlugin.json +2 -2
  317. package/schemas/plugins/IgnorePlugin.json +1 -1
  318. package/schemas/plugins/ManifestPlugin.json +3 -3
  319. package/schemas/plugins/ProgressPlugin.json +1 -1
  320. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  321. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  322. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  323. package/types.d.ts +440 -137
@@ -17,6 +17,9 @@ const makeSerializable = require("../util/makeSerializable");
17
17
  const { rangeToString, stringifyHoley } = require("../util/semver");
18
18
  const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependency");
19
19
 
20
+ /** @type {WeakMap<ModuleGraph, WeakMap<ConsumeSharedModule, Module | null>>} */
21
+ const fallbackModuleCache = new WeakMap();
22
+
20
23
  /** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
21
24
  /** @typedef {import("../Compilation")} Compilation */
22
25
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
@@ -27,7 +30,10 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
27
30
  /** @typedef {import("../Module").LibIdent} LibIdent */
28
31
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
29
32
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
33
+ /** @typedef {import("../Module").Sources} Sources */
30
34
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
35
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
36
+ /** @typedef {import("../Module").ExportsType} ExportsType */
31
37
  /** @typedef {import("../RequestShortener")} RequestShortener */
32
38
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
33
39
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -153,6 +159,57 @@ class ConsumeSharedModule extends Module {
153
159
  return CONSUME_SHARED_TYPES;
154
160
  }
155
161
 
162
+ /**
163
+ * @param {ModuleGraph} moduleGraph the module graph
164
+ * @returns {Module | null} fallback module
165
+ */
166
+ _getFallbackModule(moduleGraph) {
167
+ let moduleCache = fallbackModuleCache.get(moduleGraph);
168
+ if (!moduleCache) {
169
+ moduleCache = new WeakMap();
170
+ fallbackModuleCache.set(moduleGraph, moduleCache);
171
+ }
172
+ const cached = moduleCache.get(this);
173
+ if (cached !== undefined) {
174
+ return cached;
175
+ }
176
+
177
+ /** @type {undefined | null | Module} */
178
+ let fallbackModule = null;
179
+
180
+ if (this.options.import) {
181
+ if (this.options.eager) {
182
+ const dep = this.dependencies[0];
183
+ if (dep) {
184
+ fallbackModule = moduleGraph.getModule(dep);
185
+ }
186
+ } else {
187
+ const block = this.blocks[0];
188
+ if (block && block.dependencies.length > 0) {
189
+ fallbackModule = moduleGraph.getModule(block.dependencies[0]);
190
+ }
191
+ }
192
+ }
193
+
194
+ moduleCache.set(this, fallbackModule);
195
+ return fallbackModule;
196
+ }
197
+
198
+ /**
199
+ * @param {ModuleGraph} moduleGraph the module graph
200
+ * @param {boolean | undefined} strict the importing module is strict
201
+ * @returns {ExportsType} export type
202
+ * "namespace": Exports is already a namespace object. namespace = exports.
203
+ * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
204
+ * "default-only": Provide a namespace object with only default export. namespace = { default: exports }
205
+ * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
206
+ */
207
+ getExportsType(moduleGraph, strict) {
208
+ const fallbackModule = this._getFallbackModule(moduleGraph);
209
+ if (!fallbackModule) return "dynamic";
210
+ return fallbackModule.getExportsType(moduleGraph, strict);
211
+ }
212
+
156
213
  /**
157
214
  * @param {string=} type the source type for which the size should be estimated
158
215
  * @returns {number} the estimated size of the module (must be non-zero)
@@ -186,6 +243,7 @@ class ConsumeSharedModule extends Module {
186
243
  singleton,
187
244
  eager
188
245
  } = this.options;
246
+ /** @type {undefined | string} */
189
247
  let fallbackCode;
190
248
  if (request) {
191
249
  if (eager) {
@@ -219,6 +277,7 @@ class ConsumeSharedModule extends Module {
219
277
  args.push(fallbackCode);
220
278
  }
221
279
 
280
+ /** @type {string} */
222
281
  let fn;
223
282
 
224
283
  if (requiredVersion) {
@@ -232,6 +291,7 @@ class ConsumeSharedModule extends Module {
232
291
  }
233
292
 
234
293
  const code = runtimeTemplate.returningFunction(`${fn}(${args.join(", ")})`);
294
+ /** @type {Sources} */
235
295
  const sources = new Map();
236
296
  sources.set("consume-shared", new RawSource(code));
237
297
  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
@@ -386,12 +386,10 @@ const uniqueOrderedArray = (items, selector, comparator) =>
386
386
  * @returns {MappedValues<T, R>} mapped object
387
387
  */
388
388
  const mapObject = (obj, fn) => {
389
+ /** @type {MappedValues<T, R>} */
389
390
  const newObj = Object.create(null);
390
- for (const key of Object.keys(obj)) {
391
- newObj[key] = fn(
392
- obj[/** @type {keyof T} */ (key)],
393
- /** @type {keyof T} */ (key)
394
- );
391
+ for (const key of /** @type {(keyof T)[]} */ (Object.keys(obj))) {
392
+ newObj[key] = fn(obj[key], key);
395
393
  }
396
394
  return newObj;
397
395
  };
@@ -507,8 +505,8 @@ const EXTRACT_ERROR = {
507
505
  object.details = /** @type {WebpackError} */ (error).details;
508
506
  }
509
507
  },
510
- errorStack: (object, error) => {
511
- if (typeof error !== "string") {
508
+ errorStack: (object, error, _context, { errorStack }) => {
509
+ if (typeof error !== "string" && errorStack) {
512
510
  object.stack = error.stack;
513
511
  }
514
512
  },
@@ -545,6 +543,8 @@ const EXTRACT_ERROR = {
545
543
  }
546
544
  };
547
545
 
546
+ /** @typedef {((value: string) => boolean)} FilterItemTypeFn */
547
+
548
548
  /** @type {SimpleExtractors} */
549
549
  const SIMPLE_EXTRACTORS = {
550
550
  compilation: {
@@ -587,6 +587,7 @@ const SIMPLE_EXTRACTORS = {
587
587
  const util = require("util");
588
588
 
589
589
  object.logging = {};
590
+ /** @type {Set<keyof LogType>} */
590
591
  let acceptedTypes;
591
592
  let collapsedGroups = false;
592
593
  switch (logging) {
@@ -677,6 +678,7 @@ const SIMPLE_EXTRACTORS = {
677
678
  if (depthInCollapsedGroup > 0) depthInCollapsedGroup--;
678
679
  continue;
679
680
  }
681
+ /** @type {undefined | string} */
680
682
  let message;
681
683
  if (entry.type === LogType.time) {
682
684
  const [label, first, second] =
@@ -1229,7 +1231,7 @@ const SIMPLE_EXTRACTORS = {
1229
1231
  const codeGenerated = compilation.codeGeneratedModules.has(module);
1230
1232
  const buildTimeExecuted =
1231
1233
  compilation.buildTimeExecutedModules.has(module);
1232
- /** @type {{[x: string]: number}} */
1234
+ /** @type {{ [x: string]: number }} */
1233
1235
  const sizes = {};
1234
1236
  for (const sourceType of module.getSourceTypes()) {
1235
1237
  sizes[sourceType] = module.size(sourceType);
@@ -1826,6 +1828,7 @@ const getTotalItems = (children) => {
1826
1828
  */
1827
1829
  const collapse = (children) => {
1828
1830
  // After collapse each child must take exactly one line
1831
+ /** @type {Children<T>[]} */
1829
1832
  const newChildren = [];
1830
1833
  for (const child of children) {
1831
1834
  if (child.children) {
@@ -1872,6 +1875,7 @@ const spaceLimited = (
1872
1875
  /** @type {number[]} */
1873
1876
  const groupSizes = [];
1874
1877
  // This are the items, which take 1 line each
1878
+ /** @type {Children<T>[]} */
1875
1879
  const items = [];
1876
1880
  // The total of group sizes
1877
1881
  let groupsSize = 0;
@@ -1907,6 +1911,7 @@ const spaceLimited = (
1907
1911
  if (limit < max) {
1908
1912
  // calculate how much we are over the size limit
1909
1913
  // this allows to approach the limit faster
1914
+ /** @type {number} */
1910
1915
  let oversize;
1911
1916
  // If each group would take 1 line the total would be below the maximum
1912
1917
  // collapse some groups, keep items
@@ -2097,6 +2102,8 @@ const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/;
2097
2102
  * @typedef {BaseGroup & { children: T[], size: number }} BaseGroupWithChildren
2098
2103
  */
2099
2104
 
2105
+ /** @typedef {(name: string, asset: StatsAsset) => boolean} AssetFilterItemFn */
2106
+
2100
2107
  /**
2101
2108
  * @typedef {{
2102
2109
  * _: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroup & { filteredChildren: number, size: number } | BaseGroupWithChildren<KnownStatsAsset>>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
@@ -2256,6 +2263,8 @@ const ASSETS_GROUPERS = {
2256
2263
  * }} ModulesGroupers
2257
2264
  */
2258
2265
 
2266
+ /** @typedef {(name: string, module: StatsModule, type: "module" | "chunk" | "root-of-chunk" | "nested") => boolean} ModuleFilterItemTypeFn */
2267
+
2259
2268
  /**
2260
2269
  * @type {(type: ExcludeModulesType) => ModulesGroupers}
2261
2270
  */
@@ -2377,6 +2386,7 @@ const MODULES_GROUPERS = (type) => ({
2377
2386
  const pathMatch =
2378
2387
  groupModulesByPath && GROUP_PATH_REGEXP.exec(resource);
2379
2388
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2389
+ /** @type {string[]} */
2380
2390
  const keys = [];
2381
2391
  if (groupModulesByPath) {
2382
2392
  if (extension) {
@@ -2442,9 +2452,7 @@ const MODULES_GROUPERS = (type) => ({
2442
2452
  });
2443
2453
 
2444
2454
  /**
2445
- * @typedef {{
2446
- * groupReasonsByOrigin: (groupConfigs: GroupConfig<KnownStatsModuleReason, BaseGroup & { module: string, children: KnownStatsModuleReason[], active: boolean }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void
2447
- * }} ModuleReasonsGroupers
2455
+ * @typedef {{ groupReasonsByOrigin: (groupConfigs: GroupConfig<KnownStatsModuleReason, BaseGroup & { module: string, children: KnownStatsModuleReason[], active: boolean }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void }} ModuleReasonsGroupers
2448
2456
  */
2449
2457
 
2450
2458
  /** @type {ModuleReasonsGroupers} */
@@ -2541,7 +2549,7 @@ const sortByField = (field) => {
2541
2549
  /**
2542
2550
  * @typedef {{
2543
2551
  * assetsSort: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2544
- * _: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void
2552
+ * _: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2545
2553
  * }} AssetSorters
2546
2554
  */
2547
2555
 
@@ -245,6 +245,7 @@ const COMPILATION_SIMPLE_PRINTERS = {
245
245
  nameMessage && versionMessage
246
246
  ? `${nameMessage} (${versionMessage})`
247
247
  : versionMessage || nameMessage || "webpack";
248
+ /** @type {string} */
248
249
  let statusMessage;
249
250
  if (errorsMessage && warningsMessage) {
250
251
  statusMessage = `compiled with ${errorsMessage} and ${warningsMessage}`;
@@ -587,8 +588,7 @@ const MODULE_SIMPLE_PRINTERS = {
587
588
  };
588
589
 
589
590
  /**
590
- * @typedef {Printers<KnownStatsModuleIssuer, "moduleIssuer"> &
591
- * Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} ModuleIssuerPrinters
591
+ * @typedef {Printers<KnownStatsModuleIssuer, "moduleIssuer"> & Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} ModuleIssuerPrinters
592
592
  */
593
593
 
594
594
  /** @type {ModuleIssuerPrinters} */
@@ -598,8 +598,7 @@ const MODULE_ISSUER_PRINTERS = {
598
598
  };
599
599
 
600
600
  /**
601
- * @typedef {Printers<KnownStatsModuleReason, "moduleReason"> &
602
- * { ["moduleReason.filteredChildren"]?: SimplePrinter<number, "moduleReason"> }} ModuleReasonsPrinters
601
+ * @typedef {Printers<KnownStatsModuleReason, "moduleReason"> & { ["moduleReason.filteredChildren"]?: SimplePrinter<number, "moduleReason"> }} ModuleReasonsPrinters
603
602
  */
604
603
 
605
604
  /** @type {ModuleReasonsPrinters} */
@@ -799,7 +798,7 @@ const ERROR_PRINTERS = {
799
798
  "error.file": (file, { bold }) => bold(file),
800
799
  "error.moduleName": (moduleName, { bold }) =>
801
800
  moduleName.includes("!")
802
- ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})`
801
+ ? `${bold(moduleName.replace(/^([\s\S])*!/, ""))} (${moduleName})`
803
802
  : `${bold(moduleName)}`,
804
803
  "error.loc": (loc, { green }) => green(loc),
805
804
  "error.message": (message, { bold, formatError }) =>
@@ -1193,6 +1192,7 @@ const joinOneLine = (items) =>
1193
1192
  * @returns {string} result
1194
1193
  */
1195
1194
  const joinInBrackets = (items) => {
1195
+ /** @type {string[]} */
1196
1196
  const res = [];
1197
1197
  let mode = 0;
1198
1198
  for (const item of items) {
@@ -1296,6 +1296,7 @@ const joinError =
1296
1296
  /** @type {Record<string, SimpleElementJoiner>} */
1297
1297
  const SIMPLE_ELEMENT_JOINERS = {
1298
1298
  compilation: (items) => {
1299
+ /** @type {string[]} */
1299
1300
  const result = [];
1300
1301
  let lastNeedMore = false;
1301
1302
  for (const item of items) {
@@ -161,7 +161,7 @@ class StatsFactory {
161
161
  /**
162
162
  * @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
163
163
  * @template {HM extends HookMap<infer H> ? H : never} H
164
- * @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
164
+ * @template {H extends import("tapable").Hook<EXPECTED_ANY, infer R> ? R : never} R
165
165
  * @param {HM} hookMap hook map
166
166
  * @param {Caches<H>} cache cache
167
167
  * @param {string} type type
@@ -197,7 +197,7 @@ class StatsFactory {
197
197
  /**
198
198
  * @template {StatsFactoryHooks[keyof StatsFactoryHooks]} T
199
199
  * @template {T extends HookMap<infer H> ? H : never} H
200
- * @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
200
+ * @template {H extends import("tapable").Hook<EXPECTED_ANY, infer R> ? R : never} R
201
201
  * @param {T} hookMap hook map
202
202
  * @param {Caches<H>} cache cache
203
203
  * @param {string} type type
@@ -54,9 +54,7 @@ const isMetaUrl = (parser, arg) => {
54
54
  return true;
55
55
  };
56
56
 
57
- /**
58
- * @type {WeakMap<NewExpressionNode, BasicEvaluatedExpression | undefined>}
59
- */
57
+ /** @type {WeakMap<NewExpressionNode, BasicEvaluatedExpression | undefined>} */
60
58
  const getEvaluatedExprCache = new WeakMap();
61
59
 
62
60
  /**
@@ -95,6 +93,7 @@ class URLParserPlugin {
95
93
  * @param {JavascriptParserOptions} options options
96
94
  */
97
95
  constructor(options) {
96
+ /** @type {JavascriptParserOptions} */
98
97
  this.options = options;
99
98
  }
100
99
 
@@ -167,6 +166,7 @@ class URLParserPlugin {
167
166
  const evaluatedExpr = getEvaluatedExpr(expr, parser);
168
167
  if (!evaluatedExpr) return;
169
168
 
169
+ /** @type {string | undefined} */
170
170
  let request;
171
171
 
172
172
  // static URL
@@ -190,7 +190,9 @@ class URLParserPlugin {
190
190
  if (this.options.dynamicUrl === false) return;
191
191
 
192
192
  // context URL
193
+ /** @type {undefined | RegExp} */
193
194
  let include;
195
+ /** @type {undefined | RegExp} */
194
196
  let exclude;
195
197
 
196
198
  if (importOptions) {
@@ -0,0 +1,57 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * @template T
10
+ */
11
+ class AppendOnlyStackedSet {
12
+ /**
13
+ * @param {Set<T>[]} sets an optional array of sets
14
+ */
15
+ constructor(sets = []) {
16
+ /** @type {Set<T>[]} */
17
+ this._sets = sets;
18
+ /** @type {Set<T> | undefined} */
19
+ this._current = undefined;
20
+ }
21
+
22
+ /**
23
+ * @param {T} el element
24
+ */
25
+ add(el) {
26
+ if (!this._current) {
27
+ this._current = new Set();
28
+ this._sets.push(this._current);
29
+ }
30
+ this._current.add(el);
31
+ }
32
+
33
+ /**
34
+ * @param {T} el element
35
+ * @returns {boolean} result
36
+ */
37
+ has(el) {
38
+ for (const set of this._sets) {
39
+ if (set.has(el)) return true;
40
+ }
41
+ return false;
42
+ }
43
+
44
+ clear() {
45
+ this._sets = [];
46
+ if (this._current) this._current.clear();
47
+ }
48
+
49
+ /**
50
+ * @returns {AppendOnlyStackedSet<T>} child
51
+ */
52
+ createChild() {
53
+ return new AppendOnlyStackedSet(this._sets.length ? [...this._sets] : []);
54
+ }
55
+ }
56
+
57
+ module.exports = AppendOnlyStackedSet;
package/lib/util/Hash.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../../declarations/WebpackOptions").HashDigest} Encoding */
9
+ /** @typedef {string | typeof Hash} HashFunction */
9
10
 
10
11
  class Hash {
11
12
  /* istanbul ignore next */
@@ -11,6 +11,7 @@
11
11
  * @returns {T | undefined} last item
12
12
  */
13
13
  const last = (set) => {
14
+ /** @type {T | undefined} */
14
15
  let last;
15
16
  for (const item of set) last = item;
16
17
  return last;
@@ -56,6 +56,7 @@ class LazyBucketSortedSet {
56
56
  this._keys = new SortableSet(undefined, comparator);
57
57
  /** @type {Map<K, Entry<T, K>>} */
58
58
  this._map = new Map();
59
+ /** @type {Set<T>} */
59
60
  this._unsortedItems = new Set();
60
61
  this.size = 0;
61
62
  }
@@ -222,6 +222,7 @@ class LazySet {
222
222
  */
223
223
  static deserialize({ read }) {
224
224
  const count = read();
225
+ /** @type {T[]} */
225
226
  const items = [];
226
227
  for (let i = 0; i < count; i++) {
227
228
  items.push(read());
@@ -35,6 +35,7 @@ class ParallelismFactorCalculator {
35
35
  a < b ? -1 : 1
36
36
  );
37
37
  const parallelism = segments.map(() => 0);
38
+ /** @type {number[]} */
38
39
  const rangeStartIndices = [];
39
40
  for (let i = 0; i < this._rangePoints.length; i += 2) {
40
41
  const start = this._rangePoints[i];
@@ -88,6 +88,7 @@ class SortableSet extends Set {
88
88
  return;
89
89
  }
90
90
 
91
+ /** @type {T[]} */
91
92
  const sortedArray = [...this].sort(sortFn);
92
93
  super.clear();
93
94
  for (let i = 0; i < sortedArray.length; i += 1) {
@@ -62,6 +62,7 @@ class StringXor {
62
62
  const valueLen = value.length;
63
63
  if (valueLen < len) {
64
64
  const newValue = (this._value = Buffer.allocUnsafe(len));
65
+ /** @type {number} */
65
66
  let i;
66
67
  for (i = 0; i < valueLen; i++) {
67
68
  newValue[i] = value[i] ^ str.charCodeAt(i);