@depup/webpack 5.106.1-depup.0 → 5.109.2-depup.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 (669) hide show
  1. package/README.md +9 -11
  2. package/bin/webpack.js +12 -0
  3. package/changes.json +16 -24
  4. package/hot/dev-server.js +2 -0
  5. package/lib/APIPlugin.js +60 -35
  6. package/lib/AsyncDependenciesBlock.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +6 -1
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +27 -5
  10. package/lib/CacheFacade.js +41 -0
  11. package/lib/Chunk.js +71 -25
  12. package/lib/ChunkGraph.js +153 -19
  13. package/lib/ChunkGroup.js +115 -28
  14. package/lib/ChunkTemplate.js +9 -0
  15. package/lib/CircularModulesPlugin.js +190 -0
  16. package/lib/CleanPlugin.js +27 -28
  17. package/lib/CodeGenerationResults.js +19 -0
  18. package/lib/CompatibilityPlugin.js +85 -37
  19. package/lib/Compilation.js +656 -112
  20. package/lib/Compiler.js +109 -35
  21. package/lib/ConcatenationScope.js +34 -4
  22. package/lib/ConditionalInitFragment.js +6 -0
  23. package/lib/ConstPlugin.js +15 -12
  24. package/lib/ContextExclusionPlugin.js +3 -1
  25. package/lib/ContextModule.js +345 -55
  26. package/lib/ContextModuleFactory.js +193 -51
  27. package/lib/ContextReplacementPlugin.js +8 -1
  28. package/lib/DefinePlugin.js +537 -139
  29. package/lib/DependenciesBlock.js +6 -1
  30. package/lib/Dependency.js +159 -11
  31. package/lib/DependencyTemplate.js +7 -1
  32. package/lib/DependencyTemplates.js +4 -0
  33. package/lib/DotenvPlugin.js +3 -0
  34. package/lib/DynamicEntryPlugin.js +3 -1
  35. package/lib/EntryOptionPlugin.js +42 -2
  36. package/lib/EntryPlugin.js +4 -1
  37. package/lib/Entrypoint.js +5 -1
  38. package/lib/EnvironmentPlugin.js +3 -2
  39. package/lib/ErrorHelpers.js +7 -0
  40. package/lib/EvalDevToolModulePlugin.js +3 -1
  41. package/lib/EvalSourceMapDevToolPlugin.js +11 -11
  42. package/lib/ExportsInfo.js +421 -113
  43. package/lib/ExportsInfoApiPlugin.js +4 -3
  44. package/lib/ExternalModule.js +381 -80
  45. package/lib/ExternalModuleFactoryPlugin.js +75 -3
  46. package/lib/ExternalsPlugin.js +3 -1
  47. package/lib/FileSystemInfo.js +701 -175
  48. package/lib/FlagAllModulesAsUsedPlugin.js +3 -6
  49. package/lib/FlagDependencyExportsPlugin.js +82 -9
  50. package/lib/FlagDependencyUsagePlugin.js +115 -8
  51. package/lib/FlagEntryExportAsUsedPlugin.js +4 -1
  52. package/lib/Generator.js +24 -3
  53. package/lib/HotModuleReplacementPlugin.js +110 -44
  54. package/lib/IgnorePlugin.js +5 -2
  55. package/lib/IgnoreWarningsPlugin.js +2 -1
  56. package/lib/InitFragment.js +33 -30
  57. package/lib/JavascriptMetaInfoPlugin.js +9 -6
  58. package/lib/LazyBarrel.js +389 -0
  59. package/lib/LibraryTemplatePlugin.js +2 -1
  60. package/lib/LoaderOptionsPlugin.js +3 -1
  61. package/lib/LoaderTargetPlugin.js +3 -1
  62. package/lib/MainTemplate.js +15 -0
  63. package/lib/ManifestPlugin.js +9 -2
  64. package/lib/Module.js +121 -57
  65. package/lib/ModuleFactory.js +6 -1
  66. package/lib/ModuleFilenameHelpers.js +18 -4
  67. package/lib/ModuleGraph.js +69 -2
  68. package/lib/ModuleGraphConnection.js +9 -0
  69. package/lib/ModuleInfoHeaderPlugin.js +5 -0
  70. package/lib/ModuleNotFoundError.js +3 -83
  71. package/lib/ModuleProfile.js +27 -1
  72. package/lib/ModuleSourceTypeConstants.js +52 -19
  73. package/lib/ModuleTemplate.js +10 -0
  74. package/lib/ModuleTypeConstants.js +20 -4
  75. package/lib/MultiCompiler.js +59 -4
  76. package/lib/MultiStats.js +9 -0
  77. package/lib/MultiWatching.js +6 -0
  78. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  79. package/lib/NodeStuffPlugin.js +78 -46
  80. package/lib/NormalModule.js +519 -206
  81. package/lib/NormalModuleFactory.js +156 -31
  82. package/lib/NormalModuleReplacementPlugin.js +3 -1
  83. package/lib/NullFactory.js +1 -0
  84. package/lib/OptionsApply.js +1 -0
  85. package/lib/Parser.js +3 -1
  86. package/lib/PlatformPlugin.js +2 -1
  87. package/lib/PrefetchPlugin.js +4 -1
  88. package/lib/ProgressPlugin.js +351 -161
  89. package/lib/ProvidePlugin.js +6 -3
  90. package/lib/RawModule.js +32 -16
  91. package/lib/RecordIdsPlugin.js +9 -0
  92. package/lib/RequestShortener.js +8 -0
  93. package/lib/ResolverFactory.js +5 -0
  94. package/lib/RuntimeGlobals.js +58 -5
  95. package/lib/RuntimeModule.js +22 -7
  96. package/lib/RuntimePlugin.js +123 -118
  97. package/lib/RuntimeTemplate.js +616 -37
  98. package/lib/SelfModuleFactory.js +3 -0
  99. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
  100. package/lib/SourceMapDevToolPlugin.js +341 -63
  101. package/lib/Stats.js +6 -0
  102. package/lib/Template.js +52 -6
  103. package/lib/TemplatedPathPlugin.js +505 -138
  104. package/lib/UseStrictPlugin.js +3 -2
  105. package/lib/WarnCaseSensitiveModulesPlugin.js +72 -3
  106. package/lib/WarnDeprecatedOptionPlugin.js +6 -2
  107. package/lib/WarnNoModeSetPlugin.js +18 -2
  108. package/lib/WatchIgnorePlugin.js +5 -1
  109. package/lib/Watching.js +25 -3
  110. package/lib/WebpackError.js +3 -74
  111. package/lib/WebpackIsIncludedPlugin.js +4 -2
  112. package/lib/WebpackOptionsApply.js +88 -25
  113. package/lib/WebpackOptionsDefaulter.js +1 -0
  114. package/lib/asset/AssetBytesGenerator.js +28 -10
  115. package/lib/asset/AssetBytesParser.js +1 -0
  116. package/lib/asset/AssetGenerator.js +199 -60
  117. package/lib/asset/AssetModule.js +47 -0
  118. package/lib/asset/AssetModulesPlugin.js +115 -24
  119. package/lib/asset/AssetParser.js +4 -2
  120. package/lib/asset/AssetSourceGenerator.js +26 -8
  121. package/lib/asset/AssetSourceParser.js +1 -0
  122. package/lib/asset/RawDataUrlModule.js +23 -13
  123. package/lib/asset/WebManifestGenerator.js +164 -0
  124. package/lib/asset/WebManifestParser.js +130 -0
  125. package/lib/async-modules/AsyncModuleHelpers.js +1 -0
  126. package/lib/async-modules/AwaitDependenciesInitFragment.js +18 -4
  127. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  128. package/lib/async-modules/isGeneratorLowered.js +26 -0
  129. package/lib/buildChunkGraph.js +107 -15
  130. package/lib/bun/BunTargetPlugin.js +42 -0
  131. package/lib/cache/AddBuildDependenciesPlugin.js +3 -1
  132. package/lib/cache/AddManagedPathsPlugin.js +5 -1
  133. package/lib/cache/IdleFileCachePlugin.js +6 -1
  134. package/lib/cache/MemoryCachePlugin.js +1 -1
  135. package/lib/cache/MemoryWithGcCachePlugin.js +4 -1
  136. package/lib/cache/PackFileCacheStrategy.js +302 -12
  137. package/lib/cache/ResolverCachePlugin.js +12 -1
  138. package/lib/cache/getLazyHashedEtag.js +13 -2
  139. package/lib/cache/mergeEtags.js +4 -0
  140. package/lib/cli.js +142 -20
  141. package/lib/config/browserslistTargetHandler.js +141 -0
  142. package/lib/config/defaults.js +612 -43
  143. package/lib/config/defineConfig.js +31 -0
  144. package/lib/config/normalization.js +46 -1
  145. package/lib/config/target.js +200 -2
  146. package/lib/container/ContainerEntryDependency.js +2 -0
  147. package/lib/container/ContainerEntryModule.js +27 -14
  148. package/lib/container/ContainerEntryModuleFactory.js +1 -0
  149. package/lib/container/ContainerExposedDependency.js +6 -2
  150. package/lib/container/ContainerPlugin.js +2 -1
  151. package/lib/container/ContainerReferencePlugin.js +3 -2
  152. package/lib/container/FallbackDependency.js +9 -7
  153. package/lib/container/FallbackItemDependency.js +1 -0
  154. package/lib/container/FallbackModule.js +22 -9
  155. package/lib/container/FallbackModuleFactory.js +1 -0
  156. package/lib/container/HoistContainerReferencesPlugin.js +47 -55
  157. package/lib/container/ModuleFederationPlugin.js +21 -29
  158. package/lib/container/RemoteModule.js +33 -10
  159. package/lib/container/RemoteRuntimeModule.js +15 -12
  160. package/lib/container/RemoteToExternalDependency.js +1 -0
  161. package/lib/container/options.js +7 -0
  162. package/lib/css/CssGenerator.js +540 -272
  163. package/lib/css/CssInjectStyleRuntimeModule.js +86 -70
  164. package/lib/css/CssLoadingRuntimeModule.js +173 -81
  165. package/lib/{CssModule.js → css/CssModule.js} +72 -37
  166. package/lib/css/CssModulesPlugin.js +371 -208
  167. package/lib/css/CssParser.js +3538 -1963
  168. package/lib/css/syntax.js +4155 -0
  169. package/lib/debug/ProfilingPlugin.js +33 -2
  170. package/lib/deno/DenoTargetPlugin.js +41 -0
  171. package/lib/dependencies/AMDDefineDependency.js +29 -17
  172. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +19 -6
  173. package/lib/dependencies/AMDPlugin.js +6 -3
  174. package/lib/dependencies/AMDRequireArrayDependency.js +13 -11
  175. package/lib/dependencies/AMDRequireContextDependency.js +10 -11
  176. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
  177. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -14
  178. package/lib/dependencies/AMDRequireDependency.js +28 -20
  179. package/lib/dependencies/AMDRequireItemDependency.js +1 -0
  180. package/lib/dependencies/AMDRuntimeModules.js +3 -0
  181. package/lib/dependencies/CachedConstDependency.js +9 -1
  182. package/lib/dependencies/CommonJsDependencyHelpers.js +104 -0
  183. package/lib/dependencies/CommonJsExportRequireDependency.js +157 -38
  184. package/lib/dependencies/CommonJsExportsDependency.js +74 -20
  185. package/lib/dependencies/CommonJsExportsParserPlugin.js +246 -15
  186. package/lib/dependencies/CommonJsFullRequireDependency.js +91 -27
  187. package/lib/dependencies/CommonJsImportsParserPlugin.js +189 -24
  188. package/lib/dependencies/CommonJsPlugin.js +7 -4
  189. package/lib/dependencies/CommonJsRequireContextDependency.js +13 -13
  190. package/lib/dependencies/CommonJsRequireDependency.js +135 -13
  191. package/lib/dependencies/CommonJsSelfReferenceDependency.js +60 -16
  192. package/lib/dependencies/ConstDependency.js +22 -12
  193. package/lib/dependencies/ContextDependency.js +13 -2
  194. package/lib/dependencies/ContextDependencyHelpers.js +7 -4
  195. package/lib/dependencies/ContextDependencyTemplateAsId.js +2 -1
  196. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  197. package/lib/dependencies/ContextElementDependency.js +27 -14
  198. package/lib/dependencies/CreateRequireParserPlugin.js +14 -7
  199. package/lib/dependencies/CreateScriptUrlDependency.js +9 -7
  200. package/lib/dependencies/CriticalDependencyWarning.js +3 -1
  201. package/lib/dependencies/CssIcssExportDependency.js +681 -367
  202. package/lib/dependencies/CssIcssImportDependency.js +62 -17
  203. package/lib/dependencies/CssIcssSymbolDependency.js +36 -17
  204. package/lib/dependencies/CssImportDependency.js +37 -1
  205. package/lib/dependencies/CssUrlDependency.js +87 -14
  206. package/lib/dependencies/DelegatedSourceDependency.js +1 -0
  207. package/lib/dependencies/DllEntryDependency.js +12 -13
  208. package/lib/dependencies/DynamicExports.js +5 -0
  209. package/lib/dependencies/EntryDependency.js +1 -0
  210. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  211. package/lib/dependencies/ExportsInfoDependency.js +18 -12
  212. package/lib/dependencies/ExternalModuleDependency.js +13 -5
  213. package/lib/dependencies/ExternalModuleInitFragment.js +10 -5
  214. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +19 -12
  215. package/lib/dependencies/HarmonyAcceptDependency.js +24 -26
  216. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -0
  217. package/lib/dependencies/HarmonyCompatibilityDependency.js +33 -14
  218. package/lib/dependencies/HarmonyDetectionParserPlugin.js +108 -30
  219. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +34 -3
  220. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +70 -33
  221. package/lib/dependencies/HarmonyExportExpressionDependency.js +133 -43
  222. package/lib/dependencies/HarmonyExportHeaderDependency.js +11 -9
  223. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +268 -44
  224. package/lib/dependencies/HarmonyExportInitFragment.js +28 -20
  225. package/lib/dependencies/HarmonyExportSpecifierDependency.js +88 -18
  226. package/lib/dependencies/HarmonyExports.js +6 -1
  227. package/lib/dependencies/HarmonyImportDependency.js +60 -4
  228. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +139 -146
  229. package/lib/dependencies/HarmonyImportGuard.js +427 -0
  230. package/lib/dependencies/HarmonyImportSideEffectDependency.js +22 -1
  231. package/lib/dependencies/HarmonyImportSpecifierDependency.js +146 -24
  232. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +6 -3
  233. package/lib/dependencies/HarmonyModulesPlugin.js +11 -1
  234. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +2 -1
  235. package/lib/dependencies/HtmlEntryDependency.js +1295 -0
  236. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  237. package/lib/dependencies/HtmlInlineScriptDependency.js +126 -0
  238. package/lib/dependencies/HtmlInlineStyleDependency.js +152 -0
  239. package/lib/dependencies/HtmlSourceDependency.js +172 -0
  240. package/lib/dependencies/ImportContextDependency.js +9 -9
  241. package/lib/dependencies/ImportDependency.js +92 -3
  242. package/lib/dependencies/ImportEagerDependency.js +2 -0
  243. package/lib/dependencies/ImportMetaContextDependency.js +1 -0
  244. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +35 -19
  245. package/lib/dependencies/ImportMetaContextPlugin.js +40 -8
  246. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  247. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  248. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  249. package/lib/dependencies/ImportMetaHotAcceptDependency.js +2 -0
  250. package/lib/dependencies/ImportMetaHotDeclineDependency.js +2 -0
  251. package/lib/dependencies/ImportMetaPlugin.js +595 -209
  252. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  253. package/lib/dependencies/ImportParserPlugin.js +114 -27
  254. package/lib/dependencies/ImportPhase.js +17 -11
  255. package/lib/dependencies/ImportPlugin.js +2 -1
  256. package/lib/dependencies/ImportWeakDependency.js +3 -0
  257. package/lib/dependencies/JsonExportsDependency.js +15 -10
  258. package/lib/dependencies/LoaderDependency.js +2 -0
  259. package/lib/dependencies/LoaderImportDependency.js +3 -0
  260. package/lib/dependencies/LoaderPlugin.js +9 -2
  261. package/lib/dependencies/LocalModule.js +15 -12
  262. package/lib/dependencies/LocalModuleDependency.js +15 -13
  263. package/lib/dependencies/LocalModulesHelpers.js +3 -0
  264. package/lib/dependencies/ModuleDecoratorDependency.js +16 -10
  265. package/lib/dependencies/ModuleDependency.js +14 -0
  266. package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
  267. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  268. package/lib/dependencies/ModuleHotAcceptDependency.js +2 -0
  269. package/lib/dependencies/ModuleHotDeclineDependency.js +2 -0
  270. package/lib/dependencies/ModuleInitFragmentDependency.js +19 -11
  271. package/lib/dependencies/NullDependency.js +2 -0
  272. package/lib/dependencies/PrefetchDependency.js +1 -0
  273. package/lib/dependencies/ProvidedDependency.js +36 -27
  274. package/lib/dependencies/PureExpressionDependency.js +14 -10
  275. package/lib/dependencies/RequireContextDependency.js +1 -0
  276. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -1
  277. package/lib/dependencies/RequireContextPlugin.js +2 -1
  278. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
  279. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +4 -6
  280. package/lib/dependencies/RequireEnsureDependency.js +16 -13
  281. package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
  282. package/lib/dependencies/RequireEnsurePlugin.js +2 -1
  283. package/lib/dependencies/RequireHeaderDependency.js +7 -4
  284. package/lib/dependencies/RequireIncludeDependency.js +2 -0
  285. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +11 -12
  286. package/lib/dependencies/RequireIncludePlugin.js +2 -1
  287. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
  288. package/lib/dependencies/RequireResolveContextDependency.js +10 -11
  289. package/lib/dependencies/RequireResolveDependency.js +2 -0
  290. package/lib/dependencies/RequireResolveHeaderDependency.js +8 -5
  291. package/lib/dependencies/RuntimeRequirementsDependency.js +11 -8
  292. package/lib/dependencies/StaticExportsDependency.js +13 -10
  293. package/lib/dependencies/SystemPlugin.js +9 -6
  294. package/lib/dependencies/SystemRuntimeModule.js +1 -0
  295. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  296. package/lib/dependencies/URLContextDependency.js +8 -7
  297. package/lib/dependencies/URLDependency.js +157 -33
  298. package/lib/dependencies/URLPlugin.js +2 -0
  299. package/lib/dependencies/UnsupportedDependency.js +12 -13
  300. package/lib/dependencies/WebAssemblyExportImportedDependency.js +15 -16
  301. package/lib/dependencies/WebAssemblyImportDependency.js +19 -18
  302. package/lib/dependencies/WebpackIsIncludedDependency.js +3 -0
  303. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +364 -114
  304. package/lib/dependencies/WorkerDependency.js +111 -27
  305. package/lib/dependencies/WorkletDependency.js +278 -0
  306. package/lib/dependencies/getFunctionExpression.js +1 -0
  307. package/lib/dependencies/processExportInfo.js +14 -11
  308. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +71 -44
  309. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +27 -4
  310. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +5 -3
  311. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +9 -5
  312. package/lib/{DllModule.js → dll/DllModule.js} +36 -24
  313. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
  314. package/lib/{DllPlugin.js → dll/DllPlugin.js} +24 -6
  315. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +26 -18
  316. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +14 -10
  317. package/lib/electron/ElectronTargetPlugin.js +24 -5
  318. package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
  319. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
  320. package/lib/errors/BuildCycleError.js +1 -1
  321. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  322. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  323. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
  324. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +5 -2
  325. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +5 -5
  326. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +20 -16
  327. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +7 -4
  328. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +6 -3
  329. package/lib/errors/JSONParseError.js +115 -0
  330. package/lib/errors/LoaderLoadingError.js +20 -0
  331. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +22 -16
  332. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +10 -3
  333. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +13 -5
  334. package/lib/{ModuleError.js → errors/ModuleError.js} +10 -14
  335. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +5 -1
  336. package/lib/errors/ModuleNotFoundError.js +94 -0
  337. package/lib/errors/ModuleParseError.js +141 -0
  338. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +4 -1
  339. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +5 -1
  340. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +13 -14
  341. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +7 -5
  342. package/lib/errors/NonErrorEmittedError.js +30 -0
  343. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +9 -2
  344. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
  345. package/lib/errors/WebpackError.js +84 -0
  346. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  347. package/lib/esm/ModuleChunkFormatPlugin.js +52 -15
  348. package/lib/esm/ModuleChunkLoadingPlugin.js +11 -3
  349. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +80 -52
  350. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  351. package/lib/hmr/HotModuleReplacementRuntimeModule.js +8 -0
  352. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  353. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
  354. package/lib/hmr/LazyCompilationPlugin.js +154 -7
  355. package/lib/hmr/lazyCompilationBackend.js +53 -12
  356. package/lib/html/HtmlGenerator.js +1490 -0
  357. package/lib/html/HtmlModule.js +41 -0
  358. package/lib/html/HtmlModulesPlugin.js +1129 -0
  359. package/lib/html/HtmlParser.js +1970 -0
  360. package/lib/html/favicon.svg +1 -0
  361. package/lib/html/syntax.js +9106 -0
  362. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
  363. package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
  364. package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
  365. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  366. package/lib/ids/IdHelpers.js +49 -12
  367. package/lib/ids/NamedChunkIdsPlugin.js +3 -1
  368. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  369. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  370. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  371. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
  372. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
  373. package/lib/ids/SyncModuleIdsPlugin.js +3 -1
  374. package/lib/index.js +66 -15
  375. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -6
  376. package/lib/javascript/BasicEvaluatedExpression.js +370 -49
  377. package/lib/javascript/ChunkFormatHelpers.js +2 -1
  378. package/lib/javascript/ChunkHelpers.js +1 -0
  379. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  380. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -1
  381. package/lib/javascript/JavascriptGenerator.js +213 -51
  382. package/lib/javascript/JavascriptModule.js +54 -0
  383. package/lib/javascript/JavascriptModulesPlugin.js +628 -198
  384. package/lib/javascript/JavascriptParser.js +1334 -471
  385. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  386. package/lib/javascript/StartupHelpers.js +5 -0
  387. package/lib/javascript/syntax.js +5037 -0
  388. package/lib/json/JsonData.js +5 -0
  389. package/lib/json/JsonGenerator.js +21 -0
  390. package/lib/json/JsonModule.js +40 -0
  391. package/lib/json/JsonModulesPlugin.js +8 -1
  392. package/lib/json/JsonParser.js +18 -27
  393. package/lib/library/AbstractLibraryPlugin.js +17 -2
  394. package/lib/library/AmdLibraryPlugin.js +8 -0
  395. package/lib/library/AssignLibraryPlugin.js +21 -3
  396. package/lib/library/EnableLibraryPlugin.js +8 -2
  397. package/lib/library/ExportPropertyLibraryPlugin.js +10 -0
  398. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +2 -1
  399. package/lib/library/JsonpLibraryPlugin.js +8 -0
  400. package/lib/library/ModuleLibraryPlugin.js +154 -7
  401. package/lib/library/SystemLibraryPlugin.js +11 -3
  402. package/lib/library/UmdLibraryPlugin.js +16 -0
  403. package/lib/loaders/LoaderRunner.js +714 -0
  404. package/lib/loaders/loadLoader.js +100 -0
  405. package/lib/logging/Logger.js +17 -0
  406. package/lib/logging/createConsoleLogger.js +7 -0
  407. package/lib/logging/runtime.js +2 -0
  408. package/lib/logging/truncateArgs.js +2 -0
  409. package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
  410. package/lib/node/NodeEnvironmentPlugin.js +7 -3
  411. package/lib/node/NodeSourcePlugin.js +1 -1
  412. package/lib/node/NodeTargetPlugin.js +4 -63
  413. package/lib/node/NodeTemplatePlugin.js +3 -1
  414. package/lib/node/NodeWatchFileSystem.js +40 -22
  415. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +13 -9
  416. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +33 -3
  417. package/lib/node/ReadFileCompileWasmPlugin.js +28 -3
  418. package/lib/node/RequireChunkLoadingRuntimeModule.js +21 -16
  419. package/lib/node/nodeBuiltins.js +80 -0
  420. package/lib/node/nodeConsole.js +116 -64
  421. package/lib/optimize/AggressiveMergingPlugin.js +22 -16
  422. package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
  423. package/lib/optimize/ConcatenatedModule.js +603 -130
  424. package/lib/optimize/ConstExportsPlugin.js +211 -0
  425. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
  426. package/lib/optimize/FlagIncludedChunksPlugin.js +15 -4
  427. package/lib/optimize/InlineExports.js +178 -0
  428. package/lib/optimize/InnerGraph.js +374 -262
  429. package/lib/optimize/InnerGraphPlugin.js +246 -117
  430. package/lib/optimize/LimitChunkCountPlugin.js +9 -0
  431. package/lib/optimize/MangleExportsPlugin.js +5 -1
  432. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
  433. package/lib/optimize/MinChunkSizePlugin.js +2 -1
  434. package/lib/optimize/MinMaxSizeWarning.js +5 -4
  435. package/lib/optimize/ModuleConcatenationPlugin.js +229 -55
  436. package/lib/optimize/RealContentHashPlugin.js +130 -52
  437. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  438. package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
  439. package/lib/optimize/RuntimeChunkPlugin.js +2 -1
  440. package/lib/optimize/SideEffectsFlagPlugin.js +381 -55
  441. package/lib/optimize/SplitChunksPlugin.js +200 -50
  442. package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
  443. package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
  444. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  445. package/lib/performance/SizeLimitsPlugin.js +8 -2
  446. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
  447. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +21 -0
  448. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
  449. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
  450. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +25 -13
  451. package/lib/prefetch/ResourceHintPlugin.js +687 -0
  452. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  453. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  454. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  455. package/lib/rules/BasicEffectRulePlugin.js +3 -0
  456. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  457. package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
  458. package/lib/rules/RuleSetCompiler.js +132 -0
  459. package/lib/rules/UseEffectRulePlugin.js +10 -3
  460. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  461. package/lib/runtime/AsyncModuleRuntimeModule.js +52 -33
  462. package/lib/runtime/AutoPublicPathRuntimeModule.js +22 -9
  463. package/lib/runtime/BaseUriRuntimeModule.js +1 -0
  464. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  465. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  466. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -1
  467. package/lib/runtime/CompatRuntimeModule.js +2 -0
  468. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  469. package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
  470. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
  471. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +34 -4
  472. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  473. package/lib/runtime/GetChunkFilenameRuntimeModule.js +88 -8
  474. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  475. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
  476. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  477. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  478. package/lib/runtime/GlobalRuntimeModule.js +1 -0
  479. package/lib/runtime/HasOwnPropertyRuntimeModule.js +2 -1
  480. package/lib/runtime/HelperRuntimeModule.js +5 -0
  481. package/lib/runtime/LoadScriptRuntimeModule.js +28 -37
  482. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +354 -37
  483. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -1
  484. package/lib/runtime/NonceRuntimeModule.js +1 -0
  485. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -4
  486. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  487. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -2
  488. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
  489. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +38 -0
  490. package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
  491. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -1
  492. package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -3
  493. package/lib/runtime/SystemContextRuntimeModule.js +1 -0
  494. package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
  495. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  496. package/lib/schemes/DataUriPlugin.js +14 -2
  497. package/lib/schemes/FileUriPlugin.js +1 -1
  498. package/lib/schemes/HttpUriPlugin.js +86 -4
  499. package/lib/schemes/VirtualUrlPlugin.js +8 -4
  500. package/lib/serialization/AggregateErrorSerializer.js +9 -6
  501. package/lib/serialization/ArraySerializer.js +6 -8
  502. package/lib/serialization/BinaryMiddleware.js +427 -1006
  503. package/lib/serialization/DateObjectSerializer.js +4 -2
  504. package/lib/serialization/ErrorObjectSerializer.js +10 -6
  505. package/lib/serialization/FileMiddleware.js +345 -59
  506. package/lib/serialization/MapObjectSerializer.js +7 -9
  507. package/lib/serialization/NullPrototypeObjectSerializer.js +9 -9
  508. package/lib/serialization/ObjectMiddleware.js +73 -13
  509. package/lib/serialization/PlainObjectSerializer.js +16 -8
  510. package/lib/serialization/RegExpObjectSerializer.js +4 -2
  511. package/lib/serialization/Serializer.js +6 -0
  512. package/lib/serialization/SerializerMiddleware.js +14 -2
  513. package/lib/serialization/SetObjectSerializer.js +6 -8
  514. package/lib/serialization/SingleItemMiddleware.js +3 -0
  515. package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
  516. package/lib/sharing/ConsumeSharedModule.js +21 -7
  517. package/lib/sharing/ConsumeSharedPlugin.js +11 -11
  518. package/lib/sharing/ConsumeSharedRuntimeModule.js +55 -45
  519. package/lib/sharing/ProvideForSharedDependency.js +1 -0
  520. package/lib/sharing/ProvideSharedDependency.js +34 -15
  521. package/lib/sharing/ProvideSharedModule.js +42 -12
  522. package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
  523. package/lib/sharing/ProvideSharedPlugin.js +13 -8
  524. package/lib/sharing/SharePlugin.js +5 -1
  525. package/lib/sharing/ShareRuntimeModule.js +19 -16
  526. package/lib/sharing/resolveMatchedConfigs.js +6 -2
  527. package/lib/sharing/utils.js +9 -1
  528. package/lib/stats/DefaultStatsFactoryPlugin.js +289 -201
  529. package/lib/stats/DefaultStatsPresetPlugin.js +14 -2
  530. package/lib/stats/DefaultStatsPrinterPlugin.js +74 -170
  531. package/lib/stats/StatsFactory.js +70 -27
  532. package/lib/stats/StatsPrinter.js +16 -2
  533. package/lib/typescript/TypeScriptPlugin.js +210 -0
  534. package/lib/url/URLParserPlugin.js +111 -23
  535. package/lib/util/ArrayHelpers.js +1 -0
  536. package/lib/util/ArrayQueue.js +10 -5
  537. package/lib/util/AsyncQueue.js +154 -74
  538. package/lib/util/Hash.js +2 -2
  539. package/lib/util/IterableHelpers.js +3 -0
  540. package/lib/util/LazyBucketSortedSet.js +26 -0
  541. package/lib/util/LazySet.js +45 -4
  542. package/lib/util/LocConverter.js +64 -0
  543. package/lib/util/ParallelismFactorCalculator.js +1 -0
  544. package/lib/util/Queue.js +6 -3
  545. package/lib/util/Semaphore.js +15 -1
  546. package/lib/util/SetHelpers.js +4 -1
  547. package/lib/util/SortableSet.js +7 -1
  548. package/lib/util/SourceProcessor.js +119 -0
  549. package/lib/util/StackedCacheMap.js +20 -3
  550. package/lib/util/StackedMap.js +162 -43
  551. package/lib/util/StringXor.js +1 -1
  552. package/lib/util/TupleQueue.js +7 -3
  553. package/lib/util/TupleSet.js +14 -0
  554. package/lib/util/URLAbsoluteSpecifier.js +1 -0
  555. package/lib/util/WeakTupleMap.js +60 -1
  556. package/lib/util/binarySearchBounds.js +3 -2
  557. package/lib/util/chainedImports.js +3 -3
  558. package/lib/util/cleverMerge.js +19 -2
  559. package/lib/util/comparators.js +35 -4
  560. package/lib/util/compileBooleanMatcher.js +9 -0
  561. package/lib/util/concatenate.js +80 -24
  562. package/lib/util/conventions.js +46 -1
  563. package/lib/util/createHash.js +0 -1
  564. package/lib/util/createHooksRegistry.js +43 -0
  565. package/lib/util/createMappings.js +118 -0
  566. package/lib/util/dataURL.js +3 -2
  567. package/lib/util/deprecation.js +19 -0
  568. package/lib/util/deterministicGrouping.js +46 -17
  569. package/lib/util/extractSourceMap.js +2 -1
  570. package/lib/util/extractUrlAndGlobal.js +1 -0
  571. package/lib/util/findGraphRoots.js +7 -0
  572. package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
  573. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +10 -3
  574. package/lib/util/fs.js +87 -14
  575. package/lib/util/generateDebugId.js +1 -0
  576. package/lib/util/globUtils.js +710 -0
  577. package/lib/util/hash/BatchedHash.js +1 -0
  578. package/lib/util/hash/BulkUpdateHash.js +1 -0
  579. package/lib/util/hash/DebugHash.js +1 -0
  580. package/lib/util/hash/hash-digest.js +32 -15
  581. package/lib/util/hash/md4.js +1 -1
  582. package/lib/util/hash/wasm-hash.js +5 -0
  583. package/lib/util/hash/xxhash64.js +1 -1
  584. package/lib/util/identifier.js +118 -7
  585. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  586. package/lib/util/internalSerializables.js +102 -60
  587. package/lib/util/magicComment.js +149 -7
  588. package/lib/util/makeSerializable.js +7 -0
  589. package/lib/util/memoize.js +2 -0
  590. package/lib/util/mimeTypes.js +176 -0
  591. package/lib/util/nonNumericOnlyHash.js +31 -1
  592. package/lib/util/numberHash.js +2 -2
  593. package/lib/util/parseJson.js +41 -0
  594. package/lib/util/processAsyncTree.js +8 -0
  595. package/lib/util/property.js +9 -2
  596. package/lib/util/publicPathPlaceholder.js +64 -0
  597. package/lib/util/registerExternalSerializer.js +24 -4
  598. package/lib/util/removeBOM.js +1 -0
  599. package/lib/util/runtime.js +32 -0
  600. package/lib/util/semver.js +15 -0
  601. package/lib/util/serialization.js +2 -0
  602. package/lib/util/smartGrouping.js +8 -0
  603. package/lib/util/source.js +23 -0
  604. package/lib/util/topologicalSort.js +69 -0
  605. package/lib/validateSchema.js +1 -0
  606. package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
  607. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +25 -18
  608. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +34 -22
  609. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  610. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
  611. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +6 -1
  612. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +22 -126
  613. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -2
  614. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +13 -2
  615. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  616. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +7 -3
  617. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +86 -19
  618. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -3
  619. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -1
  620. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +9 -3
  621. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
  622. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +20 -1
  623. package/lib/wasm-sync/WebAssemblyParser.js +9 -3
  624. package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
  625. package/lib/web/FetchCompileAsyncWasmPlugin.js +29 -1
  626. package/lib/web/FetchCompileWasmPlugin.js +27 -1
  627. package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
  628. package/lib/web/JsonpChunkLoadingRuntimeModule.js +58 -64
  629. package/lib/web/JsonpTemplatePlugin.js +2 -1
  630. package/lib/webpack.js +78 -1
  631. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
  632. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -10
  633. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  634. package/module.d.ts +21 -0
  635. package/package.json +79 -77
  636. package/schemas/WebpackOptions.check.js +1 -1
  637. package/schemas/WebpackOptions.json +1173 -80
  638. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  639. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  640. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  641. package/schemas/plugins/{DllReferencePlugin.check.d.ts → HtmlParserOptions.check.d.ts} +1 -1
  642. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  643. package/schemas/plugins/HtmlParserOptions.json +3 -0
  644. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  645. package/schemas/plugins/ProgressPlugin.json +38 -0
  646. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  647. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  648. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  649. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  650. package/schemas/plugins/container/ModuleFederationPlugin.json +2 -0
  651. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +7 -0
  652. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  653. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  654. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  655. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  656. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  657. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  658. package/types.d.ts +11053 -3019
  659. package/lib/CaseSensitiveModulesWarning.js +0 -72
  660. package/lib/GraphHelpers.js +0 -46
  661. package/lib/ModuleParseError.js +0 -125
  662. package/lib/NoModeWarning.js +0 -23
  663. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
  664. package/lib/css/walkCssTokens.js +0 -1843
  665. package/lib/util/AppendOnlyStackedSet.js +0 -78
  666. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  667. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  668. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  669. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -16,8 +16,7 @@ const {
16
16
  RawSource,
17
17
  ReplaceSource
18
18
  } = require("webpack-sources");
