webpack 5.59.0 → 5.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/README.md +48 -38
  2. package/bin/webpack.js +34 -10
  3. package/hot/dev-server.js +19 -5
  4. package/hot/lazy-compilation-node.js +13 -1
  5. package/hot/lazy-compilation-web.js +9 -0
  6. package/hot/log-apply-result.js +5 -0
  7. package/hot/log.js +23 -4
  8. package/hot/only-dev-server.js +3 -2
  9. package/hot/poll.js +5 -2
  10. package/hot/signal.js +6 -2
  11. package/lib/APIPlugin.js +226 -122
  12. package/lib/AbstractMethodError.js +10 -5
  13. package/lib/AsyncDependenciesBlock.js +13 -5
  14. package/lib/AutomaticPrefetchPlugin.js +2 -1
  15. package/lib/BannerPlugin.js +33 -12
  16. package/lib/Cache.js +16 -12
  17. package/lib/CacheFacade.js +13 -16
  18. package/lib/CaseSensitiveModulesWarning.js +8 -8
  19. package/lib/Chunk.js +60 -33
  20. package/lib/ChunkGraph.js +207 -72
  21. package/lib/ChunkGroup.js +40 -20
  22. package/lib/ChunkTemplate.js +43 -0
  23. package/lib/CleanPlugin.js +117 -32
  24. package/lib/CodeGenerationResults.js +8 -7
  25. package/lib/CommentCompilationWarning.js +0 -1
  26. package/lib/CompatibilityPlugin.js +85 -46
  27. package/lib/Compilation.js +712 -392
  28. package/lib/Compiler.js +393 -172
  29. package/lib/ConcatenationScope.js +10 -13
  30. package/lib/ConditionalInitFragment.js +22 -14
  31. package/lib/ConstPlugin.js +104 -64
  32. package/lib/ContextExclusionPlugin.js +3 -3
  33. package/lib/ContextModule.js +283 -108
  34. package/lib/ContextModuleFactory.js +151 -63
  35. package/lib/ContextReplacementPlugin.js +25 -10
  36. package/lib/CssModule.js +166 -0
  37. package/lib/DefinePlugin.js +254 -148
  38. package/lib/DelegatedModule.js +29 -6
  39. package/lib/DelegatedModuleFactoryPlugin.js +42 -22
  40. package/lib/DelegatedPlugin.js +4 -0
  41. package/lib/DependenciesBlock.js +17 -2
  42. package/lib/Dependency.js +58 -29
  43. package/lib/DependencyTemplate.js +24 -3
  44. package/lib/DependencyTemplates.js +2 -2
  45. package/lib/DllEntryPlugin.js +18 -1
  46. package/lib/DllModule.js +21 -4
  47. package/lib/DllModuleFactory.js +2 -1
  48. package/lib/DllPlugin.js +9 -7
  49. package/lib/DllReferencePlugin.js +50 -19
  50. package/lib/EntryOptionPlugin.js +6 -1
  51. package/lib/EntryPlugin.js +7 -4
  52. package/lib/Entrypoint.js +2 -2
  53. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  54. package/lib/EnvironmentPlugin.js +5 -2
  55. package/lib/ErrorHelpers.js +65 -26
  56. package/lib/EvalDevToolModulePlugin.js +37 -13
  57. package/lib/EvalSourceMapDevToolPlugin.js +50 -20
  58. package/lib/ExportsInfo.js +234 -133
  59. package/lib/ExportsInfoApiPlugin.js +31 -15
  60. package/lib/ExternalModule.js +391 -129
  61. package/lib/ExternalModuleFactoryPlugin.js +65 -17
  62. package/lib/FileSystemInfo.js +1038 -523
  63. package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
  64. package/lib/FlagDependencyExportsPlugin.js +352 -349
  65. package/lib/FlagDependencyUsagePlugin.js +10 -10
  66. package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
  67. package/lib/Generator.js +16 -8
  68. package/lib/GraphHelpers.js +3 -2
  69. package/lib/HookWebpackError.js +11 -13
  70. package/lib/HotModuleReplacementPlugin.js +221 -128
  71. package/lib/IgnoreErrorModuleFactory.js +4 -4
  72. package/lib/IgnorePlugin.js +5 -4
  73. package/lib/IgnoreWarningsPlugin.js +6 -9
  74. package/lib/InitFragment.js +39 -15
  75. package/lib/JavascriptMetaInfoPlugin.js +27 -15
  76. package/lib/LibManifestPlugin.js +45 -16
  77. package/lib/LoaderOptionsPlugin.js +13 -3
  78. package/lib/MainTemplate.js +74 -21
  79. package/lib/Module.js +155 -34
  80. package/lib/ModuleBuildError.js +13 -11
  81. package/lib/ModuleDependencyError.js +6 -4
  82. package/lib/ModuleDependencyWarning.js +6 -4
  83. package/lib/ModuleError.js +10 -5
  84. package/lib/ModuleFactory.js +4 -4
  85. package/lib/ModuleFilenameHelpers.js +164 -54
  86. package/lib/ModuleGraph.js +93 -53
  87. package/lib/ModuleGraphConnection.js +27 -13
  88. package/lib/ModuleHashingError.js +29 -0
  89. package/lib/ModuleInfoHeaderPlugin.js +92 -33
  90. package/lib/ModuleNotFoundError.js +5 -2
  91. package/lib/ModuleParseError.js +17 -9
  92. package/lib/ModuleProfile.js +1 -0
  93. package/lib/ModuleRestoreError.js +3 -1
  94. package/lib/ModuleStoreError.js +3 -2
  95. package/lib/ModuleTemplate.js +33 -1
  96. package/lib/ModuleTypeConstants.js +168 -0
  97. package/lib/ModuleWarning.js +10 -5
  98. package/lib/MultiCompiler.js +115 -38
  99. package/lib/MultiStats.js +75 -33
  100. package/lib/MultiWatching.js +6 -2
  101. package/lib/NodeStuffPlugin.js +136 -37
  102. package/lib/NormalModule.js +437 -194
  103. package/lib/NormalModuleFactory.js +313 -116
  104. package/lib/NormalModuleReplacementPlugin.js +10 -4
  105. package/lib/NullFactory.js +1 -1
  106. package/lib/OptimizationStages.js +3 -3
  107. package/lib/Parser.js +1 -1
  108. package/lib/PlatformPlugin.js +39 -0
  109. package/lib/PrefetchPlugin.js +4 -0
  110. package/lib/ProgressPlugin.js +83 -28
  111. package/lib/ProvidePlugin.js +37 -19
  112. package/lib/RawModule.js +18 -5
  113. package/lib/RecordIdsPlugin.js +8 -8
  114. package/lib/RequireJsStuffPlugin.js +22 -15
  115. package/lib/ResolverFactory.js +8 -4
  116. package/lib/RuntimeGlobals.js +99 -65
  117. package/lib/RuntimeModule.js +17 -15
  118. package/lib/RuntimePlugin.js +116 -13
  119. package/lib/RuntimeTemplate.js +304 -102
  120. package/lib/SelfModuleFactory.js +12 -0
  121. package/lib/SizeFormatHelpers.js +2 -4
  122. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  123. package/lib/SourceMapDevToolPlugin.js +89 -42
  124. package/lib/Stats.js +12 -7
  125. package/lib/Template.js +30 -33
  126. package/lib/TemplatedPathPlugin.js +102 -34
  127. package/lib/UseStrictPlugin.js +37 -12
  128. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  129. package/lib/WarnDeprecatedOptionPlugin.js +6 -0
  130. package/lib/WatchIgnorePlugin.js +46 -13
  131. package/lib/Watching.js +139 -76
  132. package/lib/WebpackError.js +14 -5
  133. package/lib/WebpackIsIncludedPlugin.js +22 -13
  134. package/lib/WebpackOptionsApply.js +162 -56
  135. package/lib/WebpackOptionsDefaulter.js +10 -3
  136. package/lib/asset/AssetGenerator.js +351 -99
  137. package/lib/asset/AssetModulesPlugin.js +57 -33
  138. package/lib/asset/AssetParser.js +15 -6
  139. package/lib/asset/AssetSourceGenerator.js +30 -10
  140. package/lib/asset/AssetSourceParser.js +8 -2
  141. package/lib/asset/RawDataUrlModule.js +162 -0
  142. package/lib/async-modules/AwaitDependenciesInitFragment.js +16 -13
  143. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  144. package/lib/buildChunkGraph.js +376 -420
  145. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  146. package/lib/cache/IdleFileCachePlugin.js +26 -13
  147. package/lib/cache/MemoryCachePlugin.js +1 -1
  148. package/lib/cache/MemoryWithGcCachePlugin.js +13 -7
  149. package/lib/cache/PackFileCacheStrategy.js +172 -94
  150. package/lib/cache/ResolverCachePlugin.js +115 -43
  151. package/lib/cache/getLazyHashedEtag.js +2 -2
  152. package/lib/cache/mergeEtags.js +16 -21
  153. package/lib/cli.js +195 -110
  154. package/lib/config/browserslistTargetHandler.js +106 -41
  155. package/lib/config/defaults.js +572 -154
  156. package/lib/config/normalization.js +361 -322
  157. package/lib/config/target.js +105 -66
  158. package/lib/container/ContainerEntryDependency.js +2 -1
  159. package/lib/container/ContainerEntryModule.js +27 -11
  160. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  161. package/lib/container/ContainerExposedDependency.js +9 -0
  162. package/lib/container/ContainerPlugin.js +18 -12
  163. package/lib/container/ContainerReferencePlugin.js +1 -1
  164. package/lib/container/FallbackDependency.js +13 -0
  165. package/lib/container/FallbackItemDependency.js +3 -0
  166. package/lib/container/FallbackModule.js +19 -8
  167. package/lib/container/FallbackModuleFactory.js +1 -1
  168. package/lib/container/ModuleFederationPlugin.js +2 -0
  169. package/lib/container/RemoteModule.js +17 -4
  170. package/lib/container/RemoteRuntimeModule.js +31 -17
  171. package/lib/container/RemoteToExternalDependency.js +3 -0
  172. package/lib/container/options.js +18 -4
  173. package/lib/css/CssExportsGenerator.js +203 -0
  174. package/lib/css/CssGenerator.js +151 -0
  175. package/lib/css/CssLoadingRuntimeModule.js +592 -0
  176. package/lib/css/CssModulesPlugin.js +888 -0
  177. package/lib/css/CssParser.js +1049 -0
  178. package/lib/css/walkCssTokens.js +775 -0
  179. package/lib/debug/ProfilingPlugin.js +102 -54
  180. package/lib/dependencies/AMDDefineDependency.js +54 -10
  181. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +204 -61
  182. package/lib/dependencies/AMDPlugin.js +44 -24
  183. package/lib/dependencies/AMDRequireArrayDependency.js +34 -10
  184. package/lib/dependencies/AMDRequireContextDependency.js +15 -0
  185. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  186. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +185 -54
  187. package/lib/dependencies/AMDRequireDependency.js +21 -6
  188. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  189. package/lib/dependencies/AMDRuntimeModules.js +4 -4
  190. package/lib/dependencies/CachedConstDependency.js +22 -1
  191. package/lib/dependencies/CommonJsDependencyHelpers.js +16 -2
  192. package/lib/dependencies/CommonJsExportRequireDependency.js +77 -47
  193. package/lib/dependencies/CommonJsExportsDependency.js +28 -5
  194. package/lib/dependencies/CommonJsExportsParserPlugin.js +111 -39
  195. package/lib/dependencies/CommonJsFullRequireDependency.js +42 -8
  196. package/lib/dependencies/CommonJsImportsParserPlugin.js +530 -130
  197. package/lib/dependencies/CommonJsPlugin.js +51 -26
  198. package/lib/dependencies/CommonJsRequireContextDependency.js +23 -2
  199. package/lib/dependencies/CommonJsRequireDependency.js +9 -1
  200. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -8
  201. package/lib/dependencies/ConstDependency.js +12 -3
  202. package/lib/dependencies/ContextDependency.js +32 -5
  203. package/lib/dependencies/ContextDependencyHelpers.js +92 -62
  204. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  205. package/lib/dependencies/ContextElementDependency.js +41 -4
  206. package/lib/dependencies/CreateScriptUrlDependency.js +22 -1
  207. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  208. package/lib/dependencies/CssExportDependency.js +156 -0
  209. package/lib/dependencies/CssImportDependency.js +125 -0
  210. package/lib/dependencies/CssLocalIdentifierDependency.js +245 -0
  211. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +111 -0
  212. package/lib/dependencies/CssUrlDependency.js +164 -0
  213. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  214. package/lib/dependencies/DllEntryDependency.js +14 -0
  215. package/lib/dependencies/DynamicExports.js +15 -11
  216. package/lib/dependencies/ExportsInfoDependency.js +26 -5
  217. package/lib/dependencies/ExternalModuleDependency.js +109 -0
  218. package/lib/dependencies/ExternalModuleInitFragment.js +133 -0
  219. package/lib/dependencies/HarmonyAcceptDependency.js +11 -2
  220. package/lib/dependencies/HarmonyAcceptImportDependency.js +9 -4
  221. package/lib/dependencies/HarmonyCompatibilityDependency.js +6 -5
  222. package/lib/dependencies/HarmonyDetectionParserPlugin.js +29 -3
  223. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +152 -0
  224. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +96 -51
  225. package/lib/dependencies/HarmonyExportExpressionDependency.js +21 -4
  226. package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
  227. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +216 -108
  228. package/lib/dependencies/HarmonyExportInitFragment.js +21 -9
  229. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
  230. package/lib/dependencies/HarmonyExports.js +13 -7
  231. package/lib/dependencies/HarmonyImportDependency.js +65 -19
  232. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +268 -74
  233. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  234. package/lib/dependencies/HarmonyImportSpecifierDependency.js +180 -36
  235. package/lib/dependencies/HarmonyModulesPlugin.js +33 -5
  236. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  237. package/lib/dependencies/ImportContextDependency.js +15 -2
  238. package/lib/dependencies/ImportDependency.js +50 -12
  239. package/lib/dependencies/ImportEagerDependency.js +11 -6
  240. package/lib/dependencies/ImportMetaContextDependency.js +42 -0
  241. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +301 -0
  242. package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
  243. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  244. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  245. package/lib/dependencies/ImportMetaPlugin.js +128 -59
  246. package/lib/dependencies/ImportParserPlugin.js +153 -83
  247. package/lib/dependencies/ImportPlugin.js +21 -7
  248. package/lib/dependencies/ImportWeakDependency.js +11 -6
  249. package/lib/dependencies/JsonExportsDependency.js +38 -30
  250. package/lib/dependencies/LoaderDependency.js +14 -0
  251. package/lib/dependencies/LoaderImportDependency.js +14 -0
  252. package/lib/dependencies/LoaderPlugin.js +54 -40
  253. package/lib/dependencies/LocalModule.js +17 -1
  254. package/lib/dependencies/LocalModuleDependency.js +15 -0
  255. package/lib/dependencies/LocalModulesHelpers.js +22 -4
  256. package/lib/dependencies/ModuleDecoratorDependency.js +9 -1
  257. package/lib/dependencies/ModuleDependency.js +24 -7
  258. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  259. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  260. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  261. package/lib/dependencies/PrefetchDependency.js +3 -0
  262. package/lib/dependencies/ProvidedDependency.js +43 -8
  263. package/lib/dependencies/PureExpressionDependency.js +73 -39
  264. package/lib/dependencies/RequireContextDependency.js +6 -16
  265. package/lib/dependencies/RequireContextDependencyParserPlugin.js +14 -6
  266. package/lib/dependencies/RequireContextPlugin.js +20 -7
  267. package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
  268. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +29 -12
  269. package/lib/dependencies/RequireEnsureDependency.js +16 -2
  270. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  271. package/lib/dependencies/RequireEnsurePlugin.js +27 -7
  272. package/lib/dependencies/RequireHeaderDependency.js +14 -1
  273. package/lib/dependencies/RequireIncludeDependency.js +6 -1
  274. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
  275. package/lib/dependencies/RequireIncludePlugin.js +25 -5
  276. package/lib/dependencies/RequireResolveContextDependency.js +19 -2
  277. package/lib/dependencies/RequireResolveDependency.js +8 -1
  278. package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
  279. package/lib/dependencies/RuntimeRequirementsDependency.js +9 -1
  280. package/lib/dependencies/StaticExportsDependency.js +8 -0
  281. package/lib/dependencies/SystemPlugin.js +49 -22
  282. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  283. package/lib/dependencies/URLDependency.js +20 -13
  284. package/lib/dependencies/URLPlugin.js +115 -27
  285. package/lib/dependencies/UnsupportedDependency.js +13 -0
  286. package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
  287. package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
  288. package/lib/dependencies/WebpackIsIncludedDependency.js +6 -1
  289. package/lib/dependencies/WorkerDependency.js +47 -3
  290. package/lib/dependencies/WorkerPlugin.js +143 -59
  291. package/lib/dependencies/getFunctionExpression.js +9 -0
  292. package/lib/dependencies/processExportInfo.js +3 -1
  293. package/lib/electron/ElectronTargetPlugin.js +1 -0
  294. package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
  295. package/lib/esm/ModuleChunkFormatPlugin.js +92 -55
  296. package/lib/esm/ModuleChunkLoadingPlugin.js +12 -1
  297. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +141 -25
  298. package/lib/formatLocation.js +1 -2
  299. package/lib/hmr/HotModuleReplacement.runtime.js +37 -25
  300. package/lib/hmr/HotModuleReplacementRuntimeModule.js +2 -1
  301. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +13 -15
  302. package/lib/hmr/LazyCompilationPlugin.js +94 -41
  303. package/lib/hmr/lazyCompilationBackend.js +107 -44
  304. package/lib/ids/ChunkModuleIdRangePlugin.js +12 -3
  305. package/lib/ids/DeterministicChunkIdsPlugin.js +13 -6
  306. package/lib/ids/DeterministicModuleIdsPlugin.js +59 -35
  307. package/lib/ids/HashedModuleIdsPlugin.js +24 -16
  308. package/lib/ids/IdHelpers.js +59 -49
  309. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  310. package/lib/ids/NamedModuleIdsPlugin.js +20 -12
  311. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  312. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  313. package/lib/ids/OccurrenceModuleIdsPlugin.js +14 -11
  314. package/lib/ids/SyncModuleIdsPlugin.js +146 -0
  315. package/lib/index.js +44 -5
  316. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +9 -7
  317. package/lib/javascript/BasicEvaluatedExpression.js +133 -19
  318. package/lib/javascript/ChunkHelpers.js +33 -0
  319. package/lib/javascript/CommonJsChunkFormatPlugin.js +18 -15
  320. package/lib/javascript/EnableChunkLoadingPlugin.js +11 -6
  321. package/lib/javascript/JavascriptGenerator.js +37 -6
  322. package/lib/javascript/JavascriptModulesPlugin.js +523 -295
  323. package/lib/javascript/JavascriptParser.js +1591 -574
  324. package/lib/javascript/JavascriptParserHelpers.js +58 -37
  325. package/lib/javascript/StartupHelpers.js +69 -47
  326. package/lib/json/JsonData.js +33 -0
  327. package/lib/json/JsonGenerator.js +29 -21
  328. package/lib/json/JsonModulesPlugin.js +13 -7
  329. package/lib/json/JsonParser.js +30 -16
  330. package/lib/library/AbstractLibraryPlugin.js +6 -2
  331. package/lib/library/AmdLibraryPlugin.js +34 -18
  332. package/lib/library/AssignLibraryPlugin.js +68 -32
  333. package/lib/library/EnableLibraryPlugin.js +39 -14
  334. package/lib/library/ExportPropertyLibraryPlugin.js +14 -5
  335. package/lib/library/JsonpLibraryPlugin.js +4 -3
  336. package/lib/library/ModernModuleLibraryPlugin.js +144 -0
  337. package/lib/library/ModuleLibraryPlugin.js +12 -7
  338. package/lib/library/SystemLibraryPlugin.js +6 -4
  339. package/lib/library/UmdLibraryPlugin.js +119 -100
  340. package/lib/logging/Logger.js +59 -6
  341. package/lib/logging/createConsoleLogger.js +25 -40
  342. package/lib/logging/runtime.js +8 -9
  343. package/lib/logging/truncateArgs.js +9 -8
  344. package/lib/node/CommonJsChunkLoadingPlugin.js +18 -2
  345. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  346. package/lib/node/NodeTargetPlugin.js +7 -0
  347. package/lib/node/NodeTemplatePlugin.js +10 -2
  348. package/lib/node/NodeWatchFileSystem.js +100 -50
  349. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +51 -26
  350. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -2
  351. package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
  352. package/lib/node/RequireChunkLoadingRuntimeModule.js +49 -26
  353. package/lib/node/nodeConsole.js +48 -31
  354. package/lib/optimize/AggressiveMergingPlugin.js +10 -4
  355. package/lib/optimize/AggressiveSplittingPlugin.js +26 -21
  356. package/lib/optimize/ConcatenatedModule.js +353 -212
  357. package/lib/optimize/EnsureChunkConditionsPlugin.js +4 -1
  358. package/lib/optimize/FlagIncludedChunksPlugin.js +14 -8
  359. package/lib/optimize/InnerGraph.js +30 -25
  360. package/lib/optimize/InnerGraphPlugin.js +105 -64
  361. package/lib/optimize/LimitChunkCountPlugin.js +32 -9
  362. package/lib/optimize/MangleExportsPlugin.js +7 -2
  363. package/lib/optimize/MinMaxSizeWarning.js +6 -1
  364. package/lib/optimize/ModuleConcatenationPlugin.js +150 -83
  365. package/lib/optimize/RealContentHashPlugin.js +99 -43
  366. package/lib/optimize/RemoveParentModulesPlugin.js +131 -48
  367. package/lib/optimize/RuntimeChunkPlugin.js +15 -2
  368. package/lib/optimize/SideEffectsFlagPlugin.js +119 -63
  369. package/lib/optimize/SplitChunksPlugin.js +129 -78
  370. package/lib/performance/SizeLimitsPlugin.js +22 -8
  371. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  372. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +4 -1
  373. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +8 -5
  374. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -3
  375. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +5 -3
  376. package/lib/rules/BasicEffectRulePlugin.js +7 -1
  377. package/lib/rules/BasicMatcherRulePlugin.js +8 -1
  378. package/lib/rules/ObjectMatcherRulePlugin.js +19 -2
  379. package/lib/rules/RuleSetCompiler.js +53 -32
  380. package/lib/rules/UseEffectRulePlugin.js +42 -36
  381. package/lib/runtime/AsyncModuleRuntimeModule.js +56 -69
  382. package/lib/runtime/AutoPublicPathRuntimeModule.js +25 -9
  383. package/lib/runtime/BaseUriRuntimeModule.js +35 -0
  384. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  385. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  386. package/lib/runtime/CompatRuntimeModule.js +7 -2
  387. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  388. package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
  389. package/lib/runtime/CreateScriptUrlRuntimeModule.js +13 -36
  390. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -3
  391. package/lib/runtime/EnsureChunkRuntimeModule.js +29 -15
  392. package/lib/runtime/GetChunkFilenameRuntimeModule.js +56 -43
  393. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  394. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  395. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +98 -0
  396. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  397. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  398. package/lib/runtime/LoadScriptRuntimeModule.js +61 -45
  399. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  400. package/lib/runtime/NonceRuntimeModule.js +24 -0
  401. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  402. package/lib/runtime/PublicPathRuntimeModule.js +9 -2
  403. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  404. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  405. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  406. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +36 -28
  407. package/lib/runtime/StartupEntrypointRuntimeModule.js +13 -9
  408. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  409. package/lib/schemes/DataUriPlugin.js +16 -3
  410. package/lib/schemes/HttpUriPlugin.js +336 -120
  411. package/lib/serialization/ArraySerializer.js +22 -6
  412. package/lib/serialization/BinaryMiddleware.js +212 -33
  413. package/lib/serialization/DateObjectSerializer.js +16 -4
  414. package/lib/serialization/ErrorObjectSerializer.js +23 -6
  415. package/lib/serialization/FileMiddleware.js +187 -86
  416. package/lib/serialization/MapObjectSerializer.js +25 -8
  417. package/lib/serialization/NullPrototypeObjectSerializer.js +26 -8
  418. package/lib/serialization/ObjectMiddleware.js +96 -66
  419. package/lib/serialization/PlainObjectSerializer.js +51 -14
  420. package/lib/serialization/RegExpObjectSerializer.js +17 -5
  421. package/lib/serialization/Serializer.js +23 -5
  422. package/lib/serialization/SerializerMiddleware.js +8 -8
  423. package/lib/serialization/SetObjectSerializer.js +22 -6
  424. package/lib/serialization/SingleItemMiddleware.js +2 -2
  425. package/lib/serialization/types.js +2 -2
  426. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  427. package/lib/sharing/ConsumeSharedModule.js +40 -17
  428. package/lib/sharing/ConsumeSharedPlugin.js +139 -102
  429. package/lib/sharing/ConsumeSharedRuntimeModule.js +144 -130
  430. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  431. package/lib/sharing/ProvideSharedDependency.js +17 -0
  432. package/lib/sharing/ProvideSharedModule.js +19 -6
  433. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  434. package/lib/sharing/ProvideSharedPlugin.js +37 -30
  435. package/lib/sharing/SharePlugin.js +2 -2
  436. package/lib/sharing/ShareRuntimeModule.js +20 -10
  437. package/lib/sharing/resolveMatchedConfigs.js +6 -5
  438. package/lib/sharing/utils.js +338 -34
  439. package/lib/stats/DefaultStatsFactoryPlugin.js +660 -396
  440. package/lib/stats/DefaultStatsPresetPlugin.js +85 -25
  441. package/lib/stats/DefaultStatsPrinterPlugin.js +525 -145
  442. package/lib/stats/StatsFactory.js +128 -57
  443. package/lib/stats/StatsPrinter.js +77 -46
  444. package/lib/util/ArrayHelpers.js +35 -1
  445. package/lib/util/ArrayQueue.js +15 -22
  446. package/lib/util/AsyncQueue.js +37 -16
  447. package/lib/util/IterableHelpers.js +3 -4
  448. package/lib/util/LazyBucketSortedSet.js +60 -44
  449. package/lib/util/LazySet.js +11 -2
  450. package/lib/util/MapHelpers.js +17 -5
  451. package/lib/util/ParallelismFactorCalculator.js +11 -1
  452. package/lib/util/Queue.js +9 -3
  453. package/lib/util/Semaphore.js +4 -7
  454. package/lib/util/SetHelpers.js +5 -5
  455. package/lib/util/SortableSet.js +19 -6
  456. package/lib/util/StackedCacheMap.js +33 -3
  457. package/lib/util/StackedMap.js +1 -3
  458. package/lib/util/StringXor.js +46 -0
  459. package/lib/util/TupleQueue.js +9 -3
  460. package/lib/util/TupleSet.js +15 -5
  461. package/lib/util/URLAbsoluteSpecifier.js +8 -8
  462. package/lib/util/WeakTupleMap.js +70 -28
  463. package/lib/util/binarySearchBounds.js +51 -9
  464. package/lib/util/chainedImports.js +97 -0
  465. package/lib/util/cleverMerge.js +51 -36
  466. package/lib/util/comparators.js +146 -83
  467. package/lib/util/compileBooleanMatcher.js +35 -7
  468. package/lib/util/conventions.js +126 -0
  469. package/lib/util/create-schema-validation.js +9 -2
  470. package/lib/util/createHash.js +49 -14
  471. package/lib/util/deprecation.js +48 -15
  472. package/lib/util/deterministicGrouping.js +71 -39
  473. package/lib/util/extractUrlAndGlobal.js +3 -0
  474. package/lib/util/findGraphRoots.js +7 -5
  475. package/lib/util/fs.js +419 -94
  476. package/lib/util/hash/BatchedHash.js +10 -4
  477. package/lib/util/hash/md4.js +20 -0
  478. package/lib/util/hash/wasm-hash.js +163 -0
  479. package/lib/util/hash/xxhash64.js +7 -141
  480. package/lib/util/identifier.js +140 -93
  481. package/lib/util/internalSerializables.js +22 -0
  482. package/lib/util/makeSerializable.js +7 -0
  483. package/lib/util/memoize.js +10 -10
  484. package/lib/util/mergeScope.js +76 -0
  485. package/lib/util/nonNumericOnlyHash.js +22 -0
  486. package/lib/util/numberHash.js +84 -34
  487. package/lib/util/objectToMap.js +0 -1
  488. package/lib/util/processAsyncTree.js +7 -1
  489. package/lib/util/propertyAccess.js +7 -55
  490. package/lib/util/propertyName.js +77 -0
  491. package/lib/util/registerExternalSerializer.js +2 -2
  492. package/lib/util/runtime.js +188 -133
  493. package/lib/util/semver.js +64 -56
  494. package/lib/util/serialization.js +26 -1
  495. package/lib/util/smartGrouping.js +10 -10
  496. package/lib/util/source.js +1 -1
  497. package/lib/validateSchema.js +6 -2
  498. package/lib/wasm/EnableWasmLoadingPlugin.js +9 -4
  499. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +70 -30
  500. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  501. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +34 -16
  502. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +32 -12
  503. package/lib/wasm-async/AsyncWebAssemblyParser.js +17 -4
  504. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +72 -31
  505. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
  506. package/lib/wasm-sync/WebAssemblyGenerator.js +72 -52
  507. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -4
  508. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
  509. package/lib/wasm-sync/WebAssemblyParser.js +23 -9
  510. package/lib/wasm-sync/WebAssemblyUtils.js +5 -4
  511. package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
  512. package/lib/web/FetchCompileWasmPlugin.js +59 -42
  513. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  514. package/lib/web/JsonpChunkLoadingRuntimeModule.js +71 -41
  515. package/lib/webpack.js +43 -12
  516. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +15 -12
  517. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +55 -40
  518. package/module.d.ts +233 -0
  519. package/package.json +85 -139
  520. package/schemas/WebpackOptions.check.js +1 -1
  521. package/schemas/WebpackOptions.json +679 -47
  522. package/schemas/plugins/BannerPlugin.check.js +1 -1
  523. package/schemas/plugins/BannerPlugin.json +9 -1
  524. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  525. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  526. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  527. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  528. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  529. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  530. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  531. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  532. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  533. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  534. package/schemas/plugins/container/ContainerPlugin.json +10 -1
  535. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  536. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  537. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  538. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  539. package/schemas/plugins/container/ModuleFederationPlugin.json +12 -1
  540. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  541. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  542. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  543. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  544. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  545. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  546. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  547. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  548. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  549. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  550. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  551. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  552. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  553. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  554. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  555. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  556. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  557. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  558. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  559. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  560. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  561. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  562. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  563. package/schemas/plugins/css/CssParserOptions.json +3 -0
  564. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  565. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  566. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  567. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  568. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  569. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  570. package/types.d.ts +5026 -1756
