@depup/webpack 5.106.0-depup.0 → 5.109.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (667) hide show
  1. package/README.md +9 -11
  2. package/changes.json +16 -24
  3. package/hot/dev-server.js +2 -0
  4. package/lib/APIPlugin.js +60 -35
  5. package/lib/AsyncDependenciesBlock.js +3 -0
  6. package/lib/AutomaticPrefetchPlugin.js +6 -1
  7. package/lib/BannerPlugin.js +13 -5
  8. package/lib/Cache.js +27 -5
  9. package/lib/CacheFacade.js +41 -0
  10. package/lib/Chunk.js +71 -25
  11. package/lib/ChunkGraph.js +141 -9
  12. package/lib/ChunkGroup.js +115 -28
  13. package/lib/ChunkTemplate.js +9 -0
  14. package/lib/CircularModulesPlugin.js +190 -0
  15. package/lib/CleanPlugin.js +23 -26
  16. package/lib/CodeGenerationResults.js +19 -0
  17. package/lib/CompatibilityPlugin.js +54 -37
  18. package/lib/Compilation.js +635 -107
  19. package/lib/Compiler.js +93 -31
  20. package/lib/ConcatenationScope.js +34 -4
  21. package/lib/ConditionalInitFragment.js +6 -0
  22. package/lib/ConstPlugin.js +15 -12
  23. package/lib/ContextExclusionPlugin.js +3 -1
  24. package/lib/ContextModule.js +345 -55
  25. package/lib/ContextModuleFactory.js +193 -51
  26. package/lib/ContextReplacementPlugin.js +8 -1
  27. package/lib/DefinePlugin.js +498 -127
  28. package/lib/DependenciesBlock.js +6 -1
  29. package/lib/Dependency.js +159 -11
  30. package/lib/DependencyTemplate.js +7 -1
  31. package/lib/DependencyTemplates.js +4 -0
  32. package/lib/DotenvPlugin.js +3 -0
  33. package/lib/DynamicEntryPlugin.js +3 -1
  34. package/lib/EntryOptionPlugin.js +42 -2
  35. package/lib/EntryPlugin.js +4 -1
  36. package/lib/Entrypoint.js +5 -1
  37. package/lib/EnvironmentPlugin.js +3 -2
  38. package/lib/ErrorHelpers.js +7 -0
  39. package/lib/EvalDevToolModulePlugin.js +3 -1
  40. package/lib/EvalSourceMapDevToolPlugin.js +11 -11
  41. package/lib/ExportsInfo.js +399 -108
  42. package/lib/ExportsInfoApiPlugin.js +4 -3
  43. package/lib/ExternalModule.js +376 -78
  44. package/lib/ExternalModuleFactoryPlugin.js +75 -3
  45. package/lib/ExternalsPlugin.js +3 -1
  46. package/lib/FileSystemInfo.js +575 -149
  47. package/lib/FlagAllModulesAsUsedPlugin.js +3 -6
  48. package/lib/FlagDependencyExportsPlugin.js +82 -9
  49. package/lib/FlagDependencyUsagePlugin.js +92 -6
  50. package/lib/FlagEntryExportAsUsedPlugin.js +4 -1
  51. package/lib/Generator.js +24 -3
  52. package/lib/HotModuleReplacementPlugin.js +110 -44
  53. package/lib/IgnorePlugin.js +5 -2
  54. package/lib/IgnoreWarningsPlugin.js +2 -1
  55. package/lib/InitFragment.js +15 -0
  56. package/lib/JavascriptMetaInfoPlugin.js +9 -6
  57. package/lib/LazyBarrel.js +389 -0
  58. package/lib/LibraryTemplatePlugin.js +2 -1
  59. package/lib/LoaderOptionsPlugin.js +3 -1
  60. package/lib/LoaderTargetPlugin.js +3 -1
  61. package/lib/MainTemplate.js +15 -0
  62. package/lib/ManifestPlugin.js +9 -2
  63. package/lib/Module.js +121 -60
  64. package/lib/ModuleFactory.js +6 -1
  65. package/lib/ModuleFilenameHelpers.js +5 -2
  66. package/lib/ModuleGraph.js +69 -2
  67. package/lib/ModuleGraphConnection.js +9 -0
  68. package/lib/ModuleInfoHeaderPlugin.js +5 -0
  69. package/lib/ModuleNotFoundError.js +3 -83
  70. package/lib/ModuleProfile.js +27 -1
  71. package/lib/ModuleSourceTypeConstants.js +52 -19
  72. package/lib/ModuleTemplate.js +10 -0
  73. package/lib/ModuleTypeConstants.js +20 -4
  74. package/lib/MultiCompiler.js +59 -4
  75. package/lib/MultiStats.js +9 -0
  76. package/lib/MultiWatching.js +6 -0
  77. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  78. package/lib/NodeStuffPlugin.js +78 -46
  79. package/lib/NormalModule.js +485 -181
  80. package/lib/NormalModuleFactory.js +148 -29
  81. package/lib/NormalModuleReplacementPlugin.js +3 -1
  82. package/lib/NullFactory.js +1 -0
  83. package/lib/OptionsApply.js +1 -0
  84. package/lib/Parser.js +3 -1
  85. package/lib/PlatformPlugin.js +2 -1
  86. package/lib/PrefetchPlugin.js +4 -1
  87. package/lib/ProgressPlugin.js +351 -161
  88. package/lib/ProvidePlugin.js +6 -3
  89. package/lib/RawModule.js +32 -16
  90. package/lib/RecordIdsPlugin.js +9 -0
  91. package/lib/RequestShortener.js +8 -0
  92. package/lib/ResolverFactory.js +5 -0
  93. package/lib/RuntimeGlobals.js +58 -5
  94. package/lib/RuntimeModule.js +22 -7
  95. package/lib/RuntimePlugin.js +104 -26
  96. package/lib/RuntimeTemplate.js +616 -37
  97. package/lib/SelfModuleFactory.js +3 -0
  98. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
  99. package/lib/SourceMapDevToolPlugin.js +341 -63
  100. package/lib/Stats.js +6 -0
  101. package/lib/Template.js +29 -3
  102. package/lib/TemplatedPathPlugin.js +505 -138
  103. package/lib/UseStrictPlugin.js +3 -2
  104. package/lib/WarnCaseSensitiveModulesPlugin.js +72 -3
  105. package/lib/WarnDeprecatedOptionPlugin.js +6 -2
  106. package/lib/WarnNoModeSetPlugin.js +18 -2
  107. package/lib/WatchIgnorePlugin.js +5 -1
  108. package/lib/Watching.js +25 -3
  109. package/lib/WebpackError.js +3 -74
  110. package/lib/WebpackIsIncludedPlugin.js +4 -2
  111. package/lib/WebpackOptionsApply.js +88 -25
  112. package/lib/WebpackOptionsDefaulter.js +1 -0
  113. package/lib/asset/AssetBytesGenerator.js +28 -10
  114. package/lib/asset/AssetBytesParser.js +1 -0
  115. package/lib/asset/AssetGenerator.js +199 -60
  116. package/lib/asset/AssetModule.js +47 -0
  117. package/lib/asset/AssetModulesPlugin.js +115 -24
  118. package/lib/asset/AssetParser.js +4 -2
  119. package/lib/asset/AssetSourceGenerator.js +26 -8
  120. package/lib/asset/AssetSourceParser.js +1 -0
  121. package/lib/asset/RawDataUrlModule.js +23 -13
  122. package/lib/asset/WebManifestGenerator.js +164 -0
  123. package/lib/asset/WebManifestParser.js +130 -0
  124. package/lib/async-modules/AsyncModuleHelpers.js +1 -0
  125. package/lib/async-modules/AwaitDependenciesInitFragment.js +18 -4
  126. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  127. package/lib/async-modules/isGeneratorLowered.js +26 -0
  128. package/lib/buildChunkGraph.js +107 -15
  129. package/lib/bun/BunTargetPlugin.js +42 -0
  130. package/lib/cache/AddBuildDependenciesPlugin.js +3 -1
  131. package/lib/cache/AddManagedPathsPlugin.js +5 -1
  132. package/lib/cache/IdleFileCachePlugin.js +6 -1
  133. package/lib/cache/MemoryCachePlugin.js +1 -1
  134. package/lib/cache/MemoryWithGcCachePlugin.js +4 -1
  135. package/lib/cache/PackFileCacheStrategy.js +43 -7
  136. package/lib/cache/ResolverCachePlugin.js +12 -1
  137. package/lib/cache/getLazyHashedEtag.js +13 -2
  138. package/lib/cache/mergeEtags.js +4 -0
  139. package/lib/cli.js +142 -20
  140. package/lib/config/browserslistTargetHandler.js +141 -0
  141. package/lib/config/defaults.js +591 -41
  142. package/lib/config/defineConfig.js +31 -0
  143. package/lib/config/normalization.js +46 -1
  144. package/lib/config/target.js +200 -2
  145. package/lib/container/ContainerEntryDependency.js +2 -0
  146. package/lib/container/ContainerEntryModule.js +27 -14
  147. package/lib/container/ContainerEntryModuleFactory.js +1 -0
  148. package/lib/container/ContainerExposedDependency.js +6 -2
  149. package/lib/container/ContainerPlugin.js +2 -1
  150. package/lib/container/ContainerReferencePlugin.js +3 -2
  151. package/lib/container/FallbackDependency.js +9 -7
  152. package/lib/container/FallbackItemDependency.js +1 -0
  153. package/lib/container/FallbackModule.js +22 -9
  154. package/lib/container/FallbackModuleFactory.js +1 -0
  155. package/lib/container/ModuleFederationPlugin.js +12 -26
  156. package/lib/container/RemoteModule.js +33 -10
  157. package/lib/container/RemoteRuntimeModule.js +15 -12
  158. package/lib/container/RemoteToExternalDependency.js +1 -0
  159. package/lib/container/options.js +7 -0
  160. package/lib/css/CssGenerator.js +534 -272
  161. package/lib/css/CssInjectStyleRuntimeModule.js +86 -70
  162. package/lib/css/CssLoadingRuntimeModule.js +156 -77
  163. package/lib/{CssModule.js → css/CssModule.js} +72 -37
  164. package/lib/css/CssModulesPlugin.js +356 -204
  165. package/lib/css/CssParser.js +3452 -1950
  166. package/lib/css/syntax.js +4058 -0
  167. package/lib/debug/ProfilingPlugin.js +33 -2
  168. package/lib/deno/DenoTargetPlugin.js +41 -0
  169. package/lib/dependencies/AMDDefineDependency.js +29 -17
  170. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +19 -6
  171. package/lib/dependencies/AMDPlugin.js +6 -3
  172. package/lib/dependencies/AMDRequireArrayDependency.js +13 -11
  173. package/lib/dependencies/AMDRequireContextDependency.js +10 -11
  174. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
  175. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -14
  176. package/lib/dependencies/AMDRequireDependency.js +28 -20
  177. package/lib/dependencies/AMDRequireItemDependency.js +1 -0
  178. package/lib/dependencies/AMDRuntimeModules.js +3 -0
  179. package/lib/dependencies/CachedConstDependency.js +9 -1
  180. package/lib/dependencies/CommonJsDependencyHelpers.js +104 -0
  181. package/lib/dependencies/CommonJsExportRequireDependency.js +138 -38
  182. package/lib/dependencies/CommonJsExportsDependency.js +74 -20
  183. package/lib/dependencies/CommonJsExportsParserPlugin.js +246 -15
  184. package/lib/dependencies/CommonJsFullRequireDependency.js +62 -27
  185. package/lib/dependencies/CommonJsImportsParserPlugin.js +187 -24
  186. package/lib/dependencies/CommonJsPlugin.js +7 -4
  187. package/lib/dependencies/CommonJsRequireContextDependency.js +13 -13
  188. package/lib/dependencies/CommonJsRequireDependency.js +135 -13
  189. package/lib/dependencies/CommonJsSelfReferenceDependency.js +60 -16
  190. package/lib/dependencies/ConstDependency.js +22 -12
  191. package/lib/dependencies/ContextDependency.js +13 -2
  192. package/lib/dependencies/ContextDependencyHelpers.js +7 -4
  193. package/lib/dependencies/ContextDependencyTemplateAsId.js +2 -1
  194. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  195. package/lib/dependencies/ContextElementDependency.js +27 -14
  196. package/lib/dependencies/CreateRequireParserPlugin.js +14 -7
  197. package/lib/dependencies/CreateScriptUrlDependency.js +9 -7
  198. package/lib/dependencies/CriticalDependencyWarning.js +3 -1
  199. package/lib/dependencies/CssIcssExportDependency.js +682 -368
  200. package/lib/dependencies/CssIcssImportDependency.js +62 -17
  201. package/lib/dependencies/CssIcssSymbolDependency.js +36 -17
  202. package/lib/dependencies/CssImportDependency.js +37 -1
  203. package/lib/dependencies/CssUrlDependency.js +87 -14
  204. package/lib/dependencies/DelegatedSourceDependency.js +1 -0
  205. package/lib/dependencies/DllEntryDependency.js +12 -13
  206. package/lib/dependencies/DynamicExports.js +5 -0
  207. package/lib/dependencies/EntryDependency.js +1 -0
  208. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  209. package/lib/dependencies/ExportsInfoDependency.js +18 -12
  210. package/lib/dependencies/ExternalModuleDependency.js +13 -5
  211. package/lib/dependencies/ExternalModuleInitFragment.js +10 -5
  212. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +19 -12
  213. package/lib/dependencies/HarmonyAcceptDependency.js +24 -26
  214. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -0
  215. package/lib/dependencies/HarmonyCompatibilityDependency.js +33 -14
  216. package/lib/dependencies/HarmonyDetectionParserPlugin.js +108 -30
  217. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -2
  218. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +70 -33
  219. package/lib/dependencies/HarmonyExportExpressionDependency.js +140 -46
  220. package/lib/dependencies/HarmonyExportHeaderDependency.js +11 -9
  221. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +253 -37
  222. package/lib/dependencies/HarmonyExportInitFragment.js +28 -20
  223. package/lib/dependencies/HarmonyExportSpecifierDependency.js +88 -18
  224. package/lib/dependencies/HarmonyExports.js +6 -1
  225. package/lib/dependencies/HarmonyImportDependency.js +59 -3
  226. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +139 -146
  227. package/lib/dependencies/HarmonyImportGuard.js +426 -0
  228. package/lib/dependencies/HarmonyImportSideEffectDependency.js +22 -1
  229. package/lib/dependencies/HarmonyImportSpecifierDependency.js +136 -17
  230. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +6 -3
  231. package/lib/dependencies/HarmonyModulesPlugin.js +11 -1
  232. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +2 -1
  233. package/lib/dependencies/HtmlEntryDependency.js +1295 -0
  234. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  235. package/lib/dependencies/HtmlInlineScriptDependency.js +126 -0
  236. package/lib/dependencies/HtmlInlineStyleDependency.js +152 -0
  237. package/lib/dependencies/HtmlSourceDependency.js +172 -0
  238. package/lib/dependencies/ImportContextDependency.js +9 -9
  239. package/lib/dependencies/ImportDependency.js +92 -3
  240. package/lib/dependencies/ImportEagerDependency.js +2 -0
  241. package/lib/dependencies/ImportMetaContextDependency.js +1 -0
  242. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +35 -19
  243. package/lib/dependencies/ImportMetaContextPlugin.js +40 -8
  244. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  245. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  246. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  247. package/lib/dependencies/ImportMetaHotAcceptDependency.js +2 -0
  248. package/lib/dependencies/ImportMetaHotDeclineDependency.js +2 -0
  249. package/lib/dependencies/ImportMetaPlugin.js +595 -209
  250. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  251. package/lib/dependencies/ImportParserPlugin.js +114 -27
  252. package/lib/dependencies/ImportPhase.js +17 -11
  253. package/lib/dependencies/ImportPlugin.js +2 -1
  254. package/lib/dependencies/ImportWeakDependency.js +3 -0
  255. package/lib/dependencies/JsonExportsDependency.js +15 -10
  256. package/lib/dependencies/LoaderDependency.js +2 -0
  257. package/lib/dependencies/LoaderImportDependency.js +3 -0
  258. package/lib/dependencies/LoaderPlugin.js +9 -2
  259. package/lib/dependencies/LocalModule.js +15 -12
  260. package/lib/dependencies/LocalModuleDependency.js +15 -13
  261. package/lib/dependencies/LocalModulesHelpers.js +3 -0
  262. package/lib/dependencies/ModuleDecoratorDependency.js +16 -10
  263. package/lib/dependencies/ModuleDependency.js +14 -0
  264. package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
  265. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  266. package/lib/dependencies/ModuleHotAcceptDependency.js +2 -0
  267. package/lib/dependencies/ModuleHotDeclineDependency.js +2 -0
  268. package/lib/dependencies/ModuleInitFragmentDependency.js +19 -11
  269. package/lib/dependencies/NullDependency.js +2 -0
  270. package/lib/dependencies/PrefetchDependency.js +1 -0
  271. package/lib/dependencies/ProvidedDependency.js +36 -27
  272. package/lib/dependencies/PureExpressionDependency.js +14 -10
  273. package/lib/dependencies/RequireContextDependency.js +1 -0
  274. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -1
  275. package/lib/dependencies/RequireContextPlugin.js +2 -1
  276. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
  277. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +4 -6
  278. package/lib/dependencies/RequireEnsureDependency.js +16 -13
  279. package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
  280. package/lib/dependencies/RequireEnsurePlugin.js +2 -1
  281. package/lib/dependencies/RequireHeaderDependency.js +7 -4
  282. package/lib/dependencies/RequireIncludeDependency.js +2 -0
  283. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +11 -12
  284. package/lib/dependencies/RequireIncludePlugin.js +2 -1
  285. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
  286. package/lib/dependencies/RequireResolveContextDependency.js +10 -11
  287. package/lib/dependencies/RequireResolveDependency.js +2 -0
  288. package/lib/dependencies/RequireResolveHeaderDependency.js +8 -5
  289. package/lib/dependencies/RuntimeRequirementsDependency.js +11 -8
  290. package/lib/dependencies/StaticExportsDependency.js +13 -10
  291. package/lib/dependencies/SystemPlugin.js +9 -6
  292. package/lib/dependencies/SystemRuntimeModule.js +1 -0
  293. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  294. package/lib/dependencies/URLContextDependency.js +8 -7
  295. package/lib/dependencies/URLDependency.js +157 -33
  296. package/lib/dependencies/URLPlugin.js +2 -0
  297. package/lib/dependencies/UnsupportedDependency.js +12 -13
  298. package/lib/dependencies/WebAssemblyExportImportedDependency.js +15 -16
  299. package/lib/dependencies/WebAssemblyImportDependency.js +19 -18
  300. package/lib/dependencies/WebpackIsIncludedDependency.js +3 -0
  301. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +364 -114
  302. package/lib/dependencies/WorkerDependency.js +111 -27
  303. package/lib/dependencies/WorkletDependency.js +278 -0
  304. package/lib/dependencies/getFunctionExpression.js +1 -0
  305. package/lib/dependencies/processExportInfo.js +14 -11
  306. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +71 -44
  307. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +27 -4
  308. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +5 -3
  309. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +9 -5
  310. package/lib/{DllModule.js → dll/DllModule.js} +36 -24
  311. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
  312. package/lib/{DllPlugin.js → dll/DllPlugin.js} +24 -6
  313. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +26 -18
  314. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +14 -10
  315. package/lib/electron/ElectronTargetPlugin.js +24 -5
  316. package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
  317. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
  318. package/lib/errors/BuildCycleError.js +1 -1
  319. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  320. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  321. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
  322. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +5 -2
  323. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +5 -5
  324. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +20 -16
  325. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +7 -4
  326. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +6 -3
  327. package/lib/errors/JSONParseError.js +115 -0
  328. package/lib/errors/LoaderLoadingError.js +20 -0
  329. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +22 -16
  330. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +10 -3
  331. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +13 -5
  332. package/lib/{ModuleError.js → errors/ModuleError.js} +10 -14
  333. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +5 -1
  334. package/lib/errors/ModuleNotFoundError.js +94 -0
  335. package/lib/errors/ModuleParseError.js +141 -0
  336. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +4 -1
  337. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +5 -1
  338. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +13 -14
  339. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +7 -5
  340. package/lib/errors/NonErrorEmittedError.js +30 -0
  341. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +9 -2
  342. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
  343. package/lib/errors/WebpackError.js +84 -0
  344. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  345. package/lib/esm/ModuleChunkFormatPlugin.js +52 -15
  346. package/lib/esm/ModuleChunkLoadingPlugin.js +11 -3
  347. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +71 -49
  348. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  349. package/lib/hmr/HotModuleReplacementRuntimeModule.js +8 -0
  350. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  351. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
  352. package/lib/hmr/LazyCompilationPlugin.js +154 -7
  353. package/lib/hmr/lazyCompilationBackend.js +34 -8
  354. package/lib/html/HtmlGenerator.js +1470 -0
  355. package/lib/html/HtmlModule.js +41 -0
  356. package/lib/html/HtmlModulesPlugin.js +1111 -0
  357. package/lib/html/HtmlParser.js +1970 -0
  358. package/lib/html/favicon.svg +1 -0
  359. package/lib/html/syntax.js +9020 -0
  360. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
  361. package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
  362. package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
  363. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  364. package/lib/ids/IdHelpers.js +25 -2
  365. package/lib/ids/NamedChunkIdsPlugin.js +3 -1
  366. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  367. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  368. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  369. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
  370. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
  371. package/lib/ids/SyncModuleIdsPlugin.js +3 -1
  372. package/lib/index.js +66 -15
  373. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -6
  374. package/lib/javascript/BasicEvaluatedExpression.js +370 -49
  375. package/lib/javascript/ChunkFormatHelpers.js +2 -1
  376. package/lib/javascript/ChunkHelpers.js +1 -0
  377. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  378. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -1
  379. package/lib/javascript/JavascriptGenerator.js +213 -51
  380. package/lib/javascript/JavascriptModule.js +54 -0
  381. package/lib/javascript/JavascriptModulesPlugin.js +579 -183
  382. package/lib/javascript/JavascriptParser.js +1289 -462
  383. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  384. package/lib/javascript/StartupHelpers.js +5 -0
  385. package/lib/javascript/syntax.js +4380 -0
  386. package/lib/json/JsonData.js +5 -0
  387. package/lib/json/JsonGenerator.js +21 -0
  388. package/lib/json/JsonModule.js +40 -0
  389. package/lib/json/JsonModulesPlugin.js +8 -1
  390. package/lib/json/JsonParser.js +18 -27
  391. package/lib/library/AbstractLibraryPlugin.js +17 -2
  392. package/lib/library/AmdLibraryPlugin.js +8 -0
  393. package/lib/library/AssignLibraryPlugin.js +21 -3
  394. package/lib/library/EnableLibraryPlugin.js +8 -2
  395. package/lib/library/ExportPropertyLibraryPlugin.js +10 -0
  396. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +2 -1
  397. package/lib/library/JsonpLibraryPlugin.js +8 -0
  398. package/lib/library/ModuleLibraryPlugin.js +154 -7
  399. package/lib/library/SystemLibraryPlugin.js +11 -3
  400. package/lib/library/UmdLibraryPlugin.js +16 -0
  401. package/lib/loaders/LoaderRunner.js +714 -0
  402. package/lib/loaders/loadLoader.js +100 -0
  403. package/lib/logging/Logger.js +17 -0
  404. package/lib/logging/createConsoleLogger.js +7 -0
  405. package/lib/logging/runtime.js +2 -0
  406. package/lib/logging/truncateArgs.js +2 -0
  407. package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
  408. package/lib/node/NodeEnvironmentPlugin.js +7 -3
  409. package/lib/node/NodeSourcePlugin.js +1 -1
  410. package/lib/node/NodeTargetPlugin.js +4 -63
  411. package/lib/node/NodeTemplatePlugin.js +3 -1
  412. package/lib/node/NodeWatchFileSystem.js +40 -22
  413. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +13 -9
  414. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +23 -1
  415. package/lib/node/ReadFileCompileWasmPlugin.js +18 -1
  416. package/lib/node/RequireChunkLoadingRuntimeModule.js +21 -16
  417. package/lib/node/nodeBuiltins.js +80 -0
  418. package/lib/node/nodeConsole.js +116 -64
  419. package/lib/optimize/AggressiveMergingPlugin.js +3 -1
  420. package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
  421. package/lib/optimize/ConcatenatedModule.js +585 -116
  422. package/lib/optimize/ConstExportsPlugin.js +211 -0
  423. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
  424. package/lib/optimize/FlagIncludedChunksPlugin.js +15 -4
  425. package/lib/optimize/InlineExports.js +178 -0
  426. package/lib/optimize/InnerGraph.js +374 -262
  427. package/lib/optimize/InnerGraphPlugin.js +246 -117
  428. package/lib/optimize/LimitChunkCountPlugin.js +9 -0
  429. package/lib/optimize/MangleExportsPlugin.js +5 -1
  430. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
  431. package/lib/optimize/MinChunkSizePlugin.js +2 -1
  432. package/lib/optimize/MinMaxSizeWarning.js +5 -4
  433. package/lib/optimize/ModuleConcatenationPlugin.js +159 -34
  434. package/lib/optimize/RealContentHashPlugin.js +125 -50
  435. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  436. package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
  437. package/lib/optimize/RuntimeChunkPlugin.js +2 -1
  438. package/lib/optimize/SideEffectsFlagPlugin.js +381 -55
  439. package/lib/optimize/SplitChunksPlugin.js +54 -6
  440. package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
  441. package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
  442. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  443. package/lib/performance/SizeLimitsPlugin.js +8 -2
  444. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
  445. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +21 -0
  446. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
  447. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
  448. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +25 -13
  449. package/lib/prefetch/ResourceHintPlugin.js +663 -0
  450. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  451. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  452. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  453. package/lib/rules/BasicEffectRulePlugin.js +3 -0
  454. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  455. package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
  456. package/lib/rules/RuleSetCompiler.js +132 -0
  457. package/lib/rules/UseEffectRulePlugin.js +10 -3
  458. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  459. package/lib/runtime/AsyncModuleRuntimeModule.js +52 -33
  460. package/lib/runtime/AutoPublicPathRuntimeModule.js +22 -9
  461. package/lib/runtime/BaseUriRuntimeModule.js +1 -0
  462. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  463. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  464. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -1
  465. package/lib/runtime/CompatRuntimeModule.js +2 -0
  466. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  467. package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
  468. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
  469. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +34 -4
  470. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  471. package/lib/runtime/GetChunkFilenameRuntimeModule.js +88 -8
  472. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  473. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
  474. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  475. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  476. package/lib/runtime/GlobalRuntimeModule.js +1 -0
  477. package/lib/runtime/HasOwnPropertyRuntimeModule.js +2 -1
  478. package/lib/runtime/HelperRuntimeModule.js +5 -0
  479. package/lib/runtime/LoadScriptRuntimeModule.js +28 -37
  480. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +354 -37
  481. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -1
  482. package/lib/runtime/NonceRuntimeModule.js +1 -0
  483. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -4
  484. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  485. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -2
  486. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
  487. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +38 -0
  488. package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
  489. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -1
  490. package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -3
  491. package/lib/runtime/SystemContextRuntimeModule.js +1 -0
  492. package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
  493. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  494. package/lib/schemes/DataUriPlugin.js +14 -2
  495. package/lib/schemes/FileUriPlugin.js +1 -1
  496. package/lib/schemes/HttpUriPlugin.js +86 -4
  497. package/lib/schemes/VirtualUrlPlugin.js +8 -4
  498. package/lib/serialization/AggregateErrorSerializer.js +9 -6
  499. package/lib/serialization/ArraySerializer.js +6 -8
  500. package/lib/serialization/BinaryMiddleware.js +552 -463
  501. package/lib/serialization/DateObjectSerializer.js +4 -2
  502. package/lib/serialization/ErrorObjectSerializer.js +10 -6
  503. package/lib/serialization/FileMiddleware.js +50 -3
  504. package/lib/serialization/MapObjectSerializer.js +7 -9
  505. package/lib/serialization/NullPrototypeObjectSerializer.js +9 -9
  506. package/lib/serialization/ObjectMiddleware.js +73 -13
  507. package/lib/serialization/PlainObjectSerializer.js +16 -8
  508. package/lib/serialization/RegExpObjectSerializer.js +4 -2
  509. package/lib/serialization/Serializer.js +6 -0
  510. package/lib/serialization/SerializerMiddleware.js +14 -2
  511. package/lib/serialization/SetObjectSerializer.js +6 -8
  512. package/lib/serialization/SingleItemMiddleware.js +3 -0
  513. package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
  514. package/lib/sharing/ConsumeSharedModule.js +21 -7
  515. package/lib/sharing/ConsumeSharedPlugin.js +11 -11
  516. package/lib/sharing/ConsumeSharedRuntimeModule.js +55 -45
  517. package/lib/sharing/ProvideForSharedDependency.js +1 -0
  518. package/lib/sharing/ProvideSharedDependency.js +34 -15
  519. package/lib/sharing/ProvideSharedModule.js +42 -12
  520. package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
  521. package/lib/sharing/ProvideSharedPlugin.js +13 -8
  522. package/lib/sharing/SharePlugin.js +5 -1
  523. package/lib/sharing/ShareRuntimeModule.js +19 -16
  524. package/lib/sharing/resolveMatchedConfigs.js +6 -2
  525. package/lib/sharing/utils.js +9 -1
  526. package/lib/stats/DefaultStatsFactoryPlugin.js +94 -12
  527. package/lib/stats/DefaultStatsPresetPlugin.js +14 -2
  528. package/lib/stats/DefaultStatsPrinterPlugin.js +64 -18
  529. package/lib/stats/StatsFactory.js +39 -18
  530. package/lib/stats/StatsPrinter.js +16 -2
  531. package/lib/typescript/TypeScriptPlugin.js +210 -0
  532. package/lib/url/URLParserPlugin.js +111 -23
  533. package/lib/util/ArrayHelpers.js +1 -0
  534. package/lib/util/ArrayQueue.js +10 -5
  535. package/lib/util/AsyncQueue.js +154 -74
  536. package/lib/util/Hash.js +2 -2
  537. package/lib/util/IterableHelpers.js +3 -0
  538. package/lib/util/LazyBucketSortedSet.js +26 -0
  539. package/lib/util/LazySet.js +45 -4
  540. package/lib/util/LocConverter.js +64 -0
  541. package/lib/util/ParallelismFactorCalculator.js +1 -0
  542. package/lib/util/Queue.js +6 -3
  543. package/lib/util/Semaphore.js +15 -1
  544. package/lib/util/SetHelpers.js +4 -1
  545. package/lib/util/SortableSet.js +7 -1
  546. package/lib/util/SourceProcessor.js +119 -0
  547. package/lib/util/StackedCacheMap.js +20 -3
  548. package/lib/util/StackedMap.js +162 -43
  549. package/lib/util/StringXor.js +1 -1
  550. package/lib/util/TupleQueue.js +7 -3
  551. package/lib/util/TupleSet.js +14 -0
  552. package/lib/util/URLAbsoluteSpecifier.js +1 -0
  553. package/lib/util/WeakTupleMap.js +60 -1
  554. package/lib/util/binarySearchBounds.js +3 -2
  555. package/lib/util/chainedImports.js +3 -3
  556. package/lib/util/cleverMerge.js +19 -2
  557. package/lib/util/comparators.js +35 -4
  558. package/lib/util/compileBooleanMatcher.js +9 -0
  559. package/lib/util/concatenate.js +80 -24
  560. package/lib/util/conventions.js +46 -1
  561. package/lib/util/createHash.js +0 -1
  562. package/lib/util/createHooksRegistry.js +43 -0
  563. package/lib/util/createMappings.js +118 -0
  564. package/lib/util/dataURL.js +3 -2
  565. package/lib/util/deprecation.js +19 -0
  566. package/lib/util/deterministicGrouping.js +46 -17
  567. package/lib/util/extractSourceMap.js +2 -1
  568. package/lib/util/extractUrlAndGlobal.js +1 -0
  569. package/lib/util/findGraphRoots.js +7 -0
  570. package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
  571. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +10 -3
  572. package/lib/util/fs.js +87 -14
  573. package/lib/util/generateDebugId.js +1 -0
  574. package/lib/util/globUtils.js +710 -0
  575. package/lib/util/hash/BatchedHash.js +1 -0
  576. package/lib/util/hash/BulkUpdateHash.js +1 -0
  577. package/lib/util/hash/DebugHash.js +1 -0
  578. package/lib/util/hash/hash-digest.js +32 -15
  579. package/lib/util/hash/md4.js +1 -1
  580. package/lib/util/hash/wasm-hash.js +5 -0
  581. package/lib/util/hash/xxhash64.js +1 -1
  582. package/lib/util/identifier.js +97 -6
  583. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  584. package/lib/util/internalSerializables.js +102 -60
  585. package/lib/util/magicComment.js +149 -7
  586. package/lib/util/makeSerializable.js +7 -0
  587. package/lib/util/memoize.js +2 -0
  588. package/lib/util/mimeTypes.js +176 -0
  589. package/lib/util/nonNumericOnlyHash.js +31 -1
  590. package/lib/util/numberHash.js +2 -2
  591. package/lib/util/parseJson.js +41 -0
  592. package/lib/util/processAsyncTree.js +8 -0
  593. package/lib/util/property.js +9 -2
  594. package/lib/util/publicPathPlaceholder.js +64 -0
  595. package/lib/util/registerExternalSerializer.js +24 -4
  596. package/lib/util/removeBOM.js +1 -0
  597. package/lib/util/runtime.js +32 -0
  598. package/lib/util/semver.js +15 -0
  599. package/lib/util/serialization.js +2 -0
  600. package/lib/util/smartGrouping.js +8 -0
  601. package/lib/util/source.js +23 -0
  602. package/lib/util/topologicalSort.js +69 -0
  603. package/lib/validateSchema.js +1 -0
  604. package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
  605. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +25 -18
  606. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +34 -22
  607. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  608. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
  609. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +6 -1
  610. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +22 -126
  611. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -2
  612. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +13 -2
  613. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  614. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +7 -3
  615. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +86 -19
  616. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -3
  617. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -1
  618. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +9 -3
  619. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
  620. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +20 -1
  621. package/lib/wasm-sync/WebAssemblyParser.js +9 -3
  622. package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
  623. package/lib/web/FetchCompileAsyncWasmPlugin.js +29 -1
  624. package/lib/web/FetchCompileWasmPlugin.js +27 -1
  625. package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
  626. package/lib/web/JsonpChunkLoadingRuntimeModule.js +58 -64
  627. package/lib/web/JsonpTemplatePlugin.js +2 -1
  628. package/lib/webpack.js +78 -1
  629. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
  630. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -10
  631. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  632. package/module.d.ts +21 -0
  633. package/package.json +79 -77
  634. package/schemas/WebpackOptions.check.js +1 -1
  635. package/schemas/WebpackOptions.json +1117 -79
  636. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  637. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  638. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  639. package/schemas/plugins/{DllReferencePlugin.check.d.ts → HtmlParserOptions.check.d.ts} +1 -1
  640. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  641. package/schemas/plugins/HtmlParserOptions.json +3 -0
  642. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  643. package/schemas/plugins/ProgressPlugin.json +38 -0
  644. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  645. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  646. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  647. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  648. package/schemas/plugins/container/ModuleFederationPlugin.json +2 -0
  649. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +7 -0
  650. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  651. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  652. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  653. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  654. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  655. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  656. package/types.d.ts +8608 -1159
  657. package/lib/CaseSensitiveModulesWarning.js +0 -72
  658. package/lib/GraphHelpers.js +0 -46
  659. package/lib/ModuleParseError.js +0 -125
  660. package/lib/NoModeWarning.js +0 -23
  661. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
  662. package/lib/css/walkCssTokens.js +0 -1843
  663. package/lib/util/AppendOnlyStackedSet.js +0 -78
  664. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  665. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  666. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  667. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -20,19 +20,21 @@ const processAsyncTree = require("./util/processAsyncTree");