19
- const Compilation = require("../Compilation");
20
- const { tryRunOrWebpackError } = require("../HookWebpackError");
19
+ /** @typedef {import("../Compilation")} Compilation */
21
20
  const HotUpdateChunk = require("../HotUpdateChunk");
22
21
  const InitFragment = require("../InitFragment");
23
22
  const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
@@ -30,6 +29,7 @@ const {
30
29
  const NormalModule = require("../NormalModule");
31
30
  const RuntimeGlobals = require("../RuntimeGlobals");
32
31
  const Template = require("../Template");
32
+ const { tryRunOrWebpackError } = require("../errors/HookWebpackError");
33
33
  const { last, someInIterable } = require("../util/IterableHelpers");
34
34
  const StringXor = require("../util/StringXor");
35
35
  const { compareModulesByFullName } = require("../util/comparators");
@@ -42,16 +42,33 @@ const {
42
42
  getUsedNamesInScopeInfo
43
43
  } = require("../util/concatenate");
44
44
  const createHash = require("../util/createHash");
45
- const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
45
+ const createHooksRegistry = require("../util/createHooksRegistry");
46
+ const { digestNonNumericOnlyWithFull } = require("../util/nonNumericOnlyHash");
46
47
  const removeBOM = require("../util/removeBOM");
47
48
  const { intersectRuntime } = require("../util/runtime");
49
+ const { getAllChunks } = require("./ChunkHelpers");
48
50
  const JavascriptGenerator = require("./JavascriptGenerator");
51
+ const JavascriptModule = require("./JavascriptModule");
49
52
  const JavascriptParser = require("./JavascriptParser");
50
53
 
51
- /** @typedef {import("eslint-scope").Reference} Reference */
52
- /** @typedef {import("eslint-scope").Scope} Scope */
53
- /** @typedef {import("eslint-scope").Variable} Variable */
54
54
  /** @typedef {import("estree").Program} Program */
55
+ /** @typedef {import("estree").Node} Node */
56
+ /** @typedef {import("estree").Identifier} Identifier */
57
+ /** @typedef {import("estree").CatchClause} CatchClause */
58
+ /** @typedef {import("estree").ClassDeclaration} ClassDeclaration */
59
+ /** @typedef {import("estree").ClassExpression} ClassExpression */
60
+ /** @typedef {import("estree").FunctionDeclaration} FunctionDeclaration */
61
+ /** @typedef {import("estree").FunctionExpression} FunctionExpression */
62
+ /** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
63
+ /** @typedef {import("estree").VariableDeclarator} VariableDeclarator */
64
+ /** @typedef {import("estree").VariableDeclaration} VariableDeclaration */
65
+ /** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
66
+ /** @typedef {import("estree").ImportSpecifier} ImportSpecifier */
67
+ /** @typedef {import("estree").ImportDefaultSpecifier} ImportDefaultSpecifier */
68
+ /** @typedef {import("estree").ImportNamespaceSpecifier} ImportNamespaceSpecifier */
69
+ /** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
70
+ /** @typedef {import("estree").ForInStatement} ForInStatement */
71
+ /** @typedef {import("estree").ForOfStatement} ForOfStatement */
55
72
  /** @typedef {import("webpack-sources").Source} Source */
56
73
  /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
57
74
  /** @typedef {import("../Chunk")} Chunk */
@@ -69,17 +86,73 @@ const JavascriptParser = require("./JavascriptParser");
69
86
  /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
70
87
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
71
88
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
72
- /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
73
- /** @typedef {import("../WebpackError")} WebpackError */
89
+ /** @typedef {import("../Chunk").ChunkFilenameTemplate} ChunkFilenameTemplate */
90
+ /** @typedef {import("../errors/WebpackError")} WebpackError */
74
91
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
75
92
  /** @typedef {import("../util/Hash")} Hash */
76
93
  /** @typedef {import("../util/concatenate").ScopeSet} ScopeSet */
77
94
  /** @typedef {import("../util/concatenate").UsedNamesInScopeInfo} UsedNamesInScopeInfo */
78
95
 
96
+ // TODO remove these types when we will update `eslint-scope` to the latest version and import them from `eslint-scope`
97
+ /**
98
+ * @typedef {object} Scope
99
+ * @property {"block" | "catch" | "class" | "class-field-initializer" | "class-static-block" | "for" | "function" | "function-expression-name" | "global" | "module" | "switch" | "with" | "TDZ"} type
100
+ * @property {boolean} isStrict
101
+ * @property {Scope | null} upper
102
+ * @property {Scope[]} childScopes
103
+ * @property {Scope} variableScope
104
+ * @property {Node} block
105
+ * @property {Variable[]} variables
106
+ * @property {Map<string, Variable>} set
107
+ * @property {Reference[]} references
108
+ * @property {Reference[]} through
109
+ * @property {boolean} functionExpressionScope
110
+ * @property {{ variables: Variable[], set: Map<string, Variable> }=} implicit
111
+ */
112
+
113
+ /**
114
+ * @typedef {
115
+ * | { type: "CatchClause", node: CatchClause, parent: null }
116
+ * | { type: "ClassName", node: ClassDeclaration | ClassExpression, parent: null }
117
+ * | { type: "FunctionName", node: FunctionDeclaration | FunctionExpression, parent: null }
118
+ * | { type: "ImplicitGlobalVariable", node: AssignmentExpression | ForInStatement | ForOfStatement, parent: null }
119
+ * | { type: "ImportBinding", node: ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier, parent: ImportDeclaration }
120
+ * | { type: "Parameter", node: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression, parent: null }
121
+ * | { type: "TDZ", node: any, parent: null }
122
+ * | { type: "Variable", node: VariableDeclarator, parent: VariableDeclaration }
123
+ * } DefinitionType
124
+ */
125
+
126
+ /** @typedef {DefinitionType & { name: Identifier }} Definition */
127
+
128
+ /**
129
+ * @typedef {object} Variable
130
+ * @property {string} name
131
+ * @property {Scope} scope
132
+ * @property {Identifier[]} identifiers
133
+ * @property {Reference[]} references
134
+ * @property {Definition[]} defs
135
+ */
136
+
137
+ /**
138
+ * @typedef {object} Reference
139
+ * @property {Identifier} identifier
140
+ * @property {Scope} from
141
+ * @property {Variable | null} resolved
142
+ * @property {Node | null} writeExpr
143
+ * @property {boolean} init
144
+ * @property {() => boolean} isWrite
145
+ * @property {() => boolean} isRead
146
+ * @property {() => boolean} isWriteOnly
147
+ * @property {() => boolean} isReadOnly
148
+ * @property {() => boolean} isReadWrite
149
+ */
150
+
79
151
  /** @type {WeakMap<ChunkGraph, WeakMap<Chunk, boolean>>} */
80
152
  const chunkHasJsCache = new WeakMap();
81
153
 
82
154
  /**
155
+ * Returns true, when a JS file is needed for this chunk.
83
156
  * @param {Chunk} chunk a chunk
84
157
  * @param {ChunkGraph} chunkGraph the chunk graph
85
158
  * @returns {boolean} true, when a JS file is needed for this chunk
@@ -99,6 +172,7 @@ const _chunkHasJs = (chunk, chunkGraph) => {
99
172
  };
100
173
 
101
174
  /**
175
+ * Returns true, when a JS file is needed for this chunk.
102
176
  * @param {Chunk} chunk a chunk
103
177
  * @param {ChunkGraph} chunkGraph the chunk graph
104
178
  * @returns {boolean} true, when a JS file is needed for this chunk
@@ -121,6 +195,7 @@ const chunkHasJs = (chunk, chunkGraph) => {
121
195
  };
122
196
 
123
197
  /**
198
+ * Chunk has runtime or js.
124
199
  * @param {Chunk} chunk a chunk
125
200
  * @param {ChunkGraph} chunkGraph the chunk graph
126
201
  * @returns {boolean} true, when a JS file is needed for this chunk
@@ -148,6 +223,7 @@ const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
148
223
  };
149
224
 
150
225
  /**
226
+ * Print generated code for stack.
151
227
  * @param {Module} module a module
152
228
  * @param {string} code the code
153
229
  * @returns {string} generated code for the stack
@@ -158,6 +234,7 @@ const printGeneratedCodeForStack = (module, code) => {
158
234
  return `\n\nGenerated code for ${module.identifier()}\n${lines
159
235
  .map(
160
236
  /**
237
+ * Handles the callback logic for this hook.
161
238
  * @param {string} line the line
162
239
  * @param {number} i the index
163
240
  * @param {string[]} _lines the lines
@@ -172,6 +249,7 @@ const printGeneratedCodeForStack = (module, code) => {
172
249
  };
173
250
 
174
251
  /**
252
+ * Defines the render context type used by this module.
175
253
  * @typedef {object} RenderContext
176
254
  * @property {Chunk} chunk the chunk
177
255
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -183,6 +261,7 @@ const printGeneratedCodeForStack = (module, code) => {
183
261
  */
184
262
 
185
263
  /**
264
+ * Defines the main render context type used by this module.
186
265
  * @typedef {object} MainRenderContext
187
266
  * @property {Chunk} chunk the chunk
188
267
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -195,6 +274,7 @@ const printGeneratedCodeForStack = (module, code) => {
195
274
  */
196
275
 
197
276
  /**
277
+ * Defines the chunk render context type used by this module.
198
278
  * @typedef {object} ChunkRenderContext
199
279
  * @property {Chunk} chunk the chunk
200
280
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -204,9 +284,12 @@ const printGeneratedCodeForStack = (module, code) => {
204
284
  * @property {CodeGenerationResults} codeGenerationResults results of code generation
205
285
  * @property {InitFragment<ChunkRenderContext>[]} chunkInitFragments init fragments for the chunk
206
286
  * @property {boolean | undefined} strictMode rendering in strict context
287
+ * @property {Module=} inlinedEntryModule entry module inlined at the chunk top level instead of the registry
288
+ * @property {Source=} inlinedEntrySource rendered body of the inlined entry module
207
289
  */
208
290
 
209
291
  /**
292
+ * Defines the render bootstrap context type used by this module.
210
293
  * @typedef {object} RenderBootstrapContext
211
294
  * @property {Chunk} chunk the chunk
212
295
  * @property {CodeGenerationResults} codeGenerationResults results of code generation
@@ -217,6 +300,7 @@ const printGeneratedCodeForStack = (module, code) => {
217
300
  */
218
301
 
219
302
  /**
303
+ * Defines the startup render context type used by this module.
220
304
  * @typedef {object} StartupRenderContext
221
305
  * @property {Chunk} chunk the chunk
222
306
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -231,6 +315,7 @@ const printGeneratedCodeForStack = (module, code) => {
231
315
  */
232
316
 
233
317
  /**
318
+ * Defines the module render context type used by this module.
234
319
  * @typedef {object} ModuleRenderContext
235
320
  * @property {Chunk} chunk the chunk
236
321
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -245,81 +330,165 @@ const printGeneratedCodeForStack = (module, code) => {
245
330
  * @property {boolean=} renderInObject render module in object container
246
331
  */
247
332
 
333
+ const createCompilationHooks = () => ({
334
+ /**
335
+ * @type {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>}
336
+ */
337
+ renderModuleContent: new SyncWaterfallHook([
338
+ "source",
339
+ "module",
340
+ "moduleRenderContext"
341
+ ]),
342
+ /**
343
+ * @type {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>}
344
+ */
345
+ renderModuleContainer: new SyncWaterfallHook([
346
+ "source",
347
+ "module",
348
+ "moduleRenderContext"
349
+ ]),
350
+ /**
351
+ * @type {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>}
352
+ */
353
+ renderModulePackage: new SyncWaterfallHook([
354
+ "source",
355
+ "module",
356
+ "moduleRenderContext"
357
+ ]),
358
+ /**
359
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
360
+ */
361
+ render: new SyncWaterfallHook(["source", "renderContext"]),
362
+ /**
363
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
364
+ * @since 5.41.0
365
+ */
366
+ renderContent: new SyncWaterfallHook(["source", "renderContext"]),
367
+ /**
368
+ * @type {SyncWaterfallHook<[Source, Module, StartupRenderContext]>}
369
+ * @since 5.22.0
370
+ */
371
+ renderStartup: new SyncWaterfallHook([
372
+ "source",
373
+ "module",
374
+ "startupRenderContext"
375
+ ]),
376
+ /**
377
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
378
+ */
379
+ renderChunk: new SyncWaterfallHook(["source", "renderContext"]),
380
+ /**
381
+ * @type {SyncWaterfallHook<[Source, RenderContext]>}
382
+ */
383
+ renderMain: new SyncWaterfallHook(["source", "renderContext"]),
384
+ /**
385
+ * @type {SyncWaterfallHook<[string, RenderBootstrapContext]>}
386
+ */
387
+ renderRequire: new SyncWaterfallHook(["code", "renderContext"]),
388
+ /**
389
+ * @type {SyncBailHook<[Module, Partial<RenderBootstrapContext>], string | void>}
390
+ * @since 5.22.0
391
+ */
392
+ inlineInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
393
+ /**
394
+ * @type {SyncBailHook<[Module, RenderContext], string | void>}
395
+ * @since 5.22.0
396
+ */
397
+ embedInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
398
+ /**
399
+ * @type {SyncBailHook<[RenderContext], string | void>}
400
+ * @since 5.26.1
401
+ */
402
+ strictRuntimeBailout: new SyncBailHook(["renderContext"]),
403
+ /**
404
+ * @type {SyncHook<[Chunk, Hash, ChunkHashContext]>}
405
+ */
406
+ chunkHash: new SyncHook(["chunk", "hash", "context"]),
407
+ /**
408
+ * @type {SyncBailHook<[Chunk, RenderContext], boolean | void>}
409
+ * @since 5.2.1
410
+ */
411
+ useSourceMap: new SyncBailHook(["chunk", "renderContext"])
412
+ });
413
+
414
+ /**
415
+ * @typedef {ReturnType<typeof createCompilationHooks>} CompilationHooks
416
+ */
417
+
248
418
  /**
249
- * @typedef {object} CompilationHooks
250
- * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContent
251
- * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContainer
252
- * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModulePackage
253
- * @property {SyncWaterfallHook<[Source, RenderContext]>} renderChunk
254
- * @property {SyncWaterfallHook<[Source, RenderContext]>} renderMain
255
- * @property {SyncWaterfallHook<[Source, RenderContext]>} renderContent
256
- * @property {SyncWaterfallHook<[Source, RenderContext]>} render
257
- * @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
258
- * @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
259
- * @property {SyncBailHook<[Module, Partial<RenderBootstrapContext>], string | void>} inlineInRuntimeBailout
260
- * @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
261
- * @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
262
- * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
263
- * @property {SyncBailHook<[Chunk, RenderContext], boolean | void>} useSourceMap
419
+ * Renames an inlined module's top-level declaration (and all its references) when
420
+ * its name is already taken in the shared startup scope, recording the chosen name
421
+ * in `allUsedNames`. Lets inlined modules be emitted without a per-entry/per-chunk
422
+ * IIFE by resolving name collisions instead of isolating each module.
423
+ * @param {InstanceType<typeof import("webpack-sources").ReplaceSource>} source the module source to edit
424
+ * @param {Program} ast the parsed module AST
425
+ * @param {Variable} variable the top-level variable to check/rename
426
+ * @param {string} moduleIdentifier the module identifier (for scope caching)
427
+ * @param {string} readableIdentifier the readable module identifier (for new names)
428
+ * @param {Set<string>} allUsedNames names already used in the shared scope (mutated)
429
+ * @returns {void}
264
430
  */
431
+ const renameInlinedModuleVariable = (
432
+ source,
433
+ ast,
434
+ variable,
435
+ moduleIdentifier,
436
+ readableIdentifier,
437
+ allUsedNames
438
+ ) => {
439
+ /** @type {UsedNamesInScopeInfo} */
440
+ const usedNamesInScopeInfo = new Map();
441
+ /** @type {ScopeSet} */
442
+ const ignoredScopes = new Set();
443
+
444
+ const name = variable.name;
445
+ const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
446
+ usedNamesInScopeInfo,
447
+ moduleIdentifier,
448
+ name
449
+ );
450
+
451
+ if (allUsedNames.has(name) || usedNames.has(name)) {
452
+ const references = getAllReferences(variable);
453
+ const allIdentifiers = new Set([
454
+ ...references.map((r) => r.identifier),
455
+ ...variable.identifiers
456
+ ]);
457
+ for (const ref of references) {
458
+ addScopeSymbols(ref.from, usedNames, alreadyCheckedScopes, ignoredScopes);
459
+ }
265
460
 
266
- /** @type {WeakMap<Compilation, CompilationHooks>} */
267
- const compilationHooksMap = new WeakMap();
461
+ const newName = findNewName(
462
+ name,
463
+ allUsedNames,
464
+ usedNames,
465
+ readableIdentifier
466
+ );
467
+ allUsedNames.add(newName);
468
+ for (const identifier of allIdentifiers) {
469
+ const r = /** @type {Range} */ (identifier.range);
470
+ const path = getPathInAst(ast, identifier);
471
+ if (path && path.length > 1) {
472
+ const maybeProperty =
473
+ path[1].type === "AssignmentPattern" && path[1].left === path[0]
474
+ ? path[2]
475
+ : path[1];
476
+ if (maybeProperty.type === "Property" && maybeProperty.shorthand) {
477
+ source.insert(r[1], `: ${newName}`);
478
+ continue;
479
+ }
480
+ }
481
+ source.replace(r[0], r[1] - 1, newName);
482
+ }
483
+ }
484
+ allUsedNames.add(name);
485
+ };
268
486
 
