webpack 5.112.0 → 5.112.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 (263) hide show
  1. package/bin/webpack.js +13 -7
  2. package/lib/Compilation.js +152 -60
  3. package/lib/Compiler.js +12 -25
  4. package/lib/asset/AssetBytesGenerator.js +14 -6
  5. package/lib/asset/AssetBytesParser.js +10 -8
  6. package/lib/asset/AssetGenerator.js +36 -48
  7. package/lib/asset/AssetModule.js +11 -0
  8. package/lib/asset/AssetModulesPlugin.js +5 -4
  9. package/lib/asset/AssetParser.js +8 -8
  10. package/lib/asset/AssetSourceGenerator.js +16 -8
  11. package/lib/asset/AssetSourceParser.js +10 -8
  12. package/lib/asset/WebManifestGenerator.js +11 -6
  13. package/lib/asset/WebManifestParser.js +3 -3
  14. package/lib/async-modules/AsyncModuleHelpers.js +8 -2
  15. package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
  16. package/lib/cache/CacheFacade.js +1 -1
  17. package/lib/cache/PackFileCacheStrategy.js +6 -10
  18. package/lib/cache/ResolverCachePlugin.js +58 -8
  19. package/lib/config/WebpackOptionsApply.js +8 -28
  20. package/lib/config/cli.js +9 -6
  21. package/lib/config/defaults.js +24 -13
  22. package/lib/config/getClaimedAssetTypes.js +2 -2
  23. package/lib/config/target.js +1 -1
  24. package/lib/context/ContextModule.js +1 -1
  25. package/lib/context/ContextModuleFactory.js +1 -1
  26. package/lib/context/ContextReplacementPlugin.js +3 -9
  27. package/lib/css/CssGenerator.js +40 -37
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +2 -2
  30. package/lib/css/CssParser.js +33 -32
  31. package/lib/css/conventions.js +1 -1
  32. package/lib/css/data.js +224 -219
  33. package/lib/css/syntax-parser.js +1159 -298
  34. package/lib/css/syntax-printer.js +90 -35
  35. package/lib/debug/ProfilingPlugin.js +65 -43
  36. package/lib/define/DefinePlugin.js +10 -15
  37. package/lib/define/DotenvPlugin.js +10 -6
  38. package/lib/define/EnvironmentPlugin.js +4 -2
  39. package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
  40. package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  41. package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
  42. package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
  43. package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
  44. package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
  45. package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
  46. package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
  47. package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
  48. package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
  49. package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
  50. package/lib/dependencies/core/CachedConstDependency.js +9 -6
  51. package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
  52. package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
  53. package/lib/dependencies/css/CssUrlDependency.js +2 -6
  54. package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
  55. package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
  56. package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
  57. package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
  58. package/lib/dependencies/esm/ESMExports.js +2 -10
  59. package/lib/dependencies/esm/ESMImportDependency.js +17 -2
  60. package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
  61. package/lib/dependencies/esm/ESMImportGuard.js +11 -23
  62. package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
  63. package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
  64. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  65. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  66. package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
  67. package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
  68. package/lib/dependencies/helpers/DynamicExports.js +4 -6
  69. package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
  70. package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
  71. package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
  72. package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
  73. package/lib/dependencies/import/ImportParserPlugin.js +3 -6
  74. package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
  75. package/lib/dependencies/url/URLParserPlugin.js +1 -1
  76. package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
  77. package/lib/devtool/ModuleFilenameHelpers.js +1 -1
  78. package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
  79. package/lib/dll/DelegatedModule.js +3 -3
  80. package/lib/dll/DllModule.js +3 -1
  81. package/lib/dll/DllReferencePlugin.js +1 -4
  82. package/lib/errors/AbstractMethodError.js +1 -1
  83. package/lib/errors/ErrorHelpers.js +2 -1
  84. package/lib/errors/HookWebpackError.js +2 -1
  85. package/lib/errors/JSONParseError.js +4 -4
  86. package/lib/errors/WebpackError.js +3 -2
  87. package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
  88. package/lib/externals/ExternalModule.js +12 -9
  89. package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
  90. package/lib/externals/ExternalsPlugin.js +1 -1
  91. package/lib/fs/FileSystemInfo.js +4 -4
  92. package/lib/graph/AsyncDependenciesBlock.js +1 -1
  93. package/lib/graph/ChunkGraph.js +5 -0
  94. package/lib/graph/Dependency.js +8 -2
  95. package/lib/graph/ExportsInfo.js +1 -1
  96. package/lib/graph/ModuleGraph.js +14 -3
  97. package/lib/graph/buildChunkGraph.js +17 -19
  98. package/lib/graph/findGraphRoots.js +1 -1
  99. package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
  100. package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
  101. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
  102. package/lib/hmr/LazyCompilationPlugin.js +1 -7
  103. package/lib/html/HtmlGenerator.js +25 -17
  104. package/lib/html/HtmlModule.js +11 -1
  105. package/lib/html/HtmlModulesPlugin.js +12 -11
  106. package/lib/html/HtmlParser.js +10 -9
  107. package/lib/html/builtinEmbeddedRenderer.js +31 -33
  108. package/lib/html/data.js +42 -21
  109. package/lib/html/htmlMinify.js +4 -1
  110. package/lib/html/syntax-parser.js +34 -35
  111. package/lib/html/syntax-printer.js +2 -3
  112. package/lib/html/xmlMinify.js +4 -1
  113. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  114. package/lib/index.js +13 -12
  115. package/lib/javascript/APIPlugin.js +7 -13
  116. package/lib/javascript/BasicEvaluatedExpression.js +5 -5
  117. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
  118. package/lib/javascript/ConstPlugin.js +1 -1
  119. package/lib/javascript/JavascriptGenerator.js +16 -11
  120. package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
  121. package/lib/javascript/JavascriptModule.js +10 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +2 -4
  123. package/lib/javascript/JavascriptParser.js +99 -11
  124. package/lib/javascript/ScopeAnalyzer.js +183 -107
  125. package/lib/javascript/UseStrictPlugin.js +2 -5
  126. package/lib/javascript/jsMinify.js +1 -1
  127. package/lib/javascript/regexp.js +2 -2
  128. package/lib/javascript/syntax-parser.js +2114 -1506
  129. package/lib/javascript/syntax-printer-data.js +167 -1
  130. package/lib/javascript/syntax-printer.js +9554 -2782
  131. package/lib/json/JsonGenerator.js +15 -7
  132. package/lib/json/JsonModule.js +11 -0
  133. package/lib/json/JsonParser.js +7 -6
  134. package/lib/library/AssignLibraryPlugin.js +1 -1
  135. package/lib/library/JsonpLibraryPlugin.js +1 -1
  136. package/lib/library/ModuleLibraryPlugin.js +399 -23
  137. package/lib/loaders/LoaderRunner.js +76 -38
  138. package/lib/loaders/loadLoader.js +16 -10
  139. package/lib/module/Generator.js +17 -9
  140. package/lib/module/Module.js +2 -2
  141. package/lib/module/NormalModule.js +7 -5
  142. package/lib/module/NormalModuleFactory.js +11 -17
  143. package/lib/module/Parser.js +9 -2
  144. package/lib/module/extractSourceMap.js +69 -18
  145. package/lib/module/findCaseMismatch.js +2 -2
  146. package/lib/node/ExternalModuleInitFragment.js +2 -2
  147. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
  148. package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
  149. package/lib/node/nodeConsole.js +4 -3
  150. package/lib/optimize/CircularModulesPlugin.js +1 -1
  151. package/lib/optimize/ConcatenatedModule.js +2 -6
  152. package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
  153. package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
  154. package/lib/optimize/InlineExports.js +4 -7
  155. package/lib/optimize/LazyBarrels.js +41 -5
  156. package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
  157. package/lib/optimize/RealContentHashPlugin.js +2 -6
  158. package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
  159. package/lib/optimize/SplitChunksPlugin.js +11 -24
  160. package/lib/optimize/TupleQueue.js +1 -1
  161. package/lib/output/CleanPlugin.js +3 -1
  162. package/lib/output/CopyPlugin.js +3 -4
  163. package/lib/performance/EvalUsagePlugin.js +1 -3
  164. package/lib/performance/HotspotsPlugin.js +33 -9
  165. package/lib/performance/PureAnnotationsPlugin.js +16 -10
  166. package/lib/performance/TopLevelThisPlugin.js +17 -9
  167. package/lib/prefetch/ResourceHintPlugin.js +1 -1
  168. package/lib/provide/ProvidedDependency.js +36 -4
  169. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  170. package/lib/rules/RuleSetCompiler.js +15 -5
  171. package/lib/rules/UseEffectRulePlugin.js +1 -3
  172. package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
  173. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
  174. package/lib/runtime/RuntimeGlobals.js +6 -0
  175. package/lib/runtime/RuntimePlugin.js +2 -0
  176. package/lib/schemes/HttpUriPlugin.js +1 -2
  177. package/lib/schemes/VirtualUrlPlugin.js +3 -1
  178. package/lib/serialization/AggregateErrorSerializer.js +3 -3
  179. package/lib/serialization/BinaryMiddleware.js +4 -1
  180. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  181. package/lib/serialization/ObjectMiddleware.js +17 -15
  182. package/lib/serialization/PlainObjectSerializer.js +3 -7
  183. package/lib/serialization/Serializer.js +21 -11
  184. package/lib/serialization/SerializerMiddleware.js +8 -6
  185. package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
  186. package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
  187. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
  188. package/lib/stats/StatsFactory.js +194 -24
  189. package/lib/stats/StatsPrinter.js +126 -13
  190. package/lib/template/DependencyTemplate.js +1 -1
  191. package/lib/template/RuntimeTemplate.js +13 -32
  192. package/lib/template/Template.js +1 -1
  193. package/lib/util/SourceProcessor.js +98 -15
  194. package/lib/util/WeakTupleMap.js +10 -4
  195. package/lib/util/cleverMerge.js +61 -33
  196. package/lib/util/comparators.js +9 -5
  197. package/lib/util/dataURL.js +2 -0
  198. package/lib/util/deprecation.js +4 -3
  199. package/lib/util/globUtils.js +1 -4
  200. package/lib/util/internalSerializables.js +2 -0
  201. package/lib/util/makeSerializable.js +6 -4
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/parseJson.js +2 -2
  204. package/lib/util/serialization.js +31 -27
  205. package/lib/wasm/AsyncWasmModule.js +12 -2
  206. package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
  207. package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
  208. package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
  209. package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
  210. package/lib/wasm-sync/SyncWasmModule.js +16 -1
  211. package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
  212. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
  213. package/lib/wasm-sync/WebAssemblyParser.js +10 -12
  214. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
  215. package/lib/web/FetchCompileWasmPlugin.js +2 -6
  216. package/package.json +16 -18
  217. package/schemas/WebpackOptions.check.js +3 -3
  218. package/schemas/WebpackOptions.json +2 -2
  219. package/schemas/plugins/BannerPlugin.check.js +3 -3
  220. package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
  221. package/schemas/plugins/HtmlParserOptions.check.js +3 -3
  222. package/schemas/plugins/IgnorePlugin.check.js +3 -3
  223. package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
  224. package/schemas/plugins/ManifestPlugin.check.js +3 -3
  225. package/schemas/plugins/ProgressPlugin.check.js +3 -3
  226. package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
  227. package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
  228. package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
  229. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
  230. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
  231. package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
  232. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
  233. package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
  234. package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
  235. package/schemas/plugins/container/ExternalsType.check.js +3 -3
  236. package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
  237. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
  238. package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
  239. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
  240. package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
  241. package/schemas/plugins/css/CssParserOptions.check.js +3 -3
  242. package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
  243. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  244. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  245. package/schemas/plugins/dll/DllPlugin.check.js +3 -3
  246. package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
  247. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
  248. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
  249. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
  250. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
  251. package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
  252. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
  253. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
  254. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
  255. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
  256. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  257. package/schemas/plugins/output/CleanOptions.json +3 -0
  258. package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
  259. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
  260. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
  261. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
  262. package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
  263. package/types.d.ts +1482 -358