20
20
 
21
21
  /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
22
22
  /** @typedef {import("enhanced-resolve").ResolveFunctionAsync} ResolveFunctionAsync */
23
- /** @typedef {import("./WebpackError")} WebpackError */
24
- /** @typedef {import("./logging/Logger").Logger} Logger */
25
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
26
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
27
23
  /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
24
+ /** @typedef {import("./logging/Logger").Logger} Logger */
25
+ /** @typedef {import("./errors/WebpackError")} WebpackError */
28
26
  /** @typedef {import("./util/fs").JsonObject} JsonObject */
29
27
  /** @typedef {import("./util/fs").IStats} IStats */
30
28
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
29
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
30
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
31
31
  /**
32
+ * Defines the processor callback type used by this module.
32
33
  * @template T
33
34
  * @typedef {import("./util/AsyncQueue").Callback<T>} ProcessorCallback
34
35
  */
35
36
  /**
37
+ * Defines the processor type used by this module.
36
38
  * @template T, R
37
39
  * @typedef {import("./util/AsyncQueue").Processor<T, R>} Processor
38
40
  */
@@ -66,12 +68,14 @@ const INVALID = Symbol("invalid");
66
68
  /** @typedef {{ }} ExistenceOnlyTimeEntry */
67
69
 
68
70
  /**
71
+ * Defines the file system info entry type used by this module.
69
72
  * @typedef {object} FileSystemInfoEntry
70
73
  * @property {number} safeTime
71
74
  * @property {number=} timestamp
72
75
  */