269
487
  const PLUGIN_NAME = "JavascriptModulesPlugin";
270
488
 
271
489
  /** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */
272
490
 
273
491
  class JavascriptModulesPlugin {
274
- /**
275
- * @param {Compilation} compilation the compilation
276
- * @returns {CompilationHooks} the attached hooks
277
- */
278
- static getCompilationHooks(compilation) {
279
- if (!(compilation instanceof Compilation)) {
280
- throw new TypeError(
281
- "The 'compilation' argument must be an instance of Compilation"
282
- );
283
- }
284
- let hooks = compilationHooksMap.get(compilation);
285
- if (hooks === undefined) {
286
- hooks = {
287
- renderModuleContent: new SyncWaterfallHook([
288
- "source",
289
- "module",
290
- "moduleRenderContext"
291
- ]),
292
- renderModuleContainer: new SyncWaterfallHook([
293
- "source",
294
- "module",
295
- "moduleRenderContext"
296
- ]),
297
- renderModulePackage: new SyncWaterfallHook([
298
- "source",
299
- "module",
300
- "moduleRenderContext"
301
- ]),
302
- render: new SyncWaterfallHook(["source", "renderContext"]),
303
- renderContent: new SyncWaterfallHook(["source", "renderContext"]),
304
- renderStartup: new SyncWaterfallHook([
305
- "source",
306
- "module",
307
- "startupRenderContext"
308
- ]),
309
- renderChunk: new SyncWaterfallHook(["source", "renderContext"]),
310
- renderMain: new SyncWaterfallHook(["source", "renderContext"]),
311
- renderRequire: new SyncWaterfallHook(["code", "renderContext"]),
312
- inlineInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
313
- embedInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
314
- strictRuntimeBailout: new SyncBailHook(["renderContext"]),
315
- chunkHash: new SyncHook(["chunk", "hash", "context"]),
316
- useSourceMap: new SyncBailHook(["chunk", "renderContext"])
317
- };
318
- compilationHooksMap.set(compilation, hooks);
319
- }
320
- return hooks;
321
- }
322
-
323
492
  constructor(options = {}) {
324
493
  this.options = options;
325
494
  /** @type {WeakMap<Source, { source: Source, needModule: boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined, renderShorthand: boolean }>} */
@@ -327,7 +496,7 @@ class JavascriptModulesPlugin {
327
496
  }
328
497
 
329
498
  /**
330
- * Apply the plugin
499
+ * Applies the plugin by registering its hooks on the compiler.
331
500
  * @param {Compiler} compiler the compiler instance
332
501
  * @returns {void}
333
502
  */
@@ -342,21 +511,44 @@ class JavascriptModulesPlugin {
342
511
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
343
512
  JAVASCRIPT_MODULE_TYPE_ESM
344
513
  ]) {
514
+ normalModuleFactory.hooks.createModuleClass
515
+ .for(type)
516
+ .tap(
517
+ PLUGIN_NAME,
518
+ (createData, _resolveData) => new JavascriptModule(createData)
519
+ );
345
520
  normalModuleFactory.hooks.createParser
346
521
  .for(type)
347
522
  .tap(PLUGIN_NAME, (options) => {
348
523
  switch (type) {
349
524
  case JAVASCRIPT_MODULE_TYPE_AUTO: {
350
- return new JavascriptParser("auto", { parse: options.parse });
525
+ return new JavascriptParser("auto", {
526
+ parse: options.parse,
527
+ typescript: options.typescript,
528
+ importPhases: Boolean(
529
+ options.deferImport || options.sourceImport
530
+ ),
531
+ strictModeViolations: options.strictModeViolations
532
+ });
351
533
  }
352
534
  case JAVASCRIPT_MODULE_TYPE_DYNAMIC: {
353
535
  return new JavascriptParser("script", {
354
- parse: options.parse
536
+ parse: options.parse,
537
+ typescript: options.typescript,
538
+ importPhases: Boolean(
539
+ options.deferImport || options.sourceImport
540
+ ),
541
+ strictModeViolations: options.strictModeViolations
355
542
  });
356
543
  }
357
544
  case JAVASCRIPT_MODULE_TYPE_ESM: {
358
545
  return new JavascriptParser("module", {
359
- parse: options.parse
546
+ parse: options.parse,
547
+ typescript: options.typescript,
548
+ importPhases: Boolean(
549
+ options.deferImport || options.sourceImport
550
+ ),
551
+ strictModeViolations: options.strictModeViolations
360
552
  });
361
553
  }
362
554
  }
@@ -554,11 +746,8 @@ class JavascriptModulesPlugin {
554
746
  }
555
747
  xor.updateHash(hash);
556
748
  }
557
- const digest = hash.digest(hashDigest);
558
- chunk.contentHash.javascript = nonNumericOnlyHash(
559
- digest,
560
- hashDigestLength
561
- );
749
+ [chunk.contentHash.javascript, chunk.contentHashFull.javascript] =
750
+ digestNonNumericOnlyWithFull(hash, hashDigest, hashDigestLength);
562
751
  });
563
752
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
564
753
  PLUGIN_NAME,
@@ -642,15 +831,22 @@ class JavascriptModulesPlugin {
642
831
  }
643
832
 
644
833
  /**
834
+ * Gets chunk filename template.
645
835
  * @param {Chunk} chunk chunk
646
836
  * @param {OutputOptions} outputOptions output options
647
- * @returns {TemplatePath} used filename template
837
+ * @returns {ChunkFilenameTemplate} used filename template
648
838
  */
649
839
  static getChunkFilenameTemplate(chunk, outputOptions) {
650
840
  if (chunk.filenameTemplate) {
651
841
  return chunk.filenameTemplate;
652
842
  } else if (chunk instanceof HotUpdateChunk) {
653
843
  return outputOptions.hotUpdateChunkFilename;
844
+ }
845
+ const entryOptions = chunk.getEntryOptions();
846
+ // A worker entry (`new Worker` or `entry.worker`) uses workerChunkFilename;
847
+ // chunks it loads internally keep `chunkFilename`
848
+ if (entryOptions !== undefined && entryOptions.worker) {
849
+ return outputOptions.workerChunkFilename;
654
850
  } else if (chunk.canBeInitial()) {
655
851
  return outputOptions.filename;
656
852
  }
@@ -658,6 +854,7 @@ class JavascriptModulesPlugin {
658
854
  }
659
855
 
660
856
  /**
857
+ * Renders the newly generated source from rendering.
661
858
  * @param {Module} module the rendered module
662
859
  * @param {ModuleRenderContext} renderContext options object
663
860
  * @param {CompilationHooks} hooks hooks
@@ -797,6 +994,7 @@ class JavascriptModulesPlugin {
797
994
  }
798
995
 
799
996
  /**
997
+ * Renders the rendered source.
800
998
  * @param {RenderContext} renderContext the render context
801
999
  * @param {CompilationHooks} hooks hooks
802
1000
  * @returns {Source} the rendered source
@@ -828,10 +1026,30 @@ class JavascriptModulesPlugin {
828
1026
  chunkInitFragments: [],
829
1027
  strictMode: allStrict
830
1028
  };
1029
+ // ESM entry chunk whose runtime lives in a separate chunk: inline the
1030
+ // single entry module at the top level (instead of the module registry)
1031
+ // so its own top-level declarations stay live ESM bindings for consumers.
1032
+ const inlinedEntryModule = this._getEsmEntryModuleToInline(
1033
+ renderContext,
1034
+ allModules
1035
+ );
1036
+ let registryModules = allModules;
1037
+ if (inlinedEntryModule) {
1038
+ const inlinedEntrySource = this.renderModule(
1039
+ inlinedEntryModule,
1040
+ { ...chunkRenderContext, factory: false },
1041
+ hooks
1042
+ );
1043
+ if (inlinedEntrySource) {
1044
+ registryModules = allModules.filter((m) => m !== inlinedEntryModule);
1045
+ chunkRenderContext.inlinedEntryModule = inlinedEntryModule;
1046
+ chunkRenderContext.inlinedEntrySource = inlinedEntrySource;
1047
+ }
1048
+ }
831
1049
  const moduleSources =
832
1050
  Template.renderChunkModules(
833
1051
  chunkRenderContext,
834
- allModules,
1052
+ registryModules,
835
1053
  (module, renderInObject) =>
836
1054
  this.renderModule(
837
1055
  module,
@@ -875,6 +1093,93 @@ class JavascriptModulesPlugin {
875
1093
  }
876
1094
 
877
1095
  /**
1096
+ * Returns the chunk's single entry module when it can be inlined at the top
1097
+ * level of an ESM output chunk (instead of the module registry), which keeps
1098
+ * its exports as live ESM bindings. Only a self-contained ESM entry whose
1099
+ * top-level declarations can be lifted into the chunk scope qualifies;
1100
+ * otherwise `undefined` is returned and the registry path is used.
1101
+ * @param {RenderContext} renderContext render context
1102
+ * @param {Module[]} allModules all javascript modules of the chunk
1103
+ * @returns {Module | undefined} the entry module to inline, if any
1104
+ */
1105
+ _getEsmEntryModuleToInline(renderContext, allModules) {
1106
+ const {
1107
+ chunk,
1108
+ chunkGraph,
1109
+ moduleGraph,
1110
+ runtimeTemplate,
1111
+ codeGenerationResults
1112
+ } = renderContext;
1113
+
1114
+ // Only a single ESM entry whose runtime lives in a separate chunk.
1115
+ if (
1116
+ !runtimeTemplate.isModule() ||
1117
+ chunk.hasRuntime() ||
1118
+ chunkGraph.getNumberOfEntryModules(chunk) !== 1
1119
+ ) {
1120
+ return undefined;
1121
+ }
1122
+ const [entryEntry] =
1123
+ chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk);
1124
+ const [entryModule, entrypoint] = /** @type {[Module, Entrypoint]} */ (
1125
+ entryEntry
1126
+ );
1127
+
1128
+ // Module-local safety: the body is lifted verbatim, so it must use the
1129
+ // standard exports binding (not `module`/`this`) and expose top-level
1130
+ // declarations whose names can't collide with runtime/startup identifiers.
1131
+ const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
1132
+ entryModule,
1133
+ chunk.runtime
1134
+ );
1135
+ if (
1136
+ entryModule.exportsArgument !== RuntimeGlobals.exports ||
1137
+ runtimeRequirements.has(RuntimeGlobals.module) ||
1138
+ runtimeRequirements.has(RuntimeGlobals.thisAsExports)
1139
+ ) {
1140
+ return undefined;
1141
+ }
1142
+ const topLevelDeclarations =
1143
+ codeGenerationResults.getData(
1144
+ entryModule,
1145
+ chunk.runtime,
1146
+ "topLevelDeclarations"
1147
+ ) ||
1148
+ (entryModule.buildInfo && entryModule.buildInfo.topLevelDeclarations);
1149
+ if (!topLevelDeclarations || topLevelDeclarations.size === 0) {
1150
+ return undefined;
1151
+ }
1152
+ for (const name of topLevelDeclarations) {
1153
+ if (RESERVED_NAMES.has(name) || name.startsWith("__webpack_")) {
1154
+ return undefined;
1155
+ }
1156
+ }
1157
+
1158
+ // Self-contained: the entry must not be imported by another module (which
1159
+ // needs it in the registry), and must not require other chunks or
1160
+ // `dependOn` parents to execute first.
1161
+ if (
1162
+ entrypoint.getParents().length > 0 ||
1163
+ getAllChunks(entrypoint, chunk, entrypoint.getRuntimeChunk()).size > 0
1164
+ ) {
1165
+ return undefined;
1166
+ }
1167
+ const referenced = someInIterable(
1168
+ moduleGraph.getIncomingConnectionsByOriginModule(entryModule),
1169
+ ([originModule, connections]) =>
1170
+ originModule &&
1171
+ originModule !== entryModule &&
1172
+ connections.some((c) => c.isTargetActive(chunk.runtime)) &&
1173
+ someInIterable(
1174
+ chunkGraph.getModuleRuntimes(originModule),
1175
+ (runtime) => intersectRuntime(runtime, chunk.runtime) !== undefined
1176
+ )
1177
+ );
1178
+ return referenced ? undefined : entryModule;
1179
+ }
1180
+
1181
+ /**
1182
+ * Renders the newly generated source from rendering.
878
1183
  * @param {MainRenderContext} renderContext options object
879
1184
  * @param {CompilationHooks} hooks hooks
880
1185
  * @param {Compilation} compilation the compilation
@@ -926,9 +1231,7 @@ class JavascriptModulesPlugin {
926
1231
  const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
927
1232
  if (strictBailout) {
928
1233
  source.add(
929
- `${
930
- prefix
931
- }// runtime can't be in strict mode because ${strictBailout}.\n`
1234
+ `${prefix}// runtime can't be in strict mode because ${strictBailout}.\n`
932
1235
  );
933
1236
  } else {
934
1237
  allStrict = true;
@@ -1052,10 +1355,8 @@ class JavascriptModulesPlugin {
1052
1355
 
1053
1356
  const iife = innerStrict
1054
1357
  ? "it needs to be in strict mode."
1055
- : inlinedModules.size > 1
1056
- ? // TODO check globals and top-level declarations of other entries and chunk modules
1057
- // to make a better decision
1058
- "it needs to be isolated against other entry modules."
1358
+ : inlinedModules.size > 1 && !renamedInlinedModule
1359
+ ? "it needs to be isolated against other entry modules."
1059
1360
  : chunkModules && !renamedInlinedModule
1060
1361
  ? "it needs to be isolated against other modules in the chunk."
1061
1362
  : exports && !webpackExports
@@ -1099,10 +1400,14 @@ class JavascriptModulesPlugin {
1099
1400
  }
1100
1401
  if (exports) {
1101
1402
  if (m !== lastInlinedModule) {
1102
- startupSource.add(`var ${m.exportsArgument} = {};\n`);
1403
+ startupSource.add(
1404
+ `${runtimeTemplate.renderLet()} ${m.exportsArgument} = {};\n`
1405
+ );
1103
1406
  } else if (m.exportsArgument !== RuntimeGlobals.exports) {
1104
1407
  startupSource.add(
1105
- `var ${m.exportsArgument} = ${RuntimeGlobals.exports};\n`
1408
+ `${runtimeTemplate.renderLet()} ${m.exportsArgument} = ${
1409
+ RuntimeGlobals.exports
1410
+ };\n`
1106
1411
  );
1107
1412
  }
1108
1413
  }
@@ -1145,7 +1450,7 @@ class JavascriptModulesPlugin {
1145
1450
  }
1146
1451
  if (startupRenderContext.needExportsDeclaration) {
1147
1452
  renderedStartup = new ConcatSource(
1148
- `var ${RuntimeGlobals.exports} = {};\n`,
1453
+ `${runtimeTemplate.renderLet()} ${RuntimeGlobals.exports} = {};\n`,
1149
1454
  renderedStartup
1150
1455
  );
1151
1456
  }
@@ -1240,6 +1545,7 @@ class JavascriptModulesPlugin {
1240
1545
  }
1241
1546
 
1242
1547
  /**
1548
+ * Updates hash with bootstrap.
1243
1549
  * @param {Hash} hash the hash to be updated
1244
1550
  * @param {RenderBootstrapContext} renderContext options object
1245
1551
  * @param {CompilationHooks} hooks hooks
@@ -1260,6 +1566,7 @@ class JavascriptModulesPlugin {
1260
1566
  }
1261
1567
 
1262
1568
  /**
1569
+ * Renders the generated source of the bootstrap code.
1263
1570
  * @param {RenderBootstrapContext} renderContext options object
1264
1571
  * @param {CompilationHooks} hooks hooks
1265
1572
  * @returns {Bootstrap} the generated source of the bootstrap code
@@ -1321,9 +1628,10 @@ class JavascriptModulesPlugin {
1321
1628
  result.allowInlineStartup = false;
1322
1629
  }
1323
1630
 
1631
+ const bootstrapCst = runtimeTemplate.renderConst();
1324
1632
  if (useRequire || moduleCache) {
1325
1633
  buf.push("// The module cache");
1326
- buf.push("var __webpack_module_cache__ = {};");
1634
+ buf.push(`${bootstrapCst} __webpack_module_cache__ = {};`);
1327
1635
  buf.push("");
1328
1636
  }
1329
1637
 
@@ -1333,7 +1641,16 @@ class JavascriptModulesPlugin {
1333
1641
  // This requires all deferred imports to a module can get the module export object before the module
1334
1642
  // is evaluated.
1335
1643
  buf.push("// The deferred module cache");
1336
- buf.push("var __webpack_module_deferred_exports__ = {};");
1644
+ buf.push(`${bootstrapCst} __webpack_module_deferred_exports__ = {};`);
1645
+ // Per the TC39 import-defer spec, every defer-import call site for
1646
+ // the same module must yield the same Deferred Module Namespace
1647
+ // Exotic Object (and a distinct one from any eager namespace).
1648
+ // Cache the deferred namespace proxy here so calls from different
1649
+ // files share identity.
1650
+ buf.push("// The deferred namespace cache");
1651
+ buf.push(
1652
+ `${bootstrapCst} __webpack_module_deferred_namespace_cache__ = {};`
1653
+ );
1337
1654
  buf.push("");
1338
1655
  }
1339
1656
 
@@ -1345,7 +1662,7 @@ class JavascriptModulesPlugin {
1345
1662
  buf.push("");
1346
1663
  } else if (runtimeRequirements.has(RuntimeGlobals.requireScope)) {
1347
1664
  buf.push("// The require scope");
1348
- buf.push(`var ${RuntimeGlobals.require} = {};`);
1665
+ buf.push(`${bootstrapCst} ${RuntimeGlobals.require} = {};`);
1349
1666
  buf.push("");
1350
1667
  }
1351
1668
 
@@ -1481,9 +1798,17 @@ class JavascriptModulesPlugin {
1481
1798
  result.allowInlineStartup = false;
1482
1799
  }
1483
1800
 
1801
+ // `__webpack_exports__` may be reassigned later — by the
1802
+ // `onChunksLoaded` wrapper below, by an inlined entry
1803
+ // module that uses top-level `await` (the emitted
1804
+ // bridge reassigns `__webpack_exports__` to the awaited
1805
+ // value), or by other downstream codegen. Always declare
1806
+ // with `let` (or `var` if `let` is unsupported) so
1807
+ // reassignment is allowed.
1808
+ const exportsDecl = runtimeTemplate.renderLet();
1484
1809
  if (chunks.length > 0) {
1485
1810
  buf2.push(
1486
- `${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1811
+ `${i === 0 ? `${exportsDecl} ${RuntimeGlobals.exports} = ` : ""}${
1487
1812
  RuntimeGlobals.onChunksLoaded
1488
1813
  }(undefined, ${JSON.stringify(
1489
1814
  chunks.map((c) => c.id)
@@ -1493,12 +1818,14 @@ class JavascriptModulesPlugin {
1493
1818
  );
1494
1819
  } else if (useRequire) {
1495
1820
  buf2.push(
1496
- `${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1821
+ `${i === 0 ? `${exportsDecl} ${RuntimeGlobals.exports} = ` : ""}${
1497
1822
  RuntimeGlobals.require
1498
1823
  }(${moduleIdExpr});`
1499
1824
  );
1500
1825
  } else {
1501
- if (i === 0) buf2.push(`var ${RuntimeGlobals.exports} = {};`);
1826
+ if (i === 0) {
1827
+ buf2.push(`${exportsDecl} ${RuntimeGlobals.exports} = {};`);
1828
+ }
1502
1829
  const needThisAsExports = entryRuntimeRequirements.has(
1503
1830
  RuntimeGlobals.thisAsExports
1504
1831
  );
@@ -1520,9 +1847,13 @@ class JavascriptModulesPlugin {
1520
1847
  (() => {
1521
1848
  if (needThisAsExports) {
1522
1849
  const comma = args.length ? "," : "";
1523
- return `__webpack_modules__[${moduleIdExpr}].call(${RuntimeGlobals.exports}${comma}${args.join(",")});`;
1850
+ return `__webpack_modules__[${moduleIdExpr}].call(${
1851
+ RuntimeGlobals.exports
1852
+ }${comma}${args.join(",")});`;
1524
1853
  }
1525
- return `__webpack_modules__[${moduleIdExpr}](${args.join(",")});`;
1854
+ return `__webpack_modules__[${moduleIdExpr}](${args.join(
1855
+ ","
1856
+ )});`;
1526
1857
  })()
1527
1858
  )
1528
1859
  );
@@ -1605,29 +1936,30 @@ class JavascriptModulesPlugin {
1605
1936
  }
1606
1937
 
1607
1938
  /**
1939
+ * Renders the generated source of the require function.
1608
1940
  * @param {RenderBootstrapContext} renderContext options object
1609
1941
  * @param {CompilationHooks} hooks hooks
1610
1942
  * @returns {string} the generated source of the require function
1611
1943
  */