package/bin/webpack.js CHANGED
@@ -4,11 +4,21 @@
4
4
 
5
5
  // Cache compiled module bytecode on disk (available since Node.js 22.8)
6
6
  // eslint-disable-next-line n/no-unsupported-features/node-builtins
7
- const { enableCompileCache } = require("module");
7
+ const { constants, enableCompileCache } = require("module");
8
8
 
9
9
  if (enableCompileCache) {
10
10
  try {
11
- enableCompileCache();
11
+ const { status, directory } = enableCompileCache();
12
+ // Minimizer workers and other child processes start without the cache;
13
+ // the variable Node reads at startup hands them the same directory. Only a
14
+ // fresh start returns the base directory, which children tag by version.
15
+ if (
16
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
17
+ status === constants.compileCacheStatus.ENABLED &&
18
+ process.env.NODE_COMPILE_CACHE === undefined
19
+ ) {
20
+ process.env.NODE_COMPILE_CACHE = directory;
21
+ }
12
22
  } catch (_error) {
13
23
  // Nothing
14
24
  }
@@ -190,11 +200,7 @@ if (!cli.installed) {
190
200
  }')...`
191
201
  );
192
202
 
193
- runCommand(
194
- /** @type {string} */
195
- (packageManager),
196
- [...installOptions, cli.package]
197
- )
203
+ runCommand(packageManager, [...installOptions, cli.package])
198
204
  .then(() => {
199
205
  runCli(cli);
200
206
  })
