webpack 5.104.1 → 5.105.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/bin/webpack.js +6 -3
  2. package/lib/APIPlugin.js +85 -15
  3. package/lib/AbstractMethodError.js +1 -0
  4. package/lib/AsyncDependenciesBlock.js +13 -1
  5. package/lib/AsyncDependencyToInitialChunkError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +2 -0
  8. package/lib/CacheFacade.js +2 -2
  9. package/lib/CaseSensitiveModulesWarning.js +1 -0
  10. package/lib/Chunk.js +8 -4
  11. package/lib/ChunkGraph.js +30 -9
  12. package/lib/ChunkGroup.js +6 -3
  13. package/lib/ChunkRenderError.js +2 -0
  14. package/lib/CleanPlugin.js +4 -1
  15. package/lib/CodeGenerationError.js +7 -1
  16. package/lib/CodeGenerationResults.js +10 -3
  17. package/lib/CommentCompilationWarning.js +2 -1
  18. package/lib/Compilation.js +280 -236
  19. package/lib/Compiler.js +3 -2
  20. package/lib/ConcatenationScope.js +2 -1
  21. package/lib/ConcurrentCompilationError.js +3 -3
  22. package/lib/ContextModule.js +248 -111
  23. package/lib/ContextModuleFactory.js +14 -2
  24. package/lib/DefinePlugin.js +3 -1
  25. package/lib/DelegatedModule.js +6 -0
  26. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  27. package/lib/Dependency.js +6 -1
  28. package/lib/DependencyTemplates.js +3 -2
  29. package/lib/DllModule.js +2 -0
  30. package/lib/DllReferencePlugin.js +1 -0
  31. package/lib/DotenvPlugin.js +11 -5
  32. package/lib/DynamicEntryPlugin.js +1 -0
  33. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  34. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  35. package/lib/ExportsInfo.js +8 -4
  36. package/lib/ExternalModule.js +16 -0
  37. package/lib/FalseIIFEUmdWarning.js +1 -0
  38. package/lib/FileSystemInfo.js +49 -25
  39. package/lib/FlagDependencyExportsPlugin.js +8 -1
  40. package/lib/FlagDependencyUsagePlugin.js +9 -7
  41. package/lib/HarmonyLinkingError.js +1 -0
  42. package/lib/HookWebpackError.js +2 -0
  43. package/lib/HotModuleReplacementPlugin.js +16 -2
  44. package/lib/InitFragment.js +1 -0
  45. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  46. package/lib/LibManifestPlugin.js +1 -0
  47. package/lib/ManifestPlugin.js +4 -1
  48. package/lib/Module.js +7 -4
  49. package/lib/ModuleBuildError.js +3 -1
  50. package/lib/ModuleDependencyError.js +1 -0
  51. package/lib/ModuleDependencyWarning.js +1 -0
  52. package/lib/ModuleError.js +2 -1
  53. package/lib/ModuleFilenameHelpers.js +2 -1
  54. package/lib/ModuleGraph.js +3 -0
  55. package/lib/ModuleGraphConnection.js +10 -1
  56. package/lib/ModuleHashingError.js +2 -0
  57. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  58. package/lib/ModuleNotFoundError.js +1 -0
  59. package/lib/ModuleParseError.js +5 -1
  60. package/lib/ModuleProfile.js +1 -1
  61. package/lib/ModuleRestoreError.js +2 -0
  62. package/lib/ModuleSourceTypeConstants.js +1 -11
  63. package/lib/ModuleStoreError.js +2 -0
  64. package/lib/ModuleWarning.js +3 -1
  65. package/lib/MultiCompiler.js +11 -7
  66. package/lib/MultiWatching.js +2 -2
  67. package/lib/NoModeWarning.js +1 -0
  68. package/lib/NodeStuffInWebError.js +1 -0
  69. package/lib/NormalModule.js +26 -5
  70. package/lib/NormalModuleFactory.js +20 -4
  71. package/lib/OptionsApply.js +3 -1
  72. package/lib/ProgressPlugin.js +4 -0
  73. package/lib/RawModule.js +2 -0
  74. package/lib/RuntimeModule.js +10 -0
  75. package/lib/RuntimePlugin.js +7 -9
  76. package/lib/RuntimeTemplate.js +14 -7
  77. package/lib/SourceMapDevToolPlugin.js +30 -23
  78. package/lib/Template.js +10 -5
  79. package/lib/TemplatedPathPlugin.js +4 -2
  80. package/lib/UnhandledSchemeError.js +1 -0
  81. package/lib/UnsupportedFeatureWarning.js +1 -0
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  83. package/lib/WatchIgnorePlugin.js +1 -1
  84. package/lib/Watching.js +5 -0
  85. package/lib/WebpackError.js +4 -0
  86. package/lib/WebpackOptionsApply.js +60 -40
  87. package/lib/asset/AssetBytesGenerator.js +1 -0
  88. package/lib/asset/AssetGenerator.js +9 -3
  89. package/lib/asset/AssetModulesPlugin.js +33 -2
  90. package/lib/asset/AssetSourceGenerator.js +1 -0
  91. package/lib/asset/RawDataUrlModule.js +4 -0
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +31 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  95. package/lib/cache/PackFileCacheStrategy.js +41 -8
  96. package/lib/cache/getLazyHashedEtag.js +13 -4
  97. package/lib/cache/mergeEtags.js +3 -1
  98. package/lib/cli.js +3 -1
  99. package/lib/config/defaults.js +65 -44
  100. package/lib/config/normalization.js +96 -0
  101. package/lib/container/ContainerEntryModule.js +4 -0
  102. package/lib/container/FallbackModule.js +2 -0
  103. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  104. package/lib/container/RemoteModule.js +19 -0
  105. package/lib/css/CssGenerator.js +31 -4
  106. package/lib/css/CssModulesPlugin.js +26 -30
  107. package/lib/css/CssParser.js +12 -9
  108. package/lib/debug/ProfilingPlugin.js +1 -0
  109. package/lib/dependencies/AMDDefineDependency.js +3 -1
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  111. package/lib/dependencies/AMDPlugin.js +1 -1
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  113. package/lib/dependencies/CachedConstDependency.js +1 -0
  114. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  118. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  120. package/lib/dependencies/ConstDependency.js +1 -0
  121. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  122. package/lib/dependencies/ContextElementDependency.js +1 -0
  123. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  124. package/lib/dependencies/CssIcssExportDependency.js +5 -4
  125. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  126. package/lib/dependencies/CssUrlDependency.js +2 -3
  127. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  128. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  129. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  130. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
  131. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  133. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  134. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  135. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
  136. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  137. package/lib/dependencies/ImportDependency.js +1 -0
  138. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  139. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  140. package/lib/dependencies/ImportParserPlugin.js +7 -12
  141. package/lib/dependencies/LoaderPlugin.js +3 -0
  142. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +1 -0
  144. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  145. package/lib/dependencies/ProvidedDependency.js +1 -0
  146. package/lib/dependencies/RequireContextPlugin.js +1 -0
  147. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  148. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  149. package/lib/dependencies/WorkerDependency.js +9 -3
  150. package/lib/dependencies/WorkerPlugin.js +1 -0
  151. package/lib/dependencies/getFunctionExpression.js +3 -1
  152. package/lib/errors/BuildCycleError.js +4 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  156. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  157. package/lib/hmr/lazyCompilationBackend.js +3 -2
  158. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
  159. package/lib/ids/IdHelpers.js +10 -8
  160. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
  161. package/lib/ids/SyncModuleIdsPlugin.js +5 -1
  162. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  163. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  164. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  165. package/lib/javascript/JavascriptParser.js +47 -14
  166. package/lib/json/JsonParser.js +6 -0
  167. package/lib/library/AbstractLibraryPlugin.js +4 -1
  168. package/lib/library/AmdLibraryPlugin.js +2 -1
  169. package/lib/library/AssignLibraryPlugin.js +6 -2
  170. package/lib/library/EnableLibraryPlugin.js +1 -0
  171. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  172. package/lib/library/JsonpLibraryPlugin.js +1 -1
  173. package/lib/library/ModuleLibraryPlugin.js +130 -13
  174. package/lib/library/SystemLibraryPlugin.js +4 -1
  175. package/lib/library/UmdLibraryPlugin.js +4 -3
  176. package/lib/logging/createConsoleLogger.js +3 -0
  177. package/lib/logging/truncateArgs.js +1 -1
  178. package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
  179. package/lib/node/NodeTargetPlugin.js +1 -0
  180. package/lib/node/NodeWatchFileSystem.js +3 -0
  181. package/lib/node/nodeConsole.js +18 -1
  182. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  183. package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
  184. package/lib/optimize/ConcatenatedModule.js +33 -19
  185. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  186. package/lib/optimize/InnerGraph.js +5 -3
  187. package/lib/optimize/InnerGraphPlugin.js +25 -25
  188. package/lib/optimize/MangleExportsPlugin.js +14 -2
  189. package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
  190. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  191. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  192. package/lib/optimize/RealContentHashPlugin.js +35 -27
  193. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  194. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  195. package/lib/optimize/SplitChunksPlugin.js +14 -3
  196. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  197. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  198. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  199. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  200. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  201. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  202. package/lib/rules/RuleSetCompiler.js +2 -0
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  204. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  205. package/lib/runtime/CompatRuntimeModule.js +1 -0
  206. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  207. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  208. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  209. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  210. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  211. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
  212. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  213. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  214. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  215. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  216. package/lib/schemes/HttpUriPlugin.js +27 -7
  217. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  218. package/lib/serialization/BinaryMiddleware.js +4 -0
  219. package/lib/serialization/FileMiddleware.js +9 -4
  220. package/lib/serialization/ObjectMiddleware.js +34 -11
  221. package/lib/serialization/PlainObjectSerializer.js +2 -0
  222. package/lib/sharing/ConsumeSharedModule.js +60 -0
  223. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  224. package/lib/sharing/ProvideSharedModule.js +4 -0
  225. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  226. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  227. package/lib/sharing/utils.js +8 -6
  228. package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
  229. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  230. package/lib/stats/StatsFactory.js +2 -2
  231. package/lib/url/URLParserPlugin.js +4 -3
  232. package/lib/util/AppendOnlyStackedSet.js +57 -0
  233. package/lib/util/Hash.js +1 -0
  234. package/lib/util/IterableHelpers.js +1 -0
  235. package/lib/util/LazyBucketSortedSet.js +1 -0
  236. package/lib/util/LazySet.js +1 -0
  237. package/lib/util/ParallelismFactorCalculator.js +1 -0
  238. package/lib/util/SortableSet.js +1 -0
  239. package/lib/util/StringXor.js +1 -0
  240. package/lib/util/binarySearchBounds.js +15 -8
  241. package/lib/util/chainedImports.js +1 -1
  242. package/lib/util/cleverMerge.js +6 -1
  243. package/lib/util/comparators.js +21 -1
  244. package/lib/util/compileBooleanMatcher.js +3 -3
  245. package/lib/util/concatenate.js +3 -2
  246. package/lib/util/conventions.js +3 -2
  247. package/lib/util/deterministicGrouping.js +13 -1
  248. package/lib/util/extractSourceMap.js +12 -13
  249. package/lib/util/fs.js +15 -19
  250. package/lib/util/hash/BatchedHash.js +3 -0
  251. package/lib/util/hash/BulkUpdateHash.js +7 -1
  252. package/lib/util/hash/hash-digest.js +1 -0
  253. package/lib/util/hash/wasm-hash.js +16 -1
  254. package/lib/util/identifier.js +7 -2
  255. package/lib/util/magicComment.js +1 -1
  256. package/lib/util/propertyName.js +1 -1
  257. package/lib/util/registerExternalSerializer.js +1 -0
  258. package/lib/util/runtime.js +15 -1
  259. package/lib/util/semver.js +1 -0
  260. package/lib/util/serialization.js +2 -2
  261. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
  262. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  263. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  264. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  265. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  266. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  267. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  268. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  269. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  270. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  271. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  272. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  273. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  274. package/lib/webpack.js +13 -3
  275. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  276. package/package.json +20 -28
  277. package/schemas/WebpackOptions.check.js +1 -1
  278. package/schemas/WebpackOptions.json +71 -5
  279. package/types.d.ts +339 -93
