webpack 5.101.2 → 5.102.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 (323) hide show
  1. package/README.md +21 -26
  2. package/lib/APIPlugin.js +30 -36
  3. package/lib/AsyncDependenciesBlock.js +1 -4
  4. package/lib/BannerPlugin.js +0 -1
  5. package/lib/Cache.js +7 -6
  6. package/lib/CacheFacade.js +0 -1
  7. package/lib/Chunk.js +49 -31
  8. package/lib/ChunkGraph.js +35 -25
  9. package/lib/ChunkGroup.js +8 -10
  10. package/lib/ChunkTemplate.js +1 -1
  11. package/lib/CleanPlugin.js +3 -3
  12. package/lib/CodeGenerationResults.js +2 -1
  13. package/lib/CompatibilityPlugin.js +29 -12
  14. package/lib/Compilation.js +204 -185
  15. package/lib/Compiler.js +36 -35
  16. package/lib/ConcatenationScope.js +6 -1
  17. package/lib/ConditionalInitFragment.js +1 -1
  18. package/lib/ConstPlugin.js +18 -10
  19. package/lib/ContextExclusionPlugin.js +0 -1
  20. package/lib/ContextModule.js +22 -20
  21. package/lib/ContextModuleFactory.js +30 -11
  22. package/lib/ContextReplacementPlugin.js +38 -15
  23. package/lib/DefinePlugin.js +18 -8
  24. package/lib/DelegatedModule.js +7 -11
  25. package/lib/DependenciesBlock.js +0 -2
  26. package/lib/Dependency.js +9 -11
  27. package/lib/DependencyTemplates.js +1 -3
  28. package/lib/DllModule.js +1 -7
  29. package/lib/DllReferencePlugin.js +2 -4
  30. package/lib/DynamicEntryPlugin.js +0 -2
  31. package/lib/EntryOptionPlugin.js +0 -5
  32. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  33. package/lib/EvalDevToolModulePlugin.js +4 -3
  34. package/lib/EvalSourceMapDevToolPlugin.js +3 -4
  35. package/lib/ExportsInfo.js +50 -49
  36. package/lib/ExternalModule.js +84 -52
  37. package/lib/ExternalModuleFactoryPlugin.js +27 -7
  38. package/lib/ExternalsPlugin.js +24 -17
  39. package/lib/FileSystemInfo.js +96 -78
  40. package/lib/FlagDependencyUsagePlugin.js +3 -4
  41. package/lib/Generator.js +2 -13
  42. package/lib/GraphHelpers.js +0 -3
  43. package/lib/HookWebpackError.js +0 -2
  44. package/lib/HotModuleReplacementPlugin.js +22 -24
  45. package/lib/HotUpdateChunk.js +0 -3
  46. package/lib/IgnorePlugin.js +5 -2
  47. package/lib/InitFragment.js +41 -29
  48. package/lib/InvalidDependenciesModuleWarning.js +0 -1
  49. package/lib/LibManifestPlugin.js +4 -6
  50. package/lib/LoaderOptionsPlugin.js +1 -10
  51. package/lib/MainTemplate.js +8 -19
  52. package/lib/Module.js +32 -20
  53. package/lib/ModuleFactory.js +1 -1
  54. package/lib/ModuleFilenameHelpers.js +41 -24
  55. package/lib/ModuleGraph.js +30 -16
  56. package/lib/ModuleInfoHeaderPlugin.js +0 -1
  57. package/lib/ModuleTemplate.js +0 -2
  58. package/lib/ModuleTypeConstants.js +11 -1
  59. package/lib/MultiCompiler.js +23 -15
  60. package/lib/MultiWatching.js +6 -10
  61. package/lib/NodeStuffPlugin.js +2 -10
  62. package/lib/NormalModule.js +145 -88
  63. package/lib/NormalModuleFactory.js +59 -40
  64. package/lib/OptionsApply.js +1 -1
  65. package/lib/Parser.js +1 -1
  66. package/lib/ProgressPlugin.js +6 -10
  67. package/lib/ProvidePlugin.js +5 -7
  68. package/lib/RawModule.js +1 -6
  69. package/lib/RecordIdsPlugin.js +10 -6
  70. package/lib/ResolverFactory.js +0 -2
  71. package/lib/RuntimeGlobals.js +5 -0
  72. package/lib/RuntimeModule.js +1 -3
  73. package/lib/RuntimePlugin.js +26 -22
  74. package/lib/RuntimeTemplate.js +12 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
  76. package/lib/SourceMapDevToolPlugin.js +6 -11
  77. package/lib/Stats.js +0 -1
  78. package/lib/Template.js +6 -11
  79. package/lib/TemplatedPathPlugin.js +2 -1
  80. package/lib/WatchIgnorePlugin.js +2 -3
  81. package/lib/Watching.js +15 -15
  82. package/lib/WebpackIsIncludedPlugin.js +0 -2
  83. package/lib/WebpackOptionsApply.js +74 -107
  84. package/lib/asset/AssetBytesGenerator.js +166 -0
  85. package/lib/asset/AssetBytesParser.js +37 -0
  86. package/lib/asset/AssetGenerator.js +20 -34
  87. package/lib/asset/AssetModulesPlugin.js +34 -16
  88. package/lib/asset/AssetParser.js +7 -3
  89. package/lib/asset/AssetSourceGenerator.js +1 -1
  90. package/lib/asset/RawDataUrlModule.js +3 -2
  91. package/lib/async-modules/AsyncModuleHelpers.js +6 -4
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +0 -1
  94. package/lib/cache/MemoryCachePlugin.js +0 -2
  95. package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
  96. package/lib/cache/PackFileCacheStrategy.js +14 -1
  97. package/lib/cache/ResolverCachePlugin.js +9 -15
  98. package/lib/config/defaults.js +155 -21
  99. package/lib/config/normalization.js +18 -3
  100. package/lib/container/ContainerEntryDependency.js +0 -1
  101. package/lib/container/ContainerEntryModule.js +3 -7
  102. package/lib/container/ContainerPlugin.js +1 -2
  103. package/lib/container/ContainerReferencePlugin.js +0 -1
  104. package/lib/container/FallbackDependency.js +2 -1
  105. package/lib/container/FallbackModule.js +6 -7
  106. package/lib/container/ModuleFederationPlugin.js +0 -1
  107. package/lib/container/RemoteModule.js +8 -8
  108. package/lib/container/RemoteRuntimeModule.js +2 -2
  109. package/lib/css/CssGenerator.js +3 -6
  110. package/lib/css/CssLoadingRuntimeModule.js +6 -9
  111. package/lib/css/CssModulesPlugin.js +11 -13
  112. package/lib/css/CssParser.js +3 -3
  113. package/lib/css/walkCssTokens.js +1 -1
  114. package/lib/debug/ProfilingPlugin.js +35 -8
  115. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
  116. package/lib/dependencies/AMDPlugin.js +2 -2
  117. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
  118. package/lib/dependencies/CachedConstDependency.js +0 -4
  119. package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
  120. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  121. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
  122. package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
  123. package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
  124. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  125. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  126. package/lib/dependencies/ConstDependency.js +2 -2
  127. package/lib/dependencies/ContextDependency.js +9 -4
  128. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  129. package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
  130. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
  131. package/lib/dependencies/ContextElementDependency.js +22 -11
  132. package/lib/dependencies/CssIcssImportDependency.js +0 -2
  133. package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
  134. package/lib/dependencies/CssImportDependency.js +0 -8
  135. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
  136. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
  137. package/lib/dependencies/CssUrlDependency.js +0 -6
  138. package/lib/dependencies/ExportsInfoDependency.js +7 -9
  139. package/lib/dependencies/ExternalModuleDependency.js +0 -3
  140. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  141. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  142. package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
  143. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  144. package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
  145. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
  146. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
  147. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
  148. package/lib/dependencies/HarmonyImportDependency.js +30 -14
  149. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +38 -24
  150. package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
  151. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
  152. package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
  153. package/lib/dependencies/ImportDependency.js +18 -6
  154. package/lib/dependencies/ImportEagerDependency.js +2 -3
  155. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
  156. package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
  157. package/lib/dependencies/ImportMetaPlugin.js +8 -1
  158. package/lib/dependencies/ImportParserPlugin.js +294 -45
  159. package/lib/dependencies/ImportWeakDependency.js +2 -3
  160. package/lib/dependencies/JsonExportsDependency.js +0 -1
  161. package/lib/dependencies/LoaderDependency.js +0 -3
  162. package/lib/dependencies/LoaderImportDependency.js +0 -3
  163. package/lib/dependencies/LoaderPlugin.js +11 -5
  164. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  165. package/lib/dependencies/ModuleDependency.js +3 -9
  166. package/lib/dependencies/NullDependency.js +2 -0
  167. package/lib/dependencies/ProvidedDependency.js +6 -8
  168. package/lib/dependencies/PureExpressionDependency.js +0 -1
  169. package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
  170. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
  171. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  172. package/lib/dependencies/RequireResolveDependency.js +2 -2
  173. package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
  174. package/lib/dependencies/StaticExportsDependency.js +3 -5
  175. package/lib/dependencies/URLDependency.js +2 -7
  176. package/lib/dependencies/URLPlugin.js +1 -2
  177. package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
  178. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  179. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  180. package/lib/dependencies/WorkerDependency.js +2 -3
  181. package/lib/dependencies/WorkerPlugin.js +3 -9
  182. package/lib/dependencies/processExportInfo.js +2 -3
  183. package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
  184. package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
  185. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
  186. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  187. package/lib/hmr/lazyCompilationBackend.js +13 -10
  188. package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
  189. package/lib/ids/NamedChunkIdsPlugin.js +1 -6
  190. package/lib/ids/NamedModuleIdsPlugin.js +1 -5
  191. package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
  192. package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
  193. package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
  194. package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
  195. package/lib/ids/SyncModuleIdsPlugin.js +4 -3
  196. package/lib/index.js +8 -7
  197. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
  198. package/lib/javascript/BasicEvaluatedExpression.js +13 -6
  199. package/lib/javascript/ChunkFormatHelpers.js +1 -1
  200. package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
  201. package/lib/javascript/JavascriptGenerator.js +2 -3
  202. package/lib/javascript/JavascriptModulesPlugin.js +44 -21
  203. package/lib/javascript/JavascriptParser.js +159 -93
  204. package/lib/javascript/JavascriptParserHelpers.js +2 -2
  205. package/lib/javascript/StartupHelpers.js +2 -4
  206. package/lib/json/JsonData.js +1 -1
  207. package/lib/json/JsonGenerator.js +4 -5
  208. package/lib/json/JsonModulesPlugin.js +0 -3
  209. package/lib/json/JsonParser.js +4 -2
  210. package/lib/library/AbstractLibraryPlugin.js +2 -2
  211. package/lib/library/AmdLibraryPlugin.js +0 -1
  212. package/lib/library/AssignLibraryPlugin.js +23 -12
  213. package/lib/library/EnableLibraryPlugin.js +7 -11
  214. package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
  215. package/lib/library/JsonpLibraryPlugin.js +5 -2
  216. package/lib/library/ModuleLibraryPlugin.js +88 -43
  217. package/lib/library/SystemLibraryPlugin.js +0 -1
  218. package/lib/library/UmdLibraryPlugin.js +12 -18
  219. package/lib/logging/Logger.js +12 -10
  220. package/lib/logging/createConsoleLogger.js +15 -14
  221. package/lib/logging/truncateArgs.js +1 -1
  222. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  223. package/lib/node/NodeWatchFileSystem.js +4 -4
  224. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  225. package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
  226. package/lib/node/nodeConsole.js +2 -2
  227. package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
  228. package/lib/optimize/ConcatenatedModule.js +142 -100
  229. package/lib/optimize/InnerGraph.js +17 -11
  230. package/lib/optimize/InnerGraphPlugin.js +0 -3
  231. package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
  232. package/lib/optimize/RuntimeChunkPlugin.js +0 -1
  233. package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
  234. package/lib/optimize/SplitChunksPlugin.js +46 -40
  235. package/lib/performance/SizeLimitsPlugin.js +2 -1
  236. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  237. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
  238. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
  239. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  240. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  241. package/lib/rules/BasicMatcherRulePlugin.js +0 -2
  242. package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
  243. package/lib/rules/RuleSetCompiler.js +8 -6
  244. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  245. package/lib/runtime/CompatRuntimeModule.js +0 -1
  246. package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
  247. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  248. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
  249. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  250. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  251. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  252. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  253. package/lib/schemes/DataUriPlugin.js +2 -28
  254. package/lib/schemes/FileUriPlugin.js +5 -2
  255. package/lib/schemes/HttpUriPlugin.js +4 -2
  256. package/lib/schemes/VirtualUrlPlugin.js +11 -11
  257. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  258. package/lib/serialization/ObjectMiddleware.js +30 -19
  259. package/lib/serialization/SerializerMiddleware.js +1 -3
  260. package/lib/serialization/types.js +1 -1
  261. package/lib/sharing/ConsumeSharedModule.js +3 -5
  262. package/lib/sharing/ConsumeSharedPlugin.js +2 -4
  263. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
  264. package/lib/sharing/ProvideSharedModule.js +3 -7
  265. package/lib/sharing/SharePlugin.js +0 -2
  266. package/lib/sharing/ShareRuntimeModule.js +4 -1
  267. package/lib/sharing/resolveMatchedConfigs.js +14 -6
  268. package/lib/sharing/utils.js +0 -6
  269. package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
  270. package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
  271. package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
  272. package/lib/stats/StatsFactory.js +14 -11
  273. package/lib/url/URLParserPlugin.js +2 -4
  274. package/lib/util/ArrayHelpers.js +4 -4
  275. package/lib/util/AsyncQueue.js +1 -0
  276. package/lib/util/LazySet.js +2 -2
  277. package/lib/util/StackedCacheMap.js +0 -2
  278. package/lib/util/TupleSet.js +9 -4
  279. package/lib/util/URLAbsoluteSpecifier.js +0 -1
  280. package/lib/util/WeakTupleMap.js +1 -1
  281. package/lib/util/chainedImports.js +3 -1
  282. package/lib/util/cleverMerge.js +15 -18
  283. package/lib/util/comparators.js +2 -4
  284. package/lib/util/compileBooleanMatcher.js +11 -9
  285. package/lib/util/concatenate.js +1 -2
  286. package/lib/util/create-schema-validation.js +0 -1
  287. package/lib/util/dataURL.js +39 -0
  288. package/lib/util/deprecation.js +29 -31
  289. package/lib/util/deterministicGrouping.js +34 -30
  290. package/lib/util/extractSourceMap.js +319 -0
  291. package/lib/util/findGraphRoots.js +15 -5
  292. package/lib/util/fs.js +29 -8
  293. package/lib/util/semver.js +9 -8
  294. package/lib/util/smartGrouping.js +41 -26
  295. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  296. package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
  297. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  298. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
  299. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
  300. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
  301. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
  302. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
  303. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
  304. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
  305. package/lib/wasm-sync/WebAssemblyParser.js +1 -4
  306. package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
  307. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  308. package/lib/web/JsonpTemplatePlugin.js +0 -1
  309. package/lib/webpack.js +21 -8
  310. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
  311. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  312. package/package.json +13 -13
  313. package/schemas/WebpackOptions.check.js +1 -1
  314. package/schemas/WebpackOptions.json +77 -93
  315. package/schemas/plugins/BannerPlugin.check.js +1 -1
  316. package/schemas/plugins/BannerPlugin.json +4 -0
  317. package/schemas/plugins/IgnorePlugin.json +1 -1
  318. package/schemas/plugins/ProgressPlugin.json +1 -1
  319. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  320. package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
  321. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  322. package/types.d.ts +1140 -505
  323. package/SECURITY.md +0 -9