1612
1944
  renderRequire(renderContext, hooks) {
1613
- const {
1614
- chunk,
1615
- chunkGraph,
1616
- runtimeTemplate: { outputOptions }
1617
- } = renderContext;
1945
+ const { chunk, chunkGraph, runtimeTemplate } = renderContext;
1946
+ const { outputOptions } = runtimeTemplate;
1947
+ const cst = runtimeTemplate.renderConst();
1948
+ const lt = runtimeTemplate.renderLet();
1618
1949
  const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
1619
1950
 
1620
1951
  /**
1952
+ * Renders missing module error.
1621
1953
  * @param {string} condition guard expression
1622
1954
  * @returns {string[]} source
1623
1955
  */
1624
1956
  const renderMissingModuleError = (condition) =>
1625
- outputOptions.pathinfo
1957
+ outputOptions.strictModuleResolution
1626
1958
  ? [
1627
1959
  `if (${condition}) {`,
1628
1960
  Template.indent([
1629
1961
  "delete __webpack_module_cache__[moduleId];",
1630
- 'var e = new Error("Cannot find module \'" + moduleId + "\'");',
1962
+ `${cst} e = new Error("Cannot find module '" + moduleId + "'");`,
1631
1963
  "e.code = 'MODULE_NOT_FOUND';",
1632
1964
  "throw e;"
1633
1965
  ]),
@@ -1639,7 +1971,7 @@ class JavascriptModulesPlugin {
1639
1971
  RuntimeGlobals.interceptModuleExecution
1640
1972
  )
1641
1973
  ? Template.asString([
1642
- `var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`,
1974
+ `${cst} execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`,
1643
1975
  `${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`,
1644
1976
  ...renderMissingModuleError("!execOptions.factory"),
1645
1977
  "module = execOptions.module;",
@@ -1661,11 +1993,29 @@ class JavascriptModulesPlugin {
1661
1993
  const needModuleDefer = runtimeRequirements.has(
1662
1994
  RuntimeGlobals.makeDeferredNamespaceObject
1663
1995
  );
1996
+ // Both deferred-namespace runtimes re-invoke `__webpack_require__` on
1997
+ // access, so a module's evaluation error must be retained and re-thrown
1998
+ // (a Cyclic Module Record's [[EvaluationError]]); the optimized variant
1999
+ // does not use `__webpack_module_deferred_exports__`, so it is tracked
2000
+ // separately from `needModuleDefer`.
2001
+ const needModuleDeferAny =
2002
+ needModuleDefer ||
2003
+ runtimeRequirements.has(
2004
+ RuntimeGlobals.makeOptimizedDeferredNamespaceObject
2005
+ );
2006
+ const needModuleErrorCaching =
2007
+ outputOptions.strictModuleErrorHandling || needModuleDeferAny;
2008
+ // `module` is reassigned by the interceptModuleExecution path; use `let`.
2009
+ const moduleDecl = runtimeRequirements.has(
2010
+ RuntimeGlobals.interceptModuleExecution
2011
+ )
2012
+ ? lt
2013
+ : cst;
1664
2014
  const content = Template.asString([
1665
2015
  "// Check if module is in cache",
1666
- "var cachedModule = __webpack_module_cache__[moduleId];",
2016
+ `${cst} cachedModule = __webpack_module_cache__[moduleId];`,
1667
2017
  "if (cachedModule !== undefined) {",
1668
- outputOptions.strictModuleErrorHandling
2018
+ needModuleErrorCaching
1669
2019
  ? Template.indent([
1670
2020
  "if (cachedModule.error !== undefined) throw cachedModule.error;",
1671
2021
  "return cachedModule.exports;"
@@ -1673,7 +2023,7 @@ class JavascriptModulesPlugin {
1673
2023
  : Template.indent("return cachedModule.exports;"),
1674
2024
  "}",
1675
2025
  "// Create a new module (and put it into the cache)",
1676
- "var module = __webpack_module_cache__[moduleId] = {",
2026
+ `${moduleDecl} module = __webpack_module_cache__[moduleId] = {`,
1677
2027
  Template.indent([
1678
2028
  needModuleId ? "id: moduleId," : "// no module.id needed",
1679
2029
  needModuleLoaded ? "loaded: false," : "// no module.loaded needed",
@@ -1683,10 +2033,10 @@ class JavascriptModulesPlugin {
1683
2033
  ]),
1684
2034
  "};",
1685
2035
  "",
1686
- outputOptions.strictModuleExceptionHandling
2036
+ outputOptions.strictModuleExceptionHandling && !needModuleErrorCaching
1687
2037
  ? Template.asString([
1688
2038
  "// Execute the module function",
1689
- "var threw = true;",
2039
+ `${lt} threw = true;`,
1690
2040
  "try {",
1691
2041
  Template.indent([
1692
2042
  moduleExecution,
@@ -1701,20 +2051,27 @@ class JavascriptModulesPlugin {
1701
2051
  ]),
1702
2052
  "}"
1703
2053
  ])
1704
- : outputOptions.strictModuleErrorHandling
2054
+ : needModuleErrorCaching
1705
2055
  ? Template.asString([
1706
2056
  "// Execute the module function",
2057
+ // Mark the module as evaluating so a deferred namespace that
2058
+ // forces evaluation of an already-evaluating module can throw
2059
+ // instead of exposing its partial exports.
2060
+ ...(needModuleDeferAny ? ["module.evaluating = true;"] : []),
1707
2061
  "try {",
1708
- Template.indent(
1709
- needModuleDefer
1710
- ? [
1711
- moduleExecution,
1712
- "delete __webpack_module_deferred_exports__[moduleId];"
1713
- ]
1714
- : moduleExecution
1715
- ),
2062
+ Template.indent([
2063
+ moduleExecution,
2064
+ ...(needModuleDefer
2065
+ ? ["delete __webpack_module_deferred_exports__[moduleId];"]
2066
+ : []),
2067
+ ...(needModuleDeferAny ? ["module.evaluating = false;"] : [])
2068
+ ]),
1716
2069
  "} catch(e) {",
1717
- Template.indent(["module.error = e;", "throw e;"]),
2070
+ Template.indent([
2071
+ ...(needModuleDeferAny ? ["module.evaluating = false;"] : []),
2072
+ "module.error = e;",
2073
+ "throw e;"
2074
+ ]),
1718
2075
  "}"
1719
2076
  ])
1720
2077
  : Template.asString([
@@ -1742,6 +2099,7 @@ class JavascriptModulesPlugin {
1742
2099
  }
1743
2100
 
1744
2101
  /**
2102
+ * Get renamed inline module.
1745
2103
  * @param {Compilation} compilation compilation
1746
2104
  * @param {Module[]} allModules allModules
1747
2105
  * @param {MainRenderContext} renderContext renderContext
@@ -1767,11 +2125,11 @@ class JavascriptModulesPlugin {
1767
2125
  allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict);
1768
2126
  const isMultipleEntries = inlinedModules.size > 1;
1769
2127
  const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
1770
- // TODO:
1771
- // This step is before the IIFE reason calculation. Ideally, it should only be executed when this function can optimize the
1772
- // IIFE reason. Otherwise, it should directly return false. There are four reasons now, we have skipped two already, the left
1773
- // one is 'it uses a non-standard name for the exports'.
1774
- if (isMultipleEntries || innerStrict || !singleEntryWithModules) {
2128
+ // This step is before the IIFE reason calculation; it only runs for the
2129
+ // cases whose IIFE reason it can remove: multiple inlined entry modules, or a
2130
+ // single inlined entry alongside other chunk modules. The remaining reason
2131
+ // ('it uses a non-standard name for the exports') is not handled here.
2132
+ if (innerStrict || (!isMultipleEntries && !singleEntryWithModules)) {
1775
2133
  return false;
1776
2134
  }
1777
2135
 
@@ -1784,6 +2142,8 @@ class JavascriptModulesPlugin {
1784
2142
  const inlinedModulesToInfo = new Map();
1785
2143
  /** @type {Set<string>} */
1786
2144
  const nonInlinedModuleThroughIdentifiers = new Set();
2145
+ /** @type {Map<Module, Source>} */
2146
+ const inlinedModuleSources = new Map();
1787
2147
 
1788
2148
  for (const m of allModules) {
1789
2149
  const isInlinedModule = inlinedModules && inlinedModules.has(m);
@@ -1798,13 +2158,24 @@ class JavascriptModulesPlugin {
1798
2158
  );
1799
2159
 
1800
2160
  if (!moduleSource) continue;
2161
+ if (isInlinedModule) {
2162
+ // Parsing the inlined entry (often the whole concatenated app) is
2163
+ // expensive; defer it until we know renaming is actually needed.
2164
+ inlinedModuleSources.set(m, moduleSource);
2165
+ continue;
2166
+ }
1801
2167
  const code = /** @type {string} */ (moduleSource.source());
1802
2168
 
2169
+ const { experiments } = compilation.options;
1803
2170
  const { ast } = JavascriptParser._parse(
1804
2171
  code,
1805
2172
  {
1806
2173
  sourceType: "auto",
1807
- ranges: true
2174
+ ranges: true,
2175
+ // generated code contains phase imports when the experiments are on
2176
+ importPhases: Boolean(
2177
+ experiments.deferImport || experiments.sourceImport
2178
+ )
1808
2179
  },
1809
2180
  JavascriptParser._getModuleParseFunction(compilation, m)
1810
2181
  );
@@ -1817,22 +2188,93 @@ class JavascriptModulesPlugin {
1817
2188
  });
1818
2189
 
1819
2190
  const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
1820
- if (inlinedModules && inlinedModules.has(m)) {
1821
- const moduleScope = globalScope.childScopes[0];
1822
- inlinedModulesToInfo.set(m, {
1823
- source: moduleSource,
1824
- ast,
1825
- module: m,
1826
- variables: new Set(moduleScope.variables),
1827
- through: new Set(moduleScope.through),
1828
- usedInNonInlined: new Set(),
1829
- moduleScope
1830
- });
1831
- } else {
1832
- for (const ref of globalScope.through) {
1833
- nonInlinedModuleThroughIdentifiers.add(ref.identifier.name);
2191
+ for (const ref of globalScope.through) {
2192
+ nonInlinedModuleThroughIdentifiers.add(ref.identifier.name);
2193
+ }
2194
+ }
2195
+
2196
+ // Fast path: codegen reports each inlined entry's rendered top-level
2197
+ // declarations and free names (post-concatenation), so when no declaration
2198
+ // collides with a free name of any other module, another entry's
2199
+ // declarations, or a reserved name, no renaming is needed and the entries
2200
+ // don't have to be parsed at all.
2201
+ fastPath: {
2202
+ const { codeGenerationResults, chunk } = renderContext;
2203
+ /** @type {Set<string>} */
2204
+ const usedNames = new Set(nonInlinedModuleThroughIdentifiers);
2205
+ for (const name of RESERVED_NAMES) usedNames.add(name);
2206
+ /** @type {Set<string>[]} */
2207
+ const declarationsList = [];
2208
+ for (const m of inlinedModuleSources.keys()) {
2209
+ if (!codeGenerationResults.has(m, chunk.runtime)) break fastPath;
2210
+ const result = codeGenerationResults.get(m, chunk.runtime);
2211
+ const data = result.data;
2212
+ if (!data) break fastPath;
2213
+ const declarations = data.get("topLevelDeclarations");
2214
+ if (!declarations) break fastPath;
2215
+ declarationsList.push(declarations);
2216
+ if (!isMultipleEntries) continue;
2217
+ // Entries share the startup scope: an entry's free names and runtime
2218
+ // globals must not be shadowed by another entry's declarations.
2219
+ const freeNames = data.get("freeNames");
2220
+ if (!freeNames) break fastPath;
2221
+ for (const name of freeNames) usedNames.add(name);
2222
+ if (result.runtimeRequirements) {
2223
+ for (const req of result.runtimeRequirements) {
2224
+ const dot = req.indexOf(".");
2225
+ usedNames.add(dot === -1 ? req : req.slice(0, dot));
2226
+ }
2227
+ }
2228
+ }
2229
+ for (const declarations of declarationsList) {
2230
+ for (const name of declarations) {
2231
+ if (usedNames.has(name)) break fastPath;
1834
2232
  }
2233
+ // earlier entries' declarations join the used set so later entries
2234
+ // are checked against them
2235
+ for (const name of declarations) usedNames.add(name);
1835
2236
  }
2237
+ for (const [m, moduleSource] of inlinedModuleSources) {
2238
+ renamedInlinedModules.set(m, moduleSource);
2239
+ }
2240
+ return renamedInlinedModules;
2241
+ }
2242
+
2243
+ for (const [m, moduleSource] of inlinedModuleSources) {
2244
+ const code = /** @type {string} */ (moduleSource.source());
2245
+
2246
+ const { experiments } = compilation.options;
2247
+ const { ast } = JavascriptParser._parse(
2248
+ code,
2249
+ {
2250
+ sourceType: "auto",
2251
+ ranges: true,
2252
+ // generated code contains phase imports when the experiments are on
2253
+ importPhases: Boolean(
2254
+ experiments.deferImport || experiments.sourceImport
2255
+ )
2256
+ },
2257
+ JavascriptParser._getModuleParseFunction(compilation, m)
2258
+ );
2259
+
2260
+ const scopeManager = eslintScope.analyze(ast, {
2261
+ ecmaVersion: 6,
2262
+ sourceType: "module",
2263
+ optimistic: true,
2264
+ ignoreEval: true
2265
+ });
2266
+
2267
+ const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
2268
+ const moduleScope = globalScope.childScopes[0];
2269
+ inlinedModulesToInfo.set(m, {
2270
+ source: moduleSource,
2271
+ ast,
2272
+ module: m,
2273
+ variables: new Set(moduleScope.variables),
2274
+ through: new Set(moduleScope.through),
2275
+ usedInNonInlined: new Set(),
2276
+ moduleScope
2277
+ });
1836
2278
  }
1837
2279
 
1838
2280
  for (const [, { variables, usedInNonInlined }] of inlinedModulesToInfo) {
@@ -1846,6 +2288,36 @@ class JavascriptModulesPlugin {
1846
2288
  }
1847
2289
  }
1848
2290
 
2291
+ // Multiple inlined entry modules share the chunk's startup scope. Rename any
2292
+ // top-level declaration that would collide with another inlined module's
2293
+ // declaration, with any inlined or non-inlined module's free (global)
2294
+ // reference, or with a reserved name, so the modules can be emitted without a
2295
+ // per-entry IIFE.
2296
+ if (isMultipleEntries) {
2297
+ /** @type {Set<string>} */
2298
+ const allUsedNames = new Set(nonInlinedModuleThroughIdentifiers);
2299
+ for (const name of RESERVED_NAMES) allUsedNames.add(name);
2300
+ for (const { through } of inlinedModulesToInfo.values()) {
2301
+ for (const ref of through) allUsedNames.add(ref.identifier.name);
2302
+ }
2303
+ for (const [m, moduleInfo] of inlinedModulesToInfo) {
2304
+ const { ast, source: _source } = moduleInfo;
2305
+ const source = new ReplaceSource(_source);
2306
+ for (const variable of moduleInfo.variables) {
2307
+ renameInlinedModuleVariable(
2308
+ source,
2309
+ ast,
2310
+ variable,
2311
+ moduleInfo.module.identifier(),
2312
+ m.readableIdentifier(runtimeTemplate.requestShortener),
2313
+ allUsedNames
2314
+ );
2315
+ }
2316
+ renamedInlinedModules.set(m, source);
2317
+ }
2318
+ return renamedInlinedModules;
2319
+ }
2320
+
1849
2321
  for (const [m, moduleInfo] of inlinedModulesToInfo) {
1850
2322
  const { ast, source: _source, usedInNonInlined } = moduleInfo;
1851
2323
  const source = new ReplaceSource(_source);
@@ -1864,60 +2336,14 @@ class JavascriptModulesPlugin {
1864
2336
  }
1865
2337
 
1866
2338
  for (const variable of info.variables) {
1867
- /** @type {UsedNamesInScopeInfo} */
1868
- const usedNamesInScopeInfo = new Map();
1869
- /** @type {ScopeSet} */
1870
- const ignoredScopes = new Set();
1871
-
1872
- const name = variable.name;
1873
- const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
1874
- usedNamesInScopeInfo,
2339
+ renameInlinedModuleVariable(
2340
+ source,
2341
+ ast,
2342
+ variable,
1875
2343
  info.module.identifier(),
1876
- name
2344
+ m.readableIdentifier(runtimeTemplate.requestShortener),
2345
+ allUsedNames
1877
2346
  );
1878
-
1879
- if (allUsedNames.has(name) || usedNames.has(name)) {
1880
- const references = getAllReferences(variable);
1881
- const allIdentifiers = new Set([
1882
- ...references.map((r) => r.identifier),
1883
- ...variable.identifiers
1884
- ]);
1885
- for (const ref of references) {
1886
- addScopeSymbols(
1887
- ref.from,
1888
- usedNames,
1889
- alreadyCheckedScopes,
1890
- ignoredScopes
1891
- );
1892
- }
1893
-
1894
- const newName = findNewName(
1895
- variable.name,
1896
- allUsedNames,
1897
- usedNames,
1898
- m.readableIdentifier(runtimeTemplate.requestShortener)
1899
- );
1900
- allUsedNames.add(newName);
1901
- for (const identifier of allIdentifiers) {
1902
- const r = /** @type {Range} */ (identifier.range);
1903
- const path = getPathInAst(ast, identifier);
1904
- if (path && path.length > 1) {
1905
- const maybeProperty =
1906
- path[1].type === "AssignmentPattern" && path[1].left === path[0]
1907
- ? path[2]
1908
- : path[1];
1909
- if (
1910
- maybeProperty.type === "Property" &&
1911
- maybeProperty.shorthand
1912
- ) {
1913
- source.insert(r[1], `: ${newName}`);
1914
- continue;
1915
- }
1916
- }
1917
- source.replace(r[0], r[1] - 1, newName);
1918
- }
1919
- }
1920
- allUsedNames.add(name);
1921
2347
  }
1922
2348
 
1923
2349
  renamedInlinedModules.set(m, source);
@@ -1927,5 +2353,9 @@ class JavascriptModulesPlugin {
1927
2353
  }
1928
2354
  }
1929
2355
 
2356
+ JavascriptModulesPlugin.getCompilationHooks = createHooksRegistry(
2357
+ createCompilationHooks
2358
+ );
2359
+
1930
2360
  module.exports = JavascriptModulesPlugin;
1931
2361
  module.exports.chunkHasJs = chunkHasJs;