73
76
 
74
77
  /**
78
+ * Defines the resolved context file system info entry type used by this module.
75
79
  * @typedef {object} ResolvedContextFileSystemInfoEntry
76
80
  * @property {number} safeTime
77
81
  * @property {string=} timestampHash
@@ -80,6 +84,7 @@ const INVALID = Symbol("invalid");
80
84
  /** @typedef {Set<string>} Symlinks */
81
85
 
82
86
  /**
87
+ * Defines the context file system info entry type used by this module.
83
88
  * @typedef {object} ContextFileSystemInfoEntry
84
89
  * @property {number} safeTime
85
90
  * @property {string=} timestampHash
@@ -88,6 +93,7 @@ const INVALID = Symbol("invalid");
88
93
  */
89
94
 
90
95
  /**
96
+ * Defines the timestamp and hash type used by this module.
91
97
  * @typedef {object} TimestampAndHash
92
98
  * @property {number} safeTime
93
99
  * @property {number=} timestamp
@@ -95,6 +101,7 @@ const INVALID = Symbol("invalid");
95
101
  */
96
102
 
97
103
  /**
104
+ * Defines the resolved context timestamp and hash type used by this module.
98
105
  * @typedef {object} ResolvedContextTimestampAndHash
99
106
  * @property {number} safeTime
100
107
  * @property {string=} timestampHash
@@ -102,6 +109,7 @@ const INVALID = Symbol("invalid");
102
109
  */
103
110
 
104
111
  /**
112
+ * Defines the context timestamp and hash type used by this module.
105
113
  * @typedef {object} ContextTimestampAndHash
106
114
  * @property {number} safeTime
107
115
  * @property {string=} timestampHash
@@ -111,6 +119,7 @@ const INVALID = Symbol("invalid");
111
119
  */
112
120
 
113
121
  /**
122
+ * Defines the context hash type used by this module.
114
123
  * @typedef {object} ContextHash
115
124
  * @property {string} hash
116
125
  * @property {string=} resolved
@@ -120,6 +129,7 @@ const INVALID = Symbol("invalid");
120
129
  /** @typedef {Set<string>} SnapshotContent */
121
130
 
122
131
  /**
132
+ * Defines the snapshot optimization entry type used by this module.
123
133
  * @typedef {object} SnapshotOptimizationEntry
124
134
  * @property {Snapshot} snapshot
125
135
  * @property {number} shared
@@ -134,6 +144,7 @@ const INVALID = Symbol("invalid");
134
144
  /** @typedef {Set<string>} Missing */
135
145
 
136
146
  /**
147
+ * Defines the resolve dependencies type used by this module.
137
148
  * @typedef {object} ResolveDependencies
138
149
  * @property {Files} files list of files
139
150
  * @property {Directories} directories list of directories
@@ -141,6 +152,7 @@ const INVALID = Symbol("invalid");
141
152
  */
142
153
 
143
154
  /**
155
+ * Defines the resolve build dependencies result type used by this module.
144
156
  * @typedef {object} ResolveBuildDependenciesResult
145
157
  * @property {Files} files list of files
146
158
  * @property {Directories} directories list of directories
@@ -150,6 +162,7 @@ const INVALID = Symbol("invalid");
150
162
  */
151
163
 
152
164
  /**
165
+ * Defines the snapshot options type used by this module.
153
166
  * @typedef {object} SnapshotOptions
154
167
  * @property {boolean=} hash should use hash to snapshot
155
168
  * @property {boolean=} timestamp should use timestamp to snapshot
@@ -163,6 +176,7 @@ const DONE_ITERATOR_RESULT = new Set().keys().next();
163
176
 
164
177
  class SnapshotIterator {
165
178
  /**
179
+ * Creates an instance of SnapshotIterator.
166
180
  * @param {() => IteratorResult<string>} next next
167
181
  */