@@ -12,6 +12,7 @@ const createSchemaValidation = require("./util/create-schema-validation");
12
12
  /** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
13
13
  /** @typedef {import("./Compiler")} Compiler */
14
14
  /** @typedef {import("./NormalModuleFactory").ResolveData} ResolveData */
15
+ /** @typedef {import("./ContextModuleFactory").BeforeContextResolveData} BeforeContextResolveData */
15
16
 
16
17
  const validate = createSchemaValidation(
17
18
  require("../schemas/plugins/IgnorePlugin.check"),
@@ -22,6 +23,8 @@ const validate = createSchemaValidation(
22
23
  }
23
24
  );
24
25
 
26
+ /** @typedef {(resource: string, context: string) => boolean} CheckResourceFn */
27
+
25
28
  const PLUGIN_NAME = "IgnorePlugin";
26
29
 
27
30
  class IgnorePlugin {
@@ -36,8 +39,8 @@ class IgnorePlugin {
36
39
 
37
40
  /**
38
41
  * Note that if "contextRegExp" is given, both the "resourceRegExp" and "contextRegExp" have to match.
39
- * @param {ResolveData} resolveData resolve data
40
- * @returns {false|undefined} returns false when the request should be ignored, otherwise undefined
42
+ * @param {ResolveData | BeforeContextResolveData} resolveData resolve data
43
+ * @returns {false | undefined} returns false when the request should be ignored, otherwise undefined
41
44
  */
42
45
  checkIgnore(resolveData) {
43
46
  if (
@@ -13,18 +13,32 @@ const makeSerializable = require("./util/makeSerializable");
13
13
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
14
14
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
15
 
16
+ /** @typedef {string} InitFragmentKey */
17
+
18
+ /**
19
+ * @template GenerateContext
20
+ * @typedef {object} MaybeMergeableInitFragment
21
+ * @property {InitFragmentKey=} key
22
+ * @property {number} stage
23
+ * @property {number} position
24
+ * @property {(context: GenerateContext) => string | Source | undefined} getContent
25
+ * @property {(context: GenerateContext) => string | Source | undefined} getEndContent
26
+ * @property {(fragments: MaybeMergeableInitFragment<GenerateContext>) => MaybeMergeableInitFragment<GenerateContext>=} merge
27
+ * @property {(fragments: MaybeMergeableInitFragment<GenerateContext>[]) => MaybeMergeableInitFragment<GenerateContext>[]=} mergeAll
28
+ */
29
+
16
30
  /**
17
31
  * @template T
18
- * @param {InitFragment<T>} fragment the init fragment
32
+ * @param {T} fragment the init fragment
19
33
  * @param {number} index index
20
- * @returns {[InitFragment<T>, number]} tuple with both
34
+ * @returns {[T, number]} tuple with both
21
35
  */
22
36
  const extractFragmentIndex = (fragment, index) => [fragment, index];
23
37
 
24
38
  /**
25
39
  * @template T
26
- * @param {[InitFragment<T>, number]} a first pair
27
- * @param {[InitFragment<T>, number]} b second pair
40
+ * @param {[MaybeMergeableInitFragment<T>, number]} a first pair
41
+ * @param {[MaybeMergeableInitFragment<T>, number]} b second pair
28
42
  * @returns {number} sort value
29
43
  */
30
44
  const sortFragmentWithIndex = ([a, i], [b, j]) => {
@@ -37,13 +51,14 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => {
37
51
 
38
52
  /**
39
53
  * @template GenerateContext
54
+ * @implements {MaybeMergeableInitFragment<GenerateContext>}
40
55
  */
41
56
  class InitFragment {
42
57
  /**
43
58
  * @param {string | Source | undefined} content the source code that will be included as initialization code
44
59
  * @param {number} stage category of initialization code (contribute to order)
45
60
  * @param {number} position position in the category (contribute to order)
46
- * @param {string=} key unique key to avoid emitting the same initialization code twice
61
+ * @param {InitFragmentKey=} key unique key to avoid emitting the same initialization code twice
47
62
  * @param {string | Source=} endContent the source code that will be included at the end of the module
48
63
  */
49
64
  constructor(content, stage, position, key, endContent) {
@@ -64,7 +79,7 @@ class InitFragment {
64
79
 
65
80
  /**
66
81
  * @param {GenerateContext} context context
67
- * @returns {string | Source=} the source code that will be included at the end of the module
82
+ * @returns {string | Source | undefined} the source code that will be included at the end of the module
68
83
  */
69
84
  getEndContent(context) {
70
85
  return this.endContent;
@@ -72,9 +87,8 @@ class InitFragment {
72
87
 
73
88
  /**
74
89
  * @template Context
75
- * @template T
76
90
  * @param {Source} source sources
77
- * @param {InitFragment<T>[]} initFragments init fragments
91
+ * @param {MaybeMergeableInitFragment<Context>[]} initFragments init fragments
78
92
  * @param {Context} context context
79
93
  * @returns {Source} source
80
94
  */
@@ -87,14 +101,10 @@ class InitFragment {
87
101
  .sort(sortFragmentWithIndex);
88
102
 
89
103
  // Deduplicate fragments. If a fragment has no key, it is always included.
104
+ /** @type {Map<InitFragmentKey | symbol, MaybeMergeableInitFragment<Context> | MaybeMergeableInitFragment<Context>[]>} */
90
105
  const keyedFragments = new Map();
91
106
  for (const [fragment] of sortedFragments) {
92
- if (
93
- typeof (
94
- /** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment<Context>[]) => InitFragment<Context>[] }} */
95
- (fragment).mergeAll
96
- ) === "function"
97
- ) {
107
+ if (typeof fragment.mergeAll === "function") {
98
108
  if (!fragment.key) {
99
109
  throw new Error(
100
110
  `InitFragment with mergeAll function must have a valid key: ${fragment.constructor.name}`
@@ -110,9 +120,12 @@ class InitFragment {
110
120
  }
111
121
  continue;
112
122
  } else if (typeof fragment.merge === "function") {
113
- const oldValue = keyedFragments.get(fragment.key);
123
+ const key = /** @type {InitFragmentKey} */ (fragment.key);
124
+ const oldValue =
125
+ /** @type {MaybeMergeableInitFragment<Context>} */
126
+ (keyedFragments.get(key));
114
127
  if (oldValue !== undefined) {
115
- keyedFragments.set(fragment.key, fragment.merge(oldValue));
128
+ keyedFragments.set(key, fragment.merge(oldValue));
116
129
  continue;
117
130
  }
118
131
  }
@@ -123,10 +136,19 @@ class InitFragment {
123
136
  const endContents = [];
124
137
  for (let fragment of keyedFragments.values()) {
125
138
  if (Array.isArray(fragment)) {
126
- fragment = fragment[0].mergeAll(fragment);
139
+ fragment =
140
+ /** @type {[MaybeMergeableInitFragment<Context> & { mergeAll: (fragments: MaybeMergeableInitFragment<Context>[]) => MaybeMergeableInitFragment<Context>[] }, ...MaybeMergeableInitFragment<Context>[]]} */
141
+ (fragment)[0].mergeAll(fragment);
127
142
  }
128
- concatSource.add(fragment.getContent(context));
129
- const endContent = fragment.getEndContent(context);
143
+ const content =
144
+ /** @type {MaybeMergeableInitFragment<Context>} */
145
+ (fragment).getContent(context);
146
+ if (content) {
147
+ concatSource.add(content);
148
+ }
149
+ const endContent =
150
+ /** @type {MaybeMergeableInitFragment<Context>} */
151
+ (fragment).getEndContent(context);
130
152
  if (endContent) {
131
153
  endContents.push(endContent);
132
154
  }
@@ -170,16 +192,6 @@ class InitFragment {
170
192
 
171
193
  makeSerializable(InitFragment, "webpack/lib/InitFragment");
172
194
 
173
- InitFragment.prototype.merge =
174
- /** @type {TODO} */
175
- (undefined);
176
- InitFragment.prototype.getImported =
177
- /** @type {TODO} */
178
- (undefined);
179
- InitFragment.prototype.setImported =
180
- /** @type {TODO} */
181
- (undefined);
182
-
183
195
  InitFragment.STAGE_CONSTANTS = 10;
184
196
  InitFragment.STAGE_ASYNC_BOUNDARY = 20;
185
197
  InitFragment.STAGE_HARMONY_EXPORTS = 30;
@@ -8,7 +8,6 @@
8
8
  const WebpackError = require("./WebpackError");
9
9
  const makeSerializable = require("./util/makeSerializable");
10
10
 
11
- /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
12
11
  /** @typedef {import("./Module")} Module */
13
12
 
14
13
  class InvalidDependenciesModuleWarning extends WebpackError {
@@ -15,12 +15,13 @@ const { dirname, mkdirp } = require("./util/fs");
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
16
  /** @typedef {import("./Compiler").IntermediateFileSystem} IntermediateFileSystem */
17
17
  /** @typedef {import("./Module").BuildMeta} BuildMeta */
18
+ /** @typedef {import("./ExportsInfo").ExportInfoName} ExportInfoName */
18
19
 
19
20
  /**
20
21
  * @typedef {object} ManifestModuleData
21
- * @property {string | number} id
22
+ * @property {ModuleId} id
22
23
  * @property {BuildMeta=} buildMeta
23
- * @property {boolean | string[]=} exports
24
+ * @property {ExportInfoName[]=} exports
24
25
  */
25
26
 
26
27
  /**
@@ -92,10 +93,7 @@ class LibManifestPlugin {
92
93
  continue;
93
94
  }
94
95
  const ident = module.libIdent({
95
- context:
96
- this.options.context ||
97
- /** @type {string} */
98
- (compiler.options.context),
96
+ context: this.options.context || compiler.context,
99
97
  associatedObjectForCache: compiler.root
100
98
  });
101
99
  if (ident) {
@@ -11,7 +11,6 @@ const createSchemaValidation = require("./util/create-schema-validation");
11
11
 
12
12
  /** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
13
13
  /** @typedef {import("./Compiler")} Compiler */
14
- /** @typedef {import("./ModuleFilenameHelpers").Matcher} Matcher */
15
14
  /** @typedef {import("./ModuleFilenameHelpers").MatchObject} MatchObject */
16
15
 
17
16
  /**
@@ -39,15 +38,7 @@ class LoaderOptionsPlugin {
39
38
  // If no options are set then generate empty options object
40
39
  if (typeof options !== "object") options = {};
41
40
  if (!options.test) {
42
- /** @type {Partial<RegExp>} */
43
- const defaultTrueMockRegExp = {
44
- test: () => true
45
- };
46
-
47
- /** @type {RegExp} */
48
- options.test =
49
- /** @type {RegExp} */
50
- (defaultTrueMockRegExp);
41
+ options.test = () => true;
51
42
  }
52
43
  this.options = options;
53
44
  }
@@ -11,7 +11,6 @@ const RuntimeGlobals = require("./RuntimeGlobals");
11
11
  const memoize = require("./util/memoize");
12
12
 
13
13
  /** @typedef {import("tapable").Tap} Tap */
14
- /** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
15
14
  /** @typedef {import("webpack-sources").Source} Source */
16
15
  /** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
17
16
  /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
@@ -19,19 +18,13 @@ const memoize = require("./util/memoize");
19
18
  /** @typedef {import("./Compilation")} Compilation */
20
19
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
21
20
  /** @typedef {import("./Compilation").InterpolatedPathAndAssetInfo} InterpolatedPathAndAssetInfo */
22
- /** @typedef {import("./Module")} Module} */
23
- /** @typedef {import("./util/Hash")} Hash} */
24
- /** @typedef {import("./DependencyTemplates")} DependencyTemplates} */
25
- /** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext} */
26
- /** @typedef {import("./javascript/JavascriptModulesPlugin").RenderBootstrapContext} RenderBootstrapContext} */
27
- /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkHashContext} ChunkHashContext} */
28
- /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate} */
29
- /** @typedef {import("./ModuleGraph")} ModuleGraph} */
30
- /** @typedef {import("./ChunkGraph")} ChunkGraph} */
31
- /** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions} */
32
- /** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry} */
33
- /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath} */
34
- /** @typedef {import("./TemplatedPathPlugin").PathData} PathData} */
21
+ /** @typedef {import("./util/Hash")} Hash */
22
+ /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
23
+ /** @typedef {import("./javascript/JavascriptModulesPlugin").RenderBootstrapContext} RenderBootstrapContext */
24
+ /** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */
25
+ /** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
26
+ /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
27
+ /** @typedef {import("./TemplatedPathPlugin").PathData} PathData */
35
28
  /**
36
29
  * @template T
37
30
  * @typedef {import("tapable").IfSet<T>} IfSet
@@ -324,11 +317,7 @@ class MainTemplate {
324
317
  * @param {PathData} options context data
325
318
  * @returns {string} interpolated path
326
319
  */ (options) =>
327
- compilation.getAssetPath(
328
- /** @type {string} */
329
- (compilation.outputOptions.publicPath),
330
- options
331
- ),
320
+ compilation.getAssetPath(compilation.outputOptions.publicPath, options),
332
321
  "MainTemplate.getPublicPath is deprecated (use Compilation.getAssetPath(compilation.outputOptions.publicPath, options) instead)",
333
322
  "DEP_WEBPACK_MAIN_TEMPLATE_GET_PUBLIC_PATH"
334
323
  );
package/lib/Module.js CHANGED
@@ -17,7 +17,7 @@ const makeSerializable = require("./util/makeSerializable");
17
17
 
18
18
  /** @typedef {import("webpack-sources").Source} Source */
19
19
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
20
- /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
20
+ /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
21
21
  /** @typedef {import("./Chunk")} Chunk */
22
22
  /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
23
23
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
@@ -30,15 +30,19 @@ const makeSerializable = require("./util/makeSerializable");
30
30
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
31
31
  /** @typedef {import("./DependencyTemplate").CssData} CssData */
32
32
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
33
- /** @typedef {import("./ExportsInfo").UsageStateType} UsageStateType */
34
33
  /** @typedef {import("./FileSystemInfo")} FileSystemInfo */
35
34
  /** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
36
35
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
37
36
  /** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
37
+ /** @typedef {import("./ModuleGraph").OptimizationBailouts} OptimizationBailouts */
38
38
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
39
39
  /** @typedef {import("./RequestShortener")} RequestShortener */
40
40
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
41
41
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
42
+ /**
43
+ * @template T
44
+ * @typedef {import("./InitFragment")<T>} InitFragment
45
+ */
42
46
  /** @typedef {import("./WebpackError")} WebpackError */
43
47
  /** @typedef {import("./json/JsonData")} JsonData */
44
48
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -54,11 +58,6 @@ const makeSerializable = require("./util/makeSerializable");
54
58
  * @typedef {import("./util/LazySet")<T>} LazySet<T>
55
59
  */
56
60
 
57
- /**
58
- * @template T
59
- * @typedef {import("./util/SortableSet")<T>} SortableSet<T>
60
- */
61
-
62
61
  /**
63
62
  * @typedef {object} SourceContext
64
63
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -94,10 +93,16 @@ const makeSerializable = require("./util/makeSerializable");
94
93
  /** @typedef {Set<string>} RuntimeRequirements */
95
94
  /** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
96
95
 
96
+ /** @typedef {Map<"topLevelDeclarations", Set<string>> & Map<"chunkInitFragments", InitFragment<EXPECTED_ANY>[]>} KnownCodeGenerationResultDataForJavascriptModules */
97
+ /** @typedef {Map<"url", { ["css-url"]: string }>} KnownCodeGenerationResultDataForCssModules */
98
+ /** @typedef {Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"fullContentHash", string>} KnownCodeGenerationResultDataForAssetModules */
99
+ /** @typedef {Map<"share-init", [{ shareScope: string, initStage: number, init: string }]>} KnownCodeGenerationResultForSharing */
100
+ /** @typedef {KnownCodeGenerationResultDataForJavascriptModules & KnownCodeGenerationResultDataForCssModules & KnownCodeGenerationResultDataForAssetModules & KnownCodeGenerationResultForSharing & Map<string, EXPECTED_ANY>} CodeGenerationResultData */
101
+
97
102
  /**
98
103
  * @typedef {object} CodeGenerationResult
99
104
  * @property {Map<string, Source>} sources the resulting sources for all source types
100
- * @property {Map<string, TODO>=} data the resulting data for all source types
105
+ * @property {CodeGenerationResultData=} data the resulting data for all source types
101
106
  * @property {ReadOnlyRuntimeRequirements | null} runtimeRequirements the runtime requirements
102
107
  * @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
103
108
  */
@@ -113,6 +118,7 @@ const makeSerializable = require("./util/makeSerializable");
113
118
  * @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
114
119
  * @property {(false | "redirect" | "redirect-warn")=} defaultObject
115
120
  * @property {boolean=} strictHarmonyModule
121
+ * @property {boolean=} treatAsCommonJs
116
122
  * @property {boolean=} async
117
123
  * @property {boolean=} sideEffectFree
118
124
  * @property {boolean=} isCSSModule
@@ -121,6 +127,8 @@ const makeSerializable = require("./util/makeSerializable");
121
127
  * @property {string=} factoryExportsBinding
122
128
  */
123
129
 
130
+ /** @typedef {LazySet<string>} FileSystemDependencies */
131
+
124
132
  /**
125
133
  * @typedef {object} KnownBuildInfo
126
134
  * @property {boolean=} cacheable
@@ -131,10 +139,10 @@ const makeSerializable = require("./util/makeSerializable");
131
139
  * @property {string=} moduleConcatenationBailout using in CommonJs
132
140
  * @property {boolean=} needCreateRequire using in APIPlugin
133
141
  * @property {string=} resourceIntegrity using in HttpUriPlugin
134
- * @property {LazySet<string>=} fileDependencies using in NormalModule
135
- * @property {LazySet<string>=} contextDependencies using in NormalModule
136
- * @property {LazySet<string>=} missingDependencies using in NormalModule
137
- * @property {LazySet<string>=} buildDependencies using in NormalModule
142
+ * @property {FileSystemDependencies=} fileDependencies using in NormalModule
143
+ * @property {FileSystemDependencies=} contextDependencies using in NormalModule
144
+ * @property {FileSystemDependencies=} missingDependencies using in NormalModule
145
+ * @property {FileSystemDependencies=} buildDependencies using in NormalModule
138
146
  * @property {ValueCacheVersions=} valueDependencies using in NormalModule
139
147
  * @property {Record<string, Source>=} assets using in NormalModule
140
148
  * @property {Map<string, AssetInfo | undefined>=} assetsInfo using in NormalModule
@@ -151,7 +159,8 @@ const makeSerializable = require("./util/makeSerializable");
151
159
  * @property {Set<string>=} topLevelDeclarations top level declaration names
152
160
  */
153
161
 
154
- /** @typedef {Map<string, string | Set<string>>} ValueCacheVersions */
162
+ /** @typedef {string | Set<string>} ValueCacheVersion */
163
+ /** @typedef {Map<string, ValueCacheVersion>} ValueCacheVersions */
155
164
 
156
165
  /**
157
166
  * @typedef {object} NeedBuildContext
@@ -193,6 +202,9 @@ const deprecatedNeedRebuild = util.deprecate(
193
202
  "DEP_WEBPACK_MODULE_NEED_REBUILD"
194
203
  );
195
204
 
205
+ /** @typedef {string} LibIdent */
206
+ /** @typedef {string} NameForCondition */
207
+
196
208
  /** @typedef {(requestShortener: RequestShortener) => string} OptimizationBailoutFunction */
197
209
 
198
210
  class Module extends DependenciesBlock {
@@ -412,7 +424,7 @@ class Module extends DependenciesBlock {
412
424
 
413
425
  /**
414
426
  * @deprecated
415
- * @returns {(string | OptimizationBailoutFunction)[]} list
427
+ * @returns {OptimizationBailouts} list
416
428
  */
417
429
  get optimizationBailout() {
418
430
  return ModuleGraph.getModuleGraphForModule(
@@ -967,14 +979,14 @@ class Module extends DependenciesBlock {
967
979
 
968
980
  /**
969
981
  * @param {LibIdentOptions} options options
970
- * @returns {string | null} an identifier for library inclusion
982
+ * @returns {LibIdent | null} an identifier for library inclusion
971
983
  */
972
984
  libIdent(options) {
973
985
  return null;
974
986
  }
975
987
 
976
988
  /**
977
- * @returns {string | null} absolute path which should be used for condition matching (usually the resource path)
989
+ * @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
978
990
  */
979
991
  nameForCondition() {
980
992
  return null;
@@ -1091,10 +1103,10 @@ class Module extends DependenciesBlock {
1091
1103
  }
1092
1104
 
1093
1105
  /**
1094
- * @param {LazySet<string>} fileDependencies set where file dependencies are added to
1095
- * @param {LazySet<string>} contextDependencies set where context dependencies are added to
1096
- * @param {LazySet<string>} missingDependencies set where missing dependencies are added to
1097
- * @param {LazySet<string>} buildDependencies set where build dependencies are added to
1106
+ * @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
1107
+ * @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
1108
+ * @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
1109
+ * @param {FileSystemDependencies} buildDependencies set where build dependencies are added to
1098
1110
  */
1099
1111
  addCacheDependencies(
1100
1112
  fileDependencies,
@@ -23,7 +23,7 @@
23
23
  /**
24
24
  * @typedef {object} ModuleFactoryCreateDataContextInfo
25
25
  * @property {string} issuer
26
- * @property {IssuerLayer=} issuerLayer
26
+ * @property {IssuerLayer} issuerLayer
27
27
  * @property {string=} compiler
28
28
  */
29
29
 
@@ -10,13 +10,12 @@ const { DEFAULTS } = require("./config/defaults");
10
10
  const createHash = require("./util/createHash");
11
11
  const memoize = require("./util/memoize");
12
12
 
13
- /** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */
14
13
  /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
15
14
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
16
15
  /** @typedef {import("./Module")} Module */
17
16
  /** @typedef {import("./RequestShortener")} RequestShortener */
18
17
 
19
- /** @typedef {string | RegExp | (string | RegExp)[]} Matcher */
18
+ /** @typedef {string | RegExp | ((str: string) => boolean) | (string | RegExp | ((str: string) => boolean))[]} Matcher */
20
19
  /** @typedef {{ test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
21
20
 
22
21
  const ModuleFilenameHelpers = module.exports;
@@ -94,10 +93,10 @@ const getHash =
94
93
  * Returns a lazy object. The object is lazy in the sense that the properties are
95
94
  * only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
96
95
  * @param {Record<string, () => T>} obj the object to convert to a lazy access object
97
- * @returns {T} the lazy access object
96
+ * @returns {Record<string, T>} the lazy access object
98
97
  */
99
98
  const lazyObject = (obj) => {
100
- const newObj = /** @type {T} */ ({});
99
+ const newObj = /** @type {Record<string, T>} */ ({});
101
100
  for (const key of Object.keys(obj)) {
102
101
  const fn = obj[key];
103
102
  Object.defineProperty(newObj, key, {
@@ -117,8 +116,21 @@ const lazyObject = (obj) => {
117
116
  };
118
117
 
119
118
  const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
120
-
121
- /** @typedef {((context: TODO) => string)} ModuleFilenameTemplateFunction */
119
+ /**
120
+ * @typedef {object} ModuleFilenameTemplateContext
121
+ * @property {string} identifier the identifier of the module
122
+ * @property {string} shortIdentifier the shortened identifier of the module
123
+ * @property {string} resource the resource of the module request
124
+ * @property {string} resourcePath the resource path of the module request
125
+ * @property {string} absoluteResourcePath the absolute resource path of the module request
126
+ * @property {string} loaders the loaders of the module request
127
+ * @property {string} allLoaders the all loaders of the module request
128
+ * @property {string} query the query of the module identifier
129
+ * @property {string} moduleId the module id of the module
130
+ * @property {string} hash the hash of the module identifier
131
+ * @property {string} namespace the module namespace
132
+ */
133
+ /** @typedef {((context: ModuleFilenameTemplateContext) => string)} ModuleFilenameTemplateFunction */
122
134
  /** @typedef {string | ModuleFilenameTemplateFunction} ModuleFilenameTemplate */
123
135
 
124
136
  /**
@@ -190,19 +202,22 @@ ModuleFilenameHelpers.createFilename = (
190
202
  };
191
203
  if (typeof opts.moduleFilenameTemplate === "function") {
192
204
  return opts.moduleFilenameTemplate(
193
- lazyObject({
194
- identifier,
195
- shortIdentifier,
196
- resource,
197
- resourcePath: memoize(resourcePath),
198
- absoluteResourcePath: memoize(absoluteResourcePath),
199
- loaders: memoize(loaders),
200
- allLoaders: memoize(allLoaders),
201
- query: memoize(query),
202
- moduleId: memoize(moduleId),
203
- hash: memoize(hash),
204
- namespace: () => opts.namespace
205
- })
205
+ /** @type {ModuleFilenameTemplateContext} */
206
+ (
207
+ lazyObject({
208
+ identifier,
209
+ shortIdentifier,
210
+ resource,
211
+ resourcePath: memoize(resourcePath),
212
+ absoluteResourcePath: memoize(absoluteResourcePath),
213
+ loaders: memoize(loaders),
214
+ allLoaders: memoize(allLoaders),
215
+ query: memoize(query),
216
+ moduleId: memoize(moduleId),
217
+ hash: memoize(hash),
218
+ namespace: () => opts.namespace
219
+ })
220
+ )
206
221
  );
207
222
  }
208
223
 
@@ -319,13 +334,15 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
319
334
  */
320
335
  const matchPart = (str, test) => {
321
336
  if (!test) return true;
322
- if (Array.isArray(test)) {
323
- return test.some((test) => matchPart(str, test));
324
- }
325
- if (typeof test === "string") {
337
+ if (test instanceof RegExp) {
338
+ return test.test(str);
339
+ } else if (typeof test === "string") {
326
340
  return str.startsWith(test);
341
+ } else if (typeof test === "function") {
342
+ return test(str);
327
343
  }
328
- return test.test(str);
344
+
345
+ return test.some((test) => matchPart(str, test));
329
346
  };
330
347
 
331
348
  ModuleFilenameHelpers.matchPart = matchPart;