@@ -189,6 +189,7 @@ const { toError } = ErrorHelpers;
189
189
  * @import {
190
190
  * StatsAsset,
191
191
  * StatsError,
192
+ * StatsJsonValue,
192
193
  * StatsModule
193
194
  * } from "./stats/DefaultStatsFactoryPlugin"
194
195
  */
@@ -247,7 +248,7 @@ const { toError } = ErrorHelpers;
247
248
  * @returns {void}
248
249
  */
249
250
 
250
- /** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DependencyConstructor */
251
+ /** @typedef {abstract new (...args: never[]) => Dependency} DependencyConstructor */
251
252
 
252
253
  /** @typedef {Record<string, Source>} CompilationAssets */
253
254
 
@@ -527,7 +528,7 @@ const { toError } = ErrorHelpers;
527
528
  * @property {false | "none" | "error" | "warn" | "info" | "log" | "verbose"} logging
528
529
  * @property {((value: string) => boolean)[]} loggingDebug
529
530
  * @property {boolean} loggingTrace
530
- * @property {EXPECTED_ANY} _env
531
+ * @property {StatsJsonValue} _env
531
532
  */
532
533
 
533
534
  /** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, EXPECTED_ANY>} NormalizedStatsOptions */
@@ -633,11 +634,19 @@ const unsafeCacheData = new WeakMap();
633
634
  const dependencyReportCacheTokens = new WeakMap();
634
635
 
635
636
  /**
636
- * Modules known to have no dependency errors/warnings, per cache token.
637
- * @type {WeakMap<DependencyReportCacheToken, WeakSet<Module>>}
637
+ * Modules known to have no dependency errors/warnings, per cache token, with
638
+ * the deferred requests they were checked with (`true` for none).
639
+ * @type {WeakMap<DependencyReportCacheToken, WeakMap<Module, string | true>>}
638
640
  */
639
641
  const modulesWithoutProblems = new WeakMap();
640
642
 
643
+ /**
644
+ * How many connections each stored reference map holds, so a module whose
645
+ * connection is gone or new, not only one pointing elsewhere, counts as affected.
646
+ * @type {WeakMap<WeakReferences, number>}
647
+ */
648
+ const referenceCounts = new WeakMap();
649
+
641
650
  /**
642
651
  * Reduce affect type.
643
652
  * @param {Readonly<ModuleGraphConnection[]>} connections connections
@@ -655,9 +664,13 @@ const reduceAffectType = (connections) => {
655
664
  return affected;
656
665
  };
657
666
 
658
- /** @typedef {{ id: ModuleId, modules?: Map<Module, string>, blocks?: (ChunkId | null)[], sourceTypes?: SourceTypes }} References */
667
+ /** @typedef {{ id: ModuleId, modules?: Map<Module, string>, blocks?: (ChunkId | null)[], sourceTypes?: SourceTypes, chunkSourceTypes?: string }} References */
659
668
  /** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */
660
- /** @typedef {{ chunk: Chunk, load: () => Promise<EXPECTED_ANY>, create: (loaded: EXPECTED_ANY) => RuntimeModule, chunkGraph: ChunkGraph }} PendingRuntimeModule */
669
+ /**
670
+ * A queued lazy runtime module; `create` takes exactly what its own `load`
671
+ * resolves, which differs per entry.
672
+ * @typedef {{ chunk: Chunk, load: () => Promise<EXPECTED_OBJECT>, create: (loaded: never) => RuntimeModule, chunkGraph: ChunkGraph }} PendingRuntimeModule
673
+ */
661
674
 
662
675
  class Compilation {
663
676
  /**
@@ -908,7 +921,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
908
921
  processAssetsHook.tapAsync(
909
922
  getOptions(options),
910
923
  (assets, callback) =>
911
- /** @type {EXPECTED_ANY} */ (fn)(...getArgs(), callback)
924
+ /** @type {(...args: [...AsArray<T>, typeof callback]) => void} */ (
925
+ /** @type {typeof fn | ((...args: [...AsArray<T>, typeof callback]) => void)} */ (
926
+ fn
927
+ )
928
+ )(...getArgs(), callback)
912
929
  );
913
930
  },
914
931
  /** @type {AsyncSeriesHook<T>["tapPromise"]} */
@@ -1847,8 +1864,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1847
1864
  this.options,
1848
1865
  this,
1849
1866
  this.resolverFactory.get("normal", module.resolveOptions),
1850
- /** @type {InputFileSystem} */
1851
- (this.inputFileSystem),
1867
+ this.inputFileSystem,
1852
1868
  (err) => {
1853
1869
  if (currentProfile !== undefined) {
1854
1870
  currentProfile.markBuildingEnd();
@@ -2549,9 +2565,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2549
2565
  module.restoreFromUnsafeCache &&
2550
2566
  this._unsafeCachePredicate(module)
2551
2567
  ) {
2552
- const unsafeCacheableModule =
2553
- /** @type {ModuleWithRestoreFromUnsafeCache} */
2554
- (module);
2568
+ const unsafeCacheableModule = module;
2555
2569
  for (const dependency of dependencies) {
2556
2570
  moduleGraph.setResolvedModule(
2557
2571
  connectOrigin ? originModule : null,
@@ -2969,6 +2983,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2969
2983
  });
2970
2984
  }
2971
2985
 
2986
+ /**
2987
+ * Returns the requests a lazy barrel still defers, which neither render nor
2988
+ * report what they would once requested, though no connection changes.
2989
+ * @private
2990
+ * @param {Module} module the module
2991
+ * @returns {string | undefined} the deferred requests as one key, if any
2992
+ */
2993
+ _getLazyRequests(module) {
2994
+ const lazyRequests = this._lazyBarrels.getLazyRequests(module);
2995
+ return lazyRequests && JSON.stringify([...lazyRequests]);
2996
+ }
2997
+
2972
2998
  /**
2973
2999
  * Compute affected modules.
2974
3000
  * @private
@@ -3000,13 +3026,16 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3000
3026
  const computeReferences = (module) => {
3001
3027
  /** @type {WeakReferences | undefined} */
3002
3028
  let references;
3029
+ let count = 0;
3003
3030
  for (const connection of moduleGraph.getOutgoingConnections(module)) {
3004
3031
  const d = connection.dependency;
3005
3032
  const m = connection.module;
3006
3033
  if (!d || !m || unsafeCacheDependencies.has(d)) continue;
3007
3034
  if (references === undefined) references = new WeakMap();
3008
3035
  references.set(d, m);
3036
+ count++;
3009
3037
  }
3038
+ if (references !== undefined) referenceCounts.set(references, count);
3010
3039
  return references;
3011
3040
  };
3012
3041
 
@@ -3017,15 +3046,21 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3017
3046
  * @returns {boolean} true, when the references differ
3018
3047
  */
3019
3048
  const compareReferences = (module, references) => {
3020
- if (references === undefined) return true;
3049
+ let count = 0;
3021
3050
  for (const connection of moduleGraph.getOutgoingConnections(module)) {
3022
3051
  const d = connection.dependency;
3023
3052
  if (!d) continue;
3024
- const entry = references.get(d);
3025
- if (entry === undefined) continue;
3026
- if (entry !== connection.module) return false;
3053
+ const entry = references === undefined ? undefined : references.get(d);
3054
+ if (entry === connection.module) {
3055
+ count++;
3056
+ } else if (entry !== undefined || !unsafeCacheDependencies.has(d)) {
3057
+ return false;
3058
+ }
3027
3059
  }
3028
- return true;
3060
+ return (
3061
+ count ===
3062
+ (references === undefined ? 0 : referenceCounts.get(references))
3063
+ );
3029
3064
  };
3030
3065
 
3031
3066
  const modulesWithoutCache = new Set(modules);
