webpack 5.76.1 → 5.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (436) hide show
  1. package/README.md +10 -4
  2. package/bin/webpack.js +26 -2
  3. package/hot/dev-server.js +2 -1
  4. package/hot/lazy-compilation-node.js +10 -0
  5. package/hot/lazy-compilation-web.js +9 -0
  6. package/hot/log-apply-result.js +5 -0
  7. package/hot/log.js +22 -0
  8. package/hot/only-dev-server.js +2 -1
  9. package/hot/poll.js +3 -0
  10. package/hot/signal.js +4 -0
  11. package/lib/APIPlugin.js +174 -116
  12. package/lib/AsyncDependenciesBlock.js +13 -5
  13. package/lib/AutomaticPrefetchPlugin.js +1 -0
  14. package/lib/BannerPlugin.js +4 -0
  15. package/lib/CacheFacade.js +4 -0
  16. package/lib/CaseSensitiveModulesWarning.js +3 -1
  17. package/lib/Chunk.js +36 -18
  18. package/lib/ChunkGraph.js +4 -4
  19. package/lib/ChunkGroup.js +25 -10
  20. package/lib/CleanPlugin.js +30 -7
  21. package/lib/CodeGenerationResults.js +2 -2
  22. package/lib/CompatibilityPlugin.js +85 -46
  23. package/lib/Compilation.js +17 -8
  24. package/lib/Compiler.js +12 -8
  25. package/lib/ConcatenationScope.js +2 -2
  26. package/lib/ConditionalInitFragment.js +11 -1
  27. package/lib/ConstPlugin.js +79 -44
  28. package/lib/ContextModule.js +20 -6
  29. package/lib/ContextModuleFactory.js +2 -1
  30. package/lib/ContextReplacementPlugin.js +13 -0
  31. package/lib/CssModule.js +169 -0
  32. package/lib/DefinePlugin.js +152 -86
  33. package/lib/DelegatedModule.js +22 -4
  34. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  35. package/lib/DependenciesBlock.js +17 -1
  36. package/lib/Dependency.js +19 -5
  37. package/lib/DllEntryPlugin.js +16 -1
  38. package/lib/DllModule.js +17 -2
  39. package/lib/DllModuleFactory.js +1 -1
  40. package/lib/DllReferencePlugin.js +13 -1
  41. package/lib/Entrypoint.js +1 -1
  42. package/lib/ErrorHelpers.js +62 -22
  43. package/lib/EvalSourceMapDevToolPlugin.js +9 -2
  44. package/lib/ExportsInfo.js +20 -3
  45. package/lib/ExportsInfoApiPlugin.js +30 -14
  46. package/lib/ExternalModule.js +30 -9
  47. package/lib/FileSystemInfo.js +9 -1
  48. package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
  49. package/lib/FlagDependencyExportsPlugin.js +336 -348
  50. package/lib/FlagDependencyUsagePlugin.js +9 -9
  51. package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
  52. package/lib/HookWebpackError.js +1 -1
  53. package/lib/HotModuleReplacementPlugin.js +60 -46
  54. package/lib/IgnoreErrorModuleFactory.js +1 -1
  55. package/lib/InitFragment.js +28 -5
  56. package/lib/JavascriptMetaInfoPlugin.js +27 -15
  57. package/lib/LibManifestPlugin.js +22 -5
  58. package/lib/LoaderOptionsPlugin.js +12 -2
  59. package/lib/MainTemplate.js +2 -2
  60. package/lib/Module.js +44 -12
  61. package/lib/ModuleBuildError.js +9 -0
  62. package/lib/ModuleDependencyError.js +4 -2
  63. package/lib/ModuleDependencyWarning.js +4 -2
  64. package/lib/ModuleError.js +9 -0
  65. package/lib/ModuleFactory.js +1 -1
  66. package/lib/ModuleFilenameHelpers.js +114 -4
  67. package/lib/ModuleGraph.js +33 -23
  68. package/lib/ModuleGraphConnection.js +19 -6
  69. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  70. package/lib/ModuleNotFoundError.js +5 -2
  71. package/lib/ModuleParseError.js +9 -0
  72. package/lib/ModuleProfile.js +1 -0
  73. package/lib/ModuleRestoreError.js +2 -0
  74. package/lib/ModuleStoreError.js +2 -1
  75. package/lib/ModuleTypeConstants.js +169 -0
  76. package/lib/ModuleWarning.js +9 -0
  77. package/lib/MultiWatching.js +4 -0
  78. package/lib/NodeStuffPlugin.js +65 -35
  79. package/lib/NormalModule.js +12 -2
  80. package/lib/NormalModuleFactory.js +56 -8
  81. package/lib/NormalModuleReplacementPlugin.js +5 -3
  82. package/lib/NullFactory.js +1 -1
  83. package/lib/PrefetchPlugin.js +4 -0
  84. package/lib/ProgressPlugin.js +71 -15
  85. package/lib/ProvidePlugin.js +30 -14
  86. package/lib/RawModule.js +13 -2
  87. package/lib/RecordIdsPlugin.js +4 -4
  88. package/lib/RequireJsStuffPlugin.js +22 -15
  89. package/lib/RuntimeGlobals.js +5 -0
  90. package/lib/RuntimeModule.js +12 -11
  91. package/lib/RuntimePlugin.js +10 -3
  92. package/lib/RuntimeTemplate.js +29 -11
  93. package/lib/SelfModuleFactory.js +12 -0
  94. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  95. package/lib/SourceMapDevToolPlugin.js +47 -11
  96. package/lib/Template.js +5 -3
  97. package/lib/UseStrictPlugin.js +29 -11
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  99. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  100. package/lib/WatchIgnorePlugin.js +4 -0
  101. package/lib/WebpackError.js +14 -5
  102. package/lib/WebpackIsIncludedPlugin.js +22 -13
  103. package/lib/WebpackOptionsApply.js +41 -44
  104. package/lib/WebpackOptionsDefaulter.js +10 -3
  105. package/lib/asset/AssetGenerator.js +24 -9
  106. package/lib/asset/AssetModulesPlugin.js +28 -12
  107. package/lib/asset/AssetParser.js +15 -7
  108. package/lib/asset/AssetSourceParser.js +8 -3
  109. package/lib/asset/RawDataUrlModule.js +15 -4
  110. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  111. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  112. package/lib/cache/IdleFileCachePlugin.js +2 -1
  113. package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
  114. package/lib/cache/PackFileCacheStrategy.js +42 -15
  115. package/lib/cache/ResolverCachePlugin.js +3 -0
  116. package/lib/config/browserslistTargetHandler.js +10 -10
  117. package/lib/config/defaults.js +306 -105
  118. package/lib/config/normalization.js +110 -71
  119. package/lib/config/target.js +37 -10
  120. package/lib/container/ContainerEntryModule.js +11 -1
  121. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  122. package/lib/container/ContainerExposedDependency.js +9 -0
  123. package/lib/container/ContainerPlugin.js +3 -1
  124. package/lib/container/FallbackDependency.js +13 -0
  125. package/lib/container/FallbackItemDependency.js +3 -0
  126. package/lib/container/FallbackModule.js +12 -2
  127. package/lib/container/FallbackModuleFactory.js +1 -1
  128. package/lib/container/RemoteModule.js +11 -1
  129. package/lib/container/RemoteRuntimeModule.js +3 -2
  130. package/lib/container/RemoteToExternalDependency.js +3 -0
  131. package/lib/css/CssExportsGenerator.js +9 -0
  132. package/lib/css/CssGenerator.js +5 -1
  133. package/lib/css/CssLoadingRuntimeModule.js +53 -22
  134. package/lib/css/CssModulesPlugin.js +253 -74
  135. package/lib/css/CssParser.js +697 -282
  136. package/lib/css/walkCssTokens.js +269 -138
  137. package/lib/debug/ProfilingPlugin.js +33 -12
  138. package/lib/dependencies/AMDDefineDependency.js +54 -10
  139. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +13 -2
  140. package/lib/dependencies/AMDPlugin.js +33 -20
  141. package/lib/dependencies/AMDRequireArrayDependency.js +13 -0
  142. package/lib/dependencies/AMDRequireContextDependency.js +15 -0
  143. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  144. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  145. package/lib/dependencies/AMDRequireDependency.js +16 -1
  146. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  147. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  148. package/lib/dependencies/CachedConstDependency.js +14 -0
  149. package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
  150. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
  151. package/lib/dependencies/CommonJsExportsDependency.js +16 -0
  152. package/lib/dependencies/CommonJsExportsParserPlugin.js +77 -5
  153. package/lib/dependencies/CommonJsFullRequireDependency.js +10 -1
  154. package/lib/dependencies/CommonJsImportsParserPlugin.js +174 -63
  155. package/lib/dependencies/CommonJsPlugin.js +51 -26
  156. package/lib/dependencies/CommonJsRequireContextDependency.js +17 -0
  157. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  158. package/lib/dependencies/CommonJsSelfReferenceDependency.js +16 -0
  159. package/lib/dependencies/ConstDependency.js +11 -2
  160. package/lib/dependencies/ContextDependency.js +15 -2
  161. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  162. package/lib/dependencies/ContextElementDependency.js +8 -0
  163. package/lib/dependencies/CreateScriptUrlDependency.js +10 -1
  164. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  165. package/lib/dependencies/CssExportDependency.js +8 -0
  166. package/lib/dependencies/CssImportDependency.js +55 -3
  167. package/lib/dependencies/CssLocalIdentifierDependency.js +15 -1
  168. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +10 -1
  169. package/lib/dependencies/CssUrlDependency.js +46 -16
  170. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  171. package/lib/dependencies/DllEntryDependency.js +14 -0
  172. package/lib/dependencies/DynamicExports.js +10 -6
  173. package/lib/dependencies/ExportsInfoDependency.js +25 -4
  174. package/lib/dependencies/HarmonyAcceptDependency.js +10 -1
  175. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  176. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  177. package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
  178. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -6
  179. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +5 -0
  180. package/lib/dependencies/HarmonyExportExpressionDependency.js +20 -3
  181. package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
  182. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +22 -6
  183. package/lib/dependencies/HarmonyExportInitFragment.js +2 -1
  184. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
  185. package/lib/dependencies/HarmonyExports.js +11 -5
  186. package/lib/dependencies/HarmonyImportDependency.js +10 -1
  187. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +53 -22
  188. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -2
  189. package/lib/dependencies/HarmonyImportSpecifierDependency.js +139 -16
  190. package/lib/dependencies/HarmonyModulesPlugin.js +23 -5
  191. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  192. package/lib/dependencies/ImportContextDependency.js +15 -0
  193. package/lib/dependencies/ImportDependency.js +15 -4
  194. package/lib/dependencies/ImportEagerDependency.js +7 -4
  195. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +51 -13
  196. package/lib/dependencies/ImportMetaContextPlugin.js +18 -5
  197. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  198. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  199. package/lib/dependencies/ImportMetaPlugin.js +103 -51
  200. package/lib/dependencies/ImportParserPlugin.js +83 -25
  201. package/lib/dependencies/ImportPlugin.js +21 -7
  202. package/lib/dependencies/ImportWeakDependency.js +7 -4
  203. package/lib/dependencies/JsonExportsDependency.js +9 -1
  204. package/lib/dependencies/LocalModule.js +16 -0
  205. package/lib/dependencies/LocalModuleDependency.js +15 -0
  206. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  207. package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
  208. package/lib/dependencies/ModuleDependency.js +9 -1
  209. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  210. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  211. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  212. package/lib/dependencies/PrefetchDependency.js +3 -0
  213. package/lib/dependencies/ProvidedDependency.js +14 -2
  214. package/lib/dependencies/PureExpressionDependency.js +10 -1
  215. package/lib/dependencies/RequireContextDependency.js +6 -0
  216. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  217. package/lib/dependencies/RequireContextPlugin.js +19 -6
  218. package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
  219. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  220. package/lib/dependencies/RequireEnsureDependency.js +16 -2
  221. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  222. package/lib/dependencies/RequireEnsurePlugin.js +27 -7
  223. package/lib/dependencies/RequireHeaderDependency.js +14 -1
  224. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  225. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
  226. package/lib/dependencies/RequireIncludePlugin.js +25 -5
  227. package/lib/dependencies/RequireResolveContextDependency.js +17 -0
  228. package/lib/dependencies/RequireResolveDependency.js +6 -0
  229. package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
  230. package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
  231. package/lib/dependencies/StaticExportsDependency.js +8 -0
  232. package/lib/dependencies/SystemPlugin.js +48 -21
  233. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  234. package/lib/dependencies/URLDependency.js +13 -4
  235. package/lib/dependencies/URLPlugin.js +31 -18
  236. package/lib/dependencies/UnsupportedDependency.js +13 -0
  237. package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
  238. package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
  239. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  240. package/lib/dependencies/WorkerDependency.js +47 -3
  241. package/lib/dependencies/WorkerPlugin.js +105 -32
  242. package/lib/dependencies/getFunctionExpression.js +7 -0
  243. package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
  244. package/lib/esm/ModuleChunkFormatPlugin.js +21 -8
  245. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  246. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +19 -12
  247. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  248. package/lib/hmr/LazyCompilationPlugin.js +14 -5
  249. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  250. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  251. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  252. package/lib/ids/HashedModuleIdsPlugin.js +9 -2
  253. package/lib/ids/IdHelpers.js +6 -0
  254. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  255. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  256. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  257. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  258. package/lib/ids/SyncModuleIdsPlugin.js +3 -2
  259. package/lib/index.js +8 -0
  260. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  261. package/lib/javascript/BasicEvaluatedExpression.js +137 -11
  262. package/lib/javascript/ChunkHelpers.js +2 -2
  263. package/lib/javascript/CommonJsChunkFormatPlugin.js +7 -3
  264. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  265. package/lib/javascript/JavascriptModulesPlugin.js +194 -194
  266. package/lib/javascript/JavascriptParser.js +941 -256
  267. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  268. package/lib/javascript/StartupHelpers.js +2 -2
  269. package/lib/json/JsonData.js +26 -1
  270. package/lib/json/JsonGenerator.js +21 -7
  271. package/lib/json/JsonModulesPlugin.js +14 -5
  272. package/lib/json/JsonParser.js +27 -13
  273. package/lib/library/AbstractLibraryPlugin.js +4 -0
  274. package/lib/library/AmdLibraryPlugin.js +22 -6
  275. package/lib/library/AssignLibraryPlugin.js +6 -4
  276. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  277. package/lib/library/ModuleLibraryPlugin.js +8 -4
  278. package/lib/library/SystemLibraryPlugin.js +1 -0
  279. package/lib/library/UmdLibraryPlugin.js +4 -0
  280. package/lib/logging/runtime.js +1 -1
  281. package/lib/logging/truncateArgs.js +4 -0
  282. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  283. package/lib/node/NodeTargetPlugin.js +3 -0
  284. package/lib/node/NodeTemplatePlugin.js +10 -2
  285. package/lib/node/NodeWatchFileSystem.js +1 -1
  286. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +18 -9
  287. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +12 -2
  288. package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
  289. package/lib/node/RequireChunkLoadingRuntimeModule.js +15 -8
  290. package/lib/node/nodeConsole.js +2 -4
  291. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  292. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  293. package/lib/optimize/ConcatenatedModule.js +8 -6
  294. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  295. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  296. package/lib/optimize/InnerGraph.js +5 -5
  297. package/lib/optimize/InnerGraphPlugin.js +57 -48
  298. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  299. package/lib/optimize/MangleExportsPlugin.js +1 -1
  300. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  301. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  302. package/lib/optimize/RealContentHashPlugin.js +86 -30
  303. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  304. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  305. package/lib/optimize/SideEffectsFlagPlugin.js +53 -44
  306. package/lib/optimize/SplitChunksPlugin.js +71 -31
  307. package/lib/performance/SizeLimitsPlugin.js +7 -4
  308. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  309. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  310. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  311. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  312. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  313. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  314. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  315. package/lib/rules/RuleSetCompiler.js +3 -3
  316. package/lib/rules/UseEffectRulePlugin.js +6 -4
  317. package/lib/runtime/AsyncModuleRuntimeModule.js +9 -6
  318. package/lib/runtime/AutoPublicPathRuntimeModule.js +16 -5
  319. package/lib/runtime/BaseUriRuntimeModule.js +8 -4
  320. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  321. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  322. package/lib/runtime/CompatRuntimeModule.js +7 -2
  323. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  324. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  325. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  326. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  327. package/lib/runtime/EnsureChunkRuntimeModule.js +18 -4
  328. package/lib/runtime/GetChunkFilenameRuntimeModule.js +45 -26
  329. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  330. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  331. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +27 -6
  332. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  333. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  334. package/lib/runtime/LoadScriptRuntimeModule.js +65 -50
  335. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  336. package/lib/runtime/NonceRuntimeModule.js +1 -1
  337. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  338. package/lib/runtime/PublicPathRuntimeModule.js +9 -2
  339. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  340. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  341. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  342. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +13 -4
  343. package/lib/runtime/StartupEntrypointRuntimeModule.js +11 -7
  344. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  345. package/lib/schemes/DataUriPlugin.js +16 -3
  346. package/lib/schemes/HttpUriPlugin.js +38 -0
  347. package/lib/serialization/ArraySerializer.js +22 -6
  348. package/lib/serialization/BinaryMiddleware.js +164 -1
  349. package/lib/serialization/DateObjectSerializer.js +15 -4
  350. package/lib/serialization/ErrorObjectSerializer.js +23 -8
  351. package/lib/serialization/FileMiddleware.js +17 -0
  352. package/lib/serialization/MapObjectSerializer.js +24 -8
  353. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  354. package/lib/serialization/ObjectMiddleware.js +33 -2
  355. package/lib/serialization/PlainObjectSerializer.js +23 -12
  356. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  357. package/lib/serialization/SetObjectSerializer.js +21 -6
  358. package/lib/serialization/types.js +1 -1
  359. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  360. package/lib/sharing/ConsumeSharedModule.js +13 -2
  361. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  362. package/lib/sharing/ConsumeSharedRuntimeModule.js +22 -7
  363. package/lib/sharing/ProvideSharedDependency.js +17 -0
  364. package/lib/sharing/ProvideSharedModule.js +11 -1
  365. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  366. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  367. package/lib/sharing/ShareRuntimeModule.js +19 -9
  368. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  369. package/lib/sharing/utils.js +320 -7
  370. package/lib/stats/DefaultStatsFactoryPlugin.js +105 -29
  371. package/lib/stats/DefaultStatsPresetPlugin.js +9 -0
  372. package/lib/stats/DefaultStatsPrinterPlugin.js +43 -0
  373. package/lib/util/AsyncQueue.js +4 -2
  374. package/lib/util/LazySet.js +10 -2
  375. package/lib/util/MapHelpers.js +19 -5
  376. package/lib/util/ParallelismFactorCalculator.js +10 -0
  377. package/lib/util/Semaphore.js +1 -1
  378. package/lib/util/StackedCacheMap.js +6 -0
  379. package/lib/util/StringXor.js +51 -0
  380. package/lib/util/binarySearchBounds.js +49 -0
  381. package/lib/util/compileBooleanMatcher.js +31 -0
  382. package/lib/util/createHash.js +35 -13
  383. package/lib/util/deprecation.js +18 -3
  384. package/lib/util/deterministicGrouping.js +50 -11
  385. package/lib/util/findGraphRoots.js +4 -2
  386. package/lib/util/hash/md4.js +2 -2
  387. package/lib/util/hash/xxhash64.js +1 -1
  388. package/lib/util/identifier.js +4 -0
  389. package/lib/util/internalSerializables.js +1 -0
  390. package/lib/util/makeSerializable.js +7 -0
  391. package/lib/util/memoize.js +3 -3
  392. package/lib/util/numberHash.js +75 -21
  393. package/lib/util/processAsyncTree.js +7 -1
  394. package/lib/util/propertyAccess.js +9 -54
  395. package/lib/util/propertyName.js +79 -0
  396. package/lib/util/registerExternalSerializer.js +1 -1
  397. package/lib/util/runtime.js +14 -1
  398. package/lib/util/semver.js +1 -1
  399. package/lib/util/serialization.js +10 -0
  400. package/lib/util/smartGrouping.js +1 -1
  401. package/lib/validateSchema.js +6 -2
  402. package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
  403. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +15 -2
  404. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  405. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +14 -3
  406. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +28 -8
  407. package/lib/wasm-async/AsyncWebAssemblyParser.js +11 -4
  408. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +39 -8
  409. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
  410. package/lib/wasm-sync/WebAssemblyGenerator.js +19 -5
  411. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  412. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
  413. package/lib/wasm-sync/WebAssemblyParser.js +15 -4
  414. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  415. package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
  416. package/lib/web/FetchCompileWasmPlugin.js +59 -42
  417. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  418. package/lib/web/JsonpChunkLoadingRuntimeModule.js +26 -9
  419. package/lib/webpack.js +12 -3
  420. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  421. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +20 -17
  422. package/module.d.ts +55 -37
  423. package/package.json +59 -56
  424. package/schemas/WebpackOptions.check.js +1 -1
  425. package/schemas/WebpackOptions.json +132 -5
  426. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  427. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  428. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  429. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  430. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  431. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  432. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  433. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  434. package/schemas/plugins/css/CssParserOptions.json +1 -1
  435. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  436. package/types.d.ts +1608 -667