@@ -84,7 +84,7 @@ function getGlobalObject(definition) {
84
84
  // iife
85
85
  // call expression
86
86
  // expression in parentheses
87
- /^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
87
+ /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
88
88
  ) {
89
89
  return trimmed;
90
90
  }
@@ -356,6 +356,7 @@ class RuntimeTemplate {
356
356
  * @returns {string} comment
357
357
  */
358
358
  comment({ request, chunkName, chunkReason, message, exportName }) {
359
+ /** @type {string} */
359
360
  let content;
360
361
  if (this.outputOptions.pathinfo) {
361
362
  content = [message, request, chunkName, chunkReason]
@@ -678,6 +679,7 @@ class RuntimeTemplate {
678
679
  runtimeRequirements
679
680
  });
680
681
 
682
+ /** @type {string} */
681
683
  let appending;
682
684
  let idExpr = JSON.stringify(chunkGraph.getModuleId(module));
683
685
  const comment = this.comment({
@@ -711,7 +713,10 @@ class RuntimeTemplate {
711
713
 
712
714
  if (isModuleDeferred) {
713
715
  runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
714
- const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
716
+
717
+ let mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
718
+ if (mode) mode = `${mode} | 16`;
719
+
715
720
  const asyncDeps = Array.from(
716
721
  getOutgoingAsyncModules(chunkGraph.moduleGraph, module),
717
722
  (m) => chunkGraph.getModuleId(m)
@@ -852,14 +857,14 @@ class RuntimeTemplate {
852
857
  * @param {object} options options object
853
858
  * @param {boolean=} options.update whether a new variable should be created or the existing one updated
854
859
  * @param {Module} options.module the module
860
+ * @param {Module} options.originModule module in which the statement is emitted
855
861
  * @param {ModuleGraph} options.moduleGraph the module graph
856
862
  * @param {ChunkGraph} options.chunkGraph the chunk graph
857
- * @param {string} options.request the request that should be printed as comment
863
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
858
864
  * @param {string} options.importVar name of the import variable
859
- * @param {Module} options.originModule module in which the statement is emitted
865
+ * @param {string=} options.request the request that should be printed as comment
860
866
  * @param {boolean=} options.weak true, if this is a weak dependency
861
- * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
862
- * @param {ModuleDependency} options.dependency module dependency
867
+ * @param {ModuleDependency=} options.dependency module dependency
863
868
  * @returns {[string, string]} the import statement and the compat statement
864
869
  */
865
870
  importStatement({
@@ -918,6 +923,8 @@ class RuntimeTemplate {
918
923
  (originModule.buildMeta).strictHarmonyModule
919
924
  );
920
925
  runtimeRequirements.add(RuntimeGlobals.require);
926
+
927
+ /** @type {string} */
921
928
  let importContent;
922
929
 
923
930
  const isModuleDeferred =
@@ -961,7 +968,7 @@ class RuntimeTemplate {
961
968
  * @param {string | string[]} options.exportName the export name
962
969
  * @param {Module} options.originModule the origin module
963
970
  * @param {boolean | undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
964
- * @param {boolean} options.isCall true, if expression will be called
971
+ * @param {boolean | undefined} options.isCall true, if expression will be called
965
972
  * @param {boolean | null} options.callContext when false, call context will not be preserved
966
973
  * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
967
974
  * @param {string} options.importVar the identifier name of the import variable
@@ -51,9 +51,9 @@ const validate = createSchemaValidation(
51
51
  */
52
52
 
53
53
  const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g;
54
- const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(:\w+)?\]/;
54
+ const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(?::\w+)?\]/;
55
55
  const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i;
56
- const CSS_EXTENSION_DETECT_REGEXP = /\.css($|\?)/i;
56
+ const CSS_EXTENSION_DETECT_REGEXP = /\.css(?:$|\?)/i;
57
57
  const MAP_URL_COMMENT_REGEXP = /\[map\]/g;
58
58
  const URL_COMMENT_REGEXP = /\[url\]/g;
59
59
  const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/;
@@ -93,18 +93,19 @@ const getTaskForFile = (
93
93
  compilation,
94
94
  cacheItem
95
95
  ) => {
96
+ /** @type {string | Buffer} */
96
97
  let source;
97
- /** @type {RawSourceMap} */
98
+ /** @type {null | RawSourceMap} */
98
99
  let sourceMap;
99
100
  /**
100
101
  * Check if asset can build source map
101
102
  */
102
103
  if (asset.sourceAndMap) {
103
104
  const sourceAndMap = asset.sourceAndMap(options);
104
- sourceMap = /** @type {RawSourceMap} */ (sourceAndMap.map);
105
+ sourceMap = sourceAndMap.map;
105
106
  source = sourceAndMap.source;
106
107
  } else {
107
- sourceMap = /** @type {RawSourceMap} */ (asset.map(options));
108
+ sourceMap = asset.map(options);
108
109
  source = asset.source();
109
110
  }
110
111
  if (!sourceMap || typeof source !== "string") return;
@@ -173,6 +174,7 @@ class SourceMapDevToolPlugin {
173
174
  const options = this.options;
174
175
  options.test = options.test || CSS_AND_JS_MODULE_EXTENSIONS_REGEXP;
175
176
 
177
+ /** @type {(filename: string) => boolean} */
176
178
  const matchObject = ModuleFilenameHelpers.matchObject.bind(
177
179
  undefined,
178
180
  options
@@ -310,7 +312,7 @@ class SourceMapDevToolPlugin {
310
312
 
311
313
  if (
312
314
  typeof module === "string" &&
313
- /^(data|https?):/.test(module)
315
+ /^(?:data|https?):/.test(module)
314
316
  ) {
315
317
  moduleToSourceNameMapping.set(module, module);
316
318
  continue;
@@ -416,7 +418,9 @@ class SourceMapDevToolPlugin {
416
418
  asyncLib.each(
417
419
  tasks,
418
420
  (task, callback) => {
421
+ /** @type {Record<string, Source>} */
419
422
  const assets = Object.create(null);
423
+ /** @type {Record<string, AssetInfo | undefined>} */
420
424
  const assetsInfo = Object.create(null);
421
425
  const file = task.file;
422
426
  const chunk = fileToChunk.get(file);
@@ -434,24 +438,27 @@ class SourceMapDevToolPlugin {
434
438
  moduleToSourceNameMapping.get(m)
435
439
  );
436
440
  sourceMap.sources = /** @type {string[]} */ (moduleFilenames);
437
- sourceMap.ignoreList = options.ignoreList
438
- ? sourceMap.sources.reduce(
439
- /** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
440
- (acc, sourceName, idx) => {
441
- const rule = /** @type {Rules} */ (
442
- options.ignoreList
443
- );
444
- if (
445
- ModuleFilenameHelpers.matchPart(sourceName, rule)
446
- ) {
447
- acc.push(idx);
448
- }
449
- return acc;
441
+ if (options.ignoreList) {
442
+ const ignoreList = sourceMap.sources.reduce(
443
+ /** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
444
+ (acc, sourceName, idx) => {
445
+ const rule = /** @type {Rules} */ (
446
+ options.ignoreList
447
+ );
448
+ if (
449
+ ModuleFilenameHelpers.matchPart(sourceName, rule)
450
+ ) {
451
+ acc.push(idx);
450
452
  }
451
- ),
452
- []
453
- )
454
- : [];
453
+ return acc;
454
+ }
455
+ ),
456
+ []
457
+ );
458
+ if (ignoreList.length > 0) {
459
+ sourceMap.ignoreList = ignoreList;
460
+ }
461
+ }
455
462
 
456
463
  if (options.noSources) {
457
464
  sourceMap.sourcesContent = undefined;
package/lib/Template.js CHANGED
@@ -36,10 +36,10 @@ const NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
36
36
  const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
37
37
  const INDENT_MULTILINE_REGEX = /^\t/gm;
38
38
  const LINE_SEPARATOR_REGEX = /\r?\n/g;
39
- const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/;
40
- const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g;
39
+ const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-z$_])/i;
40
+ const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-z0-9$]+/gi;
41
41
  const COMMENT_END_REGEX = /\*\//g;
42
- const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
42
+ const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-z0-9_!§$()=\-^°]+/gi;
43
43
  const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
44
44
 
45
45
  /**
@@ -83,10 +83,14 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
83
83
  * @typedef {(module: Module) => boolean} ModuleFilterPredicate
84
84
  */
85
85
 
86
+ /**
87
+ * @typedef {object} Stringable
88
+ * @property {() => string} toString
89
+ */
90
+
86
91
  class Template {
87
92
  /**
88
- * @template {EXPECTED_FUNCTION} T
89
- * @param {T} fn a runtime function (.runtime.js) "template"
93
+ * @param {Stringable} fn a runtime function (.runtime.js) "template"
90
94
  * @returns {string} the updated and normalized function string
91
95
  */
92
96
  static getFunctionContent(fn) {
@@ -359,6 +363,7 @@ class Template {
359
363
  const source = new ConcatSource();
360
364
  for (const module of runtimeModules) {
361
365
  const codeGenerationResults = renderContext.codeGenerationResults;
366
+ /** @type {undefined | Source} */
362
367
  let runtimeSource;
363
368
  if (codeGenerationResults) {
364
369
  runtimeSource = codeGenerationResults.getSource(
@@ -18,7 +18,7 @@ const { parseResource } = require("./util/identifier");
18
18
  /** @typedef {import("./Compilation").PathData} PathData */
19
19
  /** @typedef {import("./Compiler")} Compiler */
20
20
 
21
- const REGEXP = /\[\\*([\w:]+)\\*\]/gi;
21
+ const REGEXP = /\[\\*([\w:]+)\\*\]/g;
22
22
 
23
23
  /** @type {PathData["prepareId"]} */
24
24
  const prepareId = (id) => {
@@ -32,7 +32,7 @@ const prepareId = (id) => {
32
32
  } + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
33
33
  }
34
34
 
35
- return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
35
+ return id.replace(/(^[.-]|[^a-z0-9_-])+/gi, "_");
36
36
  };
37
37
 
38
38
  /**
@@ -52,6 +52,7 @@ const prepareId = (id) => {
52
52
  const hashLength = (replacer, handler, assetInfo, hashName) => {
53
53
  /** @type {Replacer} */
54
54
  const fn = (match, arg, input) => {
55
+ /** @type {string} */
55
56
  let result;
56
57
  const length = arg && Number.parseInt(arg, 10);
57
58
 
@@ -107,6 +108,7 @@ const replacer = (value, allowEmpty) => {
107
108
  return fn;
108
109
  };
109
110
 
111
+ /** @type {Map<string, (...args: EXPECTED_ANY[]) => EXPECTED_ANY>} */
110
112
  const deprecationCache = new Map();
111
113
  const deprecatedFunction = (() => () => {})();
112
114
  /**
@@ -20,6 +20,7 @@ class UnhandledSchemeError extends WebpackError {
20
20
  `\nYou may need an additional plugin to handle "${scheme}:" URIs.`
21
21
  );
22
22
  this.file = resource;
23
+ /** @type {string} */
23
24
  this.name = "UnhandledSchemeError";
24
25
  }
25
26
  }
@@ -18,6 +18,7 @@ class UnsupportedFeatureWarning extends WebpackError {
18
18
  constructor(message, loc) {
19
19
  super(message);
20
20
 
21
+ /** @type {string} */
21
22
  this.name = "UnsupportedFeatureWarning";
22
23
  this.loc = loc;
23
24
  this.hideStack = true;
@@ -48,6 +48,7 @@ class DeprecatedOptionWarning extends WebpackError {
48
48
  constructor(option, value, suggestion) {
49
49
  super();
50
50
 
51
+ /** @type {string} */
51
52
  this.name = "DeprecatedOptionWarning";
52
53
  this.message =
53
54
  "configuration\n" +
@@ -8,9 +8,9 @@
8
8
  const { groupBy } = require("./util/ArrayHelpers");
9
9
  const createSchemaValidation = require("./util/create-schema-validation");
10
10
 
11
+ /** @typedef {import("watchpack").TimeInfoEntries} TimeInfoEntries */
11
12
  /** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
12
13
  /** @typedef {import("./Compiler")} Compiler */
13
- /** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */
14
14
  /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
15
15
  /** @typedef {import("./util/fs").WatchMethod} WatchMethod */
16
16
  /** @typedef {import("./util/fs").Watcher} Watcher */
package/lib/Watching.js CHANGED
@@ -15,6 +15,7 @@ const Stats = require("./Stats");
15
15
  /** @typedef {import("./logging/Logger").Logger} Logger */
16
16
  /** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */
17
17
  /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
18
+ /** @typedef {import("./util/fs").Watcher} Watcher */
18
19
 
19
20
  /**
20
21
  * @template T
@@ -31,8 +32,10 @@ class Watching {
31
32
  * @param {Callback<Stats>} handler completion handler
32
33
  */
33
34
  constructor(compiler, watchOptions, handler) {
35
+ /** @type {null | number} */
34
36
  this.startTime = null;
35
37
  this.invalid = false;
38
+ /** @type {Callback<Stats>} */
36
39
  this.handler = handler;
37
40
  /** @type {ErrorCallback[]} */
38
41
  this.callbacks = [];
@@ -64,7 +67,9 @@ class Watching {
64
67
  this._initial = true;
65
68
  this._invalidReported = true;
66
69
  this._needRecords = true;
70
+ /** @type {undefined | null | Watcher} */
67
71
  this.watcher = undefined;
72
+ /** @type {undefined | null | Watcher} */
68
73
  this.pausedWatcher = undefined;
69
74
  /** @type {CollectedFiles | undefined} */
70
75
  this._collectedChangedFiles = undefined;
@@ -37,6 +37,9 @@ class WebpackError extends Error {
37
37
  this.file = undefined;
38
38
  }
39
39
 
40
+ /**
41
+ * @returns {string} inspect message
42
+ */
40
43
  [inspect]() {
41
44
  return (
42
45
  this.stack +
@@ -74,4 +77,5 @@ class WebpackError extends Error {
74
77
 
75
78
  makeSerializable(WebpackError, "webpack/lib/WebpackError");
76
79
 
80
+ /** @type {typeof WebpackError} */
77
81
  module.exports = WebpackError;
@@ -76,6 +76,7 @@ const { cleverMerge } = require("./util/cleverMerge");
76
76
 
77
77
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
78
78
  /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
79
+ /** @typedef {import("./config/normalization").WebpackOptionsInterception} WebpackOptionsInterception */
79
80
  /** @typedef {import("./Compiler")} Compiler */
80
81
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
81
82
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
@@ -90,9 +91,10 @@ class WebpackOptionsApply extends OptionsApply {
90
91
  /**
91
92
  * @param {WebpackOptions} options options object
92
93
  * @param {Compiler} compiler compiler object
94
+ * @param {WebpackOptionsInterception=} interception intercepted options
93
95
  * @returns {WebpackOptions} options object
94
96
  */
95
- process(options, compiler) {
97
+ process(options, compiler, interception) {
96
98
  compiler.outputPath = options.output.path;
97
99
  compiler.recordsInputPath = options.recordsInputPath || null;
98
100
  compiler.recordsOutputPath = options.recordsOutputPath || null;
@@ -113,11 +115,7 @@ class WebpackOptionsApply extends OptionsApply {
113
115
  // Some older versions of Node.js don't support all built-in modules via import, only via `require`,
114
116
  // but it seems like there shouldn't be a warning here since these versions are rarely used in real applications
115
117
  new NodeTargetPlugin(
116
- options.output.module &&
117
- compiler.platform.node === null &&
118
- compiler.platform.web === null
119
- ? "module-import"
120
- : "node-commonjs"
118
+ options.output.module ? "module-import" : "node-commonjs"
121
119
  ).apply(compiler);
122
120
 
123
121
  // Handle external CSS `@import` and `url()`
@@ -129,8 +127,8 @@ class WebpackOptionsApply extends OptionsApply {
129
127
  "module",
130
128
  ({ request, dependencyType, contextInfo }, callback) => {
131
129
  if (
132
- /\.css(\?|$)/.test(contextInfo.issuer) &&
133
- /^(\/\/|https?:\/\/|#)/.test(request)
130
+ /\.css(?:\?|$)/.test(contextInfo.issuer) &&
131
+ /^(?:\/\/|https?:\/\/|#)/.test(request)
134
132
  ) {
135
133
  if (dependencyType === "url") {
136
134
  return callback(null, `asset ${request}`);
@@ -156,7 +154,7 @@ class WebpackOptionsApply extends OptionsApply {
156
154
  const ExternalsPlugin = require("./ExternalsPlugin");
157
155
 
158
156
  new ExternalsPlugin(type, ({ request, dependencyType }, callback) => {
159
- if (/^(\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) {
157
+ if (/^(?:\/\/|https?:\/\/|#|std:|jsr:|npm:)/.test(request)) {
160
158
  if (dependencyType === "url") {
161
159
  return callback(null, `asset ${request}`);
162
160
  } else if (
@@ -166,7 +164,7 @@ class WebpackOptionsApply extends OptionsApply {
166
164
  options.experiments.css
167
165
  ) {
168
166
  return callback(null, `css-import ${request}`);
169
- } else if (/^(\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) {
167
+ } else if (/^(?:\/\/|https?:\/\/|std:|jsr:|npm:)/.test(request)) {
170
168
  return callback(null, `${type} ${request}`);
171
169
  }
172
170
  }
@@ -315,37 +313,59 @@ class WebpackOptionsApply extends OptionsApply {
315
313
  ).apply(compiler);
316
314
  }
317
315
 
318
- if (options.devtool) {
319
- if (options.devtool.includes("source-map")) {
320
- const hidden = options.devtool.includes("hidden");
321
- const inline = options.devtool.includes("inline");
322
- const evalWrapped = options.devtool.includes("eval");
323
- const cheap = options.devtool.includes("cheap");
324
- const moduleMaps = options.devtool.includes("module");
325
- const noSources = options.devtool.includes("nosources");
326
- const debugIds = options.devtool.includes("debugids");
327
- const Plugin = evalWrapped
328
- ? require("./EvalSourceMapDevToolPlugin")
329
- : require("./SourceMapDevToolPlugin");
330
- new Plugin({
331
- filename: inline ? null : options.output.sourceMapFilename,
332
- moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
333
- fallbackModuleFilenameTemplate:
334
- options.output.devtoolFallbackModuleFilenameTemplate,
335
- append: hidden ? false : undefined,
336
- module: moduleMaps ? true : !cheap,
337
- columns: !cheap,
338
- noSources,
339
- namespace: options.output.devtoolNamespace,
340
- debugIds
341
- }).apply(compiler);
342
- } else if (options.devtool.includes("eval")) {
343
- const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
316
+ let devtool =
317
+ interception === undefined ? options.devtool : interception.devtool;
318
+ devtool = Array.isArray(devtool)
319
+ ? devtool
320
+ : typeof devtool === "string"
321
+ ? [{ type: "all", use: devtool }]
322
+ : [];
323
+
324
+ for (const item of devtool) {
325
+ const { type, use } = item;
326
+
327
+ if (use) {
328
+ if (use.includes("source-map")) {
329
+ const hidden = use.includes("hidden");
330
+ const inline = use.includes("inline");
331
+ const evalWrapped = use.includes("eval");
332
+ const cheap = use.includes("cheap");
333
+ const moduleMaps = use.includes("module");
334
+ const noSources = use.includes("nosources");
335
+ const debugIds = use.includes("debugids");
336
+ const Plugin = evalWrapped
337
+ ? require("./EvalSourceMapDevToolPlugin")
338
+ : require("./SourceMapDevToolPlugin");
339
+ const assetExt =
340
+ type === "javascript"
341
+ ? /\.((c|m)?js)($|\?)/i
342
+ : type === "css"
343
+ ? /\.(css)($|\?)/i
344
+ : /\.((c|m)?js|css)($|\?)/i;
345
+
346
+ new Plugin({
347
+ test: evalWrapped ? undefined : assetExt,
348
+ filename: inline ? null : options.output.sourceMapFilename,
349
+ moduleFilenameTemplate:
350
+ options.output.devtoolModuleFilenameTemplate,
351
+ fallbackModuleFilenameTemplate:
352
+ options.output.devtoolFallbackModuleFilenameTemplate,
353
+ append: hidden ? false : undefined,
354
+ module: moduleMaps ? true : !cheap,
355
+ columns: !cheap,
356
+ noSources,
357
+ namespace: options.output.devtoolNamespace,
358
+ debugIds
359
+ }).apply(compiler);
360
+ } else if (use.includes("eval")) {
361
+ const EvalDevToolModulePlugin = require("./EvalDevToolModulePlugin");
344
362
 
345
- new EvalDevToolModulePlugin({
346
- moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
347
- namespace: options.output.devtoolNamespace
348
- }).apply(compiler);
363
+ new EvalDevToolModulePlugin({
364
+ moduleFilenameTemplate:
365
+ options.output.devtoolModuleFilenameTemplate,
366
+ namespace: options.output.devtoolNamespace
367
+ }).apply(compiler);
368
+ }
349
369
  }
350
370
  }
351
371
 
@@ -60,6 +60,7 @@ class AssetSourceGenerator extends Generator {
60
60
  runtimeRequirements.add(RuntimeGlobals.requireScope);
61
61
  runtimeRequirements.add(RuntimeGlobals.toBinary);
62
62
 
63
+ /** @type {string} */
63
64
  let sourceContent;
64
65
  if (concatenationScope) {
65
66
  concatenationScope.registerNamespaceExport(
@@ -62,12 +62,13 @@ const getMimeTypes = memoize(() => require("mime-types"));
62
62
  * @returns {T[] & U[]} array
63
63
  */
64
64
  const mergeMaybeArrays = (a, b) => {
65
+ /** @type {Set<T | U | null | undefined | string | Set<T> | Set<U>>} */
65
66
  const set = new Set();
66
67
  if (Array.isArray(a)) for (const item of a) set.add(item);
67
68
  else set.add(a);
68
69
  if (Array.isArray(b)) for (const item of b) set.add(item);
69
70
  else set.add(b);
70
- return [...set];
71
+ return /** @type {T[] & U[]} */ ([.../** @type {Set<T | U>} */ (set)]);
71
72
  };
72
73
 
73
74
  /**
@@ -333,6 +334,7 @@ class AssetGenerator extends Generator {
333
334
  runtimeTemplate
334
335
  );
335
336
 
337
+ /** @type {undefined | string} */
336
338
  let assetPath;
337
339
 
338
340
  if (generatorOptions.publicPath !== undefined && type === JAVASCRIPT_TYPE) {
@@ -457,6 +459,7 @@ class AssetGenerator extends Generator {
457
459
  generateDataUri(module) {
458
460
  const source = /** @type {Source} */ (module.originalSource());
459
461
 
462
+ /** @type {string} */
460
463
  let encodedSource;
461
464
 
462
465
  if (typeof this.dataUrlOptions === "function") {
@@ -480,6 +483,7 @@ class AssetGenerator extends Generator {
480
483
  }
481
484
  const mimeType = this.getMimeType(module);
482
485
 
486
+ /** @type {string} */
483
487
  let encodedContent;
484
488
 
485
489
  if (
@@ -490,7 +494,9 @@ class AssetGenerator extends Generator {
490
494
  /** @type {string} */ (module.resourceResolveData.encodedContent)
491
495
  ).equals(source.buffer())
492
496
  ) {
493
- encodedContent = module.resourceResolveData.encodedContent;
497
+ encodedContent =
498
+ /** @type {string} */
499
+ (module.resourceResolveData.encodedContent);
494
500
  } else {
495
501
  encodedContent = encodeDataUri(
496
502
  /** @type {"base64" | false} */ (encoding),
@@ -520,10 +526,10 @@ class AssetGenerator extends Generator {
520
526
  concatenationScope
521
527
  } = generateContext;
522
528
 
529
+ /** @type {string} */
523
530
  let content;
524
531
 
525
532
  const needContent = type === JAVASCRIPT_TYPE || type === CSS_URL_TYPE;
526
-
527
533
  const data = getData ? getData() : undefined;
528
534
 
529
535
  if (
@@ -12,17 +12,22 @@ const {
12
12
  ASSET_MODULE_TYPE_RESOURCE,
13
13
  ASSET_MODULE_TYPE_SOURCE
14
14
  } = require("../ModuleTypeConstants");
15
- const { compareModulesByIdOrIdentifier } = require("../util/comparators");
15
+ const { compareModulesByFullName } = require("../util/comparators");
16
16
  const createSchemaValidation = require("../util/create-schema-validation");
17
17
  const memoize = require("../util/memoize");
18
18
 
19
19
  /** @typedef {import("webpack-sources").Source} Source */
20
20
  /** @typedef {import("schema-utils").Schema} Schema */
21
+ /** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorDataUrl} AssetGeneratorDataUrl */
22
+ /** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
23
+ /** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
24
+ /** @typedef {import("../../declarations/WebpackOptions").FilenameTemplate} FilenameTemplate */
21
25
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
22
26
  /** @typedef {import("../Compiler")} Compiler */
23
27
  /** @typedef {import("../Module").BuildInfo} BuildInfo */
24
28
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
25
29
  /** @typedef {import("../NormalModule")} NormalModule */
30
+ /** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
26
31
 
27
32
  /**
28
33
  * @param {string} name name of definitions
@@ -76,6 +81,7 @@ const getAssetSourceGenerator = memoize(() =>
76
81
  require("./AssetSourceGenerator")
77
82
  );
78
83
  const getAssetBytesGenerator = memoize(() => require("./AssetBytesGenerator"));
84
+ const getNormalModule = memoize(() => require("../NormalModule"));
79
85
 
80
86
  const type = ASSET_MODULE_TYPE;
81
87
  const PLUGIN_NAME = "AssetModulesPlugin";
@@ -90,6 +96,27 @@ class AssetModulesPlugin {
90
96
  compiler.hooks.compilation.tap(
91
97
  PLUGIN_NAME,
92
98
  (compilation, { normalModuleFactory }) => {
99
+ const NormalModule = getNormalModule();
100
+ for (const type of [
101
+ ASSET_MODULE_TYPE,
102
+ ASSET_MODULE_TYPE_BYTES,
103
+ ASSET_MODULE_TYPE_INLINE,
104
+ ASSET_MODULE_TYPE_RESOURCE,
105
+ ASSET_MODULE_TYPE_SOURCE
106
+ ]) {
107
+ normalModuleFactory.hooks.createModuleClass
108
+ .for(type)
109
+ .tap(PLUGIN_NAME, (createData, _resolveData) => {
110
+ // TODO create the module via new AssetModule with its own properties
111
+ const module = new NormalModule(
112
+ /** @type {NormalModuleCreateData} */
113
+ (createData)
114
+ );
115
+ module.factoryMeta = { sideEffectFree: true };
116
+ return module;
117
+ });
118
+ }
119
+
93
120
  normalModuleFactory.hooks.createParser
94
121
  .for(ASSET_MODULE_TYPE)
95
122
  .tap(PLUGIN_NAME, (parserOptions) => {
@@ -146,6 +173,7 @@ class AssetModulesPlugin {
146
173
  .tap(PLUGIN_NAME, (generatorOptions) => {
147
174
  validateGeneratorOptions[type](generatorOptions);
148
175
 
176
+ /** @type {undefined | AssetGeneratorDataUrl} */
149
177
  let dataUrl;
150
178
  if (type !== ASSET_MODULE_TYPE_RESOURCE) {
151
179
  dataUrl = generatorOptions.dataUrl;
@@ -158,8 +186,11 @@ class AssetModulesPlugin {
158
186
  }
159
187
  }
160
188
 
189
+ /** @type {undefined | FilenameTemplate} */
161
190
  let filename;
191
+ /** @type {undefined | RawPublicPath} */
162
192
  let publicPath;
193
+ /** @type {undefined | AssetModuleOutputPath} */
163
194
  let outputPath;
164
195
  if (type !== ASSET_MODULE_TYPE_INLINE) {
165
196
  filename = generatorOptions.filename;
@@ -202,7 +233,7 @@ class AssetModulesPlugin {
202
233
  const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
203
234
  chunk,
204
235
  ASSET_MODULE_TYPE,
205
- compareModulesByIdOrIdentifier(chunkGraph)
236
+ compareModulesByFullName(compilation.compiler)
206
237
  );
207
238
  if (modules) {
208
239
  for (const module of modules) {
@@ -59,6 +59,7 @@ class AssetSourceGenerator extends Generator {
59
59
  const encodedSource =
60
60
  typeof content === "string" ? content : content.toString("utf8");
61
61
 
62
+ /** @type {string} */
62
63
  let sourceContent;
63
64
  if (concatenationScope) {
64
65
  concatenationScope.registerNamespaceExport(