package/lib/Compiler.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const parseJson = require("json-parse-better-errors");
8
+ const parseJson = require("json-parse-even-better-errors");
9
9
  const asyncLib = require("neo-async");
10
10
  const {
11
11
  SyncHook,
@@ -14,7 +14,7 @@ const {
14
14
  AsyncSeriesHook
15
15
  } = require("tapable");
16
16
  const { SizeOnlySource } = require("webpack-sources");
17
- const webpack = require("./");
17
+ const webpack = require(".");
18
18
  const Cache = require("./Cache");
19
19
  const CacheFacade = require("./CacheFacade");
20
20
  const ChunkGraph = require("./ChunkGraph");
@@ -40,37 +40,54 @@ const { isSourceEqual } = require("./util/source");
40
40
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
41
41
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
+ /** @typedef {import("./Compilation").References} References */
43
44
  /** @typedef {import("./Dependency")} Dependency */
44
45
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
45
46
  /** @typedef {import("./Module")} Module */
46
- /** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
47
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
48
+ /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
49
+ /** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
50
+ /** @typedef {import("./util/fs").IStats} IStats */
47
51
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
48
52
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
49
53
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
50
54
  /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
51
55
 
52
56
  /**
53
- * @typedef {Object} CompilationParams
57
+ * @template {any[]} T
58
+ * @template V
59
+ * @typedef {import("./util/WeakTupleMap")<T, V>} WeakTupleMap
60
+ */
61
+
62
+ /**
63
+ * @typedef {object} CompilationParams
54
64
  * @property {NormalModuleFactory} normalModuleFactory
55
65
  * @property {ContextModuleFactory} contextModuleFactory
56
66
  */
57
67
 
68
+ /**
69
+ * @template T
70
+ * @callback RunCallback
71
+ * @param {Error | null} err
72
+ * @param {T=} result
73
+ */
74
+
58
75
  /**
59
76
  * @template T
60
77
  * @callback Callback
61
- * @param {Error=} err
78
+ * @param {(Error | null)=} err
62
79
  * @param {T=} result
63
80
  */
64
81
 
65
82
  /**
66
83
  * @callback RunAsChildCallback
67
- * @param {Error=} err
84
+ * @param {Error | null} err
68
85
  * @param {Chunk[]=} entries
69
86
  * @param {Compilation=} compilation
70
87
  */
71
88
 
72
89
  /**
73
- * @typedef {Object} AssetEmittedInfo
90
+ * @typedef {object} AssetEmittedInfo
74
91
  * @property {Buffer} content
75
92
  * @property {Source} source
76
93
  * @property {Compilation} compilation
@@ -78,6 +95,9 @@ const { isSourceEqual } = require("./util/source");
78
95
  * @property {string} targetPath
79
96
  */
80
97
 
98
+ /** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
99
+ /** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: any, file: string }[] | undefined) }} SimilarEntry */
100
+
81
101
  /**
82
102
  * @param {string[]} array an array
83
103
  * @returns {boolean} true, if the array is sorted
@@ -90,11 +110,12 @@ const isSorted = array => {
90
110
  };
91
111
 
92
112
  /**
93
- * @param {Object} obj an object
113
+ * @param {{[key: string]: any}} obj an object
94
114
  * @param {string[]} keys the keys of the object
95
- * @returns {Object} the object with properties sorted by property name
115
+ * @returns {{[key: string]: any}} the object with properties sorted by property name
96
116
  */
97
117
  const sortObject = (obj, keys) => {
118
+ /** @type {{[key: string]: any}} */
98
119
  const o = {};
99
120
  for (const k of keys.sort()) {
100
121
  o[k] = obj[k];
@@ -111,21 +132,21 @@ const includesHash = (filename, hashes) => {
111
132
  if (!hashes) return false;
112
133
  if (Array.isArray(hashes)) {
113
134
  return hashes.some(hash => filename.includes(hash));
114
- } else {
115
- return filename.includes(hashes);
116
135
  }
136
+ return filename.includes(hashes);
117
137
  };
118
138
 
119
139
  class Compiler {
120
140
  /**
121
141
  * @param {string} context the compilation path
142
+ * @param {WebpackOptions} options options
122
143
  */
123
- constructor(context) {
144
+ constructor(context, options = /** @type {WebpackOptions} */ ({})) {
124
145
  this.hooks = Object.freeze({
125
146
  /** @type {SyncHook<[]>} */
126
147
  initialize: new SyncHook([]),
127
148
 
128
- /** @type {SyncBailHook<[Compilation], boolean>} */
149
+ /** @type {SyncBailHook<[Compilation], boolean | undefined>} */
129
150
  shouldEmit: new SyncBailHook(["compilation"]),
130
151
  /** @type {AsyncSeriesHook<[Stats]>} */
131
152
  done: new AsyncSeriesHook(["stats"]),
@@ -164,6 +185,11 @@ class Compiler {
164
185
  /** @type {AsyncSeriesHook<[Compilation]>} */
165
186
  afterCompile: new AsyncSeriesHook(["compilation"]),
166
187
 
188
+ /** @type {AsyncSeriesHook<[]>} */
189
+ readRecords: new AsyncSeriesHook([]),
190
+ /** @type {AsyncSeriesHook<[]>} */
191
+ emitRecords: new AsyncSeriesHook([]),
192
+
167
193
  /** @type {AsyncSeriesHook<[Compiler]>} */
168
194
  watchRun: new AsyncSeriesHook(["compiler"]),
169
195
  /** @type {SyncHook<[Error]>} */
@@ -175,7 +201,7 @@ class Compiler {
175
201
  /** @type {AsyncSeriesHook<[]>} */
176
202
  shutdown: new AsyncSeriesHook([]),
177
203
 
178
- /** @type {SyncBailHook<[string, string, any[]], true>} */
204
+ /** @type {SyncBailHook<[string, string, any[] | undefined], true>} */
179
205
  infrastructureLog: new SyncBailHook(["origin", "type", "args"]),
180
206
 
181
207
  // TODO the following hooks are weirdly located here
@@ -194,54 +220,67 @@ class Compiler {
194
220
 
195
221
  this.webpack = webpack;
196
222
 
197
- /** @type {string=} */
223
+ /** @type {string | undefined} */
198
224
  this.name = undefined;
199
- /** @type {Compilation=} */
225
+ /** @type {Compilation | undefined} */
200
226
  this.parentCompilation = undefined;
201
227
  /** @type {Compiler} */
202
228
  this.root = this;
203
229
  /** @type {string} */
204
230
  this.outputPath = "";
205
- /** @type {Watching} */
231
+ /** @type {Watching | undefined} */
206
232
  this.watching = undefined;
207
233
 
208
- /** @type {OutputFileSystem} */
234
+ /** @type {OutputFileSystem | null} */
209
235
  this.outputFileSystem = null;
210
- /** @type {IntermediateFileSystem} */
236
+ /** @type {IntermediateFileSystem | null} */
211
237
  this.intermediateFileSystem = null;
212
- /** @type {InputFileSystem} */
238
+ /** @type {InputFileSystem | null} */
213
239
  this.inputFileSystem = null;
214
- /** @type {WatchFileSystem} */
240
+ /** @type {WatchFileSystem | null} */
215
241
  this.watchFileSystem = null;
216
242
 
217
243
  /** @type {string|null} */
218
244
  this.recordsInputPath = null;
219
245
  /** @type {string|null} */
220
246
  this.recordsOutputPath = null;
247
+ /** @type {Record<string, TODO>} */
221
248
  this.records = {};
222
249
  /** @type {Set<string | RegExp>} */
223
250
  this.managedPaths = new Set();
224
251
  /** @type {Set<string | RegExp>} */
252
+ this.unmanagedPaths = new Set();
253
+ /** @type {Set<string | RegExp>} */
225
254
  this.immutablePaths = new Set();
226
255
 
227
- /** @type {ReadonlySet<string>} */
256
+ /** @type {ReadonlySet<string> | undefined} */
228
257
  this.modifiedFiles = undefined;
229
- /** @type {ReadonlySet<string>} */
258
+ /** @type {ReadonlySet<string> | undefined} */
230
259
  this.removedFiles = undefined;
231
- /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
260
+ /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
232
261
  this.fileTimestamps = undefined;
233
- /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
262
+ /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
234
263
  this.contextTimestamps = undefined;
235
- /** @type {number} */
264
+ /** @type {number | undefined} */
236
265
  this.fsStartTime = undefined;
237
266
 
238
267
  /** @type {ResolverFactory} */
239
268
  this.resolverFactory = new ResolverFactory();
240
269
 
270
+ /** @type {LoggingFunction | undefined} */
241
271
  this.infrastructureLogger = undefined;
242
272
 
243
- /** @type {WebpackOptions} */
244
- this.options = /** @type {WebpackOptions} */ ({});
273
+ /** @type {Readonly<PlatformTargetProperties>} */
274
+ this.platform = {
275
+ web: null,
276
+ browser: null,
277
+ webworker: null,
278
+ node: null,
279
+ nwjs: null,
280
+ electron: null
281
+ };
282
+
283
+ this.options = options;
245
284
 
246
285
  this.context = context;
247
286
 
@@ -249,7 +288,7 @@ class Compiler {
249
288
 
250
289
  this.cache = new Cache();
251
290
 
252
- /** @type {Map<Module, { buildInfo: object, references: WeakMap<Dependency, Module>, memCache: WeakTupleMap }> | undefined} */
291
+ /** @type {Map<Module, { buildInfo: BuildInfo, references: References | undefined, memCache: WeakTupleMap<any, any> }> | undefined} */
253
292
  this.moduleMemCaches = undefined;
254
293
 
255
294
  this.compilerPath = "";
@@ -263,16 +302,27 @@ class Compiler {
263
302
  /** @type {boolean} */
264
303
  this.watchMode = false;
265
304
 
266
- /** @type {Compilation} */
305
+ this._backCompat = this.options.experiments.backCompat !== false;
306
+
307
+ /** @type {Compilation | undefined} */
267
308
  this._lastCompilation = undefined;
268
- /** @type {NormalModuleFactory} */
309
+ /** @type {NormalModuleFactory | undefined} */
269
310
  this._lastNormalModuleFactory = undefined;
270
311
 
271
- /** @private @type {WeakMap<Source, { sizeOnlySource: SizeOnlySource, writtenTo: Map<string, number> }>} */
312
+ /**
313
+ * @private
314
+ * @type {WeakMap<Source, CacheEntry>}
315
+ */
272
316
  this._assetEmittingSourceCache = new WeakMap();
273
- /** @private @type {Map<string, number>} */
317
+ /**
318
+ * @private
319
+ * @type {Map<string, number>}
320
+ */
274
321
  this._assetEmittingWrittenFiles = new Map();
275
- /** @private @type {Set<string>} */
322
+ /**
323
+ * @private
324
+ * @type {Set<string>}
325
+ */
276
326
  this._assetEmittingPreviousFiles = new Set();
277
327
  }
278
328
 
@@ -308,10 +358,11 @@ class Compiler {
308
358
  );
309
359
  }
310
360
  }
311
- if (this.hooks.infrastructureLog.call(name, type, args) === undefined) {
312
- if (this.infrastructureLogger !== undefined) {
313
- this.infrastructureLogger(name, type, args);
314
- }
361
+ if (
362
+ this.hooks.infrastructureLog.call(name, type, args) === undefined &&
363
+ this.infrastructureLogger !== undefined
364
+ ) {
365
+ this.infrastructureLogger(name, type, args);
315
366
  }
316
367
  },
317
368
  childName => {
@@ -336,36 +387,33 @@ class Compiler {
336
387
  }
337
388
  return `${name}/${childName}`;
338
389
  });
339
- } else {
340
- return this.getInfrastructureLogger(() => {
341
- if (typeof name === "function") {
342
- name = name();
343
- if (!name) {
344
- throw new TypeError(
345
- "Compiler.getInfrastructureLogger(name) called with a function not returning a name"
346
- );
347
- }
348
- }
349
- return `${name}/${childName}`;
350
- });
351
390
  }
352
- } else {
353
- if (typeof childName === "function") {
354
- return this.getInfrastructureLogger(() => {
355
- if (typeof childName === "function") {
356
- childName = childName();
357
- if (!childName) {
358
- throw new TypeError(
359
- "Logger.getChildLogger(name) called with a function not returning a name"
360
- );
361
- }
391
+ return this.getInfrastructureLogger(() => {
392
+ if (typeof name === "function") {
393
+ name = name();
394
+ if (!name) {
395
+ throw new TypeError(
396
+ "Compiler.getInfrastructureLogger(name) called with a function not returning a name"
397
+ );
362
398
  }
363
- return `${name}/${childName}`;
364
- });
365
- } else {
366
- return this.getInfrastructureLogger(`${name}/${childName}`);
367
- }
399
+ }
400
+ return `${name}/${childName}`;
401
+ });
368
402
  }
403
+ if (typeof childName === "function") {
404
+ return this.getInfrastructureLogger(() => {
405
+ if (typeof childName === "function") {
406
+ childName = childName();
407
+ if (!childName) {
408
+ throw new TypeError(
409
+ "Logger.getChildLogger(name) called with a function not returning a name"
410
+ );
411
+ }
412
+ }
413
+ return `${name}/${childName}`;
414
+ });
415
+ }
416
+ return this.getInfrastructureLogger(`${name}/${childName}`);
369
417
  }
370
418
  );
371
419
  }
@@ -374,6 +422,17 @@ class Compiler {
374
422
  // e.g. move compilation specific info from Modules into ModuleGraph
375
423
  _cleanupLastCompilation() {
376
424
  if (this._lastCompilation !== undefined) {
425
+ for (const childCompilation of this._lastCompilation.children) {
426
+ for (const module of childCompilation.modules) {
427
+ ChunkGraph.clearChunkGraphForModule(module);
428
+ ModuleGraph.clearModuleGraphForModule(module);
429
+ module.cleanupForCache();
430
+ }
431
+ for (const chunk of childCompilation.chunks) {
432
+ ChunkGraph.clearChunkGraphForChunk(chunk);
433
+ }
434
+ }
435
+
377
436
  for (const module of this._lastCompilation.modules) {
378
437
  ChunkGraph.clearChunkGraphForModule(module);
379
438
  ModuleGraph.clearModuleGraphForModule(module);
@@ -396,7 +455,7 @@ class Compiler {
396
455
 
397
456
  /**
398
457
  * @param {WatchOptions} watchOptions the watcher's options
399
- * @param {Callback<Stats>} handler signals when the call finishes
458
+ * @param {RunCallback<Stats>} handler signals when the call finishes
400
459
  * @returns {Watching} a compiler watcher
401
460
  */
402
461
  watch(watchOptions, handler) {
@@ -411,7 +470,7 @@ class Compiler {
411
470
  }
412
471
 
413
472
  /**
414
- * @param {Callback<Stats>} callback signals when the call finishes
473
+ * @param {RunCallback<Stats>} callback signals when the call finishes
415
474
  * @returns {void}
416
475
  */
417
476
  run(callback) {
@@ -419,8 +478,13 @@ class Compiler {
419
478
  return callback(new ConcurrentCompilationError());
420
479
  }
421
480
 
481
+ /** @type {Logger | undefined} */
422
482
  let logger;
423
483
 
484
+ /**
485
+ * @param {Error | null} err error
486
+ * @param {Stats=} stats stats
487
+ */
424
488
  const finalCallback = (err, stats) => {
425
489
  if (logger) logger.time("beginIdle");
426
490
  this.idle = true;
@@ -432,16 +496,23 @@ class Compiler {
432
496
  this.hooks.failed.call(err);
433
497
  }
434
498
  if (callback !== undefined) callback(err, stats);
435
- this.hooks.afterDone.call(stats);
499
+ this.hooks.afterDone.call(/** @type {Stats} */ (stats));
436
500
  };
437
501
 
438
502
  const startTime = Date.now();
439
503
 
440
504
  this.running = true;
441
505
 
442
- const onCompiled = (err, compilation) => {
506
+ /**
507
+ * @param {Error | null} err error
508
+ * @param {Compilation=} _compilation compilation
509
+ * @returns {void}
510
+ */
511
+ const onCompiled = (err, _compilation) => {
443
512
  if (err) return finalCallback(err);
444
513
 
514
+ const compilation = /** @type {Compilation} */ (_compilation);
515
+
445
516
  if (this.hooks.shouldEmit.call(compilation) === false) {
446
517
  compilation.startTime = startTime;
447
518
  compilation.endTime = Date.now();
@@ -457,7 +528,8 @@ class Compiler {
457
528
  logger = compilation.getLogger("webpack.Compiler");
458
529
  logger.time("emitAssets");
459
530
  this.emitAssets(compilation, err => {
460
- logger.timeEnd("emitAssets");
531
+ /** @type {Logger} */
532
+ (logger).timeEnd("emitAssets");
461
533
  if (err) return finalCallback(err);
462
534
 
463
535
  if (compilation.hooks.needAdditionalPass.call()) {
@@ -465,10 +537,12 @@ class Compiler {
465
537
 
466
538
  compilation.startTime = startTime;
467
539
  compilation.endTime = Date.now();
468
- logger.time("done hook");
540
+ /** @type {Logger} */
541
+ (logger).time("done hook");
469
542
  const stats = new Stats(compilation);
470
543
  this.hooks.done.callAsync(stats, err => {
471
- logger.timeEnd("done hook");
544
+ /** @type {Logger} */
545
+ (logger).timeEnd("done hook");
472
546
  if (err) return finalCallback(err);
473
547
 
474
548
  this.hooks.additionalPass.callAsync(err => {
@@ -479,17 +553,21 @@ class Compiler {
479
553
  return;
480
554
  }
481
555
 
482
- logger.time("emitRecords");
556
+ /** @type {Logger} */
557
+ (logger).time("emitRecords");
483
558
  this.emitRecords(err => {
484
- logger.timeEnd("emitRecords");
559
+ /** @type {Logger} */
560
+ (logger).timeEnd("emitRecords");
485
561
  if (err) return finalCallback(err);
486
562
 
487
563
  compilation.startTime = startTime;
488
564
  compilation.endTime = Date.now();
489
- logger.time("done hook");
565
+ /** @type {Logger} */
566
+ (logger).time("done hook");
490
567
  const stats = new Stats(compilation);
491
568
  this.hooks.done.callAsync(stats, err => {
492
- logger.timeEnd("done hook");
569
+ /** @type {Logger} */
570
+ (logger).timeEnd("done hook");
493
571
  if (err) return finalCallback(err);
494
572
  this.cache.storeBuildDependencies(
495
573
  compilation.buildDependencies,
@@ -538,15 +616,42 @@ class Compiler {
538
616
  */
539
617
  runAsChild(callback) {
540
618
  const startTime = Date.now();
541
- this.compile((err, compilation) => {
542
- if (err) return callback(err);
543
619
 
544
- this.parentCompilation.children.push(compilation);
620
+ /**
621
+ * @param {Error | null} err error
622
+ * @param {Chunk[]=} entries entries
623
+ * @param {Compilation=} compilation compilation
624
+ */
625
+ const finalCallback = (err, entries, compilation) => {
626
+ try {
627
+ callback(err, entries, compilation);
628
+ } catch (runAsChildErr) {
629
+ const err = new WebpackError(
630
+ `compiler.runAsChild callback error: ${runAsChildErr}`
631
+ );
632
+ err.details = /** @type {Error} */ (runAsChildErr).stack;
633
+ /** @type {Compilation} */
634
+ (this.parentCompilation).errors.push(err);
635
+ }
636
+ };
637
+
638
+ this.compile((err, _compilation) => {
639
+ if (err) return finalCallback(err);
640
+
641
+ const compilation = /** @type {Compilation} */ (_compilation);
642
+ const parentCompilation = /** @type {Compilation} */ (
643
+ this.parentCompilation
644
+ );
645
+
646
+ parentCompilation.children.push(compilation);
647
+
545
648
  for (const { name, source, info } of compilation.getAssets()) {
546
- this.parentCompilation.emitAsset(name, source, info);
649
+ parentCompilation.emitAsset(name, source, info);
547
650
  }
548
651
 
652
+ /** @type {Chunk[]} */
549
653
  const entries = [];
654
+
550
655
  for (const ep of compilation.entrypoints.values()) {
551
656
  entries.push(...ep.chunks);
552
657
  }
@@ -554,7 +659,7 @@ class Compiler {
554
659
  compilation.startTime = startTime;
555
660
  compilation.endTime = Date.now();
556
661
 
557
- return callback(null, entries, compilation);
662
+ return finalCallback(null, entries, compilation);
558
663
  });
559
664
  }
560
665
 
@@ -570,14 +675,19 @@ class Compiler {
570
675
  * @returns {void}
571
676
  */
572
677
  emitAssets(compilation, callback) {
678
+ /** @type {string} */
573
679
  let outputPath;
574
680
 
681
+ /**
682
+ * @param {Error=} err error
683
+ * @returns {void}
684
+ */
575
685
  const emitFiles = err => {
576
686
  if (err) return callback(err);
577
687
 
578
688
  const assets = compilation.getAssets();
579
689
  compilation.assets = { ...compilation.assets };
580
- /** @type {Map<string, { path: string, source: Source, size: number, waiting: { cacheEntry: any, file: string }[] }>} */
690
+ /** @type {Map<string, SimilarEntry>} */
581
691
  const caseInsensitiveMap = new Map();
582
692
  /** @type {Set<string>} */
583
693
  const allTargetPaths = new Set();
@@ -589,7 +699,7 @@ class Compiler {
589
699
  let immutable = info.immutable;
590
700
  const queryStringIdx = targetFile.indexOf("?");
591
701
  if (queryStringIdx >= 0) {
592
- targetFile = targetFile.substr(0, queryStringIdx);
702
+ targetFile = targetFile.slice(0, queryStringIdx);
593
703
  // We may remove the hash, which is in the query string
594
704
  // So we recheck if the file is immutable
595
705
  // This doesn't cover all cases, but immutable is only a performance optimization anyway
@@ -601,10 +711,15 @@ class Compiler {
601
711
  includesHash(targetFile, info.fullhash));
602
712
  }
603
713
 
714
+ /**
715
+ * @param {Error=} err error
716
+ * @returns {void}
717
+ */
604
718
  const writeOut = err => {
605
719
  if (err) return callback(err);
606
720
  const targetPath = join(
607
- this.outputFileSystem,
721
+ /** @type {OutputFileSystem} */
722
+ (this.outputFileSystem),
608
723
  outputPath,
609
724
  targetFile
610
725
  );
@@ -624,6 +739,7 @@ class Compiler {
624
739
  this._assetEmittingSourceCache.set(source, cacheEntry);
625
740
  }
626
741
 
742
+ /** @type {SimilarEntry | undefined} */
627
743
  let similarEntry;
628
744
 
629
745
  const checkSimilarFile = () => {
@@ -651,18 +767,17 @@ ${other}`);
651
767
  callback(err);
652
768
  }
653
769
  return true;
654
- } else {
655
- caseInsensitiveMap.set(
656
- caseInsensitiveTargetPath,
657
- (similarEntry = {
658
- path: targetPath,
659
- source,
660
- size: undefined,
661
- waiting: undefined
662
- })
663
- );
664
- return false;
665
770
  }
771
+ caseInsensitiveMap.set(
772
+ caseInsensitiveTargetPath,
773
+ (similarEntry = /** @type {SimilarEntry} */ ({
774
+ path: targetPath,
775
+ source,
776
+ size: undefined,
777
+ waiting: undefined
778
+ }))
779
+ );
780
+ return false;
666
781
  };
667
782
 
668
783
  /**
@@ -672,14 +787,12 @@ ${other}`);
672
787
  const getContent = () => {
673
788
  if (typeof source.buffer === "function") {
674
789
  return source.buffer();
675
- } else {
676
- const bufferOrString = source.source();
677
- if (Buffer.isBuffer(bufferOrString)) {
678
- return bufferOrString;
679
- } else {
680
- return Buffer.from(bufferOrString, "utf8");
681
- }
682
790
  }
791
+ const bufferOrString = source.source();
792
+ if (Buffer.isBuffer(bufferOrString)) {
793
+ return bufferOrString;
794
+ }
795
+ return Buffer.from(bufferOrString, "utf8");
683
796
  };
684
797
 
685
798
  const alreadyWritten = () => {
@@ -687,9 +800,11 @@ ${other}`);
687
800
  if (targetFileGeneration === undefined) {
688
801
  const newGeneration = 1;
689
802
  this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
690
- cacheEntry.writtenTo.set(targetPath, newGeneration);
803
+ /** @type {CacheEntry} */
804
+ (cacheEntry).writtenTo.set(targetPath, newGeneration);
691
805
  } else {
692
- cacheEntry.writtenTo.set(targetPath, targetFileGeneration);
806
+ /** @type {CacheEntry} */
807
+ (cacheEntry).writtenTo.set(targetPath, targetFileGeneration);
693
808
  }
694
809
  callback();
695
810
  };
@@ -700,7 +815,8 @@ ${other}`);
700
815
  * @returns {void}
701
816
  */
702
817
  const doWrite = content => {
703
- this.outputFileSystem.writeFile(targetPath, content, err => {
818
+ /** @type {OutputFileSystem} */
819
+ (this.outputFileSystem).writeFile(targetPath, content, err => {
704
820
  if (err) return callback(err);
705
821
 
706
822
  // information marker that the asset has been emitted
@@ -711,7 +827,8 @@ ${other}`);
711
827
  targetFileGeneration === undefined
712
828
  ? 1
713
829
  : targetFileGeneration + 1;
714
- cacheEntry.writtenTo.set(targetPath, newGeneration);
830
+ /** @type {CacheEntry} */
831
+ (cacheEntry).writtenTo.set(targetPath, newGeneration);
715
832
  this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
716
833
  this.hooks.assetEmitted.callAsync(
717
834
  file,
@@ -727,16 +844,33 @@ ${other}`);
727
844
  });
728
845
  };
729
846
 
847
+ /**
848
+ * @param {number} size size
849
+ */
730
850
  const updateWithReplacementSource = size => {
731
- updateFileWithReplacementSource(file, cacheEntry, size);
732
- similarEntry.size = size;
733
- if (similarEntry.waiting !== undefined) {
734
- for (const { file, cacheEntry } of similarEntry.waiting) {
851
+ updateFileWithReplacementSource(
852
+ file,
853
+ /** @type {CacheEntry} */ (cacheEntry),
854
+ size
855
+ );
856
+ /** @type {SimilarEntry} */
857
+ (similarEntry).size = size;
858
+ if (
859
+ /** @type {SimilarEntry} */ (similarEntry).waiting !== undefined
860
+ ) {
861
+ for (const { file, cacheEntry } of /** @type {SimilarEntry} */ (
862
+ similarEntry
863
+ ).waiting) {
735
864
  updateFileWithReplacementSource(file, cacheEntry, size);
736
865
  }
737
866
  }
738
867
  };
739
868
 
869
+ /**
870
+ * @param {string} file file
871
+ * @param {CacheEntry} cacheEntry cache entry
872
+ * @param {number} size size
873
+ */
740
874
  const updateFileWithReplacementSource = (
741
875
  file,
742
876
  cacheEntry,
@@ -753,10 +887,14 @@ ${other}`);
753
887
  });
754
888
  };
755
889
 
890
+ /**
891
+ * @param {IStats} stats stats
892
+ * @returns {void}
893
+ */
756
894
  const processExistingFile = stats => {
757
895
  // skip emitting if it's already there and an immutable file
758
896
  if (immutable) {
759
- updateWithReplacementSource(stats.size);
897
+ updateWithReplacementSource(/** @type {number} */ (stats.size));
760
898
  return alreadyWritten();
761
899
  }
762
900
 
@@ -770,19 +908,17 @@ ${other}`);
770
908
  // for a fast negative match file size is compared first
771
909
  if (content.length === stats.size) {
772
910
  compilation.comparedForEmitAssets.add(file);
773
- return this.outputFileSystem.readFile(
774
- targetPath,
775
- (err, existingContent) => {
776
- if (
777
- err ||
778
- !content.equals(/** @type {Buffer} */ (existingContent))
779
- ) {
780
- return doWrite(content);
781
- } else {
782
- return alreadyWritten();
783
- }
911
+ return /** @type {OutputFileSystem} */ (
912
+ this.outputFileSystem
913
+ ).readFile(targetPath, (err, existingContent) => {
914
+ if (
915
+ err ||
916
+ !content.equals(/** @type {Buffer} */ (existingContent))
917
+ ) {
918
+ return doWrite(content);
784
919
  }
785
- );
920
+ return alreadyWritten();
921
+ });
786
922
  }
787
923
 
788
924
  return doWrite(content);
@@ -799,23 +935,28 @@ ${other}`);
799
935
  // if the target file has already been written
800
936
  if (targetFileGeneration !== undefined) {
801
937
  // check if the Source has been written to this target file
802
- const writtenGeneration = cacheEntry.writtenTo.get(targetPath);
938
+ const writtenGeneration = /** @type {CacheEntry} */ (
939
+ cacheEntry
940
+ ).writtenTo.get(targetPath);
803
941
  if (writtenGeneration === targetFileGeneration) {
804
942
  // if yes, we may skip writing the file
805
943
  // if it's already there
806
944
  // (we assume one doesn't modify files while the Compiler is running, other then removing them)
807
945
 
808
946
  if (this._assetEmittingPreviousFiles.has(targetPath)) {
947
+ const sizeOnlySource = /** @type {SizeOnlySource} */ (
948
+ /** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
949
+ );
950
+
809
951
  // We assume that assets from the last compilation say intact on disk (they are not removed)
810
- compilation.updateAsset(file, cacheEntry.sizeOnlySource, {
811
- size: cacheEntry.sizeOnlySource.size()
952
+ compilation.updateAsset(file, sizeOnlySource, {
953
+ size: sizeOnlySource.size()
812
954
  });
813
955
 
814
956
  return callback();
815
- } else {
816
- // Settings immutable will make it accept file content without comparing when file exist
817
- immutable = true;
818
957
  }
958
+ // Settings immutable will make it accept file content without comparing when file exist
959
+ immutable = true;
819
960
  } else if (!immutable) {
820
961
  if (checkSimilarFile()) return;
821
962
  // We wrote to this file before which has very likely a different content
@@ -827,11 +968,12 @@ ${other}`);
827
968
 
828
969
  if (checkSimilarFile()) return;
829
970
  if (this.options.output.compareBeforeEmit) {
830
- this.outputFileSystem.stat(targetPath, (err, stats) => {
831
- const exists = !err && stats.isFile();
971
+ /** @type {OutputFileSystem} */
972
+ (this.outputFileSystem).stat(targetPath, (err, stats) => {
973
+ const exists = !err && /** @type {IStats} */ (stats).isFile();
832
974
 
833
975
  if (exists) {
834
- processExistingFile(stats);
976
+ processExistingFile(/** @type {IStats} */ (stats));
835
977
  } else {
836
978
  processMissingFile();
837
979
  }
@@ -841,8 +983,8 @@ ${other}`);
841
983
  }
842
984
  };
843
985
 
844
- if (targetFile.match(/\/|\\/)) {
845
- const fs = this.outputFileSystem;
986
+ if (/\/|\\/.test(targetFile)) {
987
+ const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
846
988
  const dir = dirname(fs, join(fs, outputPath, targetFile));
847
989
  mkdirp(fs, dir, writeOut);
848
990
  } else {
@@ -871,7 +1013,11 @@ ${other}`);
871
1013
  this.hooks.emit.callAsync(compilation, err => {
872
1014
  if (err) return callback(err);
873
1015
  outputPath = compilation.getPath(this.outputPath, {});
874
- mkdirp(this.outputFileSystem, outputPath, emitFiles);
1016
+ mkdirp(
1017
+ /** @type {OutputFileSystem} */ (this.outputFileSystem),
1018
+ outputPath,
1019
+ emitFiles
1020
+ );
875
1021
  });
876
1022
  }
877
1023
 
@@ -880,11 +1026,34 @@ ${other}`);
880
1026
  * @returns {void}
881
1027
  */
882
1028
  emitRecords(callback) {
883
- if (!this.recordsOutputPath) return callback();
1029
+ if (this.hooks.emitRecords.isUsed()) {
1030
+ if (this.recordsOutputPath) {
1031
+ asyncLib.parallel(
1032
+ [
1033
+ cb => this.hooks.emitRecords.callAsync(cb),
1034
+ this._emitRecords.bind(this)
1035
+ ],
1036
+ err => callback(err)
1037
+ );
1038
+ } else {
1039
+ this.hooks.emitRecords.callAsync(callback);
1040
+ }
1041
+ } else if (this.recordsOutputPath) {
1042
+ this._emitRecords(callback);
1043
+ } else {
1044
+ callback();
1045
+ }
1046
+ }
884
1047
 
1048
+ /**
1049
+ * @param {Callback<void>} callback signals when the call finishes
1050
+ * @returns {void}
1051
+ */
1052
+ _emitRecords(callback) {
885
1053
  const writeFile = () => {
886
- this.outputFileSystem.writeFile(
887
- this.recordsOutputPath,
1054
+ /** @type {OutputFileSystem} */
1055
+ (this.outputFileSystem).writeFile(
1056
+ /** @type {string} */ (this.recordsOutputPath),
888
1057
  JSON.stringify(
889
1058
  this.records,
890
1059
  (n, value) => {
@@ -907,16 +1076,20 @@ ${other}`);
907
1076
  };
908
1077
 
909
1078
  const recordsOutputPathDirectory = dirname(
910
- this.outputFileSystem,
911
- this.recordsOutputPath
1079
+ /** @type {OutputFileSystem} */ (this.outputFileSystem),
1080
+ /** @type {string} */ (this.recordsOutputPath)
912
1081
  );
913
1082
  if (!recordsOutputPathDirectory) {
914
1083
  return writeFile();
915
1084
  }
916
- mkdirp(this.outputFileSystem, recordsOutputPathDirectory, err => {
917
- if (err) return callback(err);
918
- writeFile();
919
- });
1085
+ mkdirp(
1086
+ /** @type {OutputFileSystem} */ (this.outputFileSystem),
1087
+ recordsOutputPathDirectory,
1088
+ err => {
1089
+ if (err) return callback(err);
1090
+ writeFile();
1091
+ }
1092
+ );
920
1093
  }
921
1094
 
922
1095
  /**
@@ -924,27 +1097,63 @@ ${other}`);
924
1097
  * @returns {void}
925
1098
  */
926
1099
  readRecords(callback) {
1100
+ if (this.hooks.readRecords.isUsed()) {
1101
+ if (this.recordsInputPath) {
1102
+ asyncLib.parallel(
1103
+ [
1104
+ cb => this.hooks.readRecords.callAsync(cb),
1105
+ this._readRecords.bind(this)
1106
+ ],
1107
+ err => callback(err)
1108
+ );
1109
+ } else {
1110
+ this.records = {};
1111
+ this.hooks.readRecords.callAsync(callback);
1112
+ }
1113
+ } else if (this.recordsInputPath) {
1114
+ this._readRecords(callback);
1115
+ } else {
1116
+ this.records = {};
1117
+ callback();
1118
+ }
1119
+ }
1120
+
1121
+ /**
1122
+ * @param {Callback<void>} callback signals when the call finishes
1123
+ * @returns {void}
1124
+ */
1125
+ _readRecords(callback) {
927
1126
  if (!this.recordsInputPath) {
928
1127
  this.records = {};
929
1128
  return callback();
930
1129
  }
931
- this.inputFileSystem.stat(this.recordsInputPath, err => {
1130
+ /** @type {InputFileSystem} */
1131
+ (this.inputFileSystem).stat(this.recordsInputPath, err => {
932
1132
  // It doesn't exist
933
1133
  // We can ignore this.
934
1134
  if (err) return callback();
935
1135
 
936
- this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => {
937
- if (err) return callback(err);
1136
+ /** @type {InputFileSystem} */
1137
+ (this.inputFileSystem).readFile(
1138
+ /** @type {string} */ (this.recordsInputPath),
1139
+ (err, content) => {
1140
+ if (err) return callback(err);
938
1141
 
939
- try {
940
- this.records = parseJson(content.toString("utf-8"));
941
- } catch (e) {
942
- e.message = "Cannot parse records: " + e.message;
943
- return callback(e);
944
- }
1142
+ try {
1143
+ this.records = parseJson(
1144
+ /** @type {Buffer} */ (content).toString("utf-8")
1145
+ );
1146
+ } catch (parseErr) {
1147
+ return callback(
1148
+ new Error(
1149
+ `Cannot parse records: ${/** @type {Error} */ (parseErr).message}`
1150
+ )
1151
+ );
1152
+ }
945
1153
 
946
- return callback();
947
- });
1154
+ return callback();
1155
+ }
1156
+ );
948
1157
  });
949
1158
  }
950
1159
 
@@ -963,7 +1172,13 @@ ${other}`);
963
1172
  outputOptions,
964
1173
  plugins
965
1174
  ) {
966
- const childCompiler = new Compiler(this.context);
1175
+ const childCompiler = new Compiler(this.context, {
1176
+ ...this.options,
1177
+ output: {
1178
+ ...this.options.output,
1179
+ ...outputOptions
1180
+ }
1181
+ });
967
1182
  childCompiler.name = compilerName;
968
1183
  childCompiler.outputPath = this.outputPath;
969
1184
  childCompiler.inputFileSystem = this.inputFileSystem;
@@ -976,6 +1191,7 @@ ${other}`);
976
1191
  childCompiler.fsStartTime = this.fsStartTime;
977
1192
  childCompiler.cache = this.cache;
978
1193
  childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`;
1194
+ childCompiler._backCompat = this._backCompat;
979
1195
 
980
1196
  const relativeCompilerName = makePathsRelative(
981
1197
  this.context,
@@ -991,18 +1207,13 @@ ${other}`);
991
1207
  this.records[relativeCompilerName].push((childCompiler.records = {}));
992
1208
  }
993
1209
 
994
- childCompiler.options = {
995
- ...this.options,
996
- output: {
997
- ...this.options.output,
998
- ...outputOptions
999
- }
1000
- };
1001
1210
  childCompiler.parentCompilation = compilation;
1002
1211
  childCompiler.root = this.root;
1003
1212
  if (Array.isArray(plugins)) {
1004
1213
  for (const plugin of plugins) {
1005
- plugin.apply(childCompiler);
1214
+ if (plugin) {
1215
+ plugin.apply(childCompiler);
1216
+ }
1006
1217
  }
1007
1218
  }
1008
1219
  for (const name in this.hooks) {
@@ -1015,11 +1226,17 @@ ${other}`);
1015
1226
  "invalid",
1016
1227
  "done",
1017
1228
  "thisCompilation"
1018
- ].includes(name)
1229
+ ].includes(name) &&
1230
+ childCompiler.hooks[/** @type {keyof Compiler["hooks"]} */ (name)]
1019
1231
  ) {
1020
- if (childCompiler.hooks[name]) {
1021
- childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
1022
- }
1232
+ childCompiler.hooks[
1233
+ /** @type {keyof Compiler["hooks"]} */
1234
+ (name)
1235
+ ].taps =
1236
+ this.hooks[
1237
+ /** @type {keyof Compiler["hooks"]} */
1238
+ (name)
1239
+ ].taps.slice();
1023
1240
  }
1024
1241
  }
1025
1242
 
@@ -1033,9 +1250,13 @@ ${other}`);
1033
1250
  }
1034
1251
 
1035
1252
  isChild() {
1036
- return !!this.parentCompilation;
1253
+ return Boolean(this.parentCompilation);
1037
1254
  }
1038
1255
 
1256
+ /**
1257
+ * @param {CompilationParams} params the compilation parameters
1258
+ * @returns {Compilation} compilation
1259
+ */
1039
1260
  createCompilation(params) {
1040
1261
  this._cleanupLastCompilation();
1041
1262
  return (this._lastCompilation = new Compilation(this, params));
@@ -1058,7 +1279,7 @@ ${other}`);
1058
1279
  this._cleanupLastNormalModuleFactory();
1059
1280
  const normalModuleFactory = new NormalModuleFactory({
1060
1281
  context: this.options.context,
1061
- fs: this.inputFileSystem,
1282
+ fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
1062
1283
  resolverFactory: this.resolverFactory,
1063
1284
  options: this.options.module,
1064
1285
  associatedObjectForCache: this.root,
@@ -1084,7 +1305,7 @@ ${other}`);
1084
1305
  }
1085
1306
 
1086
1307
  /**
1087
- * @param {Callback<Compilation>} callback signals when the compilation finishes
1308
+ * @param {RunCallback<Compilation>} callback signals when the compilation finishes
1088
1309
  * @returns {void}
1089
1310
  */
1090
1311
  compile(callback) {
@@ -1135,7 +1356,7 @@ ${other}`);
1135
1356
  }
1136
1357
 
1137
1358
  /**
1138
- * @param {Callback<void>} callback signals when the compiler closes
1359
+ * @param {RunCallback<void>} callback signals when the compiler closes
1139
1360
  * @returns {void}
1140
1361
  */
1141
1362
  close(callback) {