@@ -3033,6 +3068,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3033
3068
  if (modulesWithoutCache.has(module)) {
3034
3069
  const buildInfo = module.buildInfo;
3035
3070
  if (buildInfo) {
3071
+ const lazyRequests = this._getLazyRequests(module);
3036
3072
  if (cachedMemCache.buildInfo !== buildInfo) {
3037
3073
  // use a new one
3038
3074
  /** @type {MemCache} */
@@ -3041,15 +3077,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3041
3077
  affectedModules.add(module);
3042
3078
  cachedMemCache.buildInfo = buildInfo;
3043
3079
  cachedMemCache.references = computeReferences(module);
3080
+ cachedMemCache.lazyRequests = lazyRequests;
3044
3081
  cachedMemCache.memCache = memCache;
3045
3082
  statChanged++;
3046
- } else if (!compareReferences(module, cachedMemCache.references)) {
3083
+ } else if (
3084
+ !compareReferences(module, cachedMemCache.references) ||
3085
+ cachedMemCache.lazyRequests !== lazyRequests
3086
+ ) {
3047
3087
  // use a new one
3048
3088
  /** @type {MemCache} */
3049
3089
  const memCache = new WeakTupleMap();
3050
3090
  moduleMemCaches.set(module, memCache);
3051
3091
  affectedModules.add(module);
3052
3092
  cachedMemCache.references = computeReferences(module);
3093
+ cachedMemCache.lazyRequests = lazyRequests;
3053
3094
  cachedMemCache.memCache = memCache;
3054
3095
  statReferencesChanged++;
3055
3096
  } else {
@@ -3076,6 +3117,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3076
3117
  moduleMemCacheCache.set(module, {
3077
3118
  buildInfo,
3078
3119
  references: computeReferences(module),
3120
+ lazyRequests: this._getLazyRequests(module),
3079
3121
  memCache
3080
3122
  });
3081
3123
  moduleMemCaches.set(module, memCache);
@@ -3168,6 +3210,17 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3168
3210
  }
3169
3211
  return key;
3170
3212
  };
3213
+ /**
3214
+ * Key the source types the chunk graph overrides for the module, which module concatenation narrows for an inner module that keeps other source types.
3215
+ * @param {Module} module module
3216
+ * @returns {string | undefined} key, undefined when the module's own source types stand
3217
+ */
3218
+ const chunkSourceTypesKey = (module) => {
3219
+ const sourceTypes = chunkGraph.getModuleSourceTypes(module);
3220
+ return sourceTypes === module.getSourceTypes()
3221
+ ? undefined
3222
+ : [...sourceTypes].join();
3223
+ };
3171
3224
  /**
3172
3225
  * Compute references.
3173
3226
  * @param {Module} module module
@@ -3210,7 +3263,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3210
3263
  id,
3211
3264
  modules,
3212
3265
  blocks,
3213
- sourceTypes: module.getReferencedSourceTypes()
3266
+ sourceTypes: module.getReferencedSourceTypes(),
3267
+ chunkSourceTypes: chunkSourceTypesKey(module)
3214
3268
  };
3215
3269
  };
3216
3270
  /**
@@ -3221,11 +3275,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3221
3275
  * @param {Map<Module, string>=} references.modules modules
3222
3276
  * @param {(string | number | null)[]=} references.blocks blocks
3223
3277
  * @param {SourceTypes=} references.sourceTypes connection-dependent source types
3278
+ * @param {string=} references.chunkSourceTypes key of the source types the chunk graph overrides
3224
3279
  * @returns {boolean} ok?
3225
3280
  */
3226
3281
  const compareReferences = (
3227
3282
  module,
3228
- { id, modules, blocks, sourceTypes }
3283
+ { id, modules, blocks, sourceTypes, chunkSourceTypes }
3229
3284
  ) => {
3230
3285
  if (id !== chunkGraph.getModuleId(module)) return false;
3231
3286
  if (modules !== undefined) {
@@ -3264,6 +3319,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3264
3319
  ) {
3265
3320
  return false;
3266
3321
  }
3322
+ if (chunkSourceTypesKey(module) !== chunkSourceTypes) return false;
3267
3323
  return true;
3268
3324
  };
3269
3325
 
@@ -3473,20 +3529,24 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3473
3529
  if (d === 0 || p === 0) continue;
3474
3530
  const t = d / p;
3475
3531
  sum += t;
3476
- if (t <= 10) continue;
3532
+ /* istanbul ignore next -- @preserve: only slow (>10ms) modules are logged, timing-dependent */
3533
+ if (t > 10) {
3534
+ logByValue(
3535
+ t,
3536
+ ` | ${Math.round(t)} ms${
3537
+ p >= 1.1 ? ` (parallelism ${Math.round(p * 10) / 10})` : ""
3538
+ } ${category} > ${module.readableIdentifier(this.requestShortener)}`
3539
+ );
3540
+ max = Math.max(max, t);
3541
+ }
3542
+ }
3543
+ /* istanbul ignore next -- @preserve: only slow (>10ms) categories are logged, timing-dependent */
3544
+ if (sum > 10) {
3477
3545
  logByValue(
3478
- t,
3479
- ` | ${Math.round(t)} ms${
3480
- p >= 1.1 ? ` (parallelism ${Math.round(p * 10) / 10})` : ""
3481
- } ${category} > ${module.readableIdentifier(this.requestShortener)}`
3546
+ Math.max(sum / 10, max),
3547
+ `${Math.round(sum)} ms ${category}`
3482
3548
  );
3483
- max = Math.max(max, t);
3484
3549
  }
3485
- if (sum <= 10) return;
3486
- logByValue(
3487
- Math.max(sum / 10, max),
3488
- `${Math.round(sum)} ms ${category}`
3489
- );
3490
3550
  };
