@depup/webpack 5.105.4-depup.37

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 (709) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +38 -0
  3. package/bin/webpack.js +196 -0
  4. package/hot/dev-server.js +90 -0
  5. package/hot/emitter-event-target.js +7 -0
  6. package/hot/emitter.js +2 -0
  7. package/hot/lazy-compilation-node.js +66 -0
  8. package/hot/lazy-compilation-universal.js +18 -0
  9. package/hot/lazy-compilation-web.js +93 -0
  10. package/hot/load-http.js +7 -0
  11. package/hot/log-apply-result.js +49 -0
  12. package/hot/log.js +78 -0
  13. package/hot/only-dev-server.js +118 -0
  14. package/hot/poll.js +41 -0
  15. package/hot/signal.js +66 -0
  16. package/lib/APIPlugin.js +392 -0
  17. package/lib/AbstractMethodError.js +56 -0
  18. package/lib/AsyncDependenciesBlock.js +128 -0
  19. package/lib/AsyncDependencyToInitialChunkError.js +34 -0
  20. package/lib/AutomaticPrefetchPlugin.js +66 -0
  21. package/lib/BannerPlugin.js +138 -0
  22. package/lib/Cache.js +168 -0
  23. package/lib/CacheFacade.js +349 -0
  24. package/lib/CaseSensitiveModulesWarning.js +72 -0
  25. package/lib/Chunk.js +899 -0
  26. package/lib/ChunkGraph.js +1968 -0
  27. package/lib/ChunkGroup.js +615 -0
  28. package/lib/ChunkRenderError.js +38 -0
  29. package/lib/ChunkTemplate.js +181 -0
  30. package/lib/CleanPlugin.js +495 -0
  31. package/lib/CodeGenerationError.js +35 -0
  32. package/lib/CodeGenerationResults.js +167 -0
  33. package/lib/CommentCompilationWarning.js +33 -0
  34. package/lib/CompatibilityPlugin.js +240 -0
  35. package/lib/Compilation.js +5876 -0
  36. package/lib/Compiler.js +1413 -0
  37. package/lib/ConcatenationScope.js +181 -0
  38. package/lib/ConcurrentCompilationError.js +18 -0
  39. package/lib/ConditionalInitFragment.js +120 -0
  40. package/lib/ConstPlugin.js +567 -0
  41. package/lib/ContextExclusionPlugin.js +33 -0
  42. package/lib/ContextModule.js +1411 -0
  43. package/lib/ContextModuleFactory.js +514 -0
  44. package/lib/ContextReplacementPlugin.js +227 -0
  45. package/lib/CssModule.js +179 -0
  46. package/lib/DefinePlugin.js +878 -0
  47. package/lib/DelegatedModule.js +279 -0
  48. package/lib/DelegatedModuleFactoryPlugin.js +116 -0
  49. package/lib/DelegatedPlugin.js +49 -0
  50. package/lib/DependenciesBlock.js +120 -0
  51. package/lib/Dependency.js +390 -0
  52. package/lib/DependencyTemplate.js +71 -0
  53. package/lib/DependencyTemplates.js +67 -0
  54. package/lib/DllEntryPlugin.js +76 -0
  55. package/lib/DllModule.js +175 -0
  56. package/lib/DllModuleFactory.js +38 -0
  57. package/lib/DllPlugin.js +73 -0
  58. package/lib/DllReferencePlugin.js +189 -0
  59. package/lib/DotenvPlugin.js +468 -0
  60. package/lib/DynamicEntryPlugin.js +93 -0
  61. package/lib/EntryOptionPlugin.js +98 -0
  62. package/lib/EntryPlugin.js +72 -0
  63. package/lib/Entrypoint.js +120 -0
  64. package/lib/EnvironmentNotSupportAsyncWarning.js +51 -0
  65. package/lib/EnvironmentPlugin.js +74 -0
  66. package/lib/ErrorHelpers.js +100 -0
  67. package/lib/EvalDevToolModulePlugin.js +135 -0
  68. package/lib/EvalSourceMapDevToolPlugin.js +252 -0
  69. package/lib/ExportsInfo.js +1663 -0
  70. package/lib/ExportsInfoApiPlugin.js +87 -0
  71. package/lib/ExternalModule.js +1169 -0
  72. package/lib/ExternalModuleFactoryPlugin.js +370 -0
  73. package/lib/ExternalsPlugin.js +93 -0
  74. package/lib/FalseIIFEUmdWarning.js +20 -0
  75. package/lib/FileSystemInfo.js +4131 -0
  76. package/lib/FlagAllModulesAsUsedPlugin.js +55 -0
  77. package/lib/FlagDependencyExportsPlugin.js +437 -0
  78. package/lib/FlagDependencyUsagePlugin.js +348 -0
  79. package/lib/FlagEntryExportAsUsedPlugin.js +56 -0
  80. package/lib/Generator.js +188 -0
  81. package/lib/GraphHelpers.js +46 -0
  82. package/lib/HarmonyLinkingError.js +17 -0
  83. package/lib/HookWebpackError.js +121 -0
  84. package/lib/HotModuleReplacementPlugin.js +930 -0
  85. package/lib/HotUpdateChunk.js +16 -0
  86. package/lib/IgnoreErrorModuleFactory.js +39 -0
  87. package/lib/IgnorePlugin.js +105 -0
  88. package/lib/IgnoreWarningsPlugin.js +41 -0
  89. package/lib/InitFragment.js +204 -0
  90. package/lib/InvalidDependenciesModuleWarning.js +44 -0
  91. package/lib/JavascriptMetaInfoPlugin.js +78 -0
  92. package/lib/LibManifestPlugin.js +144 -0
  93. package/lib/LibraryTemplatePlugin.js +48 -0
  94. package/lib/LoaderOptionsPlugin.js +81 -0
  95. package/lib/LoaderTargetPlugin.js +39 -0
  96. package/lib/MainTemplate.js +371 -0
  97. package/lib/ManifestPlugin.js +242 -0
  98. package/lib/Module.js +1319 -0
  99. package/lib/ModuleBuildError.js +83 -0
  100. package/lib/ModuleDependencyError.js +44 -0
  101. package/lib/ModuleDependencyWarning.js +49 -0
  102. package/lib/ModuleError.js +69 -0
  103. package/lib/ModuleFactory.js +57 -0
  104. package/lib/ModuleFilenameHelpers.js +388 -0
  105. package/lib/ModuleGraph.js +1024 -0
  106. package/lib/ModuleGraphConnection.js +199 -0
  107. package/lib/ModuleHashingError.js +31 -0
  108. package/lib/ModuleInfoHeaderPlugin.js +318 -0
  109. package/lib/ModuleNotFoundError.js +90 -0
  110. package/lib/ModuleParseError.js +125 -0
  111. package/lib/ModuleProfile.js +108 -0
  112. package/lib/ModuleRestoreError.js +46 -0
  113. package/lib/ModuleSourceTypeConstants.js +179 -0
  114. package/lib/ModuleStoreError.js +45 -0
  115. package/lib/ModuleTemplate.js +173 -0
  116. package/lib/ModuleTypeConstants.js +190 -0
  117. package/lib/ModuleWarning.js +68 -0
  118. package/lib/MultiCompiler.js +678 -0
  119. package/lib/MultiStats.js +213 -0
  120. package/lib/MultiWatching.js +77 -0
  121. package/lib/NoEmitOnErrorsPlugin.js +30 -0
  122. package/lib/NoModeWarning.js +23 -0
  123. package/lib/NodeStuffInWebError.js +35 -0
  124. package/lib/NodeStuffPlugin.js +587 -0
  125. package/lib/NormalModule.js +1798 -0
  126. package/lib/NormalModuleFactory.js +1455 -0
  127. package/lib/NormalModuleReplacementPlugin.js +75 -0
  128. package/lib/NullFactory.js +24 -0
  129. package/lib/OptimizationStages.js +10 -0
  130. package/lib/OptionsApply.js +24 -0
  131. package/lib/Parser.js +40 -0
  132. package/lib/PlatformPlugin.js +41 -0
  133. package/lib/PrefetchPlugin.js +56 -0
  134. package/lib/ProgressPlugin.js +712 -0
  135. package/lib/ProvidePlugin.js +121 -0
  136. package/lib/RawModule.js +180 -0
  137. package/lib/RecordIdsPlugin.js +216 -0
  138. package/lib/RequestShortener.js +36 -0
  139. package/lib/RequireJsStuffPlugin.js +84 -0
  140. package/lib/ResolverFactory.js +156 -0
  141. package/lib/RuntimeGlobals.js +450 -0
  142. package/lib/RuntimeModule.js +242 -0
  143. package/lib/RuntimePlugin.js +547 -0
  144. package/lib/RuntimeTemplate.js +1288 -0
  145. package/lib/SelfModuleFactory.js +33 -0
  146. package/lib/SingleEntryPlugin.js +8 -0
  147. package/lib/SizeFormatHelpers.js +25 -0
  148. package/lib/SourceMapDevToolModuleOptionsPlugin.js +52 -0
  149. package/lib/SourceMapDevToolPlugin.js +646 -0
  150. package/lib/Stats.js +89 -0
  151. package/lib/Template.js +427 -0
  152. package/lib/TemplatedPathPlugin.js +400 -0
  153. package/lib/UnhandledSchemeError.js +34 -0
  154. package/lib/UnsupportedFeatureWarning.js +35 -0
  155. package/lib/UseStrictPlugin.js +81 -0
  156. package/lib/WarnCaseSensitiveModulesPlugin.js +64 -0
  157. package/lib/WarnDeprecatedOptionPlugin.js +60 -0
  158. package/lib/WarnNoModeSetPlugin.js +27 -0
  159. package/lib/WatchIgnorePlugin.js +155 -0
  160. package/lib/Watching.js +531 -0
  161. package/lib/WebpackError.js +81 -0
  162. package/lib/WebpackIsIncludedPlugin.js +93 -0
  163. package/lib/WebpackOptionsApply.js +941 -0
  164. package/lib/WebpackOptionsDefaulter.js +26 -0
  165. package/lib/asset/AssetBytesGenerator.js +172 -0
  166. package/lib/asset/AssetBytesParser.js +37 -0
  167. package/lib/asset/AssetGenerator.js +816 -0
  168. package/lib/asset/AssetModulesPlugin.js +358 -0
  169. package/lib/asset/AssetParser.js +73 -0
  170. package/lib/asset/AssetSourceGenerator.js +171 -0
  171. package/lib/asset/AssetSourceParser.js +37 -0
  172. package/lib/asset/RawDataUrlModule.js +179 -0
  173. package/lib/async-modules/AsyncModuleHelpers.js +52 -0
  174. package/lib/async-modules/AwaitDependenciesInitFragment.js +90 -0
  175. package/lib/async-modules/InferAsyncModulesPlugin.js +54 -0
  176. package/lib/buildChunkGraph.js +1392 -0
  177. package/lib/cache/AddBuildDependenciesPlugin.js +32 -0
  178. package/lib/cache/AddManagedPathsPlugin.js +40 -0
  179. package/lib/cache/IdleFileCachePlugin.js +242 -0
  180. package/lib/cache/MemoryCachePlugin.js +57 -0
  181. package/lib/cache/MemoryWithGcCachePlugin.js +142 -0
  182. package/lib/cache/PackFileCacheStrategy.js +1600 -0
  183. package/lib/cache/ResolverCachePlugin.js +450 -0
  184. package/lib/cache/getLazyHashedEtag.js +91 -0
  185. package/lib/cache/mergeEtags.js +71 -0
  186. package/lib/cli.js +859 -0
  187. package/lib/config/browserslistTargetHandler.js +388 -0
  188. package/lib/config/defaults.js +2086 -0
  189. package/lib/config/normalization.js +681 -0
  190. package/lib/config/target.js +389 -0
  191. package/lib/container/ContainerEntryDependency.js +50 -0
  192. package/lib/container/ContainerEntryModule.js +303 -0
  193. package/lib/container/ContainerEntryModuleFactory.js +27 -0
  194. package/lib/container/ContainerExposedDependency.js +62 -0
  195. package/lib/container/ContainerPlugin.js +118 -0
  196. package/lib/container/ContainerReferencePlugin.js +139 -0
  197. package/lib/container/FallbackDependency.js +66 -0
  198. package/lib/container/FallbackItemDependency.js +34 -0
  199. package/lib/container/FallbackModule.js +193 -0
  200. package/lib/container/FallbackModuleFactory.js +27 -0
  201. package/lib/container/HoistContainerReferencesPlugin.js +256 -0
  202. package/lib/container/ModuleFederationPlugin.js +131 -0
  203. package/lib/container/RemoteModule.js +225 -0
  204. package/lib/container/RemoteRuntimeModule.js +144 -0
  205. package/lib/container/RemoteToExternalDependency.js +33 -0
  206. package/lib/container/options.js +105 -0
  207. package/lib/css/CssGenerator.js +587 -0
  208. package/lib/css/CssLoadingRuntimeModule.js +513 -0
  209. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  210. package/lib/css/CssModulesPlugin.js +939 -0
  211. package/lib/css/CssParser.js +2621 -0
  212. package/lib/css/walkCssTokens.js +1740 -0
  213. package/lib/debug/ProfilingPlugin.js +589 -0
  214. package/lib/dependencies/AMDDefineDependency.js +267 -0
  215. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +504 -0
  216. package/lib/dependencies/AMDPlugin.js +243 -0
  217. package/lib/dependencies/AMDRequireArrayDependency.js +124 -0
  218. package/lib/dependencies/AMDRequireContextDependency.js +69 -0
  219. package/lib/dependencies/AMDRequireDependenciesBlock.js +28 -0
  220. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +425 -0
  221. package/lib/dependencies/AMDRequireDependency.js +189 -0
  222. package/lib/dependencies/AMDRequireItemDependency.js +41 -0
  223. package/lib/dependencies/AMDRuntimeModules.js +50 -0
  224. package/lib/dependencies/CachedConstDependency.js +135 -0
  225. package/lib/dependencies/CommonJsDependencyHelpers.js +65 -0
  226. package/lib/dependencies/CommonJsExportRequireDependency.js +416 -0
  227. package/lib/dependencies/CommonJsExportsDependency.js +184 -0
  228. package/lib/dependencies/CommonJsExportsParserPlugin.js +425 -0
  229. package/lib/dependencies/CommonJsFullRequireDependency.js +162 -0
  230. package/lib/dependencies/CommonJsImportsParserPlugin.js +611 -0
  231. package/lib/dependencies/CommonJsPlugin.js +316 -0
  232. package/lib/dependencies/CommonJsRequireContextDependency.js +73 -0
  233. package/lib/dependencies/CommonJsRequireDependency.js +42 -0
  234. package/lib/dependencies/CommonJsSelfReferenceDependency.js +156 -0
  235. package/lib/dependencies/ConstDependency.js +118 -0
  236. package/lib/dependencies/ContextDependency.js +183 -0
  237. package/lib/dependencies/ContextDependencyHelpers.js +277 -0
  238. package/lib/dependencies/ContextDependencyTemplateAsId.js +63 -0
  239. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +62 -0
  240. package/lib/dependencies/ContextElementDependency.js +147 -0
  241. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  242. package/lib/dependencies/CreateScriptUrlDependency.js +75 -0
  243. package/lib/dependencies/CriticalDependencyWarning.js +29 -0
  244. package/lib/dependencies/CssIcssExportDependency.js +539 -0
  245. package/lib/dependencies/CssIcssImportDependency.js +183 -0
  246. package/lib/dependencies/CssIcssSymbolDependency.js +131 -0
  247. package/lib/dependencies/CssImportDependency.js +120 -0
  248. package/lib/dependencies/CssUrlDependency.js +189 -0
  249. package/lib/dependencies/DelegatedSourceDependency.js +33 -0
  250. package/lib/dependencies/DllEntryDependency.js +61 -0
  251. package/lib/dependencies/DynamicExports.js +73 -0
  252. package/lib/dependencies/EntryDependency.js +30 -0
  253. package/lib/dependencies/ExportsInfoDependency.js +161 -0
  254. package/lib/dependencies/ExternalModuleDependency.js +109 -0
  255. package/lib/dependencies/ExternalModuleInitFragment.js +137 -0
  256. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +87 -0
  257. package/lib/dependencies/HarmonyAcceptDependency.js +237 -0
  258. package/lib/dependencies/HarmonyAcceptImportDependency.js +37 -0
  259. package/lib/dependencies/HarmonyCompatibilityDependency.js +91 -0
  260. package/lib/dependencies/HarmonyDetectionParserPlugin.js +103 -0
  261. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +165 -0
  262. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +254 -0
  263. package/lib/dependencies/HarmonyExportExpressionDependency.js +211 -0
  264. package/lib/dependencies/HarmonyExportHeaderDependency.js +78 -0
  265. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1494 -0
  266. package/lib/dependencies/HarmonyExportInitFragment.js +191 -0
  267. package/lib/dependencies/HarmonyExportSpecifierDependency.js +127 -0
  268. package/lib/dependencies/HarmonyExports.js +46 -0
  269. package/lib/dependencies/HarmonyImportDependency.js +459 -0
  270. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +576 -0
  271. package/lib/dependencies/HarmonyImportSideEffectDependency.js +91 -0
  272. package/lib/dependencies/HarmonyImportSpecifierDependency.js +514 -0
  273. package/lib/dependencies/HarmonyModulesPlugin.js +158 -0
  274. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +39 -0
  275. package/lib/dependencies/ImportContextDependency.js +81 -0
  276. package/lib/dependencies/ImportDependency.js +158 -0
  277. package/lib/dependencies/ImportEagerDependency.js +76 -0
  278. package/lib/dependencies/ImportMetaContextDependency.js +42 -0
  279. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +312 -0
  280. package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
  281. package/lib/dependencies/ImportMetaHotAcceptDependency.js +41 -0
  282. package/lib/dependencies/ImportMetaHotDeclineDependency.js +42 -0
  283. package/lib/dependencies/ImportMetaPlugin.js +447 -0
  284. package/lib/dependencies/ImportParserPlugin.js +602 -0
  285. package/lib/dependencies/ImportPhase.js +125 -0
  286. package/lib/dependencies/ImportPlugin.js +98 -0
  287. package/lib/dependencies/ImportWeakDependency.js +74 -0
  288. package/lib/dependencies/JsonExportsDependency.js +137 -0
  289. package/lib/dependencies/LoaderDependency.js +38 -0
  290. package/lib/dependencies/LoaderImportDependency.js +39 -0
  291. package/lib/dependencies/LoaderPlugin.js +294 -0
  292. package/lib/dependencies/LocalModule.js +60 -0
  293. package/lib/dependencies/LocalModuleDependency.js +84 -0
  294. package/lib/dependencies/LocalModulesHelpers.js +68 -0
  295. package/lib/dependencies/ModuleDecoratorDependency.js +136 -0
  296. package/lib/dependencies/ModuleDependency.js +100 -0
  297. package/lib/dependencies/ModuleDependencyTemplateAsId.js +35 -0
  298. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +39 -0
  299. package/lib/dependencies/ModuleHotAcceptDependency.js +41 -0
  300. package/lib/dependencies/ModuleHotDeclineDependency.js +42 -0
  301. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  302. package/lib/dependencies/NullDependency.js +42 -0
  303. package/lib/dependencies/PrefetchDependency.js +27 -0
  304. package/lib/dependencies/ProvidedDependency.js +156 -0
  305. package/lib/dependencies/PureExpressionDependency.js +161 -0
  306. package/lib/dependencies/RequireContextDependency.js +38 -0
  307. package/lib/dependencies/RequireContextDependencyParserPlugin.js +69 -0
  308. package/lib/dependencies/RequireContextPlugin.js +167 -0
  309. package/lib/dependencies/RequireEnsureDependenciesBlock.js +29 -0
  310. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +145 -0
  311. package/lib/dependencies/RequireEnsureDependency.js +115 -0
  312. package/lib/dependencies/RequireEnsureItemDependency.js +36 -0
  313. package/lib/dependencies/RequireEnsurePlugin.js +86 -0
  314. package/lib/dependencies/RequireHeaderDependency.js +70 -0
  315. package/lib/dependencies/RequireIncludeDependency.js +79 -0
  316. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +100 -0
  317. package/lib/dependencies/RequireIncludePlugin.js +63 -0
  318. package/lib/dependencies/RequireResolveContextDependency.js +67 -0
  319. package/lib/dependencies/RequireResolveDependency.js +58 -0
  320. package/lib/dependencies/RequireResolveHeaderDependency.js +81 -0
  321. package/lib/dependencies/RuntimeRequirementsDependency.js +85 -0
  322. package/lib/dependencies/StaticExportsDependency.js +72 -0
  323. package/lib/dependencies/SystemPlugin.js +168 -0
  324. package/lib/dependencies/SystemRuntimeModule.js +35 -0
  325. package/lib/dependencies/URLContextDependency.js +65 -0
  326. package/lib/dependencies/URLDependency.js +165 -0
  327. package/lib/dependencies/URLPlugin.js +67 -0
  328. package/lib/dependencies/UnsupportedDependency.js +82 -0
  329. package/lib/dependencies/WebAssemblyExportImportedDependency.js +93 -0
  330. package/lib/dependencies/WebAssemblyImportDependency.js +108 -0
  331. package/lib/dependencies/WebpackIsIncludedDependency.js +84 -0
  332. package/lib/dependencies/WorkerDependency.js +141 -0
  333. package/lib/dependencies/WorkerPlugin.js +565 -0
  334. package/lib/dependencies/getFunctionExpression.js +66 -0
  335. package/lib/dependencies/processExportInfo.js +67 -0
  336. package/lib/electron/ElectronTargetPlugin.js +71 -0
  337. package/lib/errors/BuildCycleError.js +30 -0
  338. package/lib/esm/ExportWebpackRequireRuntimeModule.js +30 -0
  339. package/lib/esm/ModuleChunkFormatPlugin.js +273 -0
  340. package/lib/esm/ModuleChunkLoadingPlugin.js +143 -0
  341. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +426 -0
  342. package/lib/formatLocation.js +67 -0
  343. package/lib/hmr/HotModuleReplacement.runtime.js +419 -0
  344. package/lib/hmr/HotModuleReplacementRuntimeModule.js +42 -0
  345. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +471 -0
  346. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  347. package/lib/hmr/LazyCompilationPlugin.js +473 -0
  348. package/lib/hmr/lazyCompilationBackend.js +167 -0
  349. package/lib/ids/ChunkModuleIdRangePlugin.js +94 -0
  350. package/lib/ids/DeterministicChunkIdsPlugin.js +73 -0
  351. package/lib/ids/DeterministicModuleIdsPlugin.js +98 -0
  352. package/lib/ids/HashedModuleIdsPlugin.js +85 -0
  353. package/lib/ids/IdHelpers.js +492 -0
  354. package/lib/ids/NamedChunkIdsPlugin.js +92 -0
  355. package/lib/ids/NamedModuleIdsPlugin.js +68 -0
  356. package/lib/ids/NaturalChunkIdsPlugin.js +35 -0
  357. package/lib/ids/NaturalModuleIdsPlugin.js +40 -0
  358. package/lib/ids/OccurrenceChunkIdsPlugin.js +86 -0
  359. package/lib/ids/OccurrenceModuleIdsPlugin.js +168 -0
  360. package/lib/ids/SyncModuleIdsPlugin.js +161 -0
  361. package/lib/index.js +681 -0
  362. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +153 -0
  363. package/lib/javascript/BasicEvaluatedExpression.js +603 -0
  364. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  365. package/lib/javascript/ChunkHelpers.js +45 -0
  366. package/lib/javascript/CommonJsChunkFormatPlugin.js +148 -0
  367. package/lib/javascript/EnableChunkLoadingPlugin.js +127 -0
  368. package/lib/javascript/JavascriptGenerator.js +277 -0
  369. package/lib/javascript/JavascriptModulesPlugin.js +1905 -0
  370. package/lib/javascript/JavascriptParser.js +5476 -0
  371. package/lib/javascript/JavascriptParserHelpers.js +129 -0
  372. package/lib/javascript/StartupHelpers.js +178 -0
  373. package/lib/json/JsonData.js +74 -0
  374. package/lib/json/JsonGenerator.js +234 -0
  375. package/lib/json/JsonModulesPlugin.js +66 -0
  376. package/lib/json/JsonParser.js +93 -0
  377. package/lib/library/AbstractLibraryPlugin.js +339 -0
  378. package/lib/library/AmdLibraryPlugin.js +181 -0
  379. package/lib/library/AssignLibraryPlugin.js +445 -0
  380. package/lib/library/EnableLibraryPlugin.js +306 -0
  381. package/lib/library/ExportPropertyLibraryPlugin.js +116 -0
  382. package/lib/library/JsonpLibraryPlugin.js +92 -0
  383. package/lib/library/ModuleLibraryPlugin.js +438 -0
  384. package/lib/library/SystemLibraryPlugin.js +256 -0
  385. package/lib/library/UmdLibraryPlugin.js +355 -0
  386. package/lib/logging/Logger.js +223 -0
  387. package/lib/logging/createConsoleLogger.js +217 -0
  388. package/lib/logging/runtime.js +45 -0
  389. package/lib/logging/truncateArgs.js +83 -0
  390. package/lib/node/CommonJsChunkLoadingPlugin.js +120 -0
  391. package/lib/node/NodeEnvironmentPlugin.js +73 -0
  392. package/lib/node/NodeSourcePlugin.js +19 -0
  393. package/lib/node/NodeTargetPlugin.js +102 -0
  394. package/lib/node/NodeTemplatePlugin.js +42 -0
  395. package/lib/node/NodeWatchFileSystem.js +198 -0
  396. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +286 -0
  397. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +123 -0
  398. package/lib/node/ReadFileCompileWasmPlugin.js +127 -0
  399. package/lib/node/RequireChunkLoadingRuntimeModule.js +239 -0
  400. package/lib/node/nodeConsole.js +185 -0
  401. package/lib/optimize/AggressiveMergingPlugin.js +98 -0
  402. package/lib/optimize/AggressiveSplittingPlugin.js +352 -0
  403. package/lib/optimize/ConcatenatedModule.js +2290 -0
  404. package/lib/optimize/EnsureChunkConditionsPlugin.js +88 -0
  405. package/lib/optimize/FlagIncludedChunksPlugin.js +137 -0
  406. package/lib/optimize/InnerGraph.js +368 -0
  407. package/lib/optimize/InnerGraphPlugin.js +455 -0
  408. package/lib/optimize/LimitChunkCountPlugin.js +302 -0
  409. package/lib/optimize/MangleExportsPlugin.js +194 -0
  410. package/lib/optimize/MergeDuplicateChunksPlugin.js +138 -0
  411. package/lib/optimize/MinChunkSizePlugin.js +121 -0
  412. package/lib/optimize/MinMaxSizeWarning.js +35 -0
  413. package/lib/optimize/ModuleConcatenationPlugin.js +971 -0
  414. package/lib/optimize/RealContentHashPlugin.js +488 -0
  415. package/lib/optimize/RemoveEmptyChunksPlugin.js +60 -0
  416. package/lib/optimize/RemoveParentModulesPlugin.js +216 -0
  417. package/lib/optimize/RuntimeChunkPlugin.js +52 -0
  418. package/lib/optimize/SideEffectsFlagPlugin.js +417 -0
  419. package/lib/optimize/SplitChunksPlugin.js +1836 -0
  420. package/lib/performance/AssetsOverSizeLimitWarning.js +37 -0
  421. package/lib/performance/EntrypointsOverSizeLimitWarning.js +40 -0
  422. package/lib/performance/NoAsyncChunksWarning.js +21 -0
  423. package/lib/performance/SizeLimitsPlugin.js +183 -0
  424. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +46 -0
  425. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +95 -0
  426. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +56 -0
  427. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +52 -0
  428. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +46 -0
  429. package/lib/rules/BasicEffectRulePlugin.js +56 -0
  430. package/lib/rules/BasicMatcherRulePlugin.js +68 -0
  431. package/lib/rules/ObjectMatcherRulePlugin.js +79 -0
  432. package/lib/rules/RuleSetCompiler.js +447 -0
  433. package/lib/rules/UseEffectRulePlugin.js +236 -0
  434. package/lib/runtime/AsyncModuleRuntimeModule.js +199 -0
  435. package/lib/runtime/AutoPublicPathRuntimeModule.js +90 -0
  436. package/lib/runtime/BaseUriRuntimeModule.js +35 -0
  437. package/lib/runtime/ChunkNameRuntimeModule.js +28 -0
  438. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +40 -0
  439. package/lib/runtime/CompatRuntimeModule.js +83 -0
  440. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +69 -0
  441. package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
  442. package/lib/runtime/CreateScriptUrlRuntimeModule.js +38 -0
  443. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +42 -0
  444. package/lib/runtime/EnsureChunkRuntimeModule.js +69 -0
  445. package/lib/runtime/GetChunkFilenameRuntimeModule.js +299 -0
  446. package/lib/runtime/GetFullHashRuntimeModule.js +31 -0
  447. package/lib/runtime/GetMainFilenameRuntimeModule.js +49 -0
  448. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +99 -0
  449. package/lib/runtime/GlobalRuntimeModule.js +47 -0
  450. package/lib/runtime/HasOwnPropertyRuntimeModule.js +35 -0
  451. package/lib/runtime/HelperRuntimeModule.js +18 -0
  452. package/lib/runtime/LoadScriptRuntimeModule.js +174 -0
  453. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +232 -0
  454. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +39 -0
  455. package/lib/runtime/NonceRuntimeModule.js +24 -0
  456. package/lib/runtime/OnChunksLoadedRuntimeModule.js +78 -0
  457. package/lib/runtime/PublicPathRuntimeModule.js +38 -0
  458. package/lib/runtime/RelativeUrlRuntimeModule.js +44 -0
  459. package/lib/runtime/RuntimeIdRuntimeModule.js +33 -0
  460. package/lib/runtime/StartupChunkDependenciesPlugin.js +88 -0
  461. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +77 -0
  462. package/lib/runtime/StartupEntrypointRuntimeModule.js +54 -0
  463. package/lib/runtime/SystemContextRuntimeModule.js +23 -0
  464. package/lib/runtime/ToBinaryRuntimeModule.js +72 -0
  465. package/lib/schemes/DataUriPlugin.js +47 -0
  466. package/lib/schemes/FileUriPlugin.js +54 -0
  467. package/lib/schemes/HttpUriPlugin.js +1410 -0
  468. package/lib/schemes/VirtualUrlPlugin.js +248 -0
  469. package/lib/serialization/AggregateErrorSerializer.js +41 -0
  470. package/lib/serialization/ArraySerializer.js +38 -0
  471. package/lib/serialization/BinaryMiddleware.js +1164 -0
  472. package/lib/serialization/DateObjectSerializer.js +28 -0
  473. package/lib/serialization/ErrorObjectSerializer.js +49 -0
  474. package/lib/serialization/FileMiddleware.js +766 -0
  475. package/lib/serialization/MapObjectSerializer.js +48 -0
  476. package/lib/serialization/NullPrototypeObjectSerializer.js +53 -0
  477. package/lib/serialization/ObjectMiddleware.js +877 -0
  478. package/lib/serialization/PlainObjectSerializer.js +119 -0
  479. package/lib/serialization/RegExpObjectSerializer.js +29 -0
  480. package/lib/serialization/Serializer.js +82 -0
  481. package/lib/serialization/SerializerMiddleware.js +226 -0
  482. package/lib/serialization/SetObjectSerializer.js +40 -0
  483. package/lib/serialization/SingleItemMiddleware.js +36 -0
  484. package/lib/serialization/types.js +13 -0
  485. package/lib/sharing/ConsumeSharedFallbackDependency.js +33 -0
  486. package/lib/sharing/ConsumeSharedModule.js +344 -0
  487. package/lib/sharing/ConsumeSharedPlugin.js +380 -0
  488. package/lib/sharing/ConsumeSharedRuntimeModule.js +358 -0
  489. package/lib/sharing/ProvideForSharedDependency.js +33 -0
  490. package/lib/sharing/ProvideSharedDependency.js +80 -0
  491. package/lib/sharing/ProvideSharedModule.js +196 -0
  492. package/lib/sharing/ProvideSharedModuleFactory.js +37 -0
  493. package/lib/sharing/ProvideSharedPlugin.js +248 -0
  494. package/lib/sharing/SharePlugin.js +91 -0
  495. package/lib/sharing/ShareRuntimeModule.js +152 -0
  496. package/lib/sharing/resolveMatchedConfigs.js +106 -0
  497. package/lib/sharing/utils.js +421 -0
  498. package/lib/stats/DefaultStatsFactoryPlugin.js +2791 -0
  499. package/lib/stats/DefaultStatsPresetPlugin.js +417 -0
  500. package/lib/stats/DefaultStatsPrinterPlugin.js +1860 -0
  501. package/lib/stats/StatsFactory.js +406 -0
  502. package/lib/stats/StatsPrinter.js +300 -0
  503. package/lib/url/URLParserPlugin.js +266 -0
  504. package/lib/util/AppendOnlyStackedSet.js +78 -0
  505. package/lib/util/ArrayHelpers.js +46 -0
  506. package/lib/util/ArrayQueue.js +104 -0
  507. package/lib/util/AsyncQueue.js +411 -0
  508. package/lib/util/Hash.js +68 -0
  509. package/lib/util/IterableHelpers.js +46 -0
  510. package/lib/util/LazyBucketSortedSet.js +272 -0
  511. package/lib/util/LazySet.js +236 -0
  512. package/lib/util/MapHelpers.js +34 -0
  513. package/lib/util/ParallelismFactorCalculator.js +70 -0
  514. package/lib/util/Queue.js +52 -0
  515. package/lib/util/Semaphore.js +51 -0
  516. package/lib/util/SetHelpers.js +94 -0
  517. package/lib/util/SortableSet.js +176 -0
  518. package/lib/util/StackedCacheMap.js +140 -0
  519. package/lib/util/StackedMap.js +164 -0
  520. package/lib/util/StringXor.js +103 -0
  521. package/lib/util/TupleQueue.js +70 -0
  522. package/lib/util/TupleSet.js +185 -0
  523. package/lib/util/URLAbsoluteSpecifier.js +86 -0
  524. package/lib/util/WeakTupleMap.js +227 -0
  525. package/lib/util/binarySearchBounds.js +136 -0
  526. package/lib/util/chainedImports.js +99 -0
  527. package/lib/util/cleverMerge.js +676 -0
  528. package/lib/util/comparators.js +645 -0
  529. package/lib/util/compileBooleanMatcher.js +313 -0
  530. package/lib/util/concatenate.js +232 -0
  531. package/lib/util/conventions.js +126 -0
  532. package/lib/util/create-schema-validation.js +41 -0
  533. package/lib/util/createHash.js +91 -0
  534. package/lib/util/dataURL.js +39 -0
  535. package/lib/util/deprecation.js +350 -0
  536. package/lib/util/deterministicGrouping.js +561 -0
  537. package/lib/util/extractSourceMap.js +318 -0
  538. package/lib/util/extractUrlAndGlobal.js +18 -0
  539. package/lib/util/findGraphRoots.js +211 -0
  540. package/lib/util/fs.js +675 -0
  541. package/lib/util/generateDebugId.js +33 -0
  542. package/lib/util/hash/BatchedHash.js +115 -0
  543. package/lib/util/hash/BulkUpdateHash.js +145 -0
  544. package/lib/util/hash/DebugHash.js +75 -0
  545. package/lib/util/hash/hash-digest.js +217 -0
  546. package/lib/util/hash/md4.js +20 -0
  547. package/lib/util/hash/wasm-hash.js +232 -0
  548. package/lib/util/hash/xxhash64.js +20 -0
  549. package/lib/util/identifier.js +471 -0
  550. package/lib/util/internalSerializables.js +222 -0
  551. package/lib/util/magicComment.js +25 -0
  552. package/lib/util/makeSerializable.js +60 -0
  553. package/lib/util/memoize.js +36 -0
  554. package/lib/util/nonNumericOnlyHash.js +22 -0
  555. package/lib/util/numberHash.js +95 -0
  556. package/lib/util/objectToMap.js +15 -0
  557. package/lib/util/processAsyncTree.js +68 -0
  558. package/lib/util/propertyAccess.js +30 -0
  559. package/lib/util/propertyName.js +76 -0
  560. package/lib/util/registerExternalSerializer.js +334 -0
  561. package/lib/util/removeBOM.js +25 -0
  562. package/lib/util/runtime.js +717 -0
  563. package/lib/util/semver.js +604 -0
  564. package/lib/util/serialization.js +153 -0
  565. package/lib/util/smartGrouping.js +221 -0
  566. package/lib/util/source.js +62 -0
  567. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  568. package/lib/validateSchema.js +177 -0
  569. package/lib/wasm/EnableWasmLoadingPlugin.js +146 -0
  570. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +154 -0
  571. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +74 -0
  572. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +212 -0
  573. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +209 -0
  574. package/lib/wasm-async/AsyncWebAssemblyParser.js +80 -0
  575. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +107 -0
  576. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +20 -0
  577. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +422 -0
  578. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +91 -0
  579. package/lib/wasm-sync/WebAssemblyGenerator.js +535 -0
  580. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +111 -0
  581. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +236 -0
  582. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +151 -0
  583. package/lib/wasm-sync/WebAssemblyParser.js +201 -0
  584. package/lib/wasm-sync/WebAssemblyUtils.js +66 -0
  585. package/lib/web/FetchCompileAsyncWasmPlugin.js +70 -0
  586. package/lib/web/FetchCompileWasmPlugin.js +86 -0
  587. package/lib/web/JsonpChunkLoadingPlugin.js +101 -0
  588. package/lib/web/JsonpChunkLoadingRuntimeModule.js +455 -0
  589. package/lib/web/JsonpTemplatePlugin.js +37 -0
  590. package/lib/webpack.js +227 -0
  591. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +110 -0
  592. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +231 -0
  593. package/lib/webworker/WebWorkerTemplatePlugin.js +26 -0
  594. package/module.d.ts +238 -0
  595. package/package.json +258 -0
  596. package/schemas/WebpackOptions.check.d.ts +7 -0
  597. package/schemas/WebpackOptions.check.js +6 -0
  598. package/schemas/WebpackOptions.json +6179 -0
  599. package/schemas/_container.json +155 -0
  600. package/schemas/_sharing.json +118 -0
  601. package/schemas/plugins/BannerPlugin.check.d.ts +7 -0
  602. package/schemas/plugins/BannerPlugin.check.js +6 -0
  603. package/schemas/plugins/BannerPlugin.json +115 -0
  604. package/schemas/plugins/DllPlugin.check.d.ts +7 -0
  605. package/schemas/plugins/DllPlugin.check.js +6 -0
  606. package/schemas/plugins/DllPlugin.json +36 -0
  607. package/schemas/plugins/DllReferencePlugin.check.d.ts +7 -0
  608. package/schemas/plugins/DllReferencePlugin.check.js +6 -0
  609. package/schemas/plugins/DllReferencePlugin.json +206 -0
  610. package/schemas/plugins/IgnorePlugin.check.d.ts +7 -0
  611. package/schemas/plugins/IgnorePlugin.check.js +6 -0
  612. package/schemas/plugins/IgnorePlugin.json +34 -0
  613. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +7 -0
  614. package/schemas/plugins/LoaderOptionsPlugin.check.js +6 -0
  615. package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
  616. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  617. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  618. package/schemas/plugins/ManifestPlugin.json +98 -0
  619. package/schemas/plugins/ProgressPlugin.check.d.ts +7 -0
  620. package/schemas/plugins/ProgressPlugin.check.js +6 -0
  621. package/schemas/plugins/ProgressPlugin.json +65 -0
  622. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +7 -0
  623. package/schemas/plugins/SourceMapDevToolPlugin.check.js +6 -0
  624. package/schemas/plugins/SourceMapDevToolPlugin.json +168 -0
  625. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +7 -0
  626. package/schemas/plugins/WatchIgnorePlugin.check.js +6 -0
  627. package/schemas/plugins/WatchIgnorePlugin.json +25 -0
  628. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +7 -0
  629. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +6 -0
  630. package/schemas/plugins/asset/AssetGeneratorOptions.json +3 -0
  631. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +7 -0
  632. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +6 -0
  633. package/schemas/plugins/asset/AssetInlineGeneratorOptions.json +3 -0
  634. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +7 -0
  635. package/schemas/plugins/asset/AssetParserOptions.check.js +6 -0
  636. package/schemas/plugins/asset/AssetParserOptions.json +3 -0
  637. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +7 -0
  638. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +6 -0
  639. package/schemas/plugins/asset/AssetResourceGeneratorOptions.json +3 -0
  640. package/schemas/plugins/container/ContainerPlugin.check.d.ts +7 -0
  641. package/schemas/plugins/container/ContainerPlugin.check.js +6 -0
  642. package/schemas/plugins/container/ContainerPlugin.json +294 -0
  643. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +7 -0
  644. package/schemas/plugins/container/ContainerReferencePlugin.check.js +6 -0
  645. package/schemas/plugins/container/ContainerReferencePlugin.json +132 -0
  646. package/schemas/plugins/container/ExternalsType.check.d.ts +7 -0
  647. package/schemas/plugins/container/ExternalsType.check.js +6 -0
  648. package/schemas/plugins/container/ExternalsType.json +3 -0
  649. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +7 -0
  650. package/schemas/plugins/container/ModuleFederationPlugin.check.js +6 -0
  651. package/schemas/plugins/container/ModuleFederationPlugin.json +525 -0
  652. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  653. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  654. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  655. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  656. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  657. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  658. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  659. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  660. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  661. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  662. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  663. package/schemas/plugins/css/CssParserOptions.json +3 -0
  664. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +7 -0
  665. package/schemas/plugins/debug/ProfilingPlugin.check.js +6 -0
  666. package/schemas/plugins/debug/ProfilingPlugin.json +12 -0
  667. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  668. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  669. package/schemas/plugins/ids/HashedModuleIdsPlugin.json +57 -0
  670. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +7 -0
  671. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +6 -0
  672. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.json +11 -0
  673. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +7 -0
  674. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +6 -0
  675. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.json +11 -0
  676. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  677. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
  678. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  679. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  680. package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
  681. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  682. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +7 -0
  683. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +6 -0
  684. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
  685. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +7 -0
  686. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +6 -0
  687. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +21 -0
  688. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +7 -0
  689. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +6 -0
  690. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.json +11 -0
  691. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +7 -0
  692. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +6 -0
  693. package/schemas/plugins/optimize/MinChunkSizePlugin.json +20 -0
  694. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
  695. package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
  696. package/schemas/plugins/schemes/HttpUriPlugin.json +74 -0
  697. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  698. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  699. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  700. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +7 -0
  701. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +6 -0
  702. package/schemas/plugins/sharing/ConsumeSharedPlugin.json +120 -0
  703. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +7 -0
  704. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +6 -0
  705. package/schemas/plugins/sharing/ProvideSharedPlugin.json +94 -0
  706. package/schemas/plugins/sharing/SharePlugin.check.d.ts +7 -0
  707. package/schemas/plugins/sharing/SharePlugin.check.js +6 -0
  708. package/schemas/plugins/sharing/SharePlugin.json +133 -0
  709. package/types.d.ts +20217 -0