@@ -5,10 +5,19 @@
5
5
  "use strict";
6
6
 
7
7
  const { Tracer } = require("chrome-trace-event");
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
11
+ JAVASCRIPT_MODULE_TYPE_ESM,
12
+ WEBASSEMBLY_MODULE_TYPE_ASYNC,
13
+ WEBASSEMBLY_MODULE_TYPE_SYNC,
14
+ JSON_MODULE_TYPE
15
+ } = require("../ModuleTypeConstants");
8
16
  const createSchemaValidation = require("../util/create-schema-validation");
9
17
  const { dirname, mkdirpSync } = require("../util/fs");
10
18
 
11
19
  /** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
20
+ /** @typedef {import("../Compiler")} Compiler */
12
21
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
13
22
 
14
23
  const validate = createSchemaValidation(
@@ -64,6 +73,11 @@ class Profiler {
64
73
  ]);
65
74
  }
66
75
 
76
+ /**
77
+ * @param {string} method method name
78
+ * @param {object} [params] params
79
+ * @returns {Promise<TODO>} Promise for the result
80
+ */
67
81
  sendCommand(method, params) {
68
82
  if (this.hasSession()) {
69
83
  return new Promise((res, rej) => {
@@ -92,6 +106,8 @@ class Profiler {
92
106
  return this.sendCommand("Profiler.stop").then(({ profile }) => {
93
107
  const hrtime = process.hrtime();
94
108
  const endTime = hrtime[0] * 1000000 + Math.round(hrtime[1] / 1000);
109
+ // Avoid coverage problems due indirect changes
110
+ /* istanbul ignore next */
95
111
  if (profile.startTime < this._startTime || profile.endTime > endTime) {
96
112
  // In some cases timestamps mismatch and we need to adjust them
97
113
  // Both process.hrtime and the inspector timestamps claim to be relative
@@ -182,7 +198,7 @@ const createTrace = (fs, outputPath) => {
182
198
  };
183
199
  };
184
200
 
185
- const pluginName = "ProfilingPlugin";
201
+ const PLUGIN_NAME = "ProfilingPlugin";
186
202
 
187
203
  class ProfilingPlugin {
188
204
  /**
@@ -193,6 +209,11 @@ class ProfilingPlugin {
193
209
  this.outputPath = options.outputPath || "events.json";
194
210
  }
195
211
 
212
+ /**
213
+ * Apply the plugin
214
+ * @param {Compiler} compiler the compiler instance
215
+ * @returns {void}
216
+ */
196
217
  apply(compiler) {
197
218
  const tracer = createTrace(
198
219
  compiler.intermediateFileSystem,
@@ -216,7 +237,7 @@ class ProfilingPlugin {
216
237
  });
217
238
 
218
239
  compiler.hooks.compilation.tap(
219
- pluginName,
240
+ PLUGIN_NAME,
220
241
  (compilation, { normalModuleFactory, contextModuleFactory }) => {
221
242
  interceptAllHooksFor(compilation, tracer, "Compilation");
222
243
  interceptAllHooksFor(
@@ -237,7 +258,7 @@ class ProfilingPlugin {
237
258
  // We need to write out the CPU profile when we are all done.
238
259
  compiler.hooks.done.tapAsync(
239
260
  {
240
- name: pluginName,
261
+ name: PLUGIN_NAME,
241
262
  stage: Infinity
242
263
  },
243
264
  (stats, callback) => {
@@ -312,18 +333,18 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
312
333
 
313
334
  const interceptAllParserHooks = (moduleFactory, tracer) => {
314
335
  const moduleTypes = [
315
- "javascript/auto",
316
- "javascript/dynamic",
317
- "javascript/esm",
318
- "json",
319
- "webassembly/async",
320
- "webassembly/sync"
336
+ JAVASCRIPT_MODULE_TYPE_AUTO,
337
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
338
+ JAVASCRIPT_MODULE_TYPE_ESM,
339
+ JSON_MODULE_TYPE,
340
+ WEBASSEMBLY_MODULE_TYPE_ASYNC,
341
+ WEBASSEMBLY_MODULE_TYPE_SYNC
321
342
  ];
322
343
 
323
344
  moduleTypes.forEach(moduleType => {
324
345
  moduleFactory.hooks.parser
325
346
  .for(moduleType)
326
- .tap("ProfilingPlugin", (parser, parserOpts) => {
347
+ .tap(PLUGIN_NAME, (parser, parserOpts) => {
327
348
  interceptAllHooksFor(parser, tracer, "Parser");
328
349
  });
329
350
  });
@@ -347,7 +368,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
347
368
  const { name, type, fn } = tapInfo;
348
369
  const newFn =
349
370
  // Don't tap our own hooks to ensure stream can close cleanly
350
- name === pluginName
371
+ name === PLUGIN_NAME
351
372
  ? fn
352
373
  : makeNewProfiledTapFn(hookName, tracer, {
353
374
  name,
@@ -418,7 +439,7 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
418
439
  const id = ++tracer.counter;
419
440
  // Do not instrument ourself due to the CPU
420
441
  // profile needing to be the last event in the trace.
421
- if (name === pluginName) {
442
+ if (name === PLUGIN_NAME) {
422
443
  return fn(...args);
423
444
  }
424
445
 
@@ -12,12 +12,15 @@ const NullDependency = require("./NullDependency");
12
12
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
13
  /** @typedef {import("../Dependency")} Dependency */
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
16
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
18
 
16
19
  /** @type {Record<string, { definition: string, content: string, requests: string[] }>} */
17
20
  const DEFINITIONS = {
18
21
  f: {
19
22
  definition: "var __WEBPACK_AMD_DEFINE_RESULT__;",
20
- content: `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, __webpack_require__, exports, module),
23
+ content: `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, ${RuntimeGlobals.require}, exports, module),
21
24
  __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`,
22
25
  requests: [
23
26
  RuntimeGlobals.require,
@@ -35,7 +38,7 @@ const DEFINITIONS = {
35
38
  "var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;",
36
39
  content: `!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#),
37
40
  __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
38
- (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
41
+ (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, ${RuntimeGlobals.require}, exports, module)) :
39
42
  __WEBPACK_AMD_DEFINE_FACTORY__),
40
43
  __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`,
41
44
  requests: [
@@ -67,8 +70,7 @@ const DEFINITIONS = {
67
70
  },
68
71
  lf: {
69
72
  definition: "var XXX, XXXmodule;",
70
- content:
71
- "!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))",
73
+ content: `!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, ${RuntimeGlobals.require}, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))`,
72
74
  requests: [RuntimeGlobals.require, RuntimeGlobals.module]
73
75
  },
74
76
  lo: {
@@ -78,8 +80,7 @@ const DEFINITIONS = {
78
80
  },
79
81
  lof: {
80
82
  definition: "var XXX, XXXfactory, XXXmodule;",
81
- content:
82
- "!(XXXfactory = (#), (typeof XXXfactory === 'function' ? ((XXXmodule = { id: YYY, exports: {}, loaded: false }), (XXX = XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports)) : XXX = XXXfactory))",
83
+ content: `!(XXXfactory = (#), (typeof XXXfactory === 'function' ? ((XXXmodule = { id: YYY, exports: {}, loaded: false }), (XXX = XXXfactory.call(XXXmodule.exports, ${RuntimeGlobals.require}, XXXmodule.exports, XXXmodule)), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports)) : XXX = XXXfactory))`,
83
84
  requests: [RuntimeGlobals.require, RuntimeGlobals.module]
84
85
  },
85
86
  laf: {
@@ -105,6 +106,13 @@ const DEFINITIONS = {
105
106
  };
106
107
 
107
108
  class AMDDefineDependency extends NullDependency {
109
+ /**
110
+ * @param {Range} range range
111
+ * @param {Range} arrayRange array range
112
+ * @param {Range} functionRange function range
113
+ * @param {Range} objectRange object range
114
+ * @param {boolean} namedModule true, when define is called with a name
115
+ */
108
116
  constructor(range, arrayRange, functionRange, objectRange, namedModule) {
109
117
  super();
110
118
  this.range = range;
@@ -119,6 +127,9 @@ class AMDDefineDependency extends NullDependency {
119
127
  return "amd define";
120
128
  }
121
129
 
130
+ /**
131
+ * @param {ObjectSerializerContext} context context
132
+ */
122
133
  serialize(context) {
123
134
  const { write } = context;
124
135
  write(this.range);
@@ -130,6 +141,9 @@ class AMDDefineDependency extends NullDependency {
130
141
  super.serialize(context);
131
142
  }
132
143
 
144
+ /**
145
+ * @param {ObjectDeserializerContext} context context
146
+ */
133
147
  deserialize(context) {
134
148
  const { read } = context;
135
149
  this.range = read();
@@ -166,6 +180,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
166
180
  this.replace(dep, source, definition, content);
167
181
  }
168
182
 
183
+ /**
184
+ * @param {AMDDefineDependency} dependency dependency
185
+ * @returns {string} variable name
186
+ */
169
187
  localModuleVar(dependency) {
170
188
  return (
171
189
  dependency.localModule &&
@@ -174,6 +192,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
174
192
  );
175
193
  }
176
194
 
195
+ /**
196
+ * @param {AMDDefineDependency} dependency dependency
197
+ * @returns {string} branch
198
+ */
177
199
  branch(dependency) {
178
200
  const localModuleVar = this.localModuleVar(dependency) ? "l" : "";
179
201
  const arrayRange = dependency.arrayRange ? "a" : "";
@@ -182,6 +204,12 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
182
204
  return localModuleVar + arrayRange + objectRange + functionRange;
183
205
  }
184
206
 
207
+ /**
208
+ * @param {AMDDefineDependency} dependency dependency
209
+ * @param {ReplaceSource} source source
210
+ * @param {string} definition definition
211
+ * @param {string} text text
212
+ */
185
213
  replace(dependency, source, definition, text) {
186
214
  const localModuleVar = this.localModuleVar(dependency);
187
215
  if (localModuleVar) {
@@ -202,18 +230,34 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
202
230
 
203
231
  let current = dependency.range[0];
204
232
  if (dependency.arrayRange) {
205
- source.replace(current, dependency.arrayRange[0] - 1, texts.shift());
233
+ source.replace(
234
+ current,
235
+ dependency.arrayRange[0] - 1,
236
+ /** @type {string} */ (texts.shift())
237
+ );
206
238
  current = dependency.arrayRange[1];
207
239
  }
208
240
 
209
241
  if (dependency.objectRange) {
210
- source.replace(current, dependency.objectRange[0] - 1, texts.shift());
242
+ source.replace(
243
+ current,
244
+ dependency.objectRange[0] - 1,
245
+ /** @type {string} */ (texts.shift())
246
+ );
211
247
  current = dependency.objectRange[1];
212
248
  } else if (dependency.functionRange) {
213
- source.replace(current, dependency.functionRange[0] - 1, texts.shift());
249
+ source.replace(
250
+ current,
251
+ dependency.functionRange[0] - 1,
252
+ /** @type {string} */ (texts.shift())
253
+ );
214
254
  current = dependency.functionRange[1];
215
255
  }
216
- source.replace(current, dependency.range[1] - 1, texts.shift());
256
+ source.replace(
257
+ current,
258
+ dependency.range[1] - 1,
259
+ /** @type {string} */ (texts.shift())
260
+ );
217
261
  if (texts.length > 0) throw new Error("Implementation error");
218
262
  }
219
263
  };
@@ -16,6 +16,13 @@ const DynamicExports = require("./DynamicExports");
16
16
  const LocalModuleDependency = require("./LocalModuleDependency");
17
17
  const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
18
18
 
19
+ /** @typedef {import("estree").CallExpression} CallExpression */
20
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
21
+
22
+ /**
23
+ * @param {CallExpression} expr expression
24
+ * @returns {boolean} true if it's a bound function expression
25
+ */
19
26
  const isBoundFunctionExpression = expr => {
20
27
  if (expr.type !== "CallExpression") return false;
21
28
  if (expr.callee.type !== "MemberExpression") return false;
@@ -43,6 +50,10 @@ class AMDDefineDependencyParserPlugin {
43
50
  this.options = options;
44
51
  }
45
52
 
53
+ /**
54
+ * @param {JavascriptParser} parser the parser
55
+ * @returns {void}
56
+ */
46
57
  apply(parser) {
47
58
  parser.hooks.call
48
59
  .for("define")
@@ -73,7 +84,7 @@ class AMDDefineDependencyParserPlugin {
73
84
  let localModule;
74
85
  if (request === "require") {
75
86
  identifiers[idx] = request;
76
- dep = "__webpack_require__";
87
+ dep = RuntimeGlobals.require;
77
88
  } else if (["exports", "module"].includes(request)) {
78
89
  identifiers[idx] = request;
79
90
  dep = request;
@@ -109,7 +120,7 @@ class AMDDefineDependencyParserPlugin {
109
120
  } else if (param.isString()) {
110
121
  let dep, localModule;
111
122
  if (param.string === "require") {
112
- dep = new ConstDependency("__webpack_require__", param.range, [
123
+ dep = new ConstDependency(RuntimeGlobals.require, param.range, [
113
124
  RuntimeGlobals.require
114
125
  ]);
115
126
  } else if (param.string === "exports") {
@@ -5,6 +5,10 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC
11
+ } = require("../ModuleTypeConstants");
8
12
  const RuntimeGlobals = require("../RuntimeGlobals");
9
13
  const {
10
14
  approve,
@@ -28,8 +32,12 @@ const ConstDependency = require("./ConstDependency");
28
32
  const LocalModuleDependency = require("./LocalModuleDependency");
29
33
  const UnsupportedDependency = require("./UnsupportedDependency");
30
34
 
35
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
31
36
  /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
32
37
  /** @typedef {import("../Compiler")} Compiler */
38
+ /** @typedef {import("../javascript/JavascriptParser")} Parser */
39
+
40
+ const PLUGIN_NAME = "AMDPlugin";
33
41
 
34
42
  class AMDPlugin {
35
43
  /**
@@ -47,7 +55,7 @@ class AMDPlugin {
47
55
  apply(compiler) {
48
56
  const amdOptions = this.amdOptions;
49
57
  compiler.hooks.compilation.tap(
50
- "AMDPlugin",
58
+ PLUGIN_NAME,
51
59
  (compilation, { contextModuleFactory, normalModuleFactory }) => {
52
60
  compilation.dependencyTemplates.set(
53
61
  AMDRequireDependency,
@@ -94,31 +102,36 @@ class AMDPlugin {
94
102
 
95
103
  compilation.hooks.runtimeRequirementInModule
96
104
  .for(RuntimeGlobals.amdDefine)
97
- .tap("AMDPlugin", (module, set) => {
105
+ .tap(PLUGIN_NAME, (module, set) => {
98
106
  set.add(RuntimeGlobals.require);
99
107
  });
100
108
 
101
109
  compilation.hooks.runtimeRequirementInModule
102
110
  .for(RuntimeGlobals.amdOptions)
103
- .tap("AMDPlugin", (module, set) => {
111
+ .tap(PLUGIN_NAME, (module, set) => {
104
112
  set.add(RuntimeGlobals.requireScope);
105
113
  });
106
114
 
107
115
  compilation.hooks.runtimeRequirementInTree
108
116
  .for(RuntimeGlobals.amdDefine)
109
- .tap("AMDPlugin", (chunk, set) => {
117
+ .tap(PLUGIN_NAME, (chunk, set) => {
110
118
  compilation.addRuntimeModule(chunk, new AMDDefineRuntimeModule());
111
119
  });
112
120
 
113
121
  compilation.hooks.runtimeRequirementInTree
114
122
  .for(RuntimeGlobals.amdOptions)
115
- .tap("AMDPlugin", (chunk, set) => {
123
+ .tap(PLUGIN_NAME, (chunk, set) => {
116
124
  compilation.addRuntimeModule(
117
125
  chunk,
118
126
  new AMDOptionsRuntimeModule(amdOptions)
119
127
  );
120
128
  });
121
129
 
130
+ /**
131
+ * @param {Parser} parser parser parser
132
+ * @param {JavascriptParserOptions} parserOptions parserOptions
133
+ * @returns {void}
134
+ */
122
135
  const handler = (parser, parserOptions) => {
123
136
  if (parserOptions.amd !== undefined && !parserOptions.amd) return;
124
137
 
@@ -126,7 +139,7 @@ class AMDPlugin {
126
139
  parser.hooks.expression
127
140
  .for(optionExpr)
128
141
  .tap(
129
- "AMDPlugin",
142
+ PLUGIN_NAME,
130
143
  toConstantDependency(parser, RuntimeGlobals.amdOptions, [
131
144
  RuntimeGlobals.amdOptions
132
145
  ])
@@ -134,16 +147,16 @@ class AMDPlugin {
134
147
  parser.hooks.evaluateIdentifier
135
148
  .for(optionExpr)
136
149
  .tap(
137
- "AMDPlugin",
150
+ PLUGIN_NAME,
138
151
  evaluateToIdentifier(optionExpr, rootName, getMembers, true)
139
152
  );
140
153
  parser.hooks.evaluateTypeof
141
154
  .for(optionExpr)
142
- .tap("AMDPlugin", evaluateToString("object"));
155
+ .tap(PLUGIN_NAME, evaluateToString("object"));
143
156
  parser.hooks.typeof
144
157
  .for(optionExpr)
145
158
  .tap(
146
- "AMDPlugin",
159
+ PLUGIN_NAME,
147
160
  toConstantDependency(parser, JSON.stringify("object"))
148
161
  );
149
162
  };
@@ -161,7 +174,7 @@ class AMDPlugin {
161
174
  () => []
162
175
  );
163
176
 
164
- parser.hooks.expression.for("define").tap("AMDPlugin", expr => {
177
+ parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => {
165
178
  const dep = new ConstDependency(
166
179
  RuntimeGlobals.amdDefine,
167
180
  expr.range,
@@ -174,14 +187,14 @@ class AMDPlugin {
174
187
  parser.hooks.typeof
175
188
  .for("define")
176
189
  .tap(
177
- "AMDPlugin",
190
+ PLUGIN_NAME,
178
191
  toConstantDependency(parser, JSON.stringify("function"))
179
192
  );
180
193
  parser.hooks.evaluateTypeof
181
194
  .for("define")
182
- .tap("AMDPlugin", evaluateToString("function"));
183
- parser.hooks.canRename.for("define").tap("AMDPlugin", approve);
184
- parser.hooks.rename.for("define").tap("AMDPlugin", expr => {
195
+ .tap(PLUGIN_NAME, evaluateToString("function"));
196
+ parser.hooks.canRename.for("define").tap(PLUGIN_NAME, approve);
197
+ parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => {
185
198
  const dep = new ConstDependency(
186
199
  RuntimeGlobals.amdDefine,
187
200
  expr.range,
@@ -194,20 +207,20 @@ class AMDPlugin {
194
207
  parser.hooks.typeof
195
208
  .for("require")
196
209
  .tap(
197
- "AMDPlugin",
210
+ PLUGIN_NAME,
198
211
  toConstantDependency(parser, JSON.stringify("function"))
199
212
  );
200
213
  parser.hooks.evaluateTypeof
201
214
  .for("require")
202
- .tap("AMDPlugin", evaluateToString("function"));
215
+ .tap(PLUGIN_NAME, evaluateToString("function"));
203
216
  };
204
217
 
205
218
  normalModuleFactory.hooks.parser
206
- .for("javascript/auto")
207
- .tap("AMDPlugin", handler);
219
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
220
+ .tap(PLUGIN_NAME, handler);
208
221
  normalModuleFactory.hooks.parser
209
- .for("javascript/dynamic")
210
- .tap("AMDPlugin", handler);
222
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
223
+ .tap(PLUGIN_NAME, handler);
211
224
  }
212
225
  );
213
226
  }
@@ -12,8 +12,15 @@ const NullDependency = require("./NullDependency");
12
12
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
13
13
  /** @typedef {import("../Dependency")} Dependency */
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
16
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
17
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
18
 
16
19
  class AMDRequireArrayDependency extends NullDependency {
20
+ /**
21
+ * @param {TODO} depsArray deps array
22
+ * @param {Range} range range
23
+ */
17
24
  constructor(depsArray, range) {
18
25
  super();
19
26
 
@@ -29,6 +36,9 @@ class AMDRequireArrayDependency extends NullDependency {
29
36
  return "amd";
30
37
  }
31
38
 
39
+ /**
40
+ * @param {ObjectSerializerContext} context context
41
+ */
32
42
  serialize(context) {
33
43
  const { write } = context;
34
44
 
@@ -38,6 +48,9 @@ class AMDRequireArrayDependency extends NullDependency {
38
48
  super.serialize(context);
39
49
  }
40
50
 
51
+ /**
52
+ * @param {ObjectDeserializerContext} context context
53
+ */
41
54
  deserialize(context) {
42
55
  const { read } = context;
43
56
 
@@ -8,7 +8,16 @@
8
8
  const makeSerializable = require("../util/makeSerializable");
9
9
  const ContextDependency = require("./ContextDependency");
10
10
 
11
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
12
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
13
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
14
+
11
15
  class AMDRequireContextDependency extends ContextDependency {
16
+ /**
17
+ * @param {TODO} options options
18
+ * @param {Range} range range
19
+ * @param {Range} valueRange value range
20
+ */
12
21
  constructor(options, range, valueRange) {
13
22
  super(options);
14
23
 
@@ -24,6 +33,9 @@ class AMDRequireContextDependency extends ContextDependency {
24
33
  return "amd";
25
34
  }
26
35
 
36
+ /**
37
+ * @param {ObjectSerializerContext} context context
38
+ */
27
39
  serialize(context) {
28
40
  const { write } = context;
29
41
 
@@ -33,6 +45,9 @@ class AMDRequireContextDependency extends ContextDependency {
33
45
  super.serialize(context);
34
46
  }
35
47
 
48
+ /**
49
+ * @param {ObjectDeserializerContext} context context
50
+ */
36
51
  deserialize(context) {
37
52
  const { read } = context;
38
53
 
@@ -8,7 +8,13 @@
8
8
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
12
+
11
13
  class AMDRequireDependenciesBlock extends AsyncDependenciesBlock {
14
+ /**
15
+ * @param {DependencyLocation} loc location info
16
+ * @param {string=} request request
17
+ */
12
18
  constructor(loc, request) {
13
19
  super(null, loc, request);
14
20
  }
@@ -19,6 +19,8 @@ const { getLocalModule } = require("./LocalModulesHelpers");
19
19
  const UnsupportedDependency = require("./UnsupportedDependency");
20
20
  const getFunctionExpression = require("./getFunctionExpression");
21
21
 
22
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
23
+
22
24
  class AMDRequireDependenciesBlockParserPlugin {
23
25
  constructor(options) {
24
26
  this.options = options;
@@ -50,6 +52,10 @@ class AMDRequireDependenciesBlockParserPlugin {
50
52
  return bindThis;
51
53
  }
52
54
 
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @returns {void}
58
+ */
53
59
  apply(parser) {
54
60
  parser.hooks.call
55
61
  .for("require")
@@ -73,7 +79,7 @@ class AMDRequireDependenciesBlockParserPlugin {
73
79
  for (const request of param.array) {
74
80
  let dep, localModule;
75
81
  if (request === "require") {
76
- dep = "__webpack_require__";
82
+ dep = RuntimeGlobals.require;
77
83
  } else if (["exports", "module"].includes(request)) {
78
84
  dep = request;
79
85
  } else if ((localModule = getLocalModule(parser.state, request))) {
@@ -108,7 +114,7 @@ class AMDRequireDependenciesBlockParserPlugin {
108
114
  } else if (param.isString()) {
109
115
  let dep, localModule;
110
116
  if (param.string === "require") {
111
- dep = new ConstDependency("__webpack_require__", param.string, [
117
+ dep = new ConstDependency(RuntimeGlobals.require, param.string, [
112
118
  RuntimeGlobals.require
113
119
  ]);
114
120
  } else if (param.string === "module") {
@@ -13,8 +13,17 @@ const NullDependency = require("./NullDependency");
13
13
  /** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
14
14
  /** @typedef {import("../Dependency")} Dependency */
15
15
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
17
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
18
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
19
 
17
20
  class AMDRequireDependency extends NullDependency {
21
+ /**
22
+ * @param {Range} outerRange outer range
23
+ * @param {Range} arrayRange array range
24
+ * @param {Range} functionRange function range
25
+ * @param {Range} errorCallbackRange error callback range
26
+ */
18
27
  constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
19
28
  super();
20
29
 
@@ -30,6 +39,9 @@ class AMDRequireDependency extends NullDependency {
30
39
  return "amd";
31
40
  }
32
41
 
42
+ /**
43
+ * @param {ObjectSerializerContext} context context
44
+ */
33
45
  serialize(context) {
34
46
  const { write } = context;
35
47
 
@@ -43,6 +55,9 @@ class AMDRequireDependency extends NullDependency {
43
55
  super.serialize(context);
44
56
  }
45
57
 
58
+ /**
59
+ * @param {ObjectDeserializerContext} context context
60
+ */
46
61
  deserialize(context) {
47
62
  const { read } = context;
48
63
 
@@ -103,7 +118,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
103
118
  // has function range but no array range
104
119
  if (dep.functionRange && !dep.arrayRange) {
105
120
  const startBlock = `${promise}.then((`;
106
- const endBlock = `).bind(exports, __webpack_require__, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
121
+ const endBlock = `).bind(exports, ${RuntimeGlobals.require}, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
107
122
  runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
108
123
 
109
124
  source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
@@ -9,7 +9,13 @@ const makeSerializable = require("../util/makeSerializable");
9
9
  const ModuleDependency = require("./ModuleDependency");
10
10
  const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
11
11
 
12
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
13
+
12
14
  class AMDRequireItemDependency extends ModuleDependency {
15
+ /**
16
+ * @param {string} request the request string
17
+ * @param {Range} range location in source code
18
+ */
13
19
  constructor(request, range) {
14
20
  super(request);
15
21
 
@@ -14,7 +14,7 @@ class AMDDefineRuntimeModule extends RuntimeModule {
14
14
  }
15
15
 
16
16
  /**
17
- * @returns {string} runtime code
17
+ * @returns {string | null} runtime code
18
18
  */
19
19
  generate() {
20
20
  return Template.asString([
@@ -35,7 +35,7 @@ class AMDOptionsRuntimeModule extends RuntimeModule {
35
35
  }
36
36
 
37
37
  /**
38
- * @returns {string} runtime code
38
+ * @returns {string | null} runtime code
39
39
  */
40
40
  generate() {
41
41
  return Template.asString([