168
182
  constructor(next) {
@@ -171,20 +185,25 @@ class SnapshotIterator {
171
185
  }
172
186
 
173
187
  /**
188
+ * Defines the get maps function type used by this module.
174
189
  * @template T
175
190
  * @typedef {(snapshot: Snapshot) => T[]} GetMapsFunction
176
191
  */
177
192
 
178
193
  /**
194
+ * Represents SnapshotIterable.
179
195
  * @template T
180
196
  */
181
197
  class SnapshotIterable {
182
198
  /**
199
+ * Creates an instance of SnapshotIterable.
183
200
  * @param {Snapshot} snapshot snapshot
184
201
  * @param {GetMapsFunction<T>} getMaps get maps function
185
202
  */
186
203
  constructor(snapshot, getMaps) {
204
+ /** @type {Snapshot} */
187
205
  this.snapshot = snapshot;
206
+ /** @type {GetMapsFunction<T>} */
188
207
  this.getMaps = getMaps;
189
208
  }
190
209
 
@@ -214,7 +233,7 @@ class SnapshotIterable {
214
233
  const map = maps.pop();
215
234
  if (map !== undefined) {
216
235
  it =
217
- /** @type {Set<EXPECTED_ANY> | Map<string, EXPECTED_ANY>} */
236
+ /** @type {Set<string> | Map<string, EXPECTED_ANY>} */
218
237
  (map).keys();
219
238
  state = 2;
220
239
  } else {
@@ -280,6 +299,7 @@ class SnapshotIterable {
280
299
 
281
300
  class Snapshot {
282
301
  constructor() {
302
+ /** @type {number} */
283
303
  this._flags = 0;
284
304
  /** @type {Iterable<string> | undefined} */
285
305
  this._cachedFileIterable = undefined;
@@ -320,6 +340,7 @@ class Snapshot {
320
340
  }
321
341
 
322
342
  /**
343
+ * Updates start time using the provided value.
323
344
  * @param {number} value start value
324
345
  */
325
346
  setStartTime(value) {
@@ -328,6 +349,7 @@ class Snapshot {
328
349
  }
329
350
 
330
351
  /**
352
+ * Sets merged start time.
331
353
  * @param {number | undefined} value value
332
354
  * @param {Snapshot} snapshot snapshot
333
355
  */
@@ -357,6 +379,7 @@ class Snapshot {
357
379
  }
358
380
 
359
381
  /**
382
+ * Sets file timestamps.
360
383
  * @param {FileTimestamps} value file timestamps
361
384
  */
362
385
  setFileTimestamps(value) {
@@ -369,6 +392,7 @@ class Snapshot {
369
392
  }
370
393
 
371
394
  /**
395
+ * Updates file hashes using the provided value.
372
396
  * @param {FileHashes} value file hashes
373
397
  */
374
398
  setFileHashes(value) {
@@ -381,6 +405,7 @@ class Snapshot {
381
405
  }
382
406
 
383
407
  /**
408
+ * Updates file tshs using the provided value.
384
409
  * @param {FileTshs} value file tshs
385
410
  */
386
411
  setFileTshs(value) {
@@ -393,6 +418,7 @@ class Snapshot {
393
418
  }
394
419
 
395
420
  /**
421
+ * Sets context timestamps.
396
422
  * @param {ContextTimestamps} value context timestamps
397
423
  */
398
424
  setContextTimestamps(value) {
@@ -405,6 +431,7 @@ class Snapshot {
405
431
  }
406
432
 
407
433
  /**
434
+ * Sets context hashes.
408
435
  * @param {ContextHashes} value context hashes
409
436
  */
410
437
  setContextHashes(value) {
@@ -417,6 +444,7 @@ class Snapshot {
417
444
  }
418
445
 
419
446
  /**
447
+ * Updates context tshs using the provided value.
420
448
  * @param {ContextTshs} value context tshs
421
449
  */
422
450
  setContextTshs(value) {
@@ -429,6 +457,7 @@ class Snapshot {
429
457
  }
430
458
 
431
459
  /**
460
+ * Sets missing existence.
432
461
  * @param {MissingExistence} value context tshs
433
462
  */
434
463
  setMissingExistence(value) {
@@ -441,6 +470,7 @@ class Snapshot {
441
470
  }
442
471
 
443
472
  /**
473
+ * Sets managed item info.
444
474
  * @param {ManagedItemInfo} value managed item info
445
475
  */
446
476
  setManagedItemInfo(value) {
@@ -453,6 +483,7 @@ class Snapshot {
453
483
  }
454
484
 
455
485
  /**
486
+ * Sets managed files.
456
487
  * @param {ManagedFiles} value managed files
457
488
  */
458
489
  setManagedFiles(value) {
@@ -465,6 +496,7 @@ class Snapshot {
465
496
  }
466
497
 
467
498
  /**
499
+ * Sets managed contexts.
468
500
  * @param {ManagedContexts} value managed contexts
469
501
  */
470
502
  setManagedContexts(value) {
@@ -477,6 +509,7 @@ class Snapshot {
477
509
  }
478
510
 
479
511
  /**
512
+ * Sets managed missing.
480
513
  * @param {ManagedMissing} value managed missing
481
514
  */
482
515
  setManagedMissing(value) {
@@ -489,6 +522,7 @@ class Snapshot {
489
522
  }
490
523
 
491
524
  /**
525
+ * Updates children using the provided value.
492
526
  * @param {Children} value children
493
527
  */
494
528
  setChildren(value) {
@@ -497,6 +531,7 @@ class Snapshot {
497
531
  }
498
532
 
499
533
  /**
534
+ * Adds the provided child to the snapshot.
500
535
  * @param {Snapshot} child children
501
536
  */
502
537
  addChild(child) {
@@ -508,6 +543,7 @@ class Snapshot {
508
543
  }
509
544
 
510
545
  /**
546
+ * Serializes this instance into the provided serializer context.
511
547
  * @param {ObjectSerializerContext} context context
512
548
  */
513
549
  serialize({ write }) {
@@ -528,6 +564,7 @@ class Snapshot {
528
564
  }
529
565
 
530
566
  /**
567
+ * Restores this instance from the provided deserializer context.
531
568
  * @param {ObjectDeserializerContext} context context
532
569
  */
533
570
  deserialize({ read }) {
@@ -548,6 +585,7 @@ class Snapshot {
548
585
  }
549
586
 
550
587
  /**
588
+ * Creates an iterable from the provided get map.
551
589
  * @template T
552
590
  * @param {GetMapsFunction<T>} getMaps first
553
591
  * @returns {SnapshotIterable<T>} iterable
@@ -557,6 +595,7 @@ class Snapshot {
557
595
  }
558
596
 
559
597
  /**
598
+ * Gets file iterable.
560
599
  * @returns {Iterable<string>} iterable
561
600
  */
562
601
  getFileIterable() {
@@ -572,6 +611,7 @@ class Snapshot {
572
611
  }
573
612
 
574
613
  /**
614
+ * Gets context iterable.
575
615
  * @returns {Iterable<string>} iterable
576
616
  */
577
617
  getContextIterable() {
@@ -587,6 +627,7 @@ class Snapshot {
587
627
  }
588
628
 
589
629
  /**
630
+ * Gets missing iterable.
590
631
  * @returns {Iterable<string>} iterable
591
632
  */
592
633
  getMissingIterable() {
@@ -605,16 +646,19 @@ makeSerializable(Snapshot, "webpack/lib/FileSystemInfo", "Snapshot");
605
646
  const MIN_COMMON_SNAPSHOT_SIZE = 3;
606
647
 
607
648
  /**
649
+ * Defines the snapshot optimization value type used by this module.
608
650
  * @template U, T
609
651
  * @typedef {U extends true ? Set<string> : Map<string, T>} SnapshotOptimizationValue
610
652
  */
611
653
 
612
654
  /**
655
+ * Represents SnapshotOptimization.
613
656
  * @template T
614
657
  * @template {boolean} [U=false]
615
658
  */
616
659
  class SnapshotOptimization {
617
660
  /**
661
+ * Creates an instance of SnapshotOptimization.
618
662
  * @param {(snapshot: Snapshot) => boolean} has has value
619
663
  * @param {(snapshot: Snapshot) => SnapshotOptimizationValue<U, T> | undefined} get get value
620
664
  * @param {(snapshot: Snapshot, value: SnapshotOptimizationValue<U, T>) => void} set set value
@@ -631,14 +675,19 @@ class SnapshotOptimization {
631
675
  this._has = has;
632
676
  this._get = get;
633
677
  this._set = set;
678
+ /** @type {boolean} */
634
679
  this._useStartTime = useStartTime;
635
680
  /** @type {U} */
636
681
  this._isSet = isSet;
637
682
  /** @type {Map<string, SnapshotOptimizationEntry>} */
638
683
  this._map = new Map();
684
+ /** @type {number} */
639
685
  this._statItemsShared = 0;
686
+ /** @type {number} */
640
687
  this._statItemsUnshared = 0;
688
+ /** @type {number} */
641
689
  this._statSharedSnapshots = 0;
690
+ /** @type {number} */
642
691
  this._statReusedSharedSnapshots = 0;
643
692
  }
644
693
 
@@ -663,6 +712,7 @@ class SnapshotOptimization {
663
712
  }
664
713
 
665
714
  /**
715
+ * Processes the provided new snapshot.
666
716
  * @param {Snapshot} newSnapshot snapshot
667
717
  * @param {Set<string>} capturedFiles files to snapshot/share
668
718
  * @returns {void}
@@ -672,6 +722,7 @@ class SnapshotOptimization {
672
722
  return;
673
723
  }
674
724
  /**
725
+ * Increase shared and store optimization entry.
675
726
  * @param {SnapshotOptimizationEntry} entry optimization entry
676
727
  * @returns {void}
677
728
  */
@@ -685,6 +736,7 @@ class SnapshotOptimization {
685
736
  storeOptimizationEntry(entry);
686
737
  };
687
738
  /**
739
+ * Stores optimization entry.
688
740
  * @param {SnapshotOptimizationEntry} entry optimization entry
689
741
  * @returns {void}
690
742
  */
@@ -885,19 +937,125 @@ class SnapshotOptimization {
885
937
  }
886
938
  }
887
939
 
940
+ /** @type {Record<string, string>} */
941
+ const ESCAPES = {
942
+ n: "\n",
943
+ r: "\r",
944
+ t: "\t",
945
+ b: "\b",
946
+ f: "\f",
947
+ v: "\v"
948
+ };
949
+
888
950
  /**
889
- * @param {string} str input
890
- * @returns {string} result
951
+ * Cooks a JS string/template literal specifier into its evaluated value,
952
+ * matching ECMAScript escape semantics (sloppy-mode for string literals).
953
+ * @param {string} str input including the surrounding quotes
954
+ * @returns {string | null} result, or null when not a quoted literal
955
+ * @throws {Error} on a malformed escape sequence, like the JS parser would
891
956
  */
892
957
  const parseString = (str) => {
893
- if (str[0] === "'" || str[0] === "`") {
894
- str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
958
+ const q = str[0];
959
+
960
+ if (q !== '"' && q !== "'" && q !== "`") {
961
+ return null;
895
962
  }
896
- return JSON.parse(str);
963
+
964
+ const template = q === "`";
965
+ const inner = str.slice(1, -1);
966
+ const len = inner.length;
967
+ let result = "";
968
+ let i = 0;
969
+
970
+ while (i < len) {
971
+ const ch = inner[i];
972
+ if (ch !== "\\") {
973
+ // Template value normalizes raw <CR> and <CRLF> to <LF>
974
+ if (template && ch === "\r") {
975
+ result += "\n";
976
+ i += inner[i + 1] === "\n" ? 2 : 1;
977
+ } else {
978
+ result += ch;
979
+ i++;
980
+ }
981
+ continue;
982
+ }
983
+
984
+ i++;
985
+ if (i >= len) throw new Error("Unterminated escape sequence");
986
+ const esc = inner[i];
987
+
988
+ if (esc === "x") {
989
+ const hex = inner.slice(i + 1, i + 3);
990
+ if (!/^[0-9a-fA-F]{2}$/.test(hex)) {
991
+ throw new Error("Invalid hexadecimal escape sequence");
992
+ }
993
+ result += String.fromCharCode(Number.parseInt(hex, 16));
994
+ i += 3;
995
+ } else if (esc === "u") {
996
+ if (inner[i + 1] === "{") {
997
+ // \u{N...}
998
+ const closeIdx = inner.indexOf("}", i + 2);
999
+ const codeStr = closeIdx === -1 ? "" : inner.slice(i + 2, closeIdx);
1000
+ const code = Number.parseInt(codeStr, 16);
1001
+ if (!/^[0-9a-fA-F]+$/.test(codeStr) || code > 0x10ffff) {
1002
+ throw new Error("Invalid Unicode escape sequence");
1003
+ }
1004
+ result += String.fromCodePoint(code);
1005
+ i = closeIdx + 1;
1006
+ } else {
1007
+ // \uNNNN
1008
+ const hex = inner.slice(i + 1, i + 5);
1009
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
1010
+ throw new Error("Invalid Unicode escape sequence");
1011
+ }
1012
+ result += String.fromCharCode(Number.parseInt(hex, 16));
1013
+ i += 5;
1014
+ }
1015
+ } else if (esc === "\r") {
1016
+ // Line continuation: \<CR> or \<CRLF>
1017
+ i += inner[i + 1] === "\n" ? 2 : 1;
1018
+ } else if (esc === "\n" || esc === "\u2028" || esc === "\u2029") {
1019
+ // Line continuation: \<LF>, \<LS>, \<PS>
1020
+ i++;
1021
+ } else if (ESCAPES[esc] !== undefined) {
1022
+ result += ESCAPES[esc];
1023
+ i++;
1024
+ } else if (esc >= "0" && esc <= "7") {
1025
+ // \0 not followed by a digit is NUL, otherwise a legacy octal escape
1026
+ const next = inner[i + 1];
1027
+ if (esc === "0" && !(next >= "0" && next <= "9")) {
1028
+ result += "\0";
1029
+ i++;
1030
+ continue;
1031
+ }
1032
+ if (template) throw new Error("Octal escape not allowed in template");
1033
+ // Up to 3 octal digits, value capped at \377
1034
+ let oct = esc;
1035
+ i++;
1036
+ const max = esc <= "3" ? 3 : 2;
1037
+ while (oct.length < max && inner[i] >= "0" && inner[i] <= "7") {
1038
+ oct += inner[i];
1039
+ i++;
1040
+ }
1041
+ result += String.fromCharCode(Number.parseInt(oct, 8));
1042
+ } else if (esc === "8" || esc === "9") {
1043
+ if (template) throw new Error("\\8 and \\9 not allowed in template");
1044
+ result += esc;
1045
+ i++;
1046
+ } else {
1047
+ // \', \", \\, \`, and any other NonEscapeCharacter — the char itself
1048
+ result += esc;
1049
+ i++;
1050
+ }
1051
+ }
1052
+
1053
+ return result;
897
1054
  };
898
1055
 
899
1056
  /* istanbul ignore next */
900
1057
  /**
1058
+ * Processes the provided mtime.
901
1059
  * @param {number} mtime mtime
902
1060
  */
903
1061
  const applyMtime = (mtime) => {
@@ -908,6 +1066,7 @@ const applyMtime = (mtime) => {
908
1066
  };
909
1067
 
910
1068
  /**
1069
+ * Merges the provided values into a single result.
911
1070
  * @template T
912
1071
  * @template K
913
1072
  * @param {Map<T, K> | undefined} a source map
@@ -926,6 +1085,7 @@ const mergeMaps = (a, b) => {
926
1085
  };
927
1086
 
928
1087
  /**
1088
+ * Merges the provided values into a single result.
929
1089
  * @template T
930
1090
  * @param {Set<T> | undefined} a source map
931
1091
  * @param {Set<T> | undefined} b joining map
@@ -1027,6 +1187,7 @@ const getManagedItem = (managedPath, path) => {
1027
1187
  };
1028
1188
 
1029
1189
  /**
1190
+ * Gets resolved timestamp.
1030
1191
  * @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
1031
1192
  * @param {T | null} entry entry
1032
1193
  * @returns {T["resolved"] | null | undefined} the resolved entry
@@ -1038,6 +1199,7 @@ const getResolvedTimestamp = (entry) => {
1038
1199
  };
1039
1200
 
1040
1201
  /**
1202
+ * Gets resolved hash.
1041
1203
  * @param {ContextHash | null} entry entry
1042
1204
  * @returns {string | null | undefined} the resolved entry
1043
1205
  */
@@ -1048,6 +1210,7 @@ const getResolvedHash = (entry) => {
1048
1210
  };
1049
1211
 
1050
1212
  /**
1213
+ * Adds the provided source to the snapshot optimization.
1051
1214
  * @template T
1052
1215
  * @param {Set<T>} source source
1053
1216
  * @param {Set<T>} target target
@@ -1060,10 +1223,37 @@ const getEsModuleLexer = memoize(() => require("es-module-lexer"));
1060
1223
 
1061
1224
  /** @typedef {Set<string>} LoggedPaths */
1062
1225
 
1063
- /** @typedef {FileSystemInfoEntry | "ignore" | null} FileTimestamp */
1064
- /** @typedef {ContextFileSystemInfoEntry | "ignore" | null} ContextTimestamp */
1226
+ /** @typedef {FileSystemInfoEntry | ExistenceOnlyTimeEntry | "ignore" | null} FileTimestamp */
1227
+ /** @typedef {ContextFileSystemInfoEntry | ExistenceOnlyTimeEntry | "ignore" | null} ContextTimestamp */
1065
1228
  /** @typedef {ResolvedContextFileSystemInfoEntry | "ignore" | null} ResolvedContextTimestamp */
1066
1229
 
1230
+ /**
1231
+ * `watchpack` may report `{}` (existence-only) for files and directories it
1232
+ * is watching but has no time information for. Such entries cannot be used
1233
+ * for snapshot comparison, so cache lookups treat them as "no cached value"
1234
+ * and fall back to a fresh on-disk read.
1235
+ * @param {FileTimestamp | ContextTimestamp | undefined} entry cache entry
1236
+ * @returns {entry is ExistenceOnlyTimeEntry} true if the entry exists but carries no time info
1237
+ */
1238
+ const isExistenceOnly = (entry) => {
1239
+ if (entry === undefined || entry === null || entry === "ignore") return false;
1240
+ return (
1241
+ /** @type {Partial<FileSystemInfoEntry> & Partial<ContextFileSystemInfoEntry>} */
1242
+ (entry).safeTime === undefined
1243
+ );
1244
+ };
1245
+
1246
+ /**
1247
+ * Watchpack directory entries may carry `safeTime` / `timestamp` but never
1248
+ * `timestampHash`; such object caches cannot back snapshot checks or symlink walks.
1249
+ * @param {ContextFileSystemInfoEntry | null | "ignore" | undefined} entry cache entry
1250
+ * @returns {boolean} true when a non-null object entry lacks `timestampHash`
1251
+ */
1252
+ const contextCacheEntryLacksTimestampHash = (entry) =>
1253
+ entry !== null &&
1254
+ typeof entry === "object" &&
1255
+ /** @type {ContextFileSystemInfoEntry} */ (entry).timestampHash === undefined;
1256
+
1067
1257
  /** @typedef {(err?: WebpackError | null, result?: boolean) => void} CheckSnapshotValidCallback */
1068
1258
 
1069
1259
  /**
@@ -1071,6 +1261,7 @@ const getEsModuleLexer = memoize(() => require("es-module-lexer"));
1071
1261
  */
1072
1262
  class FileSystemInfo {
1073
1263
  /**
1264
+ * Creates an instance of FileSystemInfo.
1074
1265
  * @param {InputFileSystem} fs file system
1075
1266
  * @param {object} options options
1076
1267
  * @param {Iterable<string | RegExp>=} options.unmanagedPaths paths that are not managed by a package manager and the contents are subject to change
@@ -1089,52 +1280,63 @@ class FileSystemInfo {
1089
1280
  hashFunction = DEFAULTS.HASH_FUNCTION
1090
1281
  } = {}
1091
1282
  ) {
1283
+ /** @type {InputFileSystem} */
1092
1284
  this.fs = fs;
1093
1285
  this.logger = logger;
1286
+ /** @type {number} */
1094
1287
  this._remainingLogs = logger ? 40 : 0;
1095
1288
  /** @type {LoggedPaths | undefined} */
1096
1289
  this._loggedPaths = logger ? new Set() : undefined;
1290
+ /** @type {HashFunction} */
1097
1291
  this._hashFunction = hashFunction;
1098
1292
  /** @type {WeakMap<Snapshot, boolean | CheckSnapshotValidCallback[]>} */
1099
1293
  this._snapshotCache = new WeakMap();
1294
+ /** @type {SnapshotOptimization<FileSystemInfoEntry | null, false>} */
1100
1295
  this._fileTimestampsOptimization = new SnapshotOptimization(
1101
1296
  (s) => s.hasFileTimestamps(),
1102
1297
  (s) => s.fileTimestamps,
1103
1298
  (s, v) => s.setFileTimestamps(v)
1104
1299
  );
1300
+ /** @type {SnapshotOptimization<string | null, false>} */
1105
1301
  this._fileHashesOptimization = new SnapshotOptimization(
1106
1302
  (s) => s.hasFileHashes(),
1107
1303
  (s) => s.fileHashes,
1108
1304
  (s, v) => s.setFileHashes(v),
1109
1305
  false
1110
1306
  );
1307
+ /** @type {SnapshotOptimization<string | TimestampAndHash | null, false>} */
1111
1308
  this._fileTshsOptimization = new SnapshotOptimization(
1112
1309
  (s) => s.hasFileTshs(),
1113
1310
  (s) => s.fileTshs,
1114
1311
  (s, v) => s.setFileTshs(v)
1115
1312
  );
1313
+ /** @type {SnapshotOptimization<ResolvedContextFileSystemInfoEntry | null, false>} */
1116
1314
  this._contextTimestampsOptimization = new SnapshotOptimization(
1117
1315
  (s) => s.hasContextTimestamps(),
1118
1316
  (s) => s.contextTimestamps,
1119
1317
  (s, v) => s.setContextTimestamps(v)
1120
1318
  );
1319
+ /** @type {SnapshotOptimization<string | null, false>} */
1121
1320
  this._contextHashesOptimization = new SnapshotOptimization(
1122
1321
  (s) => s.hasContextHashes(),
1123
1322
  (s) => s.contextHashes,
1124
1323
  (s, v) => s.setContextHashes(v),
1125
1324
  false
1126
1325
  );
1326
+ /** @type {SnapshotOptimization<ResolvedContextTimestampAndHash | null, false>} */
1127
1327
  this._contextTshsOptimization = new SnapshotOptimization(
1128
1328
  (s) => s.hasContextTshs(),
1129
1329
  (s) => s.contextTshs,
1130
1330
  (s, v) => s.setContextTshs(v)
1131
1331
  );
1332
+ /** @type {SnapshotOptimization<boolean, false>} */
1132
1333
  this._missingExistenceOptimization = new SnapshotOptimization(
1133
1334
  (s) => s.hasMissingExistence(),
1134
1335
  (s) => s.missingExistence,
1135
1336
  (s, v) => s.setMissingExistence(v),
1136
1337
  false
1137
1338
  );
1339
+ /** @type {SnapshotOptimization<string, false>} */
1138
1340
  this._managedItemInfoOptimization = new SnapshotOptimization(
1139
1341
  (s) => s.hasManagedItemInfo(),
1140
1342
  (s) => s.managedItemInfo,
@@ -1176,6 +1378,9 @@ class FileSystemInfo {
1176
1378
  this._contextTshs = new Map();
1177
1379
  /** @type {Map<string, string>} */
1178
1380
  this._managedItems = new Map();
1381
+ // memoized checkManaged results: 0 = not managed, 1 = immutable, string = managed item
1382
+ /** @type {Map<string, 0 | 1 | string>} */
1383
+ this._pathClassificationCache = new Map();
1179
1384
  /** @type {AsyncQueue<string, string, FileSystemInfoEntry>} */
1180
1385
  this.fileTimestampQueue = new AsyncQueue({
1181
1386
  name: "file timestamp",
@@ -1248,22 +1453,32 @@ class FileSystemInfo {
1248
1453
  (p) => typeof p !== "string"
1249
1454
  );
1250
1455
 
1456
+ /** @type {Map<string, number | null> | undefined} */
1251
1457
  this._cachedDeprecatedFileTimestamps = undefined;
1458
+ /** @type {Map<string, number | null> | undefined} */
1252
1459
  this._cachedDeprecatedContextTimestamps = undefined;
1253
1460
 
1461
+ /** @type {boolean} */
1254
1462
  this._warnAboutExperimentalEsmTracking = false;
1255
1463
 
1464
+ /** @type {number} */
1256
1465
  this._statCreatedSnapshots = 0;
1466
+ /** @type {number} */
1257
1467
  this._statTestedSnapshotsCached = 0;
1468
+ /** @type {number} */
1258
1469
  this._statTestedSnapshotsNotCached = 0;
1470
+ /** @type {number} */
1259
1471
  this._statTestedChildrenCached = 0;
1472
+ /** @type {number} */
1260
1473
  this._statTestedChildrenNotCached = 0;
1474
+ /** @type {number} */
1261
1475
  this._statTestedEntries = 0;
1262
1476
  }
1263
1477
 
1264
1478
  logStatistics() {
1265
1479
  const logger = /** @type {Logger} */ (this.logger);
1266
1480
  /**
1481
+ * Processes the provided header.
1267
1482
  * @param {string} header header
1268
1483
  * @param {string | undefined} message message
1269
1484
  */
@@ -1351,6 +1566,7 @@ class FileSystemInfo {
1351
1566
  }
1352
1567
 
1353
1568
  /**
1569
+ * Processes the provided path.
1354
1570
  * @private
1355
1571
  * @param {string} path path
1356
1572
  * @param {string} reason reason
@@ -1394,7 +1610,7 @@ class FileSystemInfo {
1394
1610
  this._contextHashes.clear();
1395
1611
  this._contextTshs.clear();
1396
1612
  this._managedItems.clear();
1397
- this._managedItems.clear();
1613
+ this._pathClassificationCache.clear();
1398
1614
 
1399
1615
  this._cachedDeprecatedFileTimestamps = undefined;
1400
1616
  this._cachedDeprecatedContextTimestamps = undefined;
@@ -1408,64 +1624,84 @@ class FileSystemInfo {
1408
1624
  }
1409
1625
 
1410
1626
  /**
1411
- * @param {ReadonlyMap<string, FileSystemInfoEntry | ExistenceOnlyTimeEntry | "ignore" | null>} map timestamps
1627
+ * Adds file timestamps.
1628
+ * @param {ReadonlyMap<string, FileTimestamp>} map timestamps
1412
1629
  * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1413
1630
  * @returns {void}
1414
1631
  */
1415
1632
  addFileTimestamps(map, immutable) {
1416
- this._fileTimestamps.addAll(
1417
- /** @type {ReadonlyMap<string, FileTimestamp>} */
1418
- (map),
1419
- immutable
1420
- );
1633
+ this._fileTimestamps.addAll(map, immutable);
1421
1634
  this._cachedDeprecatedFileTimestamps = undefined;
1422
1635
  }
1423
1636
 
1424
1637
  /**
1425
- * @param {ReadonlyMap<string, ContextFileSystemInfoEntry | ExistenceOnlyTimeEntry | "ignore" | null>} map timestamps
1638
+ * Adds context timestamps.
1639
+ * @param {ReadonlyMap<string, ContextTimestamp>} map timestamps
1426
1640
  * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1427
1641
  * @returns {void}
1428
1642
  */
1429
1643
  addContextTimestamps(map, immutable) {
1430
- this._contextTimestamps.addAll(
1431
- /** @type {ReadonlyMap<string, ContextTimestamp>} */
1432
- (map),
1433
- immutable
1434
- );
1644
+ this._contextTimestamps.addAll(map, immutable);
1435
1645
  this._cachedDeprecatedContextTimestamps = undefined;
1436
1646
  }
1437
1647
 
1438
1648
  /**
1649
+ * Gets file timestamp.
1439
1650
  * @param {string} path file path
1440
- * @param {(err?: WebpackError | null, fileTimestamp?: FileTimestamp) => void} callback callback function
1651
+ * @param {(err?: WebpackError | null, fileTimestamp?: FileSystemInfoEntry | "ignore" | null) => void} callback callback function
1441
1652
  * @returns {void}
1442
1653
  */
1443
1654
  getFileTimestamp(path, callback) {
1444
1655
  const cache = this._fileTimestamps.get(path);
1445
- if (cache !== undefined) return callback(null, cache);
1656
+ if (cache !== undefined && !isExistenceOnly(cache)) {
1657
+ return callback(
1658
+ null,
1659
+ /** @type {FileSystemInfoEntry | "ignore" | null} */ (cache)
1660
+ );
1661
+ }
1446
1662
  this.fileTimestampQueue.add(path, callback);
1447
1663
  }
1448
1664
 
1449
1665
  /**
1666
+ * Gets context timestamp.
1450
1667
  * @param {string} path context path
1451
1668
  * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback function
1452
1669
  * @returns {void}
1453
1670
  */
1454
1671
  getContextTimestamp(path, callback) {
1455
1672
  const cache = this._contextTimestamps.get(path);
1456
- if (cache !== undefined) {
1673
+ if (cache !== undefined && !isExistenceOnly(cache)) {
1457
1674
  if (cache === "ignore") return callback(null, "ignore");
1458
- const resolved = getResolvedTimestamp(cache);
1675
+ const fullEntry =
1676
+ /** @type {ContextFileSystemInfoEntry | null} */
1677
+ (cache);
1678
+ const resolved = getResolvedTimestamp(fullEntry);
1459
1679
  if (resolved !== undefined) return callback(null, resolved);
1460
1680
  return this._resolveContextTimestamp(
1461
- /** @type {ResolvedContextFileSystemInfoEntry} */
1462
- (cache),
1681
+ /** @type {ContextFileSystemInfoEntry} */
1682
+ (fullEntry),
1463
1683
  callback
1464
1684
  );
1465
1685
  }
1686
+ this._readFreshContextTimestamp(path, callback);
1687
+ }
1688
+
1689
+ /**
1690
+ * Reads a context timestamp directly from disk, bypassing any cached
1691
+ * entry. Used by `getContextTimestamp` and the snapshot validity
1692
+ * checks when the cached entry is missing or is an `ExistenceOnlyTimeEntry`
1693
+ * (`{}`) supplied by watchpack — both cases require a fresh read to
1694
+ * obtain the `timestampHash`.
1695
+ * @private
1696
+ * @param {string} path context path
1697
+ * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback function
1698
+ * @returns {void}
1699
+ */
1700
+ _readFreshContextTimestamp(path, callback) {
1466
1701
  this.contextTimestampQueue.add(path, (err, _entry) => {
1467
1702
  if (err) return callback(err);
1468
- const entry = /** @type {ContextFileSystemInfoEntry} */ (_entry);
1703
+ const entry = /** @type {ContextFileSystemInfoEntry | null} */ (_entry);
1704
+ if (entry === null) return callback(null, null);
1469
1705
  const resolved = getResolvedTimestamp(entry);
1470
1706
  if (resolved !== undefined) return callback(null, resolved);
1471
1707
  this._resolveContextTimestamp(entry, callback);
@@ -1473,18 +1709,33 @@ class FileSystemInfo {
1473
1709
  }
1474
1710
 
1475
1711
  /**
1712
+ * Get unresolved context timestamp. Existence-only cache entries (`{}`)
1713
+ * are bypassed so the callback always receives a complete entry, "ignore"
1714
+ * or null.
1476
1715
  * @private
1477
1716
  * @param {string} path context path
1478
- * @param {(err?: WebpackError | null, contextTimestamp?: ContextTimestamp) => void} callback callback function
1717
+ * @param {(err?: WebpackError | null, contextTimestamp?: ContextFileSystemInfoEntry | "ignore" | null) => void} callback callback function
1479
1718
  * @returns {void}
1480
1719
  */
1481
1720
  _getUnresolvedContextTimestamp(path, callback) {
1482
1721
  const cache = this._contextTimestamps.get(path);
1483
- if (cache !== undefined) return callback(null, cache);
1722
+ if (
1723
+ cache !== undefined &&
1724
+ !isExistenceOnly(cache) &&
1725
+ !contextCacheEntryLacksTimestampHash(
1726
+ /** @type {ContextFileSystemInfoEntry | null | "ignore"} */ (cache)
1727
+ )
1728
+ ) {
1729
+ return callback(
1730
+ null,
1731
+ /** @type {ContextFileSystemInfoEntry | "ignore" | null} */ (cache)
1732
+ );
1733
+ }
1484
1734
  this.contextTimestampQueue.add(path, callback);
1485
1735
  }
1486
1736
 
1487
1737
  /**
1738
+ * Returns file hash.
1488
1739
  * @param {string} path file path
1489
1740
  * @param {(err?: WebpackError | null, hash?: string | null) => void} callback callback function
1490
1741
  * @returns {void}
@@ -1496,6 +1747,7 @@ class FileSystemInfo {
1496
1747
  }
1497
1748
 
1498
1749
  /**
1750
+ * Returns context hash.
1499
1751
  * @param {string} path context path
1500
1752
  * @param {(err?: WebpackError | null, contextHash?: string) => void} callback callback function
1501
1753
  * @returns {void}
@@ -1521,6 +1773,7 @@ class FileSystemInfo {
1521
1773
  }
1522
1774
 
1523
1775
  /**
1776
+ * Get unresolved context hash.
1524
1777
  * @private
1525
1778
  * @param {string} path context path
1526
1779
  * @param {(err?: WebpackError | null, contextHash?: ContextHash | null) => void} callback callback function
@@ -1533,6 +1786,7 @@ class FileSystemInfo {
1533
1786
  }
1534
1787
 
1535
1788
  /**
1789
+ * Returns context tsh.
1536
1790
  * @param {string} path context path
1537
1791
  * @param {(err?: WebpackError | null, resolvedContextTimestampAndHash?: ResolvedContextTimestampAndHash | null) => void} callback callback function
1538
1792
  * @returns {void}
@@ -1554,6 +1808,7 @@ class FileSystemInfo {
1554
1808
  }
1555
1809
 
1556
1810
  /**
1811
+ * Get unresolved context tsh.
1557
1812
  * @private
1558
1813
  * @param {string} path context path
1559
1814
  * @param {(err?: WebpackError | null, contextTimestampAndHash?: ContextTimestampAndHash | null) => void} callback callback function
@@ -1573,20 +1828,20 @@ class FileSystemInfo {
1573
1828
  });
1574
1829
  const resolveCjs = createResolver({
1575
1830
  extensions: [".js", ".json", ".node"],
1576
- conditionNames: ["require", "node"],
1831
+ conditionNames: ["require", "module-sync", "node"],
1577
1832
  exportsFields: ["exports"],
1578
1833
  fileSystem: this.fs
1579
1834
  });
1580
1835
  const resolveCjsAsChild = createResolver({
1581
1836
  extensions: [".js", ".json", ".node"],
1582
- conditionNames: ["require", "node"],
1837
+ conditionNames: ["require", "module-sync", "node"],
1583
1838
  exportsFields: [],
1584
1839
  fileSystem: this.fs
1585
1840
  });
1586
1841
  const resolveEsm = createResolver({
1587
1842
  extensions: [".js", ".json", ".node"],
1588
1843
  fullySpecified: true,
1589
- conditionNames: ["import", "node"],
1844
+ conditionNames: ["import", "module-sync", "node"],
1590
1845
  exportsFields: ["exports"],
1591
1846
  fileSystem: this.fs
1592
1847
  });
@@ -1594,6 +1849,7 @@ class FileSystemInfo {
1594
1849
  }
1595
1850
 
1596
1851
  /**
1852
+ * Resolves build dependencies.
1597
1853
  * @param {string} context context directory
1598
1854
  * @param {Iterable<string>} deps dependencies
1599
1855
  * @param {(err?: Error | null, resolveBuildDependenciesResult?: ResolveBuildDependenciesResult) => void} callback callback function
@@ -1629,6 +1885,7 @@ class FileSystemInfo {
1629
1885
  missingDependencies: resolveMissing
1630
1886
  };
1631
1887
  /**
1888
+ * Expected to string.
1632
1889
  * @param {undefined | boolean | string} expected expected result
1633
1890
  * @returns {string} expected result
1634
1891
  */
@@ -1637,6 +1894,7 @@ class FileSystemInfo {
1637
1894
  /** @typedef {{ type: JobType, context: string | undefined, path: string, issuer: Job | undefined, expected: undefined | boolean | string }} Job */
1638
1895
 
1639
1896
  /**
1897
+ * Returns result.
1640
1898
  * @param {Job} job job
1641
1899
  * @returns {string} result
1642
1900
  */
@@ -1666,6 +1924,7 @@ class FileSystemInfo {
1666
1924
  return `unknown ${job.type} ${job.path}`;
1667
1925
  };
1668
1926
  /**
1927
+ * Returns string value.
1669
1928
  * @param {Job} job job
1670
1929
  * @returns {string} string value
1671
1930
  */
@@ -1696,6 +1955,7 @@ class FileSystemInfo {
1696
1955
  (job, push, callback) => {
1697
1956
  const { type, context, path, expected } = job;
1698
1957
  /**
1958
+ * Resolves directory.
1699
1959
  * @param {string} path path
1700
1960
  * @returns {void}
1701
1961
  */
@@ -1733,6 +1993,7 @@ class FileSystemInfo {
1733
1993
  );
1734
1994
  };
1735
1995
  /**
1996
+ * Processes the provided path.
1736
1997
  * @param {string} path path
1737
1998
  * @param {("f" | "c" | "e")=} symbol symbol
1738
1999
  * @param {(ResolveFunctionAsync)=} resolve resolve fn
@@ -1975,19 +2236,17 @@ class FileSystemInfo {
1975
2236
  const added = new Set();
1976
2237
  for (const imp of imports) {
1977
2238
  try {
1978
- /** @type {string} */
1979
- let dependency;
1980
- if (imp.d === -1) {
1981
- // import ... from "..."
1982
- dependency = parseString(
1983
- source.slice(imp.s - 1, imp.e + 1)
1984
- );
1985
- } else if (imp.d > -1) {
1986
- // import()
1987
- const expr = source.slice(imp.s, imp.e).trim();
1988
- dependency = parseString(expr);
1989
- } else {
1990
- // e.g. import.meta
2239
+ // import.meta
2240
+ if (imp.d === -2) {
2241
+ continue;
2242
+ }
2243
+
2244
+ /** @type {string | null} */
2245
+ const dependency =
2246
+ imp.n ||
2247
+ parseString(source.slice(imp.s, imp.e).trim());
2248
+
2249
+ if (!dependency) {
1991
2250
  continue;
1992
2251
  }
1993
2252
 
@@ -2128,6 +2387,7 @@ class FileSystemInfo {
2128
2387
  }
2129
2388
 
2130
2389
  /**
2390
+ * Checks resolve results valid.
2131
2391
  * @param {ResolveResults} resolveResults results from resolving
2132
2392
  * @param {(err?: Error | null, result?: boolean) => void} callback callback with true when resolveResults resolve the same way
2133
2393
  * @returns {void}
@@ -2191,6 +2451,7 @@ class FileSystemInfo {
2191
2451
  }
2192
2452
  },
2193
2453
  /**
2454
+ * Processes the provided err.
2194
2455
  * @param {Error | typeof INVALID=} err error or invalid flag
2195
2456
  * @returns {void}
2196
2457
  */
@@ -2209,6 +2470,7 @@ class FileSystemInfo {
2209
2470
  }
2210
2471
 
2211
2472
  /**
2473
+ * Creates a snapshot.
2212
2474
  * @param {number | null | undefined} startTime when processing the files has started
2213
2475
  * @param {Iterable<string> | null | undefined} files all files
2214
2476
  * @param {Iterable<string> | null | undefined} directories all directories
@@ -2218,30 +2480,29 @@ class FileSystemInfo {
2218
2480
  * @returns {void}
2219
2481
  */
2220
2482
  createSnapshot(startTime, files, directories, missing, options, callback) {
2221
- /** @type {FileTimestamps} */
2222
- const fileTimestamps = new Map();
2223
- /** @type {FileHashes} */
2224
- const fileHashes = new Map();
2225
- /** @type {FileTshs} */
2226
- const fileTshs = new Map();
2227
- /** @type {ContextTimestamps} */
2228
- const contextTimestamps = new Map();
2229
- /** @type {ContextHashes} */
2230
- const contextHashes = new Map();
2231
- /** @type {ContextTshs} */
2232
- const contextTshs = new Map();
2233
- /** @type {MissingExistence} */
2234
- const missingExistence = new Map();
2235
- /** @type {ManagedItemInfo} */
2236
- const managedItemInfo = new Map();
2483
+ // collections are allocated lazily to avoid per-snapshot garbage for unused modes
2484
+ /** @type {FileTimestamps | undefined} */
2485
+ let fileTimestamps;
2486
+ /** @type {FileHashes | undefined} */
2487
+ let fileHashes;
2488
+ /** @type {FileTshs | undefined} */
2489
+ let fileTshs;
2490
+ /** @type {ContextTimestamps | undefined} */
2491
+ let contextTimestamps;
2492
+ /** @type {ContextHashes | undefined} */
2493
+ let contextHashes;
2494
+ /** @type {ContextTshs | undefined} */
2495
+ let contextTshs;
2496
+ /** @type {MissingExistence | undefined} */
2497
+ let missingExistence;
2498
+ /** @type {ManagedItemInfo | undefined} */
2499
+ let managedItemInfo;
2237
2500
  /** @type {ManagedFiles} */
2238
2501
  const managedFiles = new Set();
2239
2502
  /** @type {ManagedContexts} */
2240
2503
  const managedContexts = new Set();
2241
2504
  /** @type {ManagedMissing} */
2242
2505
  const managedMissing = new Set();
2243
- /** @type {Children} */
2244
- const children = new Set();
2245
2506
 
2246
2507
  const snapshot = new Snapshot();
2247
2508
  if (startTime) snapshot.setStartTime(startTime);
@@ -2255,28 +2516,28 @@ class FileSystemInfo {
2255
2516
  let jobs = 1;
2256
2517
  const jobDone = () => {
2257
2518
  if (--jobs === 0) {
2258
- if (fileTimestamps.size !== 0) {
2519
+ if (fileTimestamps !== undefined && fileTimestamps.size !== 0) {
2259
2520
  snapshot.setFileTimestamps(fileTimestamps);
2260
2521
  }
2261
- if (fileHashes.size !== 0) {
2522
+ if (fileHashes !== undefined && fileHashes.size !== 0) {
2262
2523
  snapshot.setFileHashes(fileHashes);
2263
2524
  }
2264
- if (fileTshs.size !== 0) {
2525
+ if (fileTshs !== undefined && fileTshs.size !== 0) {
2265
2526
  snapshot.setFileTshs(fileTshs);
2266
2527
  }
2267
- if (contextTimestamps.size !== 0) {
2528
+ if (contextTimestamps !== undefined && contextTimestamps.size !== 0) {
2268
2529
  snapshot.setContextTimestamps(contextTimestamps);
2269
2530
  }
2270
- if (contextHashes.size !== 0) {
2531
+ if (contextHashes !== undefined && contextHashes.size !== 0) {
2271
2532
  snapshot.setContextHashes(contextHashes);
2272
2533
  }
2273
- if (contextTshs.size !== 0) {
2534
+ if (contextTshs !== undefined && contextTshs.size !== 0) {
2274
2535
  snapshot.setContextTshs(contextTshs);
2275
2536
  }
2276
- if (missingExistence.size !== 0) {
2537
+ if (missingExistence !== undefined && missingExistence.size !== 0) {
2277
2538
  snapshot.setMissingExistence(missingExistence);
2278
2539
  }
2279
- if (managedItemInfo.size !== 0) {
2540
+ if (managedItemInfo !== undefined && managedItemInfo.size !== 0) {
2280
2541
  snapshot.setManagedItemInfo(managedItemInfo);
2281
2542
  }
2282
2543
  this._managedFilesOptimization.optimize(snapshot, managedFiles);
@@ -2291,9 +2552,6 @@ class FileSystemInfo {
2291
2552
  if (managedMissing.size !== 0) {
2292
2553
  snapshot.setManagedMissing(managedMissing);
2293
2554
  }
2294
- if (children.size !== 0) {
2295
- snapshot.setChildren(children);
2296
- }
2297
2555
  this._snapshotCache.set(snapshot, true);
2298
2556
  this._statCreatedSnapshots++;
2299
2557
 
@@ -2307,26 +2565,44 @@ class FileSystemInfo {
2307
2565
  callback(null, null);
2308
2566
  }
2309
2567
  };
2568
+ const classificationCache = this._pathClassificationCache;
2310
2569
  /**
2570
+ * Checks true when managed.
2311
2571
  * @param {string} path path
2312
2572
  * @param {ManagedFiles} managedSet managed set
2313
2573
  * @returns {boolean} true when managed
2314
2574
  */
2315
2575
  const checkManaged = (path, managedSet) => {
2576
+ // classification is a pure function of the path, so it's shared across snapshots
2577
+ const cached = classificationCache.get(path);
2578
+ if (cached !== undefined) {
2579
+ if (cached === 0) return false;
2580
+ if (cached !== 1) managedItems.add(cached);
2581
+ managedSet.add(path);
2582
+ return true;
2583
+ }
2316
2584
  for (const unmanagedPath of this.unmanagedPathsRegExps) {
2317
- if (unmanagedPath.test(path)) return false;
2585
+ if (unmanagedPath.test(path)) {
2586
+ classificationCache.set(path, 0);
2587
+ return false;
2588
+ }
2318
2589
  }
2319
2590
  for (const unmanagedPath of this.unmanagedPathsWithSlash) {
2320
- if (path.startsWith(unmanagedPath)) return false;
2591
+ if (path.startsWith(unmanagedPath)) {
2592
+ classificationCache.set(path, 0);
2593
+ return false;
2594
+ }
2321
2595
  }
2322
2596
  for (const immutablePath of this.immutablePathsRegExps) {
2323
2597
  if (immutablePath.test(path)) {
2598
+ classificationCache.set(path, 1);
2324
2599
  managedSet.add(path);
2325
2600
  return true;
2326
2601
  }
2327
2602
  }
2328
2603
  for (const immutablePath of this.immutablePathsWithSlash) {
2329
2604
  if (path.startsWith(immutablePath)) {
2605
+ classificationCache.set(path, 1);
2330
2606
  managedSet.add(path);
2331
2607
  return true;
2332
2608
  }
@@ -2336,6 +2612,7 @@ class FileSystemInfo {
2336
2612
  if (match) {
2337
2613
  const managedItem = getManagedItem(match[1], path);
2338
2614
  if (managedItem) {
2615
+ classificationCache.set(path, managedItem);
2339
2616
  managedItems.add(managedItem);
2340
2617
  managedSet.add(path);
2341
2618
  return true;
@@ -2346,15 +2623,18 @@ class FileSystemInfo {
2346
2623
  if (path.startsWith(managedPath)) {
2347
2624
  const managedItem = getManagedItem(managedPath, path);
2348
2625
  if (managedItem) {
2626
+ classificationCache.set(path, managedItem);
2349
2627
  managedItems.add(managedItem);
2350
2628
  managedSet.add(path);
2351
2629
  return true;
2352
2630
  }
2353
2631
  }
2354
2632
  }
2633
+ classificationCache.set(path, 0);
2355
2634
  return false;
2356
2635
  };
2357
2636
  /**
2637
+ * Capture non managed.
2358
2638
  * @param {Iterable<string>} items items
2359
2639
  * @param {Set<string>} managedSet managed set
2360
2640
  * @returns {Set<string>} result
@@ -2368,6 +2648,7 @@ class FileSystemInfo {
2368
2648
  return capturedItems;
2369
2649
  };
2370
2650
  /**
2651
+ * Process captured files.
2371
2652
  * @param {ManagedFiles} capturedFiles captured files
2372
2653
  */
2373
2654
  const processCapturedFiles = (capturedFiles) => {
@@ -2375,12 +2656,14 @@ class FileSystemInfo {
2375
2656
  return;
2376
2657
  }
2377
2658
  switch (mode) {
2378
- case 3:
2659
+ case 3: {
2379
2660
  this._fileTshsOptimization.optimize(snapshot, capturedFiles);
2661
+ if (fileTshs === undefined) fileTshs = new Map();
2662
+ const fileTshsMap = fileTshs;
2380
2663
  for (const path of capturedFiles) {
2381
2664
  const cache = this._fileTshs.get(path);
2382
2665
  if (cache !== undefined) {
2383
- fileTshs.set(path, cache);
2666
+ fileTshsMap.set(path, cache);
2384
2667
  } else {
2385
2668
  jobs++;
2386
2669
  this._getFileTimestampAndHash(path, (err, entry) => {
@@ -2392,19 +2675,25 @@ class FileSystemInfo {
2392
2675
  }
2393
2676
  jobError();
2394
2677
  } else {
2395
- fileTshs.set(path, /** @type {TimestampAndHash} */ (entry));
2678
+ fileTshsMap.set(
2679
+ path,
2680
+ /** @type {TimestampAndHash} */ (entry)
2681
+ );
2396
2682
  jobDone();
2397
2683
  }
2398
2684
  });
2399
2685
  }
2400
2686
  }
2401
2687
  break;
2402
- case 2:
2688
+ }
2689
+ case 2: {
2403
2690
  this._fileHashesOptimization.optimize(snapshot, capturedFiles);
2691
+ if (fileHashes === undefined) fileHashes = new Map();
2692
+ const fileHashesMap = fileHashes;
2404
2693
  for (const path of capturedFiles) {
2405
2694
  const cache = this._fileHashes.get(path);
2406
2695
  if (cache !== undefined) {
2407
- fileHashes.set(path, cache);
2696
+ fileHashesMap.set(path, cache);
2408
2697
  } else {
2409
2698
  jobs++;
2410
2699
  this.fileHashQueue.add(path, (err, entry) => {
@@ -2416,20 +2705,26 @@ class FileSystemInfo {
2416
2705
  }
2417
2706
  jobError();
2418
2707
  } else {
2419
- fileHashes.set(path, /** @type {string} */ (entry));
2708
+ fileHashesMap.set(path, /** @type {string} */ (entry));
2420
2709
  jobDone();
2421
2710
  }
2422
2711
  });
2423
2712
  }
2424
2713
  }
2425
2714
  break;
2426
- case 1:
2715
+ }
2716
+ case 1: {
2427
2717
  this._fileTimestampsOptimization.optimize(snapshot, capturedFiles);
2718
+ if (fileTimestamps === undefined) fileTimestamps = new Map();
2719
+ const fileTimestampsMap = fileTimestamps;
2428
2720
  for (const path of capturedFiles) {
2429
2721
  const cache = this._fileTimestamps.get(path);
2430
- if (cache !== undefined) {
2722
+ if (cache !== undefined && !isExistenceOnly(cache)) {
2431
2723
  if (cache !== "ignore") {
2432
- fileTimestamps.set(path, cache);
2724
+ fileTimestampsMap.set(
2725
+ path,
2726
+ /** @type {FileSystemInfoEntry | null} */ (cache)
2727
+ );
2433
2728
  }
2434
2729
  } else {
2435
2730
  jobs++;
@@ -2442,7 +2737,7 @@ class FileSystemInfo {
2442
2737
  }
2443
2738
  jobError();
2444
2739
  } else {
2445
- fileTimestamps.set(
2740
+ fileTimestampsMap.set(
2446
2741
  path,
2447
2742
  /** @type {FileSystemInfoEntry} */
2448
2743
  (entry)
@@ -2453,12 +2748,14 @@ class FileSystemInfo {
2453
2748
  }
2454
2749
  }
2455
2750
  break;
2751
+ }
2456
2752
  }
2457
2753
  };
2458
2754
  if (files) {
2459
2755
  processCapturedFiles(captureNonManaged(files, managedFiles));
2460
2756
  }
2461
2757
  /**
2758
+ * Process captured directories.
2462
2759
  * @param {ManagedContexts} capturedDirectories captured directories
2463
2760
  */
2464
2761
  const processCapturedDirectories = (capturedDirectories) => {
@@ -2466,8 +2763,10 @@ class FileSystemInfo {
2466
2763
  return;
2467
2764
  }
2468
2765
  switch (mode) {
2469
- case 3:
2766
+ case 3: {
2470
2767
  this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
2768
+ if (contextTshs === undefined) contextTshs = new Map();
2769
+ const contextTshsMap = contextTshs;
2471
2770
  for (const path of capturedDirectories) {
2472
2771
  const cache = this._contextTshs.get(path);
2473
2772
  /** @type {ResolvedContextTimestampAndHash | null | undefined} */
@@ -2476,10 +2775,11 @@ class FileSystemInfo {
2476
2775
  cache !== undefined &&
2477
2776
  (resolved = getResolvedTimestamp(cache)) !== undefined
2478
2777
  ) {
2479
- contextTshs.set(path, resolved);
2778
+ contextTshsMap.set(path, resolved);
2480
2779
  } else {
2481
2780
  jobs++;
2482
2781
  /**
2782
+ * Processes the provided err.
2483
2783
  * @param {(WebpackError | null)=} err error
2484
2784
  * @param {(ResolvedContextTimestampAndHash | null)=} entry entry
2485
2785
  * @returns {void}
@@ -2493,7 +2793,7 @@ class FileSystemInfo {
2493
2793
  }
2494
2794
  jobError();
2495
2795
  } else {
2496
- contextTshs.set(
2796
+ contextTshsMap.set(
2497
2797
  path,
2498
2798
  /** @type {ResolvedContextTimestampAndHash | null} */
2499
2799
  (entry)
@@ -2509,11 +2809,14 @@ class FileSystemInfo {
2509
2809
  }
2510
2810
  }
2511
2811
  break;
2512
- case 2:
2812
+ }
2813
+ case 2: {
2513
2814
  this._contextHashesOptimization.optimize(
2514
2815
  snapshot,
2515
2816
  capturedDirectories
2516
2817
  );
2818
+ if (contextHashes === undefined) contextHashes = new Map();
2819
+ const contextHashesMap = contextHashes;
2517
2820
  for (const path of capturedDirectories) {
2518
2821
  const cache = this._contextHashes.get(path);
2519
2822
  /** @type {undefined | null | string} */
@@ -2522,10 +2825,11 @@ class FileSystemInfo {
2522
2825
  cache !== undefined &&
2523
2826
  (resolved = getResolvedHash(cache)) !== undefined
2524
2827
  ) {
2525
- contextHashes.set(path, resolved);
2828
+ contextHashesMap.set(path, resolved);
2526
2829
  } else {
2527
2830
  jobs++;
2528
2831
  /**
2832
+ * Processes the provided err.
2529
2833
  * @param {(WebpackError | null)=} err err
2530
2834
  * @param {string=} entry entry
2531
2835
  */
@@ -2538,7 +2842,7 @@ class FileSystemInfo {
2538
2842
  }
2539
2843
  jobError();
2540
2844
  } else {
2541
- contextHashes.set(path, /** @type {string} */ (entry));
2845
+ contextHashesMap.set(path, /** @type {string} */ (entry));
2542
2846
  jobDone();
2543
2847
  }
2544
2848
  };
@@ -2550,26 +2854,38 @@ class FileSystemInfo {
2550
2854
  }
2551
2855
  }
2552
2856
  break;
2553
- case 1:
2857
+ }
2858
+ case 1: {
2554
2859
  this._contextTimestampsOptimization.optimize(
2555
2860
  snapshot,
2556
2861
  capturedDirectories
2557
2862
  );
2863
+ if (contextTimestamps === undefined) contextTimestamps = new Map();
2864
+ const contextTimestampsMap = contextTimestamps;
2558
2865
  for (const path of capturedDirectories) {
2559
2866
  const cache = this._contextTimestamps.get(path);
2560
2867
  if (cache === "ignore") continue;
2868
+ /** @type {ContextFileSystemInfoEntry | null | undefined} */
2869
+ const usableCache =
2870
+ cache === undefined || isExistenceOnly(cache)
2871
+ ? undefined
2872
+ : /** @type {ContextFileSystemInfoEntry | null} */ (cache);
2873
+ const cacheLacksHash =
2874
+ contextCacheEntryLacksTimestampHash(usableCache);
2561
2875
  /** @type {undefined | null | ResolvedContextFileSystemInfoEntry} */
2562
2876
  let resolved;
2563
2877
  if (
2564
- cache !== undefined &&
2565
- (resolved = getResolvedTimestamp(cache)) !== undefined
2878
+ usableCache !== undefined &&
2879
+ !cacheLacksHash &&
2880
+ (resolved = getResolvedTimestamp(usableCache)) !== undefined
2566
2881
  ) {
2567
- contextTimestamps.set(path, resolved);
2882
+ contextTimestampsMap.set(path, resolved);
2568
2883
  } else {
2569
2884
  jobs++;
2570
2885
  /**
2571
- * @param {(Error | null)=} err error
2572
- * @param {FileTimestamp=} entry entry
2886
+ * Processes the provided err.
2887
+ * @param {(WebpackError | null)=} err error
2888
+ * @param {ResolvedContextTimestamp=} entry entry
2573
2889
  * @returns {void}
2574
2890
  */
2575
2891
  const callback = (err, entry) => {
@@ -2581,26 +2897,27 @@ class FileSystemInfo {
2581
2897
  }
2582
2898
  jobError();
2583
2899
  } else {
2584
- contextTimestamps.set(
2900
+ contextTimestampsMap.set(
2585
2901
  path,
2586
- /** @type {FileSystemInfoEntry | null} */
2902
+ /** @type {ResolvedContextFileSystemInfoEntry | null} */
2587
2903
  (entry)
2588
2904
  );
2589
2905
  jobDone();
2590
2906
  }
2591
2907
  };
2592
- if (cache !== undefined) {
2593
- this._resolveContextTimestamp(
2594
- /** @type {ContextFileSystemInfoEntry} */
2595
- (cache),
2596
- callback
2597
- );
2908
+ if (cacheLacksHash) {
2909
+ this._readFreshContextTimestamp(path, callback);
2910
+ } else if (usableCache !== undefined && usableCache !== null) {
2911
+ this._resolveContextTimestamp(usableCache, callback);
2598
2912
  } else {
2599
- this.getContextTimestamp(path, callback);
2913
+ // Force a fresh on-disk read so the snapshot stores a
2914
+ // complete entry (with `timestampHash`).
2915
+ this._readFreshContextTimestamp(path, callback);
2600
2916
  }
2601
2917
  }
2602
2918
  }
2603
2919
  break;
2920
+ }
2604
2921
  }
2605
2922
  };
2606
2923
  if (directories) {
@@ -2609,6 +2926,7 @@ class FileSystemInfo {
2609
2926
  );
2610
2927
  }
2611
2928
  /**
2929
+ * Process captured missing.
2612
2930
  * @param {ManagedMissing} capturedMissing captured missing
2613
2931
  */
2614
2932
  const processCapturedMissing = (capturedMissing) => {
@@ -2616,11 +2934,13 @@ class FileSystemInfo {
2616
2934
  return;
2617
2935
  }
2618
2936
  this._missingExistenceOptimization.optimize(snapshot, capturedMissing);
2937
+ if (missingExistence === undefined) missingExistence = new Map();
2938
+ const missingExistenceMap = missingExistence;
2619
2939
  for (const path of capturedMissing) {
2620
2940
  const cache = this._fileTimestamps.get(path);
2621
- if (cache !== undefined) {
2941
+ if (cache !== undefined && !isExistenceOnly(cache)) {
2622
2942
  if (cache !== "ignore") {
2623
- missingExistence.set(path, Boolean(cache));
2943
+ missingExistenceMap.set(path, Boolean(cache));
2624
2944
  }
2625
2945
  } else {
2626
2946
  jobs++;
@@ -2633,7 +2953,7 @@ class FileSystemInfo {
2633
2953
  }
2634
2954
  jobError();
2635
2955
  } else {
2636
- missingExistence.set(path, Boolean(entry));
2956
+ missingExistenceMap.set(path, Boolean(entry));
2637
2957
  jobDone();
2638
2958
  }
2639
2959
  });
@@ -2644,6 +2964,10 @@ class FileSystemInfo {
2644
2964
  processCapturedMissing(captureNonManaged(missing, managedMissing));
2645
2965
  }
2646
2966
  this._managedItemInfoOptimization.optimize(snapshot, managedItems);
2967
+ if (managedItems.size !== 0 && managedItemInfo === undefined) {
2968
+ managedItemInfo = new Map();
2969
+ }
2970
+ const managedItemInfoMap = managedItemInfo;
2647
2971
  for (const path of managedItems) {
2648
2972
  const cache = this._managedItems.get(path);
2649
2973
  if (cache !== undefined) {
@@ -2652,7 +2976,7 @@ class FileSystemInfo {
2652
2976
  } else if (cache === "*nested") {
2653
2977
  managedMissing.add(join(this.fs, path, "package.json"));
2654
2978
  }
2655
- managedItemInfo.set(path, cache);
2979
+ /** @type {ManagedItemInfo} */ (managedItemInfoMap).set(path, cache);
2656
2980
  } else {
2657
2981
  jobs++;
2658
2982
  this.managedItemQueue.add(path, (err, entry) => {
@@ -2669,11 +2993,15 @@ class FileSystemInfo {
2669
2993
  } else if (cache === "*nested") {
2670
2994
  managedMissing.add(join(this.fs, path, "package.json"));
2671
2995
  }
2672
- managedItemInfo.set(path, entry);
2996
+ /** @type {ManagedItemInfo} */ (managedItemInfoMap).set(
2997
+ path,
2998
+ entry
2999
+ );
2673
3000
  jobDone();
2674
3001
  } else {
2675
3002
  // Fallback to normal snapshotting
2676
3003
  /**
3004
+ * Processes the provided set.
2677
3005
  * @param {Set<string>} set set
2678
3006
  * @param {(set: Set<string>) => void} fn fn
2679
3007
  */
@@ -2698,6 +3026,7 @@ class FileSystemInfo {
2698
3026
  }
2699
3027
 
2700
3028
  /**
3029
+ * Merges the provided values into a single result.
2701
3030
  * @param {Snapshot} snapshot1 a snapshot
2702
3031
  * @param {Snapshot} snapshot2 a snapshot
2703
3032
  * @returns {Snapshot} merged snapshot
@@ -2784,6 +3113,7 @@ class FileSystemInfo {
2784
3113
  }
2785
3114
 
2786
3115
  /**
3116
+ * Checks snapshot valid.
2787
3117
  * @param {Snapshot} snapshot the snapshot made
2788
3118
  * @param {CheckSnapshotValidCallback} callback callback function
2789
3119
  * @returns {void}
@@ -2804,6 +3134,7 @@ class FileSystemInfo {
2804
3134
  }
2805
3135
 
2806
3136
  /**
3137
+ * Check snapshot valid no cache.
2807
3138
  * @private
2808
3139
  * @param {Snapshot} snapshot the snapshot made
2809
3140
  * @param {CheckSnapshotValidCallback} callback callback function
@@ -2831,6 +3162,7 @@ class FileSystemInfo {
2831
3162
  }
2832
3163
  };
2833
3164
  /**
3165
+ * Invalid with error.
2834
3166
  * @param {string} path path
2835
3167
  * @param {WebpackError} err err
2836
3168
  */
@@ -2841,6 +3173,7 @@ class FileSystemInfo {
2841
3173
  invalid();
2842
3174
  };
2843
3175
  /**
3176
+ * Checks true, if ok.
2844
3177
  * @param {string} path file path
2845
3178
  * @param {string | null} current current hash
2846
3179
  * @param {string | null} snap snapshot hash
@@ -2857,6 +3190,7 @@ class FileSystemInfo {
2857
3190
  return true;
2858
3191
  };
2859
3192
  /**
3193
+ * Checks true, if ok.
2860
3194
  * @param {string} path file path
2861
3195
  * @param {boolean} current current entry
2862
3196
  * @param {boolean} snap entry from snapshot
@@ -2877,6 +3211,7 @@ class FileSystemInfo {
2877
3211
  return true;
2878
3212
  };
2879
3213
  /**
3214
+ * Checks true, if ok.
2880
3215
  * @param {string} path file path
2881
3216
  * @param {FileSystemInfoEntry | null} c current entry
2882
3217
  * @param {FileSystemInfoEntry | null} s entry from snapshot
@@ -2919,6 +3254,7 @@ class FileSystemInfo {
2919
3254
  return true;
2920
3255
  };
2921
3256
  /**
3257
+ * Checks true, if ok.
2922
3258
  * @param {string} path file path
2923
3259
  * @param {ResolvedContextFileSystemInfoEntry | null} c current entry
2924
3260
  * @param {ResolvedContextFileSystemInfoEntry | null} s entry from snapshot
@@ -2965,6 +3301,7 @@ class FileSystemInfo {
2965
3301
  };
2966
3302
  if (snapshot.hasChildren()) {
2967
3303
  /**
3304
+ * Processes the provided err.
2968
3305
  * @param {(WebpackError | null)=} err err
2969
3306
  * @param {boolean=} result result
2970
3307
  * @returns {void}
@@ -3001,8 +3338,15 @@ class FileSystemInfo {
3001
3338
  this._statTestedEntries += fileTimestamps.size;
3002
3339
  for (const [path, ts] of fileTimestamps) {
3003
3340
  const cache = this._fileTimestamps.get(path);
3004
- if (cache !== undefined) {
3005
- if (cache !== "ignore" && !checkFile(path, cache, ts)) {
3341
+ if (cache !== undefined && !isExistenceOnly(cache)) {
3342
+ if (
3343
+ cache !== "ignore" &&
3344
+ !checkFile(
3345
+ path,
3346
+ /** @type {FileSystemInfoEntry | null} */ (cache),
3347
+ ts
3348
+ )
3349
+ ) {
3006
3350
  invalid();
3007
3351
  return;
3008
3352
  }
@@ -3026,6 +3370,7 @@ class FileSystemInfo {
3026
3370
  }
3027
3371
  }
3028
3372
  /**
3373
+ * Process file hash snapshot.
3029
3374
  * @param {string} path file path
3030
3375
  * @param {string | null} hash hash
3031
3376
  */
@@ -3062,8 +3407,16 @@ class FileSystemInfo {
3062
3407
  processFileHashSnapshot(path, tsh);
3063
3408
  } else {
3064
3409
  const cache = this._fileTimestamps.get(path);
3065
- if (cache !== undefined) {
3066
- if (cache === "ignore" || !checkFile(path, cache, tsh, false)) {
3410
+ if (cache !== undefined && !isExistenceOnly(cache)) {
3411
+ if (
3412
+ cache === "ignore" ||
3413
+ !checkFile(
3414
+ path,
3415
+ /** @type {FileSystemInfoEntry | null} */ (cache),
3416
+ tsh,
3417
+ false
3418
+ )
3419
+ ) {
3067
3420
  processFileHashSnapshot(path, tsh && tsh.hash);
3068
3421
  }
3069
3422
  } else {
@@ -3095,11 +3448,24 @@ class FileSystemInfo {
3095
3448
  for (const [path, ts] of contextTimestamps) {
3096
3449
  const cache = this._contextTimestamps.get(path);
3097
3450
  if (cache === "ignore") continue;
3451
+ // Treat existence-only entries (`{}` from watchpack) as a cache
3452
+ // miss — they carry no time info, so we cannot compare them to
3453
+ // the snapshot.
3454
+ /** @type {ContextFileSystemInfoEntry | null | undefined} */
3455
+ const usableCache =
3456
+ cache === undefined || isExistenceOnly(cache)
3457
+ ? undefined
3458
+ : /** @type {ContextFileSystemInfoEntry | null} */ (cache);
3459
+ const cacheLacksHash =
3460
+ contextCacheEntryLacksTimestampHash(usableCache) &&
3461
+ ts !== null &&
3462
+ ts.timestampHash !== undefined;
3098
3463
  /** @type {undefined | null | ResolvedContextFileSystemInfoEntry} */
3099
3464
  let resolved;
3100
3465
  if (
3101
- cache !== undefined &&
3102
- (resolved = getResolvedTimestamp(cache)) !== undefined
3466
+ usableCache !== undefined &&
3467
+ !cacheLacksHash &&
3468
+ (resolved = getResolvedTimestamp(usableCache)) !== undefined
3103
3469
  ) {
3104
3470
  if (!checkContext(path, resolved, ts)) {
3105
3471
  invalid();
@@ -3108,6 +3474,7 @@ class FileSystemInfo {
3108
3474
  } else {
3109
3475
  jobs++;
3110
3476
  /**
3477
+ * Processes the provided err.
3111
3478
  * @param {(WebpackError | null)=} err error
3112
3479
  * @param {ResolvedContextTimestamp=} entry entry
3113
3480
  * @returns {void}
@@ -3127,12 +3494,10 @@ class FileSystemInfo {
3127
3494
  jobDone();
3128
3495
  }
3129
3496
  };
3130
- if (cache !== undefined) {
3131
- this._resolveContextTimestamp(
3132
- /** @type {ContextFileSystemInfoEntry} */
3133
- (cache),
3134
- callback
3135
- );
3497
+ if (cacheLacksHash) {
3498
+ this._readFreshContextTimestamp(path, callback);
3499
+ } else if (usableCache !== undefined && usableCache !== null) {
3500
+ this._resolveContextTimestamp(usableCache, callback);
3136
3501
  } else {
3137
3502
  this.getContextTimestamp(path, callback);
3138
3503
  }
@@ -3140,6 +3505,7 @@ class FileSystemInfo {
3140
3505
  }
3141
3506
  }
3142
3507
  /**
3508
+ * Process context hash snapshot.
3143
3509
  * @param {string} path path
3144
3510
  * @param {string | null} hash hash
3145
3511
  */
@@ -3157,6 +3523,7 @@ class FileSystemInfo {
3157
3523
  } else {
3158
3524
  jobs++;
3159
3525
  /**
3526
+ * Processes the provided err.
3160
3527
  * @param {(WebpackError | null)=} err err
3161
3528
  * @param {string=} entry entry
3162
3529
  * @returns {void}
@@ -3194,11 +3561,22 @@ class FileSystemInfo {
3194
3561
  } else {
3195
3562
  const cache = this._contextTimestamps.get(path);
3196
3563
  if (cache === "ignore") continue;
3564
+ // See the matching block in `hasContextTimestamps` above.
3565
+ /** @type {ContextFileSystemInfoEntry | null | undefined} */
3566
+ const usableCache =
3567
+ cache === undefined || isExistenceOnly(cache)
3568
+ ? undefined
3569
+ : /** @type {ContextFileSystemInfoEntry | null} */ (cache);
3570
+ const cacheLacksHash =
3571
+ contextCacheEntryLacksTimestampHash(usableCache) &&
3572
+ tsh !== null &&
3573
+ tsh.timestampHash !== undefined;
3197
3574
  /** @type {undefined | null | ResolvedContextFileSystemInfoEntry} */
3198
3575
  let resolved;
3199
3576
  if (
3200
- cache !== undefined &&
3201
- (resolved = getResolvedTimestamp(cache)) !== undefined
3577
+ usableCache !== undefined &&
3578
+ !cacheLacksHash &&
3579
+ (resolved = getResolvedTimestamp(usableCache)) !== undefined
3202
3580
  ) {
3203
3581
  if (!checkContext(path, resolved, tsh, false)) {
3204
3582
  processContextHashSnapshot(path, tsh && tsh.hash);
@@ -3206,6 +3584,7 @@ class FileSystemInfo {
3206
3584
  } else {
3207
3585
  jobs++;
3208
3586
  /**
3587
+ * Processes the provided err.
3209
3588
  * @param {(WebpackError | null)=} err error
3210
3589
  * @param {ResolvedContextTimestamp=} entry entry
3211
3590
  * @returns {void}
@@ -3215,7 +3594,6 @@ class FileSystemInfo {
3215
3594
  if (
3216
3595
  !checkContext(
3217
3596
  path,
3218
- // TODO: test with `"ignore"`
3219
3597
  /** @type {ResolvedContextFileSystemInfoEntry | null} */
3220
3598
  (entry),
3221
3599
  tsh,
@@ -3226,12 +3604,10 @@ class FileSystemInfo {
3226
3604
  }
3227
3605
  jobDone();
3228
3606
  };
3229
- if (cache !== undefined) {
3230
- this._resolveContextTimestamp(
3231
- /** @type {ContextFileSystemInfoEntry} */
3232
- (cache),
3233
- callback
3234
- );
3607
+ if (cacheLacksHash) {
3608
+ this._readFreshContextTimestamp(path, callback);
3609
+ } else if (usableCache !== undefined && usableCache !== null) {
3610
+ this._resolveContextTimestamp(usableCache, callback);
3235
3611
  } else {
3236
3612
  this.getContextTimestamp(path, callback);
3237
3613
  }
@@ -3246,7 +3622,7 @@ class FileSystemInfo {
3246
3622
  this._statTestedEntries += missingExistence.size;
3247
3623
  for (const [path, existence] of missingExistence) {
3248
3624
  const cache = this._fileTimestamps.get(path);
3249
- if (cache !== undefined) {
3625
+ if (cache !== undefined && !isExistenceOnly(cache)) {
3250
3626
  if (
3251
3627
  cache !== "ignore" &&
3252
3628
  !checkExistence(path, Boolean(cache), Boolean(existence))
@@ -3382,12 +3758,14 @@ class FileSystemInfo {
3382
3758
  }
3383
3759
 
3384
3760
  /**
3761
+ * Get file timestamp and hash.
3385
3762
  * @private
3386
3763
  * @param {string} path path
3387
3764
  * @param {(err: WebpackError | null, timestampAndHash?: TimestampAndHash | string) => void} callback callback
3388
3765
  */
3389
3766
  _getFileTimestampAndHash(path, callback) {
3390
3767
  /**
3768
+ * Continue with hash.
3391
3769
  * @param {string} hash hash
3392
3770
  * @returns {void}
3393
3771
  */
@@ -3434,6 +3812,7 @@ class FileSystemInfo {
3434
3812
  }
3435
3813
 
3436
3814
  /**
3815
+ * Processes the provided object.
3437
3816
  * @private
3438
3817
  * @template T
3439
3818
  * @template ItemType
@@ -3573,8 +3952,13 @@ class FileSystemInfo {
3573
3952
  fromFile: (file, stat, callback) => {
3574
3953
  // Prefer the cached value over our new stat to report consistent results
3575
3954
  const cache = this._fileTimestamps.get(file);
3576
- if (cache !== undefined) {
3577
- return callback(null, cache === "ignore" ? null : cache);
3955
+ if (cache !== undefined && !isExistenceOnly(cache)) {
3956
+ return callback(
3957
+ null,
3958
+ cache === "ignore"
3959
+ ? null
3960
+ : /** @type {FileSystemInfoEntry | null} */ (cache)
3961
+ );
3578
3962
  }
3579
3963
 
3580
3964
  const mtime = Number(stat.mtime);
@@ -3663,6 +4047,7 @@ class FileSystemInfo {
3663
4047
  }
3664
4048
 
3665
4049
  /**
4050
+ * Resolve context timestamp.
3666
4051
  * @private
3667
4052
  * @param {ContextFileSystemInfoEntry} entry entry
3668
4053
  * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback
@@ -3672,6 +4057,8 @@ class FileSystemInfo {
3672
4057
  /** @type {string[]} */
3673
4058
  const hashes = [];
3674
4059
  let safeTime = 0;
4060
+ // Skip already-visited symlink targets so cyclic pnpm/peer-variant graphs terminate (#21084).
4061
+ const seen = new Set(entry.symlinks);
3675
4062
  processAsyncTree(
3676
4063
  /** @type {NonNullable<ContextHash["symlinks"]>} */ (entry.symlinks),
3677
4064
  10,
@@ -3684,7 +4071,12 @@ class FileSystemInfo {
3684
4071
  safeTime = Math.max(safeTime, entry.safeTime);
3685
4072
  }
3686
4073
  if (entry.symlinks !== undefined) {
3687
- for (const target of entry.symlinks) push(target);
4074
+ for (const target of entry.symlinks) {
4075
+ if (!seen.has(target)) {
4076
+ seen.add(target);
4077
+ push(target);
4078
+ }
4079
+ }
3688
4080
  }
3689
4081
  }
3690
4082
  callback();
@@ -3744,8 +4136,9 @@ class FileSystemInfo {
3744
4136
  });
3745
4137
  },
3746
4138
  /**
4139
+ * Returns reduced hash.
3747
4140
  * @param {string[]} files files
3748
- * @param {(string | ContextHash)[]} fileHashes hashes
4141
+ * @param {(string | ContextHash | null)[]} fileHashes hashes
3749
4142
  * @returns {ContextHash} reduced hash
3750
4143
  */
3751
4144
  reduce: (files, fileHashes) => {
@@ -3755,10 +4148,13 @@ class FileSystemInfo {
3755
4148
 
3756
4149
  for (const file of files) hash.update(file);
3757
4150
  for (const entry of fileHashes) {
3758
- if (typeof entry === "string") {
4151
+ // null for unsupported entry kinds (FIFO, socket); skip like the tsh reduce
4152
+ if (!entry) {
4153
+ continue;
4154
+ } else if (typeof entry === "string") {
3759
4155
  hash.update(entry);
3760
4156
  } else {
3761
- hash.update(entry.hash);
4157
+ if (entry.hash) hash.update(entry.hash);
3762
4158
  if (entry.symlinks) {
3763
4159
  if (symlinks === undefined) symlinks = new Set();
3764
4160
  addAll(entry.symlinks, symlinks);
@@ -3784,6 +4180,7 @@ class FileSystemInfo {
3784
4180
  }
3785
4181
 
3786
4182
  /**
4183
+ * Resolve context hash.
3787
4184
  * @private
3788
4185
  * @param {ContextHash} entry context hash
3789
4186
  * @param {(err: WebpackError | null, contextHash?: string) => void} callback callback
@@ -3792,6 +4189,8 @@ class FileSystemInfo {
3792
4189
  _resolveContextHash(entry, callback) {
3793
4190
  /** @type {string[]} */
3794
4191
  const hashes = [];
4192
+ // Skip already-visited symlink targets so cyclic pnpm/peer-variant graphs terminate (#21084).
4193
+ const seen = new Set(entry.symlinks);
3795
4194
  processAsyncTree(
3796
4195
  /** @type {NonNullable<ContextHash["symlinks"]>} */ (entry.symlinks),
3797
4196
  10,
@@ -3801,7 +4200,12 @@ class FileSystemInfo {
3801
4200
  if (hash) {
3802
4201
  hashes.push(hash.hash);
3803
4202
  if (hash.symlinks !== undefined) {
3804
- for (const target of hash.symlinks) push(target);
4203
+ for (const target of hash.symlinks) {
4204
+ if (!seen.has(target)) {
4205
+ seen.add(target);
4206
+ push(target);
4207
+ }
4208
+ }
3805
4209
  }
3806
4210
  }
3807
4211
  callback();
@@ -3826,6 +4230,7 @@ class FileSystemInfo {
3826
4230
  */
3827
4231
  _readContextTimestampAndHash(path, callback) {
3828
4232
  /**
4233
+ * Processes the provided timestamp.
3829
4234
  * @param {ContextTimestamp} timestamp timestamp
3830
4235
  * @param {ContextHash} hash hash
3831
4236
  */
@@ -3887,6 +4292,7 @@ class FileSystemInfo {
3887
4292
  });
3888
4293
  },
3889
4294
  /**
4295
+ * Returns tsh.
3890
4296
  * @param {string[]} files files
3891
4297
  * @param {(Partial<TimestampAndHash> & Partial<ContextTimestampAndHash> | string | null)[]} results results
3892
4298
  * @returns {ContextTimestampAndHash} tsh
@@ -3951,6 +4357,7 @@ class FileSystemInfo {
3951
4357
  }
3952
4358
 
3953
4359
  /**
4360
+ * Resolve context tsh.
3954
4361
  * @private
3955
4362
  * @param {ContextTimestampAndHash} entry entry
3956
4363
  * @param {ProcessorCallback<ResolvedContextTimestampAndHash>} callback callback
@@ -3962,6 +4369,8 @@ class FileSystemInfo {
3962
4369
  /** @type {string[]} */
3963
4370
  const tsHashes = [];
3964
4371
  let safeTime = 0;
4372
+ // Skip already-visited symlink targets so cyclic pnpm/peer-variant graphs terminate (#21084).
4373
+ const seen = new Set(entry.symlinks);
3965
4374
  processAsyncTree(
3966
4375
  /** @type {NonNullable<ContextHash["symlinks"]>} */ (entry.symlinks),
3967
4376
  10,
@@ -3975,7 +4384,12 @@ class FileSystemInfo {
3975
4384
  safeTime = Math.max(safeTime, entry.safeTime);
3976
4385
  }
3977
4386
  if (entry.symlinks !== undefined) {
3978
- for (const target of entry.symlinks) push(target);
4387
+ for (const target of entry.symlinks) {
4388
+ if (!seen.has(target)) {
4389
+ seen.add(target);
4390
+ push(target);
4391
+ }
4392
+ }
3979
4393
  }
3980
4394
  }
3981
4395
  callback();
@@ -4111,7 +4525,13 @@ class FileSystemInfo {
4111
4525
  /** @type {Map<string, number | null>} */
4112
4526
  const map = new Map();
4113
4527
  for (const [path, info] of this._fileTimestamps) {
4114
- if (info) map.set(path, typeof info === "object" ? info.safeTime : null);
4528
+ if (info) {
4529
+ const safeTime =
4530
+ typeof info === "object"
4531
+ ? /** @type {Partial<FileSystemInfoEntry>} */ (info).safeTime
4532
+ : undefined;
4533
+ map.set(path, safeTime === undefined ? null : safeTime);
4534
+ }
4115
4535
  }
4116
4536
  return (this._cachedDeprecatedFileTimestamps = map);
4117
4537
  }
@@ -4123,7 +4543,13 @@ class FileSystemInfo {
4123
4543
  /** @type {Map<string, number | null>} */
4124
4544
  const map = new Map();
4125
4545
  for (const [path, info] of this._contextTimestamps) {
4126
- if (info) map.set(path, typeof info === "object" ? info.safeTime : null);
4546
+ if (info) {
4547
+ const safeTime =
4548
+ typeof info === "object"
4549
+ ? /** @type {Partial<ContextFileSystemInfoEntry>} */ (info).safeTime
4550
+ : undefined;
4551
+ map.set(path, safeTime === undefined ? null : safeTime);
4552
+ }
4127
4553
  }
4128
4554
  return (this._cachedDeprecatedContextTimestamps = map);
4129
4555
  }