3491
3551
  /**
3492
3552
  * Log by loaders summary.
@@ -3531,30 +3591,34 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3531
3591
  }
3532
3592
  }
3533
3593
  sum += innerSum;
3534
- if (innerSum <= 10) continue;
3535
- const idx = key.indexOf("!");
3536
- const loaders = key.slice(idx + 1);
3537
- const moduleType = key.slice(0, idx);
3538
- const t = Math.max(innerSum / 10, innerMax);
3594
+ /* istanbul ignore next -- @preserve: only slow (>10ms) loader groups are logged, timing-dependent */
3595
+ if (innerSum > 10) {
3596
+ const idx = key.indexOf("!");
3597
+ const loaders = key.slice(idx + 1);
3598
+ const moduleType = key.slice(0, idx);
3599
+ const t = Math.max(innerSum / 10, innerMax);
3600
+ logByValue(
3601
+ t,
3602
+ ` | ${Math.round(innerSum)} ms ${category} > ${
3603
+ loaders
3604
+ ? `${
3605
+ modules.length
3606
+ } x ${moduleType} with ${this.requestShortener.shorten(
3607
+ loaders
3608
+ )}`
3609
+ : `${modules.length} x ${moduleType}`
3610
+ }`
3611
+ );
3612
+ max = Math.max(max, t);
3613
+ }
3614
+ }
3615
+ /* istanbul ignore next -- @preserve: only slow (>10ms) categories are logged, timing-dependent */
3616
+ if (sum > 10) {
3539
3617
  logByValue(
3540
- t,
3541
- ` | ${Math.round(innerSum)} ms ${category} > ${
3542
- loaders
3543
- ? `${
3544
- modules.length
3545
- } x ${moduleType} with ${this.requestShortener.shorten(
3546
- loaders
3547
- )}`
3548
- : `${modules.length} x ${moduleType}`
3549
- }`
3618
+ Math.max(sum / 10, max),
3619
+ `${Math.round(sum)} ms ${category}`
3550
3620
  );
3551
- max = Math.max(max, t);
3552
3621
  }
3553
- if (sum <= 10) return;
3554
- logByValue(
3555
- Math.max(sum / 10, max),
3556
- `${Math.round(sum)} ms ${category}`
3557
- );
3558
3622
  };
3559
3623
  logNormalSummary(
3560
3624
  "resolve to new modules",
@@ -3614,7 +3678,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3614
3678
  continue;
3615
3679
  }
3616
3680
  let token;
3681
+ /** @type {string | true} */
3682
+ let clean = true;
3617
3683
  if (useReportCacheTokens) {
3684
+ // a request leaving a lazy barrel reports without any rebuild
3685
+ const lazyRequests = this._getLazyRequests(module);
3686
+ if (lazyRequests !== undefined) clean = lazyRequests;
3618
3687
  token = dependencyReportCacheTokens.get(module);
3619
3688
  const cleanModules = modulesWithoutProblems.get(
3620
3689
  /** @type {DependencyReportCacheToken} */ (token)
@@ -3622,7 +3691,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3622
3691
  if (
3623
3692
  !unresolved &&
3624
3693
  cleanModules !== undefined &&
3625
- cleanModules.has(module)
3694
+ cleanModules.get(module) === clean
3626
3695
  ) {
3627
3696
  continue;
3628
3697
  }
@@ -3659,10 +3728,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3659
3728
  if (cleanModules === undefined) {
3660
3729
  modulesWithoutProblems.set(
3661
3730
  /** @type {DependencyReportCacheToken} */ (token),
3662
- (cleanModules = new WeakSet())
3731
+ (cleanModules = new WeakMap())
3663
3732
  );
3664
3733
  }
3665
- cleanModules.add(module);
3734
+ cleanModules.set(module, clean);
3666
3735
  }
3667
3736
  }
3668
3737
  }
@@ -4364,8 +4433,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4364
4433
  if (!referencedModule) return false;
4365
4434
  return (
4366
4435
  notCodeGeneratedModules === undefined ||
4367
- /** @type {NotCodeGeneratedModules} */
4368
- (notCodeGeneratedModules).has(referencedModule)
4436
+ notCodeGeneratedModules.has(referencedModule)
4369
4437
  );
4370
4438
  })