@@ -0,0 +1,1905 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const vm = require("vm");
9
+ const eslintScope = require("eslint-scope");
10
+ const { SyncBailHook, SyncHook, SyncWaterfallHook } = require("tapable");
11
+ const {
12
+ CachedSource,
13
+ ConcatSource,
14
+ OriginalSource,
15
+ PrefixSource,
16
+ RawSource,
17
+ ReplaceSource
18
+ } = require("webpack-sources");
19
+ const Compilation = require("../Compilation");
20
+ const { tryRunOrWebpackError } = require("../HookWebpackError");
21
+ const HotUpdateChunk = require("../HotUpdateChunk");
22
+ const InitFragment = require("../InitFragment");
23
+ const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
24
+ const {
25
+ JAVASCRIPT_MODULE_TYPE_AUTO,
26
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
27
+ JAVASCRIPT_MODULE_TYPE_ESM,
28
+ WEBPACK_MODULE_TYPE_RUNTIME
29
+ } = require("../ModuleTypeConstants");
30
+ const NormalModule = require("../NormalModule");
31
+ const RuntimeGlobals = require("../RuntimeGlobals");
32
+ const Template = require("../Template");
33
+ const { last, someInIterable } = require("../util/IterableHelpers");
34
+ const StringXor = require("../util/StringXor");
35
+ const { compareModulesByFullName } = require("../util/comparators");
36
+ const {
37
+ RESERVED_NAMES,
38
+ addScopeSymbols,
39
+ findNewName,
40
+ getAllReferences,
41
+ getPathInAst,
42
+ getUsedNamesInScopeInfo
43
+ } = require("../util/concatenate");
44
+ const createHash = require("../util/createHash");
45
+ const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
46
+ const removeBOM = require("../util/removeBOM");
47
+ const { intersectRuntime } = require("../util/runtime");
48
+ const JavascriptGenerator = require("./JavascriptGenerator");
49
+ const JavascriptParser = require("./JavascriptParser");
50
+
51
+ /** @typedef {import("eslint-scope").Reference} Reference */
52
+ /** @typedef {import("eslint-scope").Scope} Scope */
53
+ /** @typedef {import("eslint-scope").Variable} Variable */
54
+ /** @typedef {import("estree").Program} Program */
55
+ /** @typedef {import("webpack-sources").Source} Source */
56
+ /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
57
+ /** @typedef {import("../Chunk")} Chunk */
58
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
59
+ /** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
60
+ /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
61
+ /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
62
+ /** @typedef {import("../Compilation").ExecuteModuleObject} ExecuteModuleObject */
63
+ /** @typedef {import("../Compilation").WebpackRequire} WebpackRequire */
64
+ /** @typedef {import("../Compiler")} Compiler */
65
+ /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
66
+ /** @typedef {import("../Entrypoint")} Entrypoint */
67
+ /** @typedef {import("../Module")} Module */
68
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
69
+ /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
70
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
71
+ /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
72
+ /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
73
+ /** @typedef {import("../WebpackError")} WebpackError */
74
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
75
+ /** @typedef {import("../util/Hash")} Hash */
76
+ /** @typedef {import("../util/concatenate").ScopeSet} ScopeSet */
77
+ /** @typedef {import("../util/concatenate").UsedNamesInScopeInfo} UsedNamesInScopeInfo */
78
+
79
+ /** @type {WeakMap<ChunkGraph, WeakMap<Chunk, boolean>>} */
80
+ const chunkHasJsCache = new WeakMap();
81
+
82
+ /**
83
+ * @param {Chunk} chunk a chunk
84
+ * @param {ChunkGraph} chunkGraph the chunk graph
85
+ * @returns {boolean} true, when a JS file is needed for this chunk
86
+ */
87
+ const _chunkHasJs = (chunk, chunkGraph) => {
88
+ if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
89
+ for (const module of chunkGraph.getChunkEntryModulesIterable(chunk)) {
90
+ if (chunkGraph.getModuleSourceTypes(module).has(JAVASCRIPT_TYPE)) {
91
+ return true;
92
+ }
93
+ }
94
+ }
95
+
96
+ return Boolean(
97
+ chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE)
98
+ );
99
+ };
100
+
101
+ /**
102
+ * @param {Chunk} chunk a chunk
103
+ * @param {ChunkGraph} chunkGraph the chunk graph
104
+ * @returns {boolean} true, when a JS file is needed for this chunk
105
+ */
106
+ const chunkHasJs = (chunk, chunkGraph) => {
107
+ let innerCache = chunkHasJsCache.get(chunkGraph);
108
+ if (innerCache === undefined) {
109
+ innerCache = new WeakMap();
110
+ chunkHasJsCache.set(chunkGraph, innerCache);
111
+ }
112
+
113
+ const cachedResult = innerCache.get(chunk);
114
+ if (cachedResult !== undefined) {
115
+ return cachedResult;
116
+ }
117
+
118
+ const result = _chunkHasJs(chunk, chunkGraph);
119
+ innerCache.set(chunk, result);
120
+ return result;
121
+ };
122
+
123
+ /**
124
+ * @param {Chunk} chunk a chunk
125
+ * @param {ChunkGraph} chunkGraph the chunk graph
126
+ * @returns {boolean} true, when a JS file is needed for this chunk
127
+ */
128
+ const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
129
+ if (chunkHasJs(chunk, chunkGraph)) {
130
+ return true;
131
+ }
132
+
133
+ if (
134
+ chunkGraph.getChunkModulesIterableBySourceType(
135
+ chunk,
136
+ WEBPACK_MODULE_TYPE_RUNTIME
137
+ )
138
+ ) {
139
+ for (const chunkGroup of chunk.groupsIterable) {
140
+ for (const c of chunkGroup.chunks) {
141
+ if (chunkHasJs(c, chunkGraph)) return true;
142
+ }
143
+ }
144
+ return false;
145
+ }
146
+
147
+ return false;
148
+ };
149
+
150
+ /**
151
+ * @param {Module} module a module
152
+ * @param {string} code the code
153
+ * @returns {string} generated code for the stack
154
+ */
155
+ const printGeneratedCodeForStack = (module, code) => {
156
+ const lines = code.split("\n");
157
+ const n = `${lines.length}`.length;
158
+ return `\n\nGenerated code for ${module.identifier()}\n${lines
159
+ .map(
160
+ /**
161
+ * @param {string} line the line
162
+ * @param {number} i the index
163
+ * @param {string[]} _lines the lines
164
+ * @returns {string} the line with line number
165
+ */
166
+ (line, i, _lines) => {
167
+ const iStr = `${i + 1}`;
168
+ return `${" ".repeat(n - iStr.length)}${iStr} | ${line}`;
169
+ }
170
+ )
171
+ .join("\n")}`;
172
+ };
173
+
174
+ /**
175
+ * @typedef {object} RenderContext
176
+ * @property {Chunk} chunk the chunk
177
+ * @property {DependencyTemplates} dependencyTemplates the dependency templates
178
+ * @property {RuntimeTemplate} runtimeTemplate the runtime template
179
+ * @property {ModuleGraph} moduleGraph the module graph
180
+ * @property {ChunkGraph} chunkGraph the chunk graph
181
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
182
+ * @property {boolean | undefined} strictMode rendering in strict context
183
+ */
184
+
185
+ /**
186
+ * @typedef {object} MainRenderContext
187
+ * @property {Chunk} chunk the chunk
188
+ * @property {DependencyTemplates} dependencyTemplates the dependency templates
189
+ * @property {RuntimeTemplate} runtimeTemplate the runtime template
190
+ * @property {ModuleGraph} moduleGraph the module graph
191
+ * @property {ChunkGraph} chunkGraph the chunk graph
192
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
193
+ * @property {string} hash hash to be used for render call
194
+ * @property {boolean | undefined} strictMode rendering in strict context
195
+ */
196
+
197
+ /**
198
+ * @typedef {object} ChunkRenderContext
199
+ * @property {Chunk} chunk the chunk
200
+ * @property {DependencyTemplates} dependencyTemplates the dependency templates
201
+ * @property {RuntimeTemplate} runtimeTemplate the runtime template
202
+ * @property {ModuleGraph} moduleGraph the module graph
203
+ * @property {ChunkGraph} chunkGraph the chunk graph
204
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
205
+ * @property {InitFragment<ChunkRenderContext>[]} chunkInitFragments init fragments for the chunk
206
+ * @property {boolean | undefined} strictMode rendering in strict context
207
+ */
208
+
209
+ /**
210
+ * @typedef {object} RenderBootstrapContext
211
+ * @property {Chunk} chunk the chunk
212
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
213
+ * @property {RuntimeTemplate} runtimeTemplate the runtime template
214
+ * @property {ModuleGraph} moduleGraph the module graph
215
+ * @property {ChunkGraph} chunkGraph the chunk graph
216
+ * @property {string} hash hash to be used for render call
217
+ */
218
+
219
+ /**
220
+ * @typedef {object} StartupRenderContext
221
+ * @property {Chunk} chunk the chunk
222
+ * @property {DependencyTemplates} dependencyTemplates the dependency templates
223
+ * @property {RuntimeTemplate} runtimeTemplate the runtime template
224
+ * @property {ModuleGraph} moduleGraph the module graph
225
+ * @property {ChunkGraph} chunkGraph the chunk graph
226
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
227
+ * @property {boolean | undefined} strictMode rendering in strict context
228
+ * @property {boolean} inlined inlined
229
+ * @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE
230
+ */
231
+
232
+ /**
233
+ * @typedef {object} ModuleRenderContext
234
+ * @property {Chunk} chunk the chunk
235
+ * @property {DependencyTemplates} dependencyTemplates the dependency templates
236
+ * @property {RuntimeTemplate} runtimeTemplate the runtime template
237
+ * @property {ModuleGraph} moduleGraph the module graph
238
+ * @property {ChunkGraph} chunkGraph the chunk graph
239
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
240
+ * @property {InitFragment<ChunkRenderContext>[]} chunkInitFragments init fragments for the chunk
241
+ * @property {boolean | undefined} strictMode rendering in strict context
242
+ * @property {boolean} factory true: renders as factory method, false: pure module content
243
+ * @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE, existing only when `factory` is set to false
244
+ * @property {boolean=} renderInObject render module in object container
245
+ */
246
+
247
+ /**
248
+ * @typedef {object} CompilationHooks
249
+ * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContent
250
+ * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContainer
251
+ * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModulePackage
252
+ * @property {SyncWaterfallHook<[Source, RenderContext]>} renderChunk
253
+ * @property {SyncWaterfallHook<[Source, RenderContext]>} renderMain
254
+ * @property {SyncWaterfallHook<[Source, RenderContext]>} renderContent
255
+ * @property {SyncWaterfallHook<[Source, RenderContext]>} render
256
+ * @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
257
+ * @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
258
+ * @property {SyncBailHook<[Module, Partial<RenderBootstrapContext>], string | void>} inlineInRuntimeBailout
259
+ * @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
260
+ * @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
261
+ * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
262
+ * @property {SyncBailHook<[Chunk, RenderContext], boolean | void>} useSourceMap
263
+ */
264
+
265
+ /** @type {WeakMap<Compilation, CompilationHooks>} */
266
+ const compilationHooksMap = new WeakMap();
267
+
268
+ const PLUGIN_NAME = "JavascriptModulesPlugin";
269
+
270
+ /** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */
271
+
272
+ class JavascriptModulesPlugin {
273
+ /**
274
+ * @param {Compilation} compilation the compilation
275
+ * @returns {CompilationHooks} the attached hooks
276
+ */
277
+ static getCompilationHooks(compilation) {
278
+ if (!(compilation instanceof Compilation)) {
279
+ throw new TypeError(
280
+ "The 'compilation' argument must be an instance of Compilation"
281
+ );
282
+ }
283
+ let hooks = compilationHooksMap.get(compilation);
284
+ if (hooks === undefined) {
285
+ hooks = {
286
+ renderModuleContent: new SyncWaterfallHook([
287
+ "source",
288
+ "module",
289
+ "moduleRenderContext"
290
+ ]),
291
+ renderModuleContainer: new SyncWaterfallHook([
292
+ "source",
293
+ "module",
294
+ "moduleRenderContext"
295
+ ]),
296
+ renderModulePackage: new SyncWaterfallHook([
297
+ "source",
298
+ "module",
299
+ "moduleRenderContext"
300
+ ]),
301
+ render: new SyncWaterfallHook(["source", "renderContext"]),
302
+ renderContent: new SyncWaterfallHook(["source", "renderContext"]),
303
+ renderStartup: new SyncWaterfallHook([
304
+ "source",
305
+ "module",
306
+ "startupRenderContext"
307
+ ]),
308
+ renderChunk: new SyncWaterfallHook(["source", "renderContext"]),
309
+ renderMain: new SyncWaterfallHook(["source", "renderContext"]),
310
+ renderRequire: new SyncWaterfallHook(["code", "renderContext"]),
311
+ inlineInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
312
+ embedInRuntimeBailout: new SyncBailHook(["module", "renderContext"]),
313
+ strictRuntimeBailout: new SyncBailHook(["renderContext"]),
314
+ chunkHash: new SyncHook(["chunk", "hash", "context"]),
315
+ useSourceMap: new SyncBailHook(["chunk", "renderContext"])
316
+ };
317
+ compilationHooksMap.set(compilation, hooks);
318
+ }
319
+ return hooks;
320
+ }
321
+
322
+ constructor(options = {}) {
323
+ this.options = options;
324
+ /** @type {WeakMap<Source, { source: Source, needModule: boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined, renderShorthand: boolean }>} */
325
+ this._moduleFactoryCache = new WeakMap();
326
+ }
327
+
328
+ /**
329
+ * Apply the plugin
330
+ * @param {Compiler} compiler the compiler instance
331
+ * @returns {void}
332
+ */
333
+ apply(compiler) {
334
+ compiler.hooks.compilation.tap(
335
+ PLUGIN_NAME,
336
+ (compilation, { normalModuleFactory }) => {
337
+ const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
338
+
339
+ for (const type of [
340
+ JAVASCRIPT_MODULE_TYPE_AUTO,
341
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
342
+ JAVASCRIPT_MODULE_TYPE_ESM
343
+ ]) {
344
+ normalModuleFactory.hooks.createParser
345
+ .for(type)
346
+ .tap(PLUGIN_NAME, (options) => {
347
+ switch (type) {
348
+ case JAVASCRIPT_MODULE_TYPE_AUTO: {
349
+ return new JavascriptParser("auto", { parse: options.parse });
350
+ }
351
+ case JAVASCRIPT_MODULE_TYPE_DYNAMIC: {
352
+ return new JavascriptParser("script", {
353
+ parse: options.parse
354
+ });
355
+ }
356
+ case JAVASCRIPT_MODULE_TYPE_ESM: {
357
+ return new JavascriptParser("module", {
358
+ parse: options.parse
359
+ });
360
+ }
361
+ }
362
+ });
363
+ normalModuleFactory.hooks.createGenerator
364
+ .for(type)
365
+ .tap(PLUGIN_NAME, () => new JavascriptGenerator());
366
+
367
+ NormalModule.getCompilationHooks(compilation).processResult.tap(
368
+ PLUGIN_NAME,
369
+ (result, module) => {
370
+ if (module.type === type) {
371
+ const [source, ...rest] = result;
372
+
373
+ return [removeBOM(source), ...rest];
374
+ }
375
+
376
+ return result;
377
+ }
378
+ );
379
+ }
380
+
381
+ compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
382
+ const {
383
+ hash,
384
+ chunk,
385
+ chunkGraph,
386
+ moduleGraph,
387
+ runtimeTemplate,
388
+ dependencyTemplates,
389
+ outputOptions,
390
+ codeGenerationResults
391
+ } = options;
392
+
393
+ const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null;
394
+ const filenameTemplate =
395
+ JavascriptModulesPlugin.getChunkFilenameTemplate(
396
+ chunk,
397
+ outputOptions
398
+ );
399
+
400
+ /** @type {() => Source} */
401
+ let render;
402
+
403
+ if (hotUpdateChunk) {
404
+ render = () =>
405
+ this.renderChunk(
406
+ {
407
+ chunk,
408
+ dependencyTemplates,
409
+ runtimeTemplate,
410
+ moduleGraph,
411
+ chunkGraph,
412
+ codeGenerationResults,
413
+ strictMode: runtimeTemplate.isModule()
414
+ },
415
+ hooks
416
+ );
417
+ } else if (chunk.hasRuntime()) {
418
+ if (!chunkHasRuntimeOrJs(chunk, chunkGraph)) {
419
+ return result;
420
+ }
421
+
422
+ render = () =>
423
+ this.renderMain(
424
+ {
425
+ hash,
426
+ chunk,
427
+ dependencyTemplates,
428
+ runtimeTemplate,
429
+ moduleGraph,
430
+ chunkGraph,
431
+ codeGenerationResults,
432
+ strictMode: runtimeTemplate.isModule()
433
+ },
434
+ hooks,
435
+ compilation
436
+ );
437
+ } else {
438
+ if (!chunkHasJs(chunk, chunkGraph)) {
439
+ return result;
440
+ }
441
+
442
+ render = () =>
443
+ this.renderChunk(
444
+ {
445
+ chunk,
446
+ dependencyTemplates,
447
+ runtimeTemplate,
448
+ moduleGraph,
449
+ chunkGraph,
450
+ codeGenerationResults,
451
+ strictMode: runtimeTemplate.isModule()
452
+ },
453
+ hooks
454
+ );
455
+ }
456
+
457
+ result.push({
458
+ render,
459
+ filenameTemplate,
460
+ pathOptions: {
461
+ hash,
462
+ runtime: chunk.runtime,
463
+ chunk,
464
+ contentHashType: "javascript"
465
+ },
466
+ info: {
467
+ javascriptModule: compilation.runtimeTemplate.isModule()
468
+ },
469
+ identifier: hotUpdateChunk
470
+ ? `hotupdatechunk${chunk.id}`
471
+ : `chunk${chunk.id}`,
472
+ hash: chunk.contentHash.javascript
473
+ });
474
+
475
+ return result;
476
+ });
477
+ compilation.hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, context) => {
478
+ hooks.chunkHash.call(chunk, hash, context);
479
+ if (chunk.hasRuntime()) {
480
+ this.updateHashWithBootstrap(
481
+ hash,
482
+ {
483
+ hash: "0000",
484
+ chunk,
485
+ codeGenerationResults: context.codeGenerationResults,
486
+ chunkGraph: context.chunkGraph,
487
+ moduleGraph: context.moduleGraph,
488
+ runtimeTemplate: context.runtimeTemplate
489
+ },
490
+ hooks
491
+ );
492
+ }
493
+ });
494
+ compilation.hooks.contentHash.tap(PLUGIN_NAME, (chunk) => {
495
+ const {
496
+ chunkGraph,
497
+ moduleGraph,
498
+ runtimeTemplate,
499
+ outputOptions: {
500
+ hashSalt,
501
+ hashDigest,
502
+ hashDigestLength,
503
+ hashFunction
504
+ }
505
+ } = compilation;
506
+ const codeGenerationResults =
507
+ /** @type {CodeGenerationResults} */
508
+ (compilation.codeGenerationResults);
509
+ const hash = createHash(hashFunction);
510
+ if (hashSalt) hash.update(hashSalt);
511
+ if (chunk.hasRuntime()) {
512
+ this.updateHashWithBootstrap(
513
+ hash,
514
+ {
515
+ hash: "0000",
516
+ chunk,
517
+ codeGenerationResults,
518
+ chunkGraph: compilation.chunkGraph,
519
+ moduleGraph: compilation.moduleGraph,
520
+ runtimeTemplate: compilation.runtimeTemplate
521
+ },
522
+ hooks
523
+ );
524
+ } else {
525
+ hash.update(`${chunk.id} `);
526
+ hash.update(chunk.ids ? chunk.ids.join(",") : "");
527
+ }
528
+ hooks.chunkHash.call(chunk, hash, {
529
+ chunkGraph,
530
+ codeGenerationResults,
531
+ moduleGraph,
532
+ runtimeTemplate
533
+ });
534
+ const modules = chunkGraph.getChunkModulesIterableBySourceType(
535
+ chunk,
536
+ JAVASCRIPT_TYPE
537
+ );
538
+ if (modules) {
539
+ const xor = new StringXor();
540
+ for (const m of modules) {
541
+ xor.add(chunkGraph.getModuleHash(m, chunk.runtime));
542
+ }
543
+ xor.updateHash(hash);
544
+ }
545
+ const runtimeModules = chunkGraph.getChunkModulesIterableBySourceType(
546
+ chunk,
547
+ WEBPACK_MODULE_TYPE_RUNTIME
548
+ );
549
+ if (runtimeModules) {
550
+ const xor = new StringXor();
551
+ for (const m of runtimeModules) {
552
+ xor.add(chunkGraph.getModuleHash(m, chunk.runtime));
553
+ }
554
+ xor.updateHash(hash);
555
+ }
556
+ const digest = hash.digest(hashDigest);
557
+ chunk.contentHash.javascript = nonNumericOnlyHash(
558
+ digest,
559
+ hashDigestLength
560
+ );
561
+ });
562
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(
563
+ PLUGIN_NAME,
564
+ (chunk, set, { chunkGraph }) => {
565
+ if (
566
+ !set.has(RuntimeGlobals.startupNoDefault) &&
567
+ chunkGraph.hasChunkEntryDependentChunks(chunk)
568
+ ) {
569
+ set.add(RuntimeGlobals.onChunksLoaded);
570
+ set.add(RuntimeGlobals.exports);
571
+ set.add(RuntimeGlobals.require);
572
+ }
573
+ }
574
+ );
575
+ compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
576
+ const source =
577
+ options.codeGenerationResult.sources.get(JAVASCRIPT_TYPE);
578
+ if (source === undefined) return;
579
+ const { module } = options;
580
+ const code = source.source();
581
+
582
+ /** @type {(this: ExecuteModuleObject["exports"], exports: ExecuteModuleObject["exports"], moduleObject: ExecuteModuleObject, webpackRequire: WebpackRequire) => void} */
583
+ const fn = vm.runInThisContext(
584
+ `(function(${module.moduleArgument}, ${module.exportsArgument}, ${RuntimeGlobals.require}) {\n${code}\n/**/})`,
585
+ {
586
+ filename: module.identifier(),
587
+ lineOffset: -1
588
+ }
589
+ );
590
+
591
+ const moduleObject =
592
+ /** @type {ExecuteModuleObject} */
593
+ (options.moduleObject);
594
+
595
+ try {
596
+ fn.call(
597
+ moduleObject.exports,
598
+ moduleObject,
599
+ moduleObject.exports,
600
+ /** @type {WebpackRequire} */
601
+ (context.__webpack_require__)
602
+ );
603
+ } catch (err) {
604
+ /** @type {Error} */
605
+ (err).stack += printGeneratedCodeForStack(
606
+ options.module,
607
+ /** @type {string} */ (code)
608
+ );
609
+ throw err;
610
+ }
611
+ });
612
+ compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
613
+ const source = options.codeGenerationResult.sources.get("runtime");
614
+ if (source === undefined) return;
615
+ let code = source.source();
616
+ if (typeof code !== "string") code = code.toString();
617
+
618
+ /** @type {(this: null, webpackRequire: WebpackRequire) => void} */
619
+ const fn = vm.runInThisContext(
620
+ `(function(${RuntimeGlobals.require}) {\n${code}\n/**/})`,
621
+ {
622
+ filename: options.module.identifier(),
623
+ lineOffset: -1
624
+ }
625
+ );
626
+ try {
627
+ // eslint-disable-next-line no-useless-call
628
+ fn.call(
629
+ null,
630
+ /** @type {WebpackRequire} */
631
+ (context.__webpack_require__)
632
+ );
633
+ } catch (err) {
634
+ /** @type {Error} */
635
+ (err).stack += printGeneratedCodeForStack(options.module, code);
636
+ throw err;
637
+ }
638
+ });
639
+ }
640
+ );
641
+ }
642
+
643
+ /**
644
+ * @param {Chunk} chunk chunk
645
+ * @param {OutputOptions} outputOptions output options
646
+ * @returns {TemplatePath} used filename template
647
+ */
648
+ static getChunkFilenameTemplate(chunk, outputOptions) {
649
+ if (chunk.filenameTemplate) {
650
+ return chunk.filenameTemplate;
651
+ } else if (chunk instanceof HotUpdateChunk) {
652
+ return outputOptions.hotUpdateChunkFilename;
653
+ } else if (chunk.canBeInitial()) {
654
+ return outputOptions.filename;
655
+ }
656
+ return outputOptions.chunkFilename;
657
+ }
658
+
659
+ /**
660
+ * @param {Module} module the rendered module
661
+ * @param {ModuleRenderContext} renderContext options object
662
+ * @param {CompilationHooks} hooks hooks
663
+ * @returns {Source | null} the newly generated source from rendering
664
+ */
665
+ renderModule(module, renderContext, hooks) {
666
+ const {
667
+ chunk,
668
+ chunkGraph,
669
+ runtimeTemplate,
670
+ codeGenerationResults,
671
+ strictMode,
672
+ factory,
673
+ renderInObject
674
+ } = renderContext;
675
+ try {
676
+ const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
677
+ const moduleSource = codeGenResult.sources.get(JAVASCRIPT_TYPE);
678
+ if (!moduleSource) return null;
679
+ if (codeGenResult.data !== undefined) {
680
+ const chunkInitFragments = codeGenResult.data.get("chunkInitFragments");
681
+ if (chunkInitFragments) {
682
+ for (const i of chunkInitFragments) {
683
+ renderContext.chunkInitFragments.push(i);
684
+ }
685
+ }
686
+ }
687
+ const moduleSourcePostContent = tryRunOrWebpackError(
688
+ () =>
689
+ hooks.renderModuleContent.call(moduleSource, module, renderContext),
690
+ "JavascriptModulesPlugin.getCompilationHooks().renderModuleContent"
691
+ );
692
+ /** @type {Source} */
693
+ let moduleSourcePostContainer;
694
+ if (factory) {
695
+ const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
696
+ module,
697
+ chunk.runtime
698
+ );
699
+ const needModule = runtimeRequirements.has(RuntimeGlobals.module);
700
+ const needExports = runtimeRequirements.has(RuntimeGlobals.exports);
701
+ const needRequire =
702
+ runtimeRequirements.has(RuntimeGlobals.require) ||
703
+ runtimeRequirements.has(RuntimeGlobals.requireScope);
704
+ const needThisAsExports = runtimeRequirements.has(
705
+ RuntimeGlobals.thisAsExports
706
+ );
707
+ const needStrict =
708
+ /** @type {BuildInfo} */
709
+ (module.buildInfo).strict && !strictMode;
710
+ const cacheEntry = this._moduleFactoryCache.get(
711
+ moduleSourcePostContent
712
+ );
713
+ const renderShorthand =
714
+ renderInObject === true && runtimeTemplate.supportsMethodShorthand();
715
+ /** @type {Source} */
716
+ let source;
717
+ if (
718
+ cacheEntry &&
719
+ cacheEntry.needModule === needModule &&
720
+ cacheEntry.needExports === needExports &&
721
+ cacheEntry.needRequire === needRequire &&
722
+ cacheEntry.needThisAsExports === needThisAsExports &&
723
+ cacheEntry.needStrict === needStrict &&
724
+ cacheEntry.renderShorthand === renderShorthand
725
+ ) {
726
+ source = cacheEntry.source;
727
+ } else {
728
+ const factorySource = new ConcatSource();
729
+ /** @type {string[]} */
730
+ const args = [];
731
+ if (needExports || needRequire || needModule) {
732
+ args.push(
733
+ needModule
734
+ ? module.moduleArgument
735
+ : `__unused_webpack_${module.moduleArgument}`
736
+ );
737
+ }
738
+ if (needExports || needRequire) {
739
+ args.push(
740
+ needExports
741
+ ? module.exportsArgument
742
+ : `__unused_webpack_${module.exportsArgument}`
743
+ );
744
+ }
745
+ if (needRequire) args.push(RuntimeGlobals.require);
746
+
747
+ if (renderShorthand) {
748
+ // we can optimize function to methodShorthand if render module factory in object
749
+ factorySource.add(`(${args.join(", ")}) {\n\n`);
750
+ } else if (
751
+ !needThisAsExports &&
752
+ runtimeTemplate.supportsArrowFunction()
753
+ ) {
754
+ factorySource.add(`/***/ ((${args.join(", ")}) => {\n\n`);
755
+ } else {
756
+ factorySource.add(`/***/ (function(${args.join(", ")}) {\n\n`);
757
+ }
758
+
759
+ if (needStrict) {
760
+ factorySource.add('"use strict";\n');
761
+ }
762
+ factorySource.add(moduleSourcePostContent);
763
+ factorySource.add(`\n\n/***/ }${renderShorthand ? "" : ")"}`);
764
+ source = new CachedSource(factorySource);
765
+ this._moduleFactoryCache.set(moduleSourcePostContent, {
766
+ source,
767
+ needModule,
768
+ needExports,
769
+ needRequire,
770
+ needThisAsExports,
771
+ needStrict,
772
+ renderShorthand
773
+ });
774
+ }
775
+ moduleSourcePostContainer = tryRunOrWebpackError(
776
+ () => hooks.renderModuleContainer.call(source, module, renderContext),
777
+ "JavascriptModulesPlugin.getCompilationHooks().renderModuleContainer"
778
+ );
779
+ } else {
780
+ moduleSourcePostContainer = moduleSourcePostContent;
781
+ }
782
+ return tryRunOrWebpackError(
783
+ () =>
784
+ hooks.renderModulePackage.call(
785
+ moduleSourcePostContainer,
786
+ module,
787
+ renderContext
788
+ ),
789
+ "JavascriptModulesPlugin.getCompilationHooks().renderModulePackage"
790
+ );
791
+ } catch (err) {
792
+ /** @type {WebpackError} */
793
+ (err).module = module;
794
+ throw err;
795
+ }
796
+ }
797
+
798
+ /**
799
+ * @param {RenderContext} renderContext the render context
800
+ * @param {CompilationHooks} hooks hooks
801
+ * @returns {Source} the rendered source
802
+ */
803
+ renderChunk(renderContext, hooks) {
804
+ const { chunk, chunkGraph, runtimeTemplate } = renderContext;
805
+ const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
806
+ chunk,
807
+ JAVASCRIPT_TYPE,
808
+ compareModulesByFullName(runtimeTemplate.compilation.compiler)
809
+ );
810
+ const allModules = modules ? [...modules] : [];
811
+ /** @type {undefined | string} */
812
+ let strictHeader;
813
+ let allStrict = renderContext.strictMode;
814
+ if (
815
+ !allStrict &&
816
+ allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict)
817
+ ) {
818
+ const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
819
+ strictHeader = strictBailout
820
+ ? `// runtime can't be in strict mode because ${strictBailout}.\n`
821
+ : '"use strict";\n';
822
+ if (!strictBailout) allStrict = true;
823
+ }
824
+ /** @type {ChunkRenderContext} */
825
+ const chunkRenderContext = {
826
+ ...renderContext,
827
+ chunkInitFragments: [],
828
+ strictMode: allStrict
829
+ };
830
+ const moduleSources =
831
+ Template.renderChunkModules(
832
+ chunkRenderContext,
833
+ allModules,
834
+ (module, renderInObject) =>
835
+ this.renderModule(
836
+ module,
837
+ { ...chunkRenderContext, factory: true, renderInObject },
838
+ hooks
839
+ )
840
+ ) || new RawSource("{}");
841
+ let source = tryRunOrWebpackError(
842
+ () => hooks.renderChunk.call(moduleSources, chunkRenderContext),
843
+ "JavascriptModulesPlugin.getCompilationHooks().renderChunk"
844
+ );
845
+ source = tryRunOrWebpackError(
846
+ () => hooks.renderContent.call(source, chunkRenderContext),
847
+ "JavascriptModulesPlugin.getCompilationHooks().renderContent"
848
+ );
849
+ if (!source) {
850
+ throw new Error(
851
+ "JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().renderContent plugins should return something"
852
+ );
853
+ }
854
+ source = InitFragment.addToSource(
855
+ source,
856
+ chunkRenderContext.chunkInitFragments,
857
+ chunkRenderContext
858
+ );
859
+ source = tryRunOrWebpackError(
860
+ () => hooks.render.call(source, chunkRenderContext),
861
+ "JavascriptModulesPlugin.getCompilationHooks().render"
862
+ );
863
+ if (!source) {
864
+ throw new Error(
865
+ "JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().render plugins should return something"
866
+ );
867
+ }
868
+ chunk.rendered = true;
869
+ return strictHeader
870
+ ? new ConcatSource(strictHeader, source, ";")
871
+ : renderContext.runtimeTemplate.isModule()
872
+ ? source
873
+ : new ConcatSource(source, ";");
874
+ }
875
+
876
+ /**
877
+ * @param {MainRenderContext} renderContext options object
878
+ * @param {CompilationHooks} hooks hooks
879
+ * @param {Compilation} compilation the compilation
880
+ * @returns {Source} the newly generated source from rendering
881
+ */
882
+ renderMain(renderContext, hooks, compilation) {
883
+ const { chunk, chunkGraph, runtimeTemplate } = renderContext;
884
+
885
+ const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
886
+ const iife = runtimeTemplate.isIIFE();
887
+
888
+ const bootstrap = this.renderBootstrap(renderContext, hooks);
889
+ const useSourceMap = hooks.useSourceMap.call(chunk, renderContext);
890
+
891
+ /** @type {Module[]} */
892
+ const allModules = [
893
+ ...(chunkGraph.getOrderedChunkModulesIterableBySourceType(
894
+ chunk,
895
+ JAVASCRIPT_TYPE,
896
+ compareModulesByFullName(runtimeTemplate.compilation.compiler)
897
+ ) || [])
898
+ ];
899
+
900
+ const hasEntryModules = chunkGraph.getNumberOfEntryModules(chunk) > 0;
901
+ /** @type {Set<Module> | undefined} */
902
+ let inlinedModules;
903
+ if (bootstrap.allowInlineStartup && hasEntryModules) {
904
+ inlinedModules = new Set(chunkGraph.getChunkEntryModulesIterable(chunk));
905
+ }
906
+
907
+ const source = new ConcatSource();
908
+ /** @type {string} */
909
+ let prefix;
910
+ if (iife) {
911
+ if (runtimeTemplate.supportsArrowFunction()) {
912
+ source.add("/******/ (() => { // webpackBootstrap\n");
913
+ } else {
914
+ source.add("/******/ (function() { // webpackBootstrap\n");
915
+ }
916
+ prefix = "/******/ \t";
917
+ } else {
918
+ prefix = "/******/ ";
919
+ }
920
+ let allStrict = renderContext.strictMode;
921
+ if (
922
+ !allStrict &&
923
+ allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict)
924
+ ) {
925
+ const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
926
+ if (strictBailout) {
927
+ source.add(
928
+ `${
929
+ prefix
930
+ }// runtime can't be in strict mode because ${strictBailout}.\n`
931
+ );
932
+ } else {
933
+ allStrict = true;
934
+ source.add(`${prefix}"use strict";\n`);
935
+ }
936
+ }
937
+
938
+ /** @type {ChunkRenderContext} */
939
+ const chunkRenderContext = {
940
+ ...renderContext,
941
+ chunkInitFragments: [],
942
+ strictMode: allStrict
943
+ };
944
+
945
+ const chunkModules = Template.renderChunkModules(
946
+ chunkRenderContext,
947
+ inlinedModules
948
+ ? allModules.filter(
949
+ (m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
950
+ )
951
+ : allModules,
952
+ (module, renderInObject) =>
953
+ this.renderModule(
954
+ module,
955
+ { ...chunkRenderContext, factory: true, renderInObject },
956
+ hooks
957
+ ),
958
+ prefix
959
+ );
960
+ if (
961
+ chunkModules ||
962
+ runtimeRequirements.has(RuntimeGlobals.moduleFactories) ||
963
+ runtimeRequirements.has(RuntimeGlobals.moduleFactoriesAddOnly) ||
964
+ runtimeRequirements.has(RuntimeGlobals.require)
965
+ ) {
966
+ source.add(`${prefix}var __webpack_modules__ = (`);
967
+ source.add(chunkModules || "{}");
968
+ source.add(");\n");
969
+ source.add(
970
+ "/************************************************************************/\n"
971
+ );
972
+ }
973
+
974
+ if (bootstrap.header.length > 0) {
975
+ const header = `${Template.asString(bootstrap.header)}\n`;
976
+ source.add(
977
+ new PrefixSource(
978
+ prefix,
979
+ useSourceMap
980
+ ? new OriginalSource(header, "webpack/bootstrap")
981
+ : new RawSource(header)
982
+ )
983
+ );
984
+ source.add(
985
+ "/************************************************************************/\n"
986
+ );
987
+ }
988
+
989
+ const runtimeModules =
990
+ renderContext.chunkGraph.getChunkRuntimeModulesInOrder(chunk);
991
+
992
+ if (runtimeModules.length > 0) {
993
+ source.add(
994
+ new PrefixSource(
995
+ prefix,
996
+ Template.renderRuntimeModules(runtimeModules, chunkRenderContext)
997
+ )
998
+ );
999
+ source.add(
1000
+ "/************************************************************************/\n"
1001
+ );
1002
+ // runtimeRuntimeModules calls codeGeneration
1003
+ for (const module of runtimeModules) {
1004
+ compilation.codeGeneratedModules.add(module);
1005
+ }
1006
+ }
1007
+ if (inlinedModules) {
1008
+ if (bootstrap.beforeStartup.length > 0) {
1009
+ const beforeStartup = `${Template.asString(bootstrap.beforeStartup)}\n`;
1010
+ source.add(
1011
+ new PrefixSource(
1012
+ prefix,
1013
+ useSourceMap
1014
+ ? new OriginalSource(beforeStartup, "webpack/before-startup")
1015
+ : new RawSource(beforeStartup)
1016
+ )
1017
+ );
1018
+ }
1019
+ const lastInlinedModule = /** @type {Module} */ (last(inlinedModules));
1020
+ const startupSource = new ConcatSource();
1021
+
1022
+ if (runtimeRequirements.has(RuntimeGlobals.exports)) {
1023
+ startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
1024
+ }
1025
+
1026
+ const avoidEntryIife = compilation.options.optimization.avoidEntryIife;
1027
+ /** @type {Map<Module, Source> | false} */
1028
+ let renamedInlinedModule = false;
1029
+ let inlinedInIIFE = false;
1030
+
1031
+ if (avoidEntryIife) {
1032
+ renamedInlinedModule = this._getRenamedInlineModule(
1033
+ compilation,
1034
+ allModules,
1035
+ renderContext,
1036
+ inlinedModules,
1037
+ chunkRenderContext,
1038
+ hooks,
1039
+ allStrict,
1040
+ Boolean(chunkModules)
1041
+ );
1042
+ }
1043
+
1044
+ for (const m of inlinedModules) {
1045
+ const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
1046
+ m,
1047
+ chunk.runtime
1048
+ );
1049
+ const exports = runtimeRequirements.has(RuntimeGlobals.exports);
1050
+ const webpackExports =
1051
+ exports && m.exportsArgument === RuntimeGlobals.exports;
1052
+
1053
+ const innerStrict =
1054
+ !allStrict && /** @type {BuildInfo} */ (m.buildInfo).strict;
1055
+
1056
+ const iife = innerStrict
1057
+ ? "it needs to be in strict mode."
1058
+ : inlinedModules.size > 1
1059
+ ? // TODO check globals and top-level declarations of other entries and chunk modules
1060
+ // to make a better decision
1061
+ "it needs to be isolated against other entry modules."
1062
+ : chunkModules && !renamedInlinedModule
1063
+ ? "it needs to be isolated against other modules in the chunk."
1064
+ : exports && !webpackExports
1065
+ ? `it uses a non-standard name for the exports (${m.exportsArgument}).`
1066
+ : hooks.embedInRuntimeBailout.call(m, renderContext);
1067
+
1068
+ if (iife) {
1069
+ inlinedInIIFE = true;
1070
+ }
1071
+
1072
+ const renderedModule = renamedInlinedModule
1073
+ ? renamedInlinedModule.get(m)
1074
+ : this.renderModule(
1075
+ m,
1076
+ {
1077
+ ...chunkRenderContext,
1078
+ factory: false,
1079
+ inlinedInIIFE
1080
+ },
1081
+ hooks
1082
+ );
1083
+
1084
+ if (renderedModule) {
1085
+ /** @type {string} */
1086
+ let footer;
1087
+ if (iife !== undefined) {
1088
+ startupSource.add(
1089
+ `// This entry needs to be wrapped in an IIFE because ${iife}\n`
1090
+ );
1091
+ const arrow = runtimeTemplate.supportsArrowFunction();
1092
+ if (arrow) {
1093
+ startupSource.add("(() => {\n");
1094
+ footer = "\n})();\n\n";
1095
+ } else {
1096
+ startupSource.add("!function() {\n");
1097
+ footer = "\n}();\n";
1098
+ }
1099
+ if (innerStrict) startupSource.add('"use strict";\n');
1100
+ } else {
1101
+ footer = "\n";
1102
+ }
1103
+ if (exports) {
1104
+ if (m !== lastInlinedModule) {
1105
+ startupSource.add(`var ${m.exportsArgument} = {};\n`);
1106
+ } else if (m.exportsArgument !== RuntimeGlobals.exports) {
1107
+ startupSource.add(
1108
+ `var ${m.exportsArgument} = ${RuntimeGlobals.exports};\n`
1109
+ );
1110
+ }
1111
+ }
1112
+ startupSource.add(renderedModule);
1113
+ startupSource.add(footer);
1114
+ }
1115
+ }
1116
+ if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
1117
+ startupSource.add(
1118
+ `${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});\n`
1119
+ );
1120
+ }
1121
+ source.add(
1122
+ hooks.renderStartup.call(startupSource, lastInlinedModule, {
1123
+ ...renderContext,
1124
+ inlined: true,
1125
+ inlinedInIIFE
1126
+ })
1127
+ );
1128
+ if (bootstrap.afterStartup.length > 0) {
1129
+ const afterStartup = `${Template.asString(bootstrap.afterStartup)}\n`;
1130
+ source.add(
1131
+ new PrefixSource(
1132
+ prefix,
1133
+ useSourceMap
1134
+ ? new OriginalSource(afterStartup, "webpack/after-startup")
1135
+ : new RawSource(afterStartup)
1136
+ )
1137
+ );
1138
+ }
1139
+ } else {
1140
+ const lastEntryModule =
1141
+ /** @type {Module} */
1142
+ (last(chunkGraph.getChunkEntryModulesIterable(chunk)));
1143
+ /** @type {(content: string[], name: string) => Source} */
1144
+ const toSource = useSourceMap
1145
+ ? (content, name) =>
1146
+ new OriginalSource(Template.asString(content), name)
1147
+ : (content) => new RawSource(Template.asString(content));
1148
+ source.add(
1149
+ new PrefixSource(
1150
+ prefix,
1151
+ new ConcatSource(
1152
+ toSource(bootstrap.beforeStartup, "webpack/before-startup"),
1153
+ "\n",
1154
+ hooks.renderStartup.call(
1155
+ toSource([...bootstrap.startup, ""], "webpack/startup"),
1156
+ lastEntryModule,
1157
+ {
1158
+ ...renderContext,
1159
+ inlined: false
1160
+ }
1161
+ ),
1162
+ toSource(bootstrap.afterStartup, "webpack/after-startup"),
1163
+ "\n"
1164
+ )
1165
+ )
1166
+ );
1167
+ }
1168
+ if (
1169
+ hasEntryModules &&
1170
+ runtimeRequirements.has(RuntimeGlobals.returnExportsFromRuntime)
1171
+ ) {
1172
+ source.add(`${prefix}return ${RuntimeGlobals.exports};\n`);
1173
+ }
1174
+ if (iife) {
1175
+ source.add("/******/ })()\n");
1176
+ }
1177
+
1178
+ /** @type {Source} */
1179
+ let finalSource = tryRunOrWebpackError(
1180
+ () => hooks.renderMain.call(source, renderContext),
1181
+ "JavascriptModulesPlugin.getCompilationHooks().renderMain"
1182
+ );
1183
+ if (!finalSource) {
1184
+ throw new Error(
1185
+ "JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().renderMain plugins should return something"
1186
+ );
1187
+ }
1188
+ finalSource = tryRunOrWebpackError(
1189
+ () => hooks.renderContent.call(finalSource, renderContext),
1190
+ "JavascriptModulesPlugin.getCompilationHooks().renderContent"
1191
+ );
1192
+ if (!finalSource) {
1193
+ throw new Error(
1194
+ "JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().renderContent plugins should return something"
1195
+ );
1196
+ }
1197
+
1198
+ finalSource = InitFragment.addToSource(
1199
+ finalSource,
1200
+ chunkRenderContext.chunkInitFragments,
1201
+ chunkRenderContext
1202
+ );
1203
+ finalSource = tryRunOrWebpackError(
1204
+ () => hooks.render.call(finalSource, renderContext),
1205
+ "JavascriptModulesPlugin.getCompilationHooks().render"
1206
+ );
1207
+ if (!finalSource) {
1208
+ throw new Error(
1209
+ "JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().render plugins should return something"
1210
+ );
1211
+ }
1212
+ chunk.rendered = true;
1213
+ return iife ? new ConcatSource(finalSource, ";") : finalSource;
1214
+ }
1215
+
1216
+ /**
1217
+ * @param {Hash} hash the hash to be updated
1218
+ * @param {RenderBootstrapContext} renderContext options object
1219
+ * @param {CompilationHooks} hooks hooks
1220
+ */
1221
+ updateHashWithBootstrap(hash, renderContext, hooks) {
1222
+ const bootstrap = this.renderBootstrap(renderContext, hooks);
1223
+ for (const _k of Object.keys(bootstrap)) {
1224
+ const key = /** @type {keyof Bootstrap} */ (_k);
1225
+ hash.update(key);
1226
+ if (Array.isArray(bootstrap[key])) {
1227
+ for (const line of bootstrap[key]) {
1228
+ hash.update(line);
1229
+ }
1230
+ } else {
1231
+ hash.update(JSON.stringify(bootstrap[key]));
1232
+ }
1233
+ }
1234
+ }
1235
+
1236
+ /**
1237
+ * @param {RenderBootstrapContext} renderContext options object
1238
+ * @param {CompilationHooks} hooks hooks
1239
+ * @returns {Bootstrap} the generated source of the bootstrap code
1240
+ */
1241
+ renderBootstrap(renderContext, hooks) {
1242
+ const {
1243
+ chunkGraph,
1244
+ codeGenerationResults,
1245
+ moduleGraph,
1246
+ chunk,
1247
+ runtimeTemplate
1248
+ } = renderContext;
1249
+
1250
+ const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
1251
+
1252
+ const requireFunction = runtimeRequirements.has(RuntimeGlobals.require);
1253
+ const moduleCache = runtimeRequirements.has(RuntimeGlobals.moduleCache);
1254
+ const moduleFactories = runtimeRequirements.has(
1255
+ RuntimeGlobals.moduleFactories
1256
+ );
1257
+ const moduleUsed = runtimeRequirements.has(RuntimeGlobals.module);
1258
+ const requireScopeUsed = runtimeRequirements.has(
1259
+ RuntimeGlobals.requireScope
1260
+ );
1261
+ const interceptModuleExecution = runtimeRequirements.has(
1262
+ RuntimeGlobals.interceptModuleExecution
1263
+ );
1264
+
1265
+ const useRequire =
1266
+ requireFunction || interceptModuleExecution || moduleUsed;
1267
+
1268
+ /**
1269
+ * @type {{ startup: string[], beforeStartup: string[], header: string[], afterStartup: string[], allowInlineStartup: boolean }}
1270
+ */
1271
+ const result = {
1272
+ header: [],
1273
+ beforeStartup: [],
1274
+ startup: [],
1275
+ afterStartup: [],
1276
+ allowInlineStartup: true
1277
+ };
1278
+
1279
+ const { header: buf, startup, beforeStartup, afterStartup } = result;
1280
+
1281
+ if (result.allowInlineStartup && moduleFactories) {
1282
+ startup.push(
1283
+ "// module factories are used so entry inlining is disabled"
1284
+ );
1285
+ result.allowInlineStartup = false;
1286
+ }
1287
+ if (result.allowInlineStartup && moduleCache) {
1288
+ startup.push("// module cache are used so entry inlining is disabled");
1289
+ result.allowInlineStartup = false;
1290
+ }
1291
+ if (result.allowInlineStartup && interceptModuleExecution) {
1292
+ startup.push(
1293
+ "// module execution is intercepted so entry inlining is disabled"
1294
+ );
1295
+ result.allowInlineStartup = false;
1296
+ }
1297
+
1298
+ if (useRequire || moduleCache) {
1299
+ buf.push("// The module cache");
1300
+ buf.push("var __webpack_module_cache__ = {};");
1301
+ buf.push("");
1302
+ }
1303
+
1304
+ if (runtimeRequirements.has(RuntimeGlobals.makeDeferredNamespaceObject)) {
1305
+ // in order to optimize of DeferredNamespaceObject, we remove all proxy handlers after the module initialize
1306
+ // (see MakeDeferredNamespaceObjectRuntimeModule)
1307
+ // This requires all deferred imports to a module can get the module export object before the module
1308
+ // is evaluated.
1309
+ buf.push("// The deferred module cache");
1310
+ buf.push("var __webpack_module_deferred_exports__ = {};");
1311
+ buf.push("");
1312
+ }
1313
+
1314
+ if (useRequire) {
1315
+ buf.push("// The require function");
1316
+ buf.push(`function ${RuntimeGlobals.require}(moduleId) {`);
1317
+ buf.push(Template.indent(this.renderRequire(renderContext, hooks)));
1318
+ buf.push("}");
1319
+ buf.push("");
1320
+ } else if (runtimeRequirements.has(RuntimeGlobals.requireScope)) {
1321
+ buf.push("// The require scope");
1322
+ buf.push(`var ${RuntimeGlobals.require} = {};`);
1323
+ buf.push("");
1324
+ }
1325
+
1326
+ if (
1327
+ moduleFactories ||
1328
+ runtimeRequirements.has(RuntimeGlobals.moduleFactoriesAddOnly)
1329
+ ) {
1330
+ buf.push("// expose the modules object (__webpack_modules__)");
1331
+ buf.push(`${RuntimeGlobals.moduleFactories} = __webpack_modules__;`);
1332
+ buf.push("");
1333
+ }
1334
+
1335
+ if (moduleCache) {
1336
+ buf.push("// expose the module cache");
1337
+ buf.push(`${RuntimeGlobals.moduleCache} = __webpack_module_cache__;`);
1338
+ buf.push("");
1339
+ }
1340
+
1341
+ if (interceptModuleExecution) {
1342
+ buf.push("// expose the module execution interceptor");
1343
+ buf.push(`${RuntimeGlobals.interceptModuleExecution} = [];`);
1344
+ buf.push("");
1345
+ }
1346
+
1347
+ if (!runtimeRequirements.has(RuntimeGlobals.startupNoDefault)) {
1348
+ if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
1349
+ /** @type {string[]} */
1350
+ const buf2 = [];
1351
+ const runtimeRequirements =
1352
+ chunkGraph.getTreeRuntimeRequirements(chunk);
1353
+ buf2.push("// Load entry module and return exports");
1354
+
1355
+ /** @type {EntryModuleWithChunkGroup[]} */
1356
+ const jsEntries = [];
1357
+ for (const [
1358
+ entryModule,
1359
+ entrypoint
1360
+ ] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) {
1361
+ if (
1362
+ chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE)
1363
+ ) {
1364
+ jsEntries.push([entryModule, entrypoint]);
1365
+ continue;
1366
+ }
1367
+ }
1368
+ let i = jsEntries.length;
1369
+ for (const [entryModule, entrypoint] of jsEntries) {
1370
+ const chunks =
1371
+ /** @type {Entrypoint} */
1372
+ (entrypoint).chunks.filter((c) => c !== chunk);
1373
+ if (result.allowInlineStartup && chunks.length > 0) {
1374
+ buf2.push(
1375
+ "// This entry module depends on other loaded chunks and execution need to be delayed"
1376
+ );
1377
+ result.allowInlineStartup = false;
1378
+ }
1379
+ if (
1380
+ result.allowInlineStartup &&
1381
+ someInIterable(
1382
+ moduleGraph.getIncomingConnectionsByOriginModule(entryModule),
1383
+ ([originModule, connections]) =>
1384
+ originModule &&
1385
+ connections.some((c) => c.isTargetActive(chunk.runtime)) &&
1386
+ someInIterable(
1387
+ chunkGraph.getModuleRuntimes(originModule),
1388
+ (runtime) =>
1389
+ intersectRuntime(runtime, chunk.runtime) !== undefined
1390
+ )
1391
+ )
1392
+ ) {
1393
+ buf2.push(
1394
+ "// This entry module is referenced by other modules so it can't be inlined"
1395
+ );
1396
+ result.allowInlineStartup = false;
1397
+ }
1398
+
1399
+ /** @type {undefined | CodeGenerationResultData} */
1400
+ let data;
1401
+ if (codeGenerationResults.has(entryModule, chunk.runtime)) {
1402
+ const result = codeGenerationResults.get(
1403
+ entryModule,
1404
+ chunk.runtime
1405
+ );
1406
+ data = result.data;
1407
+ }
1408
+ if (
1409
+ result.allowInlineStartup &&
1410
+ (!data || !data.get("topLevelDeclarations")) &&
1411
+ (!entryModule.buildInfo ||
1412
+ !entryModule.buildInfo.topLevelDeclarations)
1413
+ ) {
1414
+ buf2.push(
1415
+ "// This entry module doesn't tell about it's top-level declarations so it can't be inlined"
1416
+ );
1417
+ result.allowInlineStartup = false;
1418
+ }
1419
+ if (result.allowInlineStartup) {
1420
+ const bailout = hooks.inlineInRuntimeBailout.call(
1421
+ entryModule,
1422
+ renderContext
1423
+ );
1424
+ if (bailout !== undefined) {
1425
+ buf2.push(
1426
+ `// This entry module can't be inlined because ${bailout}`
1427
+ );
1428
+ result.allowInlineStartup = false;
1429
+ }
1430
+ }
1431
+ i--;
1432
+ const moduleId = chunkGraph.getModuleId(entryModule);
1433
+ const entryRuntimeRequirements =
1434
+ chunkGraph.getModuleRuntimeRequirements(entryModule, chunk.runtime);
1435
+ let moduleIdExpr = JSON.stringify(moduleId);
1436
+ if (runtimeRequirements.has(RuntimeGlobals.entryModuleId)) {
1437
+ moduleIdExpr = `${RuntimeGlobals.entryModuleId} = ${moduleIdExpr}`;
1438
+ }
1439
+ if (
1440
+ result.allowInlineStartup &&
1441
+ entryRuntimeRequirements.has(RuntimeGlobals.module)
1442
+ ) {
1443
+ result.allowInlineStartup = false;
1444
+ buf2.push(
1445
+ "// This entry module used 'module' so it can't be inlined"
1446
+ );
1447
+ }
1448
+ if (
1449
+ result.allowInlineStartup &&
1450
+ entryRuntimeRequirements.has(RuntimeGlobals.thisAsExports)
1451
+ ) {
1452
+ buf2.push(
1453
+ "// This entry module used `this` as exports so it can't be inlined"
1454
+ );
1455
+ result.allowInlineStartup = false;
1456
+ }
1457
+
1458
+ if (chunks.length > 0) {
1459
+ buf2.push(
1460
+ `${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1461
+ RuntimeGlobals.onChunksLoaded
1462
+ }(undefined, ${JSON.stringify(
1463
+ chunks.map((c) => c.id)
1464
+ )}, ${runtimeTemplate.returningFunction(
1465
+ `${RuntimeGlobals.require}(${moduleIdExpr})`
1466
+ )})`
1467
+ );
1468
+ } else if (useRequire) {
1469
+ buf2.push(
1470
+ `${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1471
+ RuntimeGlobals.require
1472
+ }(${moduleIdExpr});`
1473
+ );
1474
+ } else {
1475
+ if (i === 0) buf2.push(`var ${RuntimeGlobals.exports} = {};`);
1476
+ const needThisAsExports = entryRuntimeRequirements.has(
1477
+ RuntimeGlobals.thisAsExports
1478
+ );
1479
+
1480
+ /** @type {string[]} */
1481
+ const args = [];
1482
+ if (
1483
+ requireScopeUsed ||
1484
+ entryRuntimeRequirements.has(RuntimeGlobals.exports)
1485
+ ) {
1486
+ const exportsArg = i === 0 ? RuntimeGlobals.exports : "{}";
1487
+ args.push("0", exportsArg);
1488
+ if (requireScopeUsed) {
1489
+ args.push(RuntimeGlobals.require);
1490
+ }
1491
+ }
1492
+ buf2.push(
1493
+ Template.asString(
1494
+ (() => {
1495
+ if (needThisAsExports) {
1496
+ const comma = args.length ? "," : "";
1497
+ return `__webpack_modules__[${moduleIdExpr}].call(${RuntimeGlobals.exports}${comma}${args.join(",")});`;
1498
+ }
1499
+ return `__webpack_modules__[${moduleIdExpr}](${args.join(",")});`;
1500
+ })()
1501
+ )
1502
+ );
1503
+ }
1504
+ }
1505
+ if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
1506
+ buf2.push(
1507
+ `${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});`
1508
+ );
1509
+ }
1510
+ if (
1511
+ runtimeRequirements.has(RuntimeGlobals.startup) ||
1512
+ (runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore) &&
1513
+ runtimeRequirements.has(RuntimeGlobals.startupOnlyAfter))
1514
+ ) {
1515
+ result.allowInlineStartup = false;
1516
+ buf.push("// the startup function");
1517
+ buf.push(
1518
+ `${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction("", [
1519
+ ...buf2,
1520
+ `return ${RuntimeGlobals.exports};`
1521
+ ])};`
1522
+ );
1523
+ buf.push("");
1524
+ startup.push("// run startup");
1525
+ startup.push(
1526
+ `var ${RuntimeGlobals.exports} = ${RuntimeGlobals.startup}();`
1527
+ );
1528
+ } else if (runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore)) {
1529
+ buf.push("// the startup function");
1530
+ buf.push(
1531
+ `${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()};`
1532
+ );
1533
+ beforeStartup.push("// run runtime startup");
1534
+ beforeStartup.push(`${RuntimeGlobals.startup}();`);
1535
+ startup.push("// startup");
1536
+ startup.push(Template.asString(buf2));
1537
+ } else if (runtimeRequirements.has(RuntimeGlobals.startupOnlyAfter)) {
1538
+ buf.push("// the startup function");
1539
+ buf.push(
1540
+ `${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()};`
1541
+ );
1542
+ startup.push("// startup");
1543
+ startup.push(Template.asString(buf2));
1544
+ afterStartup.push("// run runtime startup");
1545
+ afterStartup.push(`${RuntimeGlobals.startup}();`);
1546
+ } else {
1547
+ startup.push("// startup");
1548
+ startup.push(Template.asString(buf2));
1549
+ }
1550
+ } else if (
1551
+ runtimeRequirements.has(RuntimeGlobals.startup) ||
1552
+ runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore) ||
1553
+ runtimeRequirements.has(RuntimeGlobals.startupOnlyAfter)
1554
+ ) {
1555
+ buf.push(
1556
+ "// the startup function",
1557
+ "// It's empty as no entry modules are in this chunk",
1558
+ `${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()};`,
1559
+ ""
1560
+ );
1561
+ }
1562
+ } else if (
1563
+ runtimeRequirements.has(RuntimeGlobals.startup) ||
1564
+ runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore) ||
1565
+ runtimeRequirements.has(RuntimeGlobals.startupOnlyAfter)
1566
+ ) {
1567
+ result.allowInlineStartup = false;
1568
+ buf.push(
1569
+ "// the startup function",
1570
+ "// It's empty as some runtime module handles the default behavior",
1571
+ `${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()};`
1572
+ );
1573
+ startup.push("// run startup");
1574
+ startup.push(
1575
+ `var ${RuntimeGlobals.exports} = ${RuntimeGlobals.startup}();`
1576
+ );
1577
+ }
1578
+ return result;
1579
+ }
1580
+
1581
+ /**
1582
+ * @param {RenderBootstrapContext} renderContext options object
1583
+ * @param {CompilationHooks} hooks hooks
1584
+ * @returns {string} the generated source of the require function
1585
+ */
1586
+ renderRequire(renderContext, hooks) {
1587
+ const {
1588
+ chunk,
1589
+ chunkGraph,
1590
+ runtimeTemplate: { outputOptions }
1591
+ } = renderContext;
1592
+ const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
1593
+
1594
+ /**
1595
+ * @param {string} condition guard expression
1596
+ * @returns {string[]} source
1597
+ */
1598
+ const renderMissingModuleError = (condition) =>
1599
+ outputOptions.pathinfo
1600
+ ? [
1601
+ `if (${condition}) {`,
1602
+ Template.indent([
1603
+ "delete __webpack_module_cache__[moduleId];",
1604
+ 'var e = new Error("Cannot find module \'" + moduleId + "\'");',
1605
+ "e.code = 'MODULE_NOT_FOUND';",
1606
+ "throw e;"
1607
+ ]),
1608
+ "}"
1609
+ ]
1610
+ : [];
1611
+
1612
+ const moduleExecution = runtimeRequirements.has(
1613
+ RuntimeGlobals.interceptModuleExecution
1614
+ )
1615
+ ? Template.asString([
1616
+ `var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`,
1617
+ `${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`,
1618
+ ...renderMissingModuleError("!execOptions.factory"),
1619
+ "module = execOptions.module;",
1620
+ "execOptions.factory.call(module.exports, module, module.exports, execOptions.require);"
1621
+ ])
1622
+ : runtimeRequirements.has(RuntimeGlobals.thisAsExports)
1623
+ ? Template.asString([
1624
+ ...renderMissingModuleError("!(moduleId in __webpack_modules__)"),
1625
+ `__webpack_modules__[moduleId].call(module.exports, module, module.exports, ${RuntimeGlobals.require});`
1626
+ ])
1627
+ : Template.asString([
1628
+ ...renderMissingModuleError("!(moduleId in __webpack_modules__)"),
1629
+ `__webpack_modules__[moduleId](module, module.exports, ${RuntimeGlobals.require});`
1630
+ ]);
1631
+ const needModuleId = runtimeRequirements.has(RuntimeGlobals.moduleId);
1632
+ const needModuleLoaded = runtimeRequirements.has(
1633
+ RuntimeGlobals.moduleLoaded
1634
+ );
1635
+ const needModuleDefer = runtimeRequirements.has(
1636
+ RuntimeGlobals.makeDeferredNamespaceObject
1637
+ );
1638
+ const content = Template.asString([
1639
+ "// Check if module is in cache",
1640
+ "var cachedModule = __webpack_module_cache__[moduleId];",
1641
+ "if (cachedModule !== undefined) {",
1642
+ outputOptions.strictModuleErrorHandling
1643
+ ? Template.indent([
1644
+ "if (cachedModule.error !== undefined) throw cachedModule.error;",
1645
+ "return cachedModule.exports;"
1646
+ ])
1647
+ : Template.indent("return cachedModule.exports;"),
1648
+ "}",
1649
+ "// Create a new module (and put it into the cache)",
1650
+ "var module = __webpack_module_cache__[moduleId] = {",
1651
+ Template.indent([
1652
+ needModuleId ? "id: moduleId," : "// no module.id needed",
1653
+ needModuleLoaded ? "loaded: false," : "// no module.loaded needed",
1654
+ needModuleDefer
1655
+ ? "exports: __webpack_module_deferred_exports__[moduleId] || {}"
1656
+ : "exports: {}"
1657
+ ]),
1658
+ "};",
1659
+ "",
1660
+ outputOptions.strictModuleExceptionHandling
1661
+ ? Template.asString([
1662
+ "// Execute the module function",
1663
+ "var threw = true;",
1664
+ "try {",
1665
+ Template.indent([
1666
+ moduleExecution,
1667
+ "threw = false;",
1668
+ ...(needModuleDefer
1669
+ ? ["delete __webpack_module_deferred_exports__[moduleId];"]
1670
+ : [])
1671
+ ]),
1672
+ "} finally {",
1673
+ Template.indent([
1674
+ "if(threw) delete __webpack_module_cache__[moduleId];"
1675
+ ]),
1676
+ "}"
1677
+ ])
1678
+ : outputOptions.strictModuleErrorHandling
1679
+ ? Template.asString([
1680
+ "// Execute the module function",
1681
+ "try {",
1682
+ Template.indent(
1683
+ needModuleDefer
1684
+ ? [
1685
+ moduleExecution,
1686
+ "delete __webpack_module_deferred_exports__[moduleId];"
1687
+ ]
1688
+ : moduleExecution
1689
+ ),
1690
+ "} catch(e) {",
1691
+ Template.indent(["module.error = e;", "throw e;"]),
1692
+ "}"
1693
+ ])
1694
+ : Template.asString([
1695
+ "// Execute the module function",
1696
+ moduleExecution,
1697
+ ...(needModuleDefer
1698
+ ? ["delete __webpack_module_deferred_exports__[moduleId];"]
1699
+ : [])
1700
+ ]),
1701
+ needModuleLoaded
1702
+ ? Template.asString([
1703
+ "",
1704
+ "// Flag the module as loaded",
1705
+ `${RuntimeGlobals.moduleLoaded} = true;`,
1706
+ ""
1707
+ ])
1708
+ : "",
1709
+ "// Return the exports of the module",
1710
+ "return module.exports;"
1711
+ ]);
1712
+ return tryRunOrWebpackError(
1713
+ () => hooks.renderRequire.call(content, renderContext),
1714
+ "JavascriptModulesPlugin.getCompilationHooks().renderRequire"
1715
+ );
1716
+ }
1717
+
1718
+ /**
1719
+ * @param {Compilation} compilation compilation
1720
+ * @param {Module[]} allModules allModules
1721
+ * @param {MainRenderContext} renderContext renderContext
1722
+ * @param {Set<Module>} inlinedModules inlinedModules
1723
+ * @param {ChunkRenderContext} chunkRenderContext chunkRenderContext
1724
+ * @param {CompilationHooks} hooks hooks
1725
+ * @param {boolean | undefined} allStrict allStrict
1726
+ * @param {boolean} hasChunkModules hasChunkModules
1727
+ * @returns {Map<Module, Source> | false} renamed inlined modules
1728
+ */
1729
+ _getRenamedInlineModule(
1730
+ compilation,
1731
+ allModules,
1732
+ renderContext,
1733
+ inlinedModules,
1734
+ chunkRenderContext,
1735
+ hooks,
1736
+ allStrict,
1737
+ hasChunkModules
1738
+ ) {
1739
+ const innerStrict =
1740
+ !allStrict &&
1741
+ allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict);
1742
+ const isMultipleEntries = inlinedModules.size > 1;
1743
+ const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
1744
+ // TODO:
1745
+ // This step is before the IIFE reason calculation. Ideally, it should only be executed when this function can optimize the
1746
+ // IIFE reason. Otherwise, it should directly return false. There are four reasons now, we have skipped two already, the left
1747
+ // one is 'it uses a non-standard name for the exports'.
1748
+ if (isMultipleEntries || innerStrict || !singleEntryWithModules) {
1749
+ return false;
1750
+ }
1751
+
1752
+ /** @type {Map<Module, Source>} */
1753
+ const renamedInlinedModules = new Map();
1754
+ const { runtimeTemplate } = renderContext;
1755
+
1756
+ /** @typedef {{ source: Source, module: Module, ast: Program, variables: Set<Variable>, through: Set<Reference>, usedInNonInlined: Set<Variable>, moduleScope: Scope }} Info */
1757
+ /** @type {Map<Module, Info>} */
1758
+ const inlinedModulesToInfo = new Map();
1759
+ /** @type {Set<string>} */
1760
+ const nonInlinedModuleThroughIdentifiers = new Set();
1761
+
1762
+ for (const m of allModules) {
1763
+ const isInlinedModule = inlinedModules && inlinedModules.has(m);
1764
+ const moduleSource = this.renderModule(
1765
+ m,
1766
+ {
1767
+ ...chunkRenderContext,
1768
+ factory: !isInlinedModule,
1769
+ inlinedInIIFE: false
1770
+ },
1771
+ hooks
1772
+ );
1773
+
1774
+ if (!moduleSource) continue;
1775
+ const code = /** @type {string} */ (moduleSource.source());
1776
+
1777
+ const { ast } = JavascriptParser._parse(
1778
+ code,
1779
+ {
1780
+ sourceType: "auto",
1781
+ ranges: true
1782
+ },
1783
+ JavascriptParser._getModuleParseFunction(compilation, m)
1784
+ );
1785
+
1786
+ const scopeManager = eslintScope.analyze(ast, {
1787
+ ecmaVersion: 6,
1788
+ sourceType: "module",
1789
+ optimistic: true,
1790
+ ignoreEval: true
1791
+ });
1792
+
1793
+ const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
1794
+ if (inlinedModules && inlinedModules.has(m)) {
1795
+ const moduleScope = globalScope.childScopes[0];
1796
+ inlinedModulesToInfo.set(m, {
1797
+ source: moduleSource,
1798
+ ast,
1799
+ module: m,
1800
+ variables: new Set(moduleScope.variables),
1801
+ through: new Set(moduleScope.through),
1802
+ usedInNonInlined: new Set(),
1803
+ moduleScope
1804
+ });
1805
+ } else {
1806
+ for (const ref of globalScope.through) {
1807
+ nonInlinedModuleThroughIdentifiers.add(ref.identifier.name);
1808
+ }
1809
+ }
1810
+ }
1811
+
1812
+ for (const [, { variables, usedInNonInlined }] of inlinedModulesToInfo) {
1813
+ for (const variable of variables) {
1814
+ if (
1815
+ nonInlinedModuleThroughIdentifiers.has(variable.name) ||
1816
+ RESERVED_NAMES.has(variable.name)
1817
+ ) {
1818
+ usedInNonInlined.add(variable);
1819
+ }
1820
+ }
1821
+ }
1822
+
1823
+ for (const [m, moduleInfo] of inlinedModulesToInfo) {
1824
+ const { ast, source: _source, usedInNonInlined } = moduleInfo;
1825
+ const source = new ReplaceSource(_source);
1826
+ if (usedInNonInlined.size === 0) {
1827
+ renamedInlinedModules.set(m, source);
1828
+ continue;
1829
+ }
1830
+
1831
+ const info = /** @type {Info} */ (inlinedModulesToInfo.get(m));
1832
+ const allUsedNames = new Set(
1833
+ Array.from(info.through, (v) => v.identifier.name)
1834
+ );
1835
+
1836
+ for (const variable of usedInNonInlined) {
1837
+ allUsedNames.add(variable.name);
1838
+ }
1839
+
1840
+ for (const variable of info.variables) {
1841
+ /** @type {UsedNamesInScopeInfo} */
1842
+ const usedNamesInScopeInfo = new Map();
1843
+ /** @type {ScopeSet} */
1844
+ const ignoredScopes = new Set();
1845
+
1846
+ const name = variable.name;
1847
+ const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
1848
+ usedNamesInScopeInfo,
1849
+ info.module.identifier(),
1850
+ name
1851
+ );
1852
+
1853
+ if (allUsedNames.has(name) || usedNames.has(name)) {
1854
+ const references = getAllReferences(variable);
1855
+ const allIdentifiers = new Set([
1856
+ ...references.map((r) => r.identifier),
1857
+ ...variable.identifiers
1858
+ ]);
1859
+ for (const ref of references) {
1860
+ addScopeSymbols(
1861
+ ref.from,
1862
+ usedNames,
1863
+ alreadyCheckedScopes,
1864
+ ignoredScopes
1865
+ );
1866
+ }
1867
+
1868
+ const newName = findNewName(
1869
+ variable.name,
1870
+ allUsedNames,
1871
+ usedNames,
1872
+ m.readableIdentifier(runtimeTemplate.requestShortener)
1873
+ );
1874
+ allUsedNames.add(newName);
1875
+ for (const identifier of allIdentifiers) {
1876
+ const r = /** @type {Range} */ (identifier.range);
1877
+ const path = getPathInAst(ast, identifier);
1878
+ if (path && path.length > 1) {
1879
+ const maybeProperty =
1880
+ path[1].type === "AssignmentPattern" && path[1].left === path[0]
1881
+ ? path[2]
1882
+ : path[1];
1883
+ if (
1884
+ maybeProperty.type === "Property" &&
1885
+ maybeProperty.shorthand
1886
+ ) {
1887
+ source.insert(r[1], `: ${newName}`);
1888
+ continue;
1889
+ }
1890
+ }
1891
+ source.replace(r[0], r[1] - 1, newName);
1892
+ }
1893
+ }
1894
+ allUsedNames.add(name);
1895
+ }
1896
+
1897
+ renamedInlinedModules.set(m, source);
1898
+ }
1899
+
1900
+ return renamedInlinedModules;
1901
+ }
1902
+ }
1903
+
1904
+ module.exports = JavascriptModulesPlugin;
1905
+ module.exports.chunkHasJs = chunkHasJs;