4371
4439
  ) {
@@ -4734,7 +4802,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4734
4802
  * is over. `runtimeRequirementInTree` is a sync hook, so a tap cannot await
4735
4803
  * the load itself; anything the tap reads off the requirement set must be
4736
4804
  * captured before queueing, since `create` runs later.
4737
- * @template T
4805
+ * @template {object} T
4738
4806
  * @param {Chunk} chunk target chunk
4739
4807
  * @param {() => Promise<T>} load resolves the runtime module implementation
4740
4808
  * @param {(loaded: T) => RuntimeModule} create builds the runtime module from it
@@ -4762,7 +4830,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4762
4830
  .then((loaded) => {
4763
4831
  for (let i = 0; i < pending.length; i++) {
4764
4832
  const { chunk, create, chunkGraph } = pending[i];
4765
- this.addRuntimeModule(chunk, create(loaded[i]), chunkGraph);
4833
+ this.addRuntimeModule(
4834
+ chunk,
4835
+ create(/** @type {never} */ (loaded[i])),
4836
+ chunkGraph
4837
+ );
4766
4838
  }
4767
4839
  })
4768
4840
  // a `runtimeModule` tap may have queued more
@@ -5288,7 +5360,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
5288
5360
 
5289
5361
  createHash() {
5290
5362
  this.logger.time("hashing: initialize hash");
5291
- const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
5363
+ const chunkGraph = this.chunkGraph;
5292
5364
  const runtimeTemplate = this.runtimeTemplate;
5293
5365
  const outputOptions = this.outputOptions;
5294
5366
  const hashFunction = outputOptions.hashFunction;
@@ -5431,6 +5503,26 @@ This prevents using hashes of each other and should be avoided.`);
5431
5503
  this.warnings.push(err);
5432
5504
  for (const i of circularRuntimeChunkInfo) runtimeChunks.push(i.chunk);
5433
5505
  }
5506
+ // An ESM entry chunk imports the chunks of the entrypoints it depends on
5507
+ // (`dependOn`) by hashed filename, so their entry chunks are hashed first.
5508
+ /** @type {Set<Chunk>} */
5509
+ const unorderedEntryChunks = new Set(entryChunks);
5510
+ entryChunks.length = 0;
5511
+ /**
5512
+ * Adds an entry chunk after the entry chunks of its parent entrypoints.
5513
+ * @param {Chunk} chunk the entry chunk
5514
+ * @returns {void}
5515
+ */
5516
+ const addEntryChunk = (chunk) => {
5517
+ if (!unorderedEntryChunks.delete(chunk)) return;
5518
+ for (const group of chunk.groupsIterable) {
5519
+ for (const parent of group.parentsIterable) {
5520
+ for (const c of parent.chunks) addEntryChunk(c);
5521
+ }
5522
+ }
5523
+ entryChunks.push(chunk);
5524
+ };
5525
+ for (const chunk of unorderedEntryChunks) addEntryChunk(chunk);
5434
5526
  this.logger.timeEnd("hashing: sort chunks");
5435
5527
 
5436
5528
  /** @type {Set<Chunk>} */
package/lib/Compiler.js CHANGED
@@ -140,7 +140,7 @@ const getConcurrentCompilationError = memoize(() =>
140
140
 
141
141
  /** @typedef {WeakMap<Dependency, Module>} WeakReferences */
142
142
  /** @typedef {import("./util/WeakTupleMap")<EXPECTED_ANY[], EXPECTED_ANY>} MemCache */
143
- /** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, memCache: MemCache }} ModuleMemCachesItem */
143
+ /** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, lazyRequests: string | undefined, memCache: MemCache }} ModuleMemCachesItem */
144
144
 
145
145
  /**
146
146
  * Checks whether this object is sorted.
@@ -925,11 +925,9 @@ ${other}`);
925
925
  if (targetFileGeneration === undefined) {
926
926
  const newGeneration = 1;
927
927
  this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
928
- /** @type {CacheEntry} */
929
- (cacheEntry).writtenTo.set(targetPath, newGeneration);
928
+ cacheEntry.writtenTo.set(targetPath, newGeneration);
930
929
  } else {
931
- /** @type {CacheEntry} */
932
- (cacheEntry).writtenTo.set(targetPath, targetFileGeneration);
930
+ cacheEntry.writtenTo.set(targetPath, targetFileGeneration);
933
931
  }
934
932
  callback();
935
933
  };
@@ -957,8 +955,7 @@ ${other}`);
957
955
  targetFileGeneration === undefined
958
956
  ? 1
959
957
  : targetFileGeneration + 1;
960
- /** @type {CacheEntry} */
961
- (cacheEntry).writtenTo.set(targetPath, newGeneration);
958
+ cacheEntry.writtenTo.set(targetPath, newGeneration);
962
959
  this._assetEmittingWrittenFiles.set(
963
960
  targetPath,
964
961
  newGeneration
@@ -983,11 +980,7 @@ ${other}`);
983
980
  * @param {number} size size
984
981
  */
985
982
  const updateWithReplacementSource = (size) => {
986
- updateFileWithReplacementSource(
987
- file,
988
- /** @type {CacheEntry} */ (cacheEntry),
989
- size
990
- );
983
+ updateFileWithReplacementSource(file, cacheEntry, size);
991
984
  /** @type {SimilarEntry} */
992
985
  (similarEntry).size = size;
993
986
  if (
@@ -1055,7 +1048,7 @@ ${other}`);
1055
1048
  const processExistingFile = (stats) => {
1056
1049
  // skip emitting if it's already there and an immutable file
1057
1050
  if (immutable) {
1058
- updateWithReplacementSource(/** @type {number} */ (stats.size));
1051
+ updateWithReplacementSource(stats.size);
1059
1052
  return keepExistingFile(stats);
1060
1053
  }
1061
1054
 
@@ -1095,9 +1088,7 @@ ${other}`);
1095
1088
  // if the target file has already been written
1096
1089
  if (targetFileGeneration !== undefined) {
1097
1090
  // check if the Source has been written to this target file
1098
- const writtenGeneration = /** @type {CacheEntry} */ (
1099
- cacheEntry
1100
- ).writtenTo.get(targetPath);
1091
+ const writtenGeneration = cacheEntry.writtenTo.get(targetPath);
1101
1092
  if (writtenGeneration === targetFileGeneration) {
1102
1093
  // if yes, we may skip writing the file
1103
1094
  // if it's already there
@@ -1105,7 +1096,7 @@ ${other}`);
1105
1096
 
1106
1097
  if (this._assetEmittingPreviousFiles.has(targetPath)) {
1107
1098
  const sizeOnlySource = /** @type {SizeOnlySource} */ (
1108
- /** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
1099
+ cacheEntry.sizeOnlySource
1109
1100
  );
1110
1101
 
1111
1102
  // We assume that assets from the last compilation say intact on disk (they are not removed)
@@ -1209,8 +1200,7 @@ ${other}`);
1209
1200
  )
1210
1201
  );
1211
1202
  }
1212
- /** @type {NonNullable<OutputFileSystem["utimes"]>} */
1213
- (fs.utimes)(
1203
+ fs.utimes(
1214
1204
  targetPath,
1215
1205
  new Date(timestamps.atime),
1216
1206
  new Date(timestamps.mtime),
@@ -1226,8 +1216,7 @@ ${other}`);
1226
1216
  )
1227
1217
  );
1228
1218
  }
1229
- /** @type {NonNullable<OutputFileSystem["chmod"]>} */
1230
- (fs.chmod)(targetPath, mode, setTimestamps);
1219
+ fs.chmod(targetPath, mode, setTimestamps);
1231
1220
  }
1232
1221
 
1233
1222
  /**
@@ -1282,13 +1271,11 @@ ${other}`);
1282
1271
 
1283
1272
  const replace = () => {
1284
1273
  if (!fs.unlink) return create();
1285
- /** @type {NonNullable<OutputFileSystem["unlink"]>} */
1286
- (fs.unlink)(targetPath, () => create());
1274
+ fs.unlink(targetPath, () => create());
1287
1275
  };
1288
1276
 
1289
1277
  if (!fs.readlink) return replace();
1290
- /** @type {NonNullable<OutputFileSystem["readlink"]>} */
1291
- (fs.readlink)(targetPath, (err, existingTarget) => {
1278
+ fs.readlink(targetPath, (err, existingTarget) => {
1292
1279
  if (!err && existingTarget === target) return callback(null);
1293
1280
  replace();
1294
1281
  });
@@ -20,6 +20,7 @@ const {
20
20
  const ConcatenationScope = require("../optimize/ConcatenationScope");
21
21
  const RuntimeGlobals = require("../runtime/RuntimeGlobals");
22
22
 
23
+ /** @import { AssetNormalModule } from "./AssetModule" */
23
24
  /** @import { Source } from "webpack-sources" */
24
25
  /** @import { GenerateContext } from "../module/Generator" */
25
26
  /**
@@ -30,8 +31,15 @@ const RuntimeGlobals = require("../runtime/RuntimeGlobals");
30
31
  * } from "../module/Module"
31
32
  */
32
33
  /** @import ModuleGraph from "../graph/ModuleGraph" */
33
- /** @import NormalModule from "../module/NormalModule" */
34
34
 
35
+ /**
36
+ * The module type the JSDoc inherited from `Generator` names.
37
+ * @typedef {AssetNormalModule} TModule
38
+ */
39
+
40
+ /**
41
+ * @extends {Generator<TModule>}
42
+ */
35
43
  class AssetBytesGenerator extends Generator {
36
44
  /**
37
45
  * Creates an instance of AssetBytesGenerator.
@@ -46,7 +54,7 @@ class AssetBytesGenerator extends Generator {
46
54
 
47
55
  /**
48
56
  * Generates generated code for this runtime module.
49
- * @param {NormalModule} module module for which the code should be generated
57
+ * @param {TModule} module module for which the code should be generated
50
58
  * @param {GenerateContext} generateContext context for generate
51
59
  * @returns {Source | null} generated code
52
60
  */
@@ -107,7 +115,7 @@ class AssetBytesGenerator extends Generator {
107
115
  /**
108
116
  * Generates fallback output for the provided error condition.
109
117
  * @param {Error} error the error
110
- * @param {NormalModule} module module for which the code should be generated
118
+ * @param {TModule} module module for which the code should be generated
111
119
  * @param {GenerateContext} generateContext context for generate
112
120
  * @returns {Source | null} generated code
113
121
  */
@@ -129,7 +137,7 @@ class AssetBytesGenerator extends Generator {
129
137
 
130
138
  /**
131
139
  * Returns the reason this module cannot be concatenated, when one exists.
132
- * @param {NormalModule} module module for which the bailout reason should be determined
140
+ * @param {TModule} module module for which the bailout reason should be determined
133
141
  * @param {ConcatenationBailoutReasonContext} context context
134
142
  * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
135
143
  */
@@ -139,7 +147,7 @@ class AssetBytesGenerator extends Generator {
139
147
 
140
148
  /**
141
149
  * Returns the source types available for this module.
142
- * @param {NormalModule} module fresh module
150
+ * @param {TModule} module fresh module
143
151
  * @returns {SourceTypes} available types (do not mutate)
144
152
  */
145
153
  getTypes(module) {
@@ -179,7 +187,7 @@ class AssetBytesGenerator extends Generator {
179
187
 
180
188
  /**
181
189
  * Returns the estimated size for the requested source type.
182
- * @param {NormalModule} module the module
190
+ * @param {TModule} module the module
183
191
  * @param {SourceType=} type source type
184
192
  * @returns {number} estimate size of the module
185
193
  */
@@ -7,9 +7,12 @@
7
7
 
8
8
  const Parser = require("../module/Parser");
9
9
 
10
- /** @import { BuildInfo, BuildMeta } from "../module/Module" */
10
+ /** @import { BuiltAssetModule } from "./AssetModule" */
11
11
  /** @import { ParserState, PreparsedAst } from "../module/Parser" */
12
12
 
13
+ /**
14
+ * @extends {Parser<BuiltAssetModule>}
15
+ */
13
16
  class AssetBytesParser extends Parser {
14
17
  /**
15
18
  * Parses the provided source and updates the parser state.
@@ -21,13 +24,12 @@ class AssetBytesParser extends Parser {
21
24
  if (typeof source === "object" && !Buffer.isBuffer(source)) {
22
25
  throw new Error("AssetBytesParser doesn't accept preparsed AST");
23
26
  }
24
- const { module } = state;
25
- /** @type {BuildInfo} */
26
- (module.buildInfo).strict = true;
27
- /** @type {BuildMeta} */
28
- (module.buildMeta).exportsType = "default";
29
- /** @type {BuildMeta} */
30
- (state.module.buildMeta).defaultObject = false;
27
+ const { buildInfo, buildMeta } = /** @type {BuiltAssetModule} */ (
28
+ state.module
29
+ );
30
+ buildInfo.strict = true;
31
+ buildMeta.exportsType = "default";
32
+ buildMeta.defaultObject = false;
31
33
 
32
34
  return state;
33
35
  }