@depup/webpack 5.105.4-depup.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (709) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +38 -0
  3. package/bin/webpack.js +196 -0
  4. package/hot/dev-server.js +90 -0
  5. package/hot/emitter-event-target.js +7 -0
  6. package/hot/emitter.js +2 -0
  7. package/hot/lazy-compilation-node.js +66 -0
  8. package/hot/lazy-compilation-universal.js +18 -0
  9. package/hot/lazy-compilation-web.js +93 -0
  10. package/hot/load-http.js +7 -0
  11. package/hot/log-apply-result.js +49 -0
  12. package/hot/log.js +78 -0
  13. package/hot/only-dev-server.js +118 -0
  14. package/hot/poll.js +41 -0
  15. package/hot/signal.js +66 -0
  16. package/lib/APIPlugin.js +392 -0
  17. package/lib/AbstractMethodError.js +56 -0
  18. package/lib/AsyncDependenciesBlock.js +128 -0
  19. package/lib/AsyncDependencyToInitialChunkError.js +34 -0
  20. package/lib/AutomaticPrefetchPlugin.js +66 -0
  21. package/lib/BannerPlugin.js +138 -0
  22. package/lib/Cache.js +168 -0
  23. package/lib/CacheFacade.js +349 -0
  24. package/lib/CaseSensitiveModulesWarning.js +72 -0
  25. package/lib/Chunk.js +899 -0
  26. package/lib/ChunkGraph.js +1968 -0
  27. package/lib/ChunkGroup.js +615 -0
  28. package/lib/ChunkRenderError.js +38 -0
  29. package/lib/ChunkTemplate.js +181 -0
  30. package/lib/CleanPlugin.js +495 -0
  31. package/lib/CodeGenerationError.js +35 -0
  32. package/lib/CodeGenerationResults.js +167 -0
  33. package/lib/CommentCompilationWarning.js +33 -0
  34. package/lib/CompatibilityPlugin.js +240 -0
  35. package/lib/Compilation.js +5876 -0
  36. package/lib/Compiler.js +1413 -0
  37. package/lib/ConcatenationScope.js +181 -0
  38. package/lib/ConcurrentCompilationError.js +18 -0
  39. package/lib/ConditionalInitFragment.js +120 -0
  40. package/lib/ConstPlugin.js +567 -0
  41. package/lib/ContextExclusionPlugin.js +33 -0
  42. package/lib/ContextModule.js +1411 -0
  43. package/lib/ContextModuleFactory.js +514 -0
  44. package/lib/ContextReplacementPlugin.js +227 -0
  45. package/lib/CssModule.js +179 -0
  46. package/lib/DefinePlugin.js +878 -0
  47. package/lib/DelegatedModule.js +279 -0
  48. package/lib/DelegatedModuleFactoryPlugin.js +116 -0
  49. package/lib/DelegatedPlugin.js +49 -0
  50. package/lib/DependenciesBlock.js +120 -0
  51. package/lib/Dependency.js +390 -0
  52. package/lib/DependencyTemplate.js +71 -0
  53. package/lib/DependencyTemplates.js +67 -0
  54. package/lib/DllEntryPlugin.js +76 -0
  55. package/lib/DllModule.js +175 -0
  56. package/lib/DllModuleFactory.js +38 -0
  57. package/lib/DllPlugin.js +73 -0
  58. package/lib/DllReferencePlugin.js +189 -0
  59. package/lib/DotenvPlugin.js +468 -0
  60. package/lib/DynamicEntryPlugin.js +93 -0
  61. package/lib/EntryOptionPlugin.js +98 -0
  62. package/lib/EntryPlugin.js +72 -0
  63. package/lib/Entrypoint.js +120 -0
  64. package/lib/EnvironmentNotSupportAsyncWarning.js +51 -0
  65. package/lib/EnvironmentPlugin.js +74 -0
  66. package/lib/ErrorHelpers.js +100 -0
  67. package/lib/EvalDevToolModulePlugin.js +135 -0
  68. package/lib/EvalSourceMapDevToolPlugin.js +252 -0
  69. package/lib/ExportsInfo.js +1663 -0
  70. package/lib/ExportsInfoApiPlugin.js +87 -0
  71. package/lib/ExternalModule.js +1169 -0
  72. package/lib/ExternalModuleFactoryPlugin.js +370 -0
  73. package/lib/ExternalsPlugin.js +93 -0
  74. package/lib/FalseIIFEUmdWarning.js +20 -0
  75. package/lib/FileSystemInfo.js +4131 -0
  76. package/lib/FlagAllModulesAsUsedPlugin.js +55 -0
  77. package/lib/FlagDependencyExportsPlugin.js +437 -0
  78. package/lib/FlagDependencyUsagePlugin.js +348 -0
  79. package/lib/FlagEntryExportAsUsedPlugin.js +56 -0
  80. package/lib/Generator.js +188 -0
  81. package/lib/GraphHelpers.js +46 -0
  82. package/lib/HarmonyLinkingError.js +17 -0
  83. package/lib/HookWebpackError.js +121 -0
  84. package/lib/HotModuleReplacementPlugin.js +930 -0
  85. package/lib/HotUpdateChunk.js +16 -0
  86. package/lib/IgnoreErrorModuleFactory.js +39 -0
  87. package/lib/IgnorePlugin.js +105 -0
  88. package/lib/IgnoreWarningsPlugin.js +41 -0
  89. package/lib/InitFragment.js +204 -0
  90. package/lib/InvalidDependenciesModuleWarning.js +44 -0
  91. package/lib/JavascriptMetaInfoPlugin.js +78 -0
  92. package/lib/LibManifestPlugin.js +144 -0
  93. package/lib/LibraryTemplatePlugin.js +48 -0
  94. package/lib/LoaderOptionsPlugin.js +81 -0
  95. package/lib/LoaderTargetPlugin.js +39 -0
  96. package/lib/MainTemplate.js +371 -0
  97. package/lib/ManifestPlugin.js +242 -0
  98. package/lib/Module.js +1319 -0
  99. package/lib/ModuleBuildError.js +83 -0
  100. package/lib/ModuleDependencyError.js +44 -0
  101. package/lib/ModuleDependencyWarning.js +49 -0
  102. package/lib/ModuleError.js +69 -0
  103. package/lib/ModuleFactory.js +57 -0
  104. package/lib/ModuleFilenameHelpers.js +388 -0
  105. package/lib/ModuleGraph.js +1024 -0
  106. package/lib/ModuleGraphConnection.js +199 -0
  107. package/lib/ModuleHashingError.js +31 -0
  108. package/lib/ModuleInfoHeaderPlugin.js +318 -0
  109. package/lib/ModuleNotFoundError.js +90 -0
  110. package/lib/ModuleParseError.js +125 -0
  111. package/lib/ModuleProfile.js +108 -0
  112. package/lib/ModuleRestoreError.js +46 -0
  113. package/lib/ModuleSourceTypeConstants.js +179 -0
  114. package/lib/ModuleStoreError.js +45 -0
  115. package/lib/ModuleTemplate.js +173 -0
  116. package/lib/ModuleTypeConstants.js +190 -0
  117. package/lib/ModuleWarning.js +68 -0
  118. package/lib/MultiCompiler.js +678 -0
  119. package/lib/MultiStats.js +213 -0
  120. package/lib/MultiWatching.js +77 -0
  121. package/lib/NoEmitOnErrorsPlugin.js +30 -0
  122. package/lib/NoModeWarning.js +23 -0
  123. package/lib/NodeStuffInWebError.js +35 -0
  124. package/lib/NodeStuffPlugin.js +587 -0
  125. package/lib/NormalModule.js +1798 -0
  126. package/lib/NormalModuleFactory.js +1455 -0
  127. package/lib/NormalModuleReplacementPlugin.js +75 -0
  128. package/lib/NullFactory.js +24 -0
  129. package/lib/OptimizationStages.js +10 -0
  130. package/lib/OptionsApply.js +24 -0
  131. package/lib/Parser.js +40 -0
  132. package/lib/PlatformPlugin.js +41 -0
  133. package/lib/PrefetchPlugin.js +56 -0
  134. package/lib/ProgressPlugin.js +712 -0
  135. package/lib/ProvidePlugin.js +121 -0
  136. package/lib/RawModule.js +180 -0
  137. package/lib/RecordIdsPlugin.js +216 -0
  138. package/lib/RequestShortener.js +36 -0
  139. package/lib/RequireJsStuffPlugin.js +84 -0
  140. package/lib/ResolverFactory.js +156 -0
  141. package/lib/RuntimeGlobals.js +450 -0
  142. package/lib/RuntimeModule.js +242 -0
  143. package/lib/RuntimePlugin.js +547 -0
  144. package/lib/RuntimeTemplate.js +1288 -0
  145. package/lib/SelfModuleFactory.js +33 -0
  146. package/lib/SingleEntryPlugin.js +8 -0
  147. package/lib/SizeFormatHelpers.js +25 -0
  148. package/lib/SourceMapDevToolModuleOptionsPlugin.js +52 -0
  149. package/lib/SourceMapDevToolPlugin.js +646 -0
  150. package/lib/Stats.js +89 -0
  151. package/lib/Template.js +427 -0
  152. package/lib/TemplatedPathPlugin.js +400 -0
  153. package/lib/UnhandledSchemeError.js +34 -0
  154. package/lib/UnsupportedFeatureWarning.js +35 -0
  155. package/lib/UseStrictPlugin.js +81 -0
  156. package/lib/WarnCaseSensitiveModulesPlugin.js +64 -0
  157. package/lib/WarnDeprecatedOptionPlugin.js +60 -0
  158. package/lib/WarnNoModeSetPlugin.js +27 -0
  159. package/lib/WatchIgnorePlugin.js +155 -0
  160. package/lib/Watching.js +531 -0
  161. package/lib/WebpackError.js +81 -0
  162. package/lib/WebpackIsIncludedPlugin.js +93 -0
  163. package/lib/WebpackOptionsApply.js +941 -0
  164. package/lib/WebpackOptionsDefaulter.js +26 -0
  165. package/lib/asset/AssetBytesGenerator.js +172 -0
  166. package/lib/asset/AssetBytesParser.js +37 -0
  167. package/lib/asset/AssetGenerator.js +816 -0
  168. package/lib/asset/AssetModulesPlugin.js +358 -0
  169. package/lib/asset/AssetParser.js +73 -0
  170. package/lib/asset/AssetSourceGenerator.js +171 -0
  171. package/lib/asset/AssetSourceParser.js +37 -0
  172. package/lib/asset/RawDataUrlModule.js +179 -0
  173. package/lib/async-modules/AsyncModuleHelpers.js +52 -0
  174. package/lib/async-modules/AwaitDependenciesInitFragment.js +90 -0
  175. package/lib/async-modules/InferAsyncModulesPlugin.js +54 -0
  176. package/lib/buildChunkGraph.js +1392 -0
  177. package/lib/cache/AddBuildDependenciesPlugin.js +32 -0
  178. package/lib/cache/AddManagedPathsPlugin.js +40 -0
  179. package/lib/cache/IdleFileCachePlugin.js +242 -0
  180. package/lib/cache/MemoryCachePlugin.js +57 -0
  181. package/lib/cache/MemoryWithGcCachePlugin.js +142 -0
  182. package/lib/cache/PackFileCacheStrategy.js +1600 -0
  183. package/lib/cache/ResolverCachePlugin.js +450 -0
  184. package/lib/cache/getLazyHashedEtag.js +91 -0
  185. package/lib/cache/mergeEtags.js +71 -0
  186. package/lib/cli.js +859 -0
  187. package/lib/config/browserslistTargetHandler.js +388 -0
  188. package/lib/config/defaults.js +2086 -0
  189. package/lib/config/normalization.js +681 -0
  190. package/lib/config/target.js +389 -0
  191. package/lib/container/ContainerEntryDependency.js +50 -0
  192. package/lib/container/ContainerEntryModule.js +303 -0
  193. package/lib/container/ContainerEntryModuleFactory.js +27 -0
  194. package/lib/container/ContainerExposedDependency.js +62 -0
  195. package/lib/container/ContainerPlugin.js +118 -0
  196. package/lib/container/ContainerReferencePlugin.js +139 -0
  197. package/lib/container/FallbackDependency.js +66 -0
  198. package/lib/container/FallbackItemDependency.js +34 -0
  199. package/lib/container/FallbackModule.js +193 -0
  200. package/lib/container/FallbackModuleFactory.js +27 -0
  201. package/lib/container/HoistContainerReferencesPlugin.js +256 -0
  202. package/lib/container/ModuleFederationPlugin.js +131 -0
  203. package/lib/container/RemoteModule.js +225 -0
  204. package/lib/container/RemoteRuntimeModule.js +144 -0
  205. package/lib/container/RemoteToExternalDependency.js +33 -0
  206. package/lib/container/options.js +105 -0
  207. package/lib/css/CssGenerator.js +587 -0
  208. package/lib/css/CssLoadingRuntimeModule.js +513 -0
  209. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  210. package/lib/css/CssModulesPlugin.js +939 -0
  211. package/lib/css/CssParser.js +2621 -0
  212. package/lib/css/walkCssTokens.js +1740 -0
  213. package/lib/debug/ProfilingPlugin.js +589 -0
  214. package/lib/dependencies/AMDDefineDependency.js +267 -0
  215. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +504 -0
  216. package/lib/dependencies/AMDPlugin.js +243 -0
  217. package/lib/dependencies/AMDRequireArrayDependency.js +124 -0
  218. package/lib/dependencies/AMDRequireContextDependency.js +69 -0
  219. package/lib/dependencies/AMDRequireDependenciesBlock.js +28 -0
  220. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +425 -0
  221. package/lib/dependencies/AMDRequireDependency.js +189 -0
  222. package/lib/dependencies/AMDRequireItemDependency.js +41 -0
  223. package/lib/dependencies/AMDRuntimeModules.js +50 -0
  224. package/lib/dependencies/CachedConstDependency.js +135 -0
  225. package/lib/dependencies/CommonJsDependencyHelpers.js +65 -0
  226. package/lib/dependencies/CommonJsExportRequireDependency.js +416 -0
  227. package/lib/dependencies/CommonJsExportsDependency.js +184 -0
  228. package/lib/dependencies/CommonJsExportsParserPlugin.js +425 -0
  229. package/lib/dependencies/CommonJsFullRequireDependency.js +162 -0
  230. package/lib/dependencies/CommonJsImportsParserPlugin.js +611 -0
  231. package/lib/dependencies/CommonJsPlugin.js +316 -0
  232. package/lib/dependencies/CommonJsRequireContextDependency.js +73 -0
  233. package/lib/dependencies/CommonJsRequireDependency.js +42 -0
  234. package/lib/dependencies/CommonJsSelfReferenceDependency.js +156 -0
  235. package/lib/dependencies/ConstDependency.js +118 -0
  236. package/lib/dependencies/ContextDependency.js +183 -0
  237. package/lib/dependencies/ContextDependencyHelpers.js +277 -0
  238. package/lib/dependencies/ContextDependencyTemplateAsId.js +63 -0
  239. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +62 -0
  240. package/lib/dependencies/ContextElementDependency.js +147 -0
  241. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  242. package/lib/dependencies/CreateScriptUrlDependency.js +75 -0
  243. package/lib/dependencies/CriticalDependencyWarning.js +29 -0
  244. package/lib/dependencies/CssIcssExportDependency.js +539 -0
  245. package/lib/dependencies/CssIcssImportDependency.js +183 -0
  246. package/lib/dependencies/CssIcssSymbolDependency.js +131 -0
  247. package/lib/dependencies/CssImportDependency.js +120 -0
  248. package/lib/dependencies/CssUrlDependency.js +189 -0
  249. package/lib/dependencies/DelegatedSourceDependency.js +33 -0
  250. package/lib/dependencies/DllEntryDependency.js +61 -0
  251. package/lib/dependencies/DynamicExports.js +73 -0
  252. package/lib/dependencies/EntryDependency.js +30 -0
  253. package/lib/dependencies/ExportsInfoDependency.js +161 -0
  254. package/lib/dependencies/ExternalModuleDependency.js +109 -0
  255. package/lib/dependencies/ExternalModuleInitFragment.js +137 -0
  256. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +87 -0
  257. package/lib/dependencies/HarmonyAcceptDependency.js +237 -0
  258. package/lib/dependencies/HarmonyAcceptImportDependency.js +37 -0
  259. package/lib/dependencies/HarmonyCompatibilityDependency.js +91 -0
  260. package/lib/dependencies/HarmonyDetectionParserPlugin.js +103 -0
  261. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +165 -0
  262. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +254 -0
  263. package/lib/dependencies/HarmonyExportExpressionDependency.js +211 -0
  264. package/lib/dependencies/HarmonyExportHeaderDependency.js +78 -0
  265. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1494 -0
  266. package/lib/dependencies/HarmonyExportInitFragment.js +191 -0
  267. package/lib/dependencies/HarmonyExportSpecifierDependency.js +127 -0
  268. package/lib/dependencies/HarmonyExports.js +46 -0
  269. package/lib/dependencies/HarmonyImportDependency.js +459 -0
  270. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +576 -0
  271. package/lib/dependencies/HarmonyImportSideEffectDependency.js +91 -0
  272. package/lib/dependencies/HarmonyImportSpecifierDependency.js +514 -0
  273. package/lib/dependencies/HarmonyModulesPlugin.js +158 -0
  274. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +39 -0
  275. package/lib/dependencies/ImportContextDependency.js +81 -0
  276. package/lib/dependencies/ImportDependency.js +158 -0
  277. package/lib/dependencies/ImportEagerDependency.js +76 -0
  278. package/lib/dependencies/ImportMetaContextDependency.js +42 -0
  279. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +312 -0
  280. package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
  281. package/lib/dependencies/ImportMetaHotAcceptDependency.js +41 -0
  282. package/lib/dependencies/ImportMetaHotDeclineDependency.js +42 -0
  283. package/lib/dependencies/ImportMetaPlugin.js +447 -0
  284. package/lib/dependencies/ImportParserPlugin.js +602 -0
  285. package/lib/dependencies/ImportPhase.js +125 -0
  286. package/lib/dependencies/ImportPlugin.js +98 -0
  287. package/lib/dependencies/ImportWeakDependency.js +74 -0
  288. package/lib/dependencies/JsonExportsDependency.js +137 -0
  289. package/lib/dependencies/LoaderDependency.js +38 -0
  290. package/lib/dependencies/LoaderImportDependency.js +39 -0
  291. package/lib/dependencies/LoaderPlugin.js +294 -0
  292. package/lib/dependencies/LocalModule.js +60 -0
  293. package/lib/dependencies/LocalModuleDependency.js +84 -0
  294. package/lib/dependencies/LocalModulesHelpers.js +68 -0
  295. package/lib/dependencies/ModuleDecoratorDependency.js +136 -0
  296. package/lib/dependencies/ModuleDependency.js +100 -0
  297. package/lib/dependencies/ModuleDependencyTemplateAsId.js +35 -0
  298. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +39 -0
  299. package/lib/dependencies/ModuleHotAcceptDependency.js +41 -0
  300. package/lib/dependencies/ModuleHotDeclineDependency.js +42 -0
  301. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  302. package/lib/dependencies/NullDependency.js +42 -0
  303. package/lib/dependencies/PrefetchDependency.js +27 -0
  304. package/lib/dependencies/ProvidedDependency.js +156 -0
  305. package/lib/dependencies/PureExpressionDependency.js +161 -0
  306. package/lib/dependencies/RequireContextDependency.js +38 -0
  307. package/lib/dependencies/RequireContextDependencyParserPlugin.js +69 -0
  308. package/lib/dependencies/RequireContextPlugin.js +167 -0
  309. package/lib/dependencies/RequireEnsureDependenciesBlock.js +29 -0
  310. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +145 -0
  311. package/lib/dependencies/RequireEnsureDependency.js +115 -0
  312. package/lib/dependencies/RequireEnsureItemDependency.js +36 -0
  313. package/lib/dependencies/RequireEnsurePlugin.js +86 -0
  314. package/lib/dependencies/RequireHeaderDependency.js +70 -0
  315. package/lib/dependencies/RequireIncludeDependency.js +79 -0
  316. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +100 -0
  317. package/lib/dependencies/RequireIncludePlugin.js +63 -0
  318. package/lib/dependencies/RequireResolveContextDependency.js +67 -0
  319. package/lib/dependencies/RequireResolveDependency.js +58 -0
  320. package/lib/dependencies/RequireResolveHeaderDependency.js +81 -0
  321. package/lib/dependencies/RuntimeRequirementsDependency.js +85 -0
  322. package/lib/dependencies/StaticExportsDependency.js +72 -0
  323. package/lib/dependencies/SystemPlugin.js +168 -0
  324. package/lib/dependencies/SystemRuntimeModule.js +35 -0
  325. package/lib/dependencies/URLContextDependency.js +65 -0
  326. package/lib/dependencies/URLDependency.js +165 -0
  327. package/lib/dependencies/URLPlugin.js +67 -0
  328. package/lib/dependencies/UnsupportedDependency.js +82 -0
  329. package/lib/dependencies/WebAssemblyExportImportedDependency.js +93 -0
  330. package/lib/dependencies/WebAssemblyImportDependency.js +108 -0
  331. package/lib/dependencies/WebpackIsIncludedDependency.js +84 -0
  332. package/lib/dependencies/WorkerDependency.js +141 -0
  333. package/lib/dependencies/WorkerPlugin.js +565 -0
  334. package/lib/dependencies/getFunctionExpression.js +66 -0
  335. package/lib/dependencies/processExportInfo.js +67 -0
  336. package/lib/electron/ElectronTargetPlugin.js +71 -0
  337. package/lib/errors/BuildCycleError.js +30 -0
  338. package/lib/esm/ExportWebpackRequireRuntimeModule.js +30 -0
  339. package/lib/esm/ModuleChunkFormatPlugin.js +273 -0
  340. package/lib/esm/ModuleChunkLoadingPlugin.js +143 -0
  341. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +426 -0
  342. package/lib/formatLocation.js +67 -0
  343. package/lib/hmr/HotModuleReplacement.runtime.js +419 -0
  344. package/lib/hmr/HotModuleReplacementRuntimeModule.js +42 -0
  345. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +471 -0
  346. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  347. package/lib/hmr/LazyCompilationPlugin.js +473 -0
  348. package/lib/hmr/lazyCompilationBackend.js +167 -0
  349. package/lib/ids/ChunkModuleIdRangePlugin.js +94 -0
  350. package/lib/ids/DeterministicChunkIdsPlugin.js +73 -0
  351. package/lib/ids/DeterministicModuleIdsPlugin.js +98 -0
  352. package/lib/ids/HashedModuleIdsPlugin.js +85 -0
  353. package/lib/ids/IdHelpers.js +492 -0
  354. package/lib/ids/NamedChunkIdsPlugin.js +92 -0
  355. package/lib/ids/NamedModuleIdsPlugin.js +68 -0
  356. package/lib/ids/NaturalChunkIdsPlugin.js +35 -0
  357. package/lib/ids/NaturalModuleIdsPlugin.js +40 -0
  358. package/lib/ids/OccurrenceChunkIdsPlugin.js +86 -0
  359. package/lib/ids/OccurrenceModuleIdsPlugin.js +168 -0
  360. package/lib/ids/SyncModuleIdsPlugin.js +161 -0
  361. package/lib/index.js +681 -0
  362. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +153 -0
  363. package/lib/javascript/BasicEvaluatedExpression.js +603 -0
  364. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  365. package/lib/javascript/ChunkHelpers.js +45 -0
  366. package/lib/javascript/CommonJsChunkFormatPlugin.js +148 -0
  367. package/lib/javascript/EnableChunkLoadingPlugin.js +127 -0
  368. package/lib/javascript/JavascriptGenerator.js +277 -0
  369. package/lib/javascript/JavascriptModulesPlugin.js +1905 -0
  370. package/lib/javascript/JavascriptParser.js +5476 -0
  371. package/lib/javascript/JavascriptParserHelpers.js +129 -0
  372. package/lib/javascript/StartupHelpers.js +178 -0
  373. package/lib/json/JsonData.js +74 -0
  374. package/lib/json/JsonGenerator.js +234 -0
  375. package/lib/json/JsonModulesPlugin.js +66 -0
  376. package/lib/json/JsonParser.js +93 -0
  377. package/lib/library/AbstractLibraryPlugin.js +339 -0
  378. package/lib/library/AmdLibraryPlugin.js +181 -0
  379. package/lib/library/AssignLibraryPlugin.js +445 -0
  380. package/lib/library/EnableLibraryPlugin.js +306 -0
  381. package/lib/library/ExportPropertyLibraryPlugin.js +116 -0
  382. package/lib/library/JsonpLibraryPlugin.js +92 -0
  383. package/lib/library/ModuleLibraryPlugin.js +438 -0
  384. package/lib/library/SystemLibraryPlugin.js +256 -0
  385. package/lib/library/UmdLibraryPlugin.js +355 -0
  386. package/lib/logging/Logger.js +223 -0
  387. package/lib/logging/createConsoleLogger.js +217 -0
  388. package/lib/logging/runtime.js +45 -0
  389. package/lib/logging/truncateArgs.js +83 -0
  390. package/lib/node/CommonJsChunkLoadingPlugin.js +120 -0
  391. package/lib/node/NodeEnvironmentPlugin.js +73 -0
  392. package/lib/node/NodeSourcePlugin.js +19 -0
  393. package/lib/node/NodeTargetPlugin.js +102 -0
  394. package/lib/node/NodeTemplatePlugin.js +42 -0
  395. package/lib/node/NodeWatchFileSystem.js +198 -0
  396. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +286 -0
  397. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +123 -0
  398. package/lib/node/ReadFileCompileWasmPlugin.js +127 -0
  399. package/lib/node/RequireChunkLoadingRuntimeModule.js +239 -0
  400. package/lib/node/nodeConsole.js +185 -0
  401. package/lib/optimize/AggressiveMergingPlugin.js +98 -0
  402. package/lib/optimize/AggressiveSplittingPlugin.js +352 -0
  403. package/lib/optimize/ConcatenatedModule.js +2290 -0
  404. package/lib/optimize/EnsureChunkConditionsPlugin.js +88 -0
  405. package/lib/optimize/FlagIncludedChunksPlugin.js +137 -0
  406. package/lib/optimize/InnerGraph.js +368 -0
  407. package/lib/optimize/InnerGraphPlugin.js +455 -0
  408. package/lib/optimize/LimitChunkCountPlugin.js +302 -0
  409. package/lib/optimize/MangleExportsPlugin.js +194 -0
  410. package/lib/optimize/MergeDuplicateChunksPlugin.js +138 -0
  411. package/lib/optimize/MinChunkSizePlugin.js +121 -0
  412. package/lib/optimize/MinMaxSizeWarning.js +35 -0
  413. package/lib/optimize/ModuleConcatenationPlugin.js +971 -0
  414. package/lib/optimize/RealContentHashPlugin.js +488 -0
  415. package/lib/optimize/RemoveEmptyChunksPlugin.js +60 -0
  416. package/lib/optimize/RemoveParentModulesPlugin.js +216 -0
  417. package/lib/optimize/RuntimeChunkPlugin.js +52 -0
  418. package/lib/optimize/SideEffectsFlagPlugin.js +417 -0
  419. package/lib/optimize/SplitChunksPlugin.js +1836 -0
  420. package/lib/performance/AssetsOverSizeLimitWarning.js +37 -0
  421. package/lib/performance/EntrypointsOverSizeLimitWarning.js +40 -0
  422. package/lib/performance/NoAsyncChunksWarning.js +21 -0
  423. package/lib/performance/SizeLimitsPlugin.js +183 -0
  424. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +46 -0
  425. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +95 -0
  426. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +56 -0
  427. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +52 -0
  428. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +46 -0
  429. package/lib/rules/BasicEffectRulePlugin.js +56 -0
  430. package/lib/rules/BasicMatcherRulePlugin.js +68 -0
  431. package/lib/rules/ObjectMatcherRulePlugin.js +79 -0
  432. package/lib/rules/RuleSetCompiler.js +447 -0
  433. package/lib/rules/UseEffectRulePlugin.js +236 -0
  434. package/lib/runtime/AsyncModuleRuntimeModule.js +199 -0
  435. package/lib/runtime/AutoPublicPathRuntimeModule.js +90 -0
  436. package/lib/runtime/BaseUriRuntimeModule.js +35 -0
  437. package/lib/runtime/ChunkNameRuntimeModule.js +28 -0
  438. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +40 -0
  439. package/lib/runtime/CompatRuntimeModule.js +83 -0
  440. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +69 -0
  441. package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
  442. package/lib/runtime/CreateScriptUrlRuntimeModule.js +38 -0
  443. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +42 -0
  444. package/lib/runtime/EnsureChunkRuntimeModule.js +69 -0
  445. package/lib/runtime/GetChunkFilenameRuntimeModule.js +299 -0
  446. package/lib/runtime/GetFullHashRuntimeModule.js +31 -0
  447. package/lib/runtime/GetMainFilenameRuntimeModule.js +49 -0
  448. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +99 -0
  449. package/lib/runtime/GlobalRuntimeModule.js +47 -0
  450. package/lib/runtime/HasOwnPropertyRuntimeModule.js +35 -0
  451. package/lib/runtime/HelperRuntimeModule.js +18 -0
  452. package/lib/runtime/LoadScriptRuntimeModule.js +174 -0
  453. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +232 -0
  454. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +39 -0
  455. package/lib/runtime/NonceRuntimeModule.js +24 -0
  456. package/lib/runtime/OnChunksLoadedRuntimeModule.js +78 -0
  457. package/lib/runtime/PublicPathRuntimeModule.js +38 -0
  458. package/lib/runtime/RelativeUrlRuntimeModule.js +44 -0
  459. package/lib/runtime/RuntimeIdRuntimeModule.js +33 -0
  460. package/lib/runtime/StartupChunkDependenciesPlugin.js +88 -0
  461. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +77 -0
  462. package/lib/runtime/StartupEntrypointRuntimeModule.js +54 -0
  463. package/lib/runtime/SystemContextRuntimeModule.js +23 -0
  464. package/lib/runtime/ToBinaryRuntimeModule.js +72 -0
  465. package/lib/schemes/DataUriPlugin.js +47 -0
  466. package/lib/schemes/FileUriPlugin.js +54 -0
  467. package/lib/schemes/HttpUriPlugin.js +1410 -0
  468. package/lib/schemes/VirtualUrlPlugin.js +248 -0
  469. package/lib/serialization/AggregateErrorSerializer.js +41 -0
  470. package/lib/serialization/ArraySerializer.js +38 -0
  471. package/lib/serialization/BinaryMiddleware.js +1164 -0
  472. package/lib/serialization/DateObjectSerializer.js +28 -0
  473. package/lib/serialization/ErrorObjectSerializer.js +49 -0
  474. package/lib/serialization/FileMiddleware.js +766 -0
  475. package/lib/serialization/MapObjectSerializer.js +48 -0
  476. package/lib/serialization/NullPrototypeObjectSerializer.js +53 -0
  477. package/lib/serialization/ObjectMiddleware.js +877 -0
  478. package/lib/serialization/PlainObjectSerializer.js +119 -0
  479. package/lib/serialization/RegExpObjectSerializer.js +29 -0
  480. package/lib/serialization/Serializer.js +82 -0
  481. package/lib/serialization/SerializerMiddleware.js +226 -0
  482. package/lib/serialization/SetObjectSerializer.js +40 -0
  483. package/lib/serialization/SingleItemMiddleware.js +36 -0
  484. package/lib/serialization/types.js +13 -0
  485. package/lib/sharing/ConsumeSharedFallbackDependency.js +33 -0
  486. package/lib/sharing/ConsumeSharedModule.js +344 -0
  487. package/lib/sharing/ConsumeSharedPlugin.js +380 -0
  488. package/lib/sharing/ConsumeSharedRuntimeModule.js +358 -0
  489. package/lib/sharing/ProvideForSharedDependency.js +33 -0
  490. package/lib/sharing/ProvideSharedDependency.js +80 -0
  491. package/lib/sharing/ProvideSharedModule.js +196 -0
  492. package/lib/sharing/ProvideSharedModuleFactory.js +37 -0
  493. package/lib/sharing/ProvideSharedPlugin.js +248 -0
  494. package/lib/sharing/SharePlugin.js +91 -0
  495. package/lib/sharing/ShareRuntimeModule.js +152 -0
  496. package/lib/sharing/resolveMatchedConfigs.js +106 -0
  497. package/lib/sharing/utils.js +421 -0
  498. package/lib/stats/DefaultStatsFactoryPlugin.js +2791 -0
  499. package/lib/stats/DefaultStatsPresetPlugin.js +417 -0
  500. package/lib/stats/DefaultStatsPrinterPlugin.js +1860 -0
  501. package/lib/stats/StatsFactory.js +406 -0
  502. package/lib/stats/StatsPrinter.js +300 -0
  503. package/lib/url/URLParserPlugin.js +266 -0
  504. package/lib/util/AppendOnlyStackedSet.js +78 -0
  505. package/lib/util/ArrayHelpers.js +46 -0
  506. package/lib/util/ArrayQueue.js +104 -0
  507. package/lib/util/AsyncQueue.js +411 -0
  508. package/lib/util/Hash.js +68 -0
  509. package/lib/util/IterableHelpers.js +46 -0
  510. package/lib/util/LazyBucketSortedSet.js +272 -0
  511. package/lib/util/LazySet.js +236 -0
  512. package/lib/util/MapHelpers.js +34 -0
  513. package/lib/util/ParallelismFactorCalculator.js +70 -0
  514. package/lib/util/Queue.js +52 -0
  515. package/lib/util/Semaphore.js +51 -0
  516. package/lib/util/SetHelpers.js +94 -0
  517. package/lib/util/SortableSet.js +176 -0
  518. package/lib/util/StackedCacheMap.js +140 -0
  519. package/lib/util/StackedMap.js +164 -0
  520. package/lib/util/StringXor.js +103 -0
  521. package/lib/util/TupleQueue.js +70 -0
  522. package/lib/util/TupleSet.js +185 -0
  523. package/lib/util/URLAbsoluteSpecifier.js +86 -0
  524. package/lib/util/WeakTupleMap.js +227 -0
  525. package/lib/util/binarySearchBounds.js +136 -0
  526. package/lib/util/chainedImports.js +99 -0
  527. package/lib/util/cleverMerge.js +676 -0
  528. package/lib/util/comparators.js +645 -0
  529. package/lib/util/compileBooleanMatcher.js +313 -0
  530. package/lib/util/concatenate.js +232 -0
  531. package/lib/util/conventions.js +126 -0
  532. package/lib/util/create-schema-validation.js +41 -0
  533. package/lib/util/createHash.js +91 -0
  534. package/lib/util/dataURL.js +39 -0
  535. package/lib/util/deprecation.js +350 -0
  536. package/lib/util/deterministicGrouping.js +561 -0
  537. package/lib/util/extractSourceMap.js +318 -0
  538. package/lib/util/extractUrlAndGlobal.js +18 -0
  539. package/lib/util/findGraphRoots.js +211 -0
  540. package/lib/util/fs.js +675 -0
  541. package/lib/util/generateDebugId.js +33 -0
  542. package/lib/util/hash/BatchedHash.js +115 -0
  543. package/lib/util/hash/BulkUpdateHash.js +145 -0
  544. package/lib/util/hash/DebugHash.js +75 -0
  545. package/lib/util/hash/hash-digest.js +217 -0
  546. package/lib/util/hash/md4.js +20 -0
  547. package/lib/util/hash/wasm-hash.js +232 -0
  548. package/lib/util/hash/xxhash64.js +20 -0
  549. package/lib/util/identifier.js +471 -0
  550. package/lib/util/internalSerializables.js +222 -0
  551. package/lib/util/magicComment.js +25 -0
  552. package/lib/util/makeSerializable.js +60 -0
  553. package/lib/util/memoize.js +36 -0
  554. package/lib/util/nonNumericOnlyHash.js +22 -0
  555. package/lib/util/numberHash.js +95 -0
  556. package/lib/util/objectToMap.js +15 -0
  557. package/lib/util/processAsyncTree.js +68 -0
  558. package/lib/util/propertyAccess.js +30 -0
  559. package/lib/util/propertyName.js +76 -0
  560. package/lib/util/registerExternalSerializer.js +334 -0
  561. package/lib/util/removeBOM.js +25 -0
  562. package/lib/util/runtime.js +717 -0
  563. package/lib/util/semver.js +604 -0
  564. package/lib/util/serialization.js +153 -0
  565. package/lib/util/smartGrouping.js +221 -0
  566. package/lib/util/source.js +62 -0
  567. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  568. package/lib/validateSchema.js +177 -0
  569. package/lib/wasm/EnableWasmLoadingPlugin.js +146 -0
  570. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +154 -0
  571. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +74 -0
  572. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +212 -0
  573. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +209 -0
  574. package/lib/wasm-async/AsyncWebAssemblyParser.js +80 -0
  575. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +107 -0
  576. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +20 -0
  577. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +422 -0
  578. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +91 -0
  579. package/lib/wasm-sync/WebAssemblyGenerator.js +535 -0
  580. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +111 -0
  581. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +236 -0
  582. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +151 -0
  583. package/lib/wasm-sync/WebAssemblyParser.js +201 -0
  584. package/lib/wasm-sync/WebAssemblyUtils.js +66 -0
  585. package/lib/web/FetchCompileAsyncWasmPlugin.js +70 -0
  586. package/lib/web/FetchCompileWasmPlugin.js +86 -0
  587. package/lib/web/JsonpChunkLoadingPlugin.js +101 -0
  588. package/lib/web/JsonpChunkLoadingRuntimeModule.js +455 -0
  589. package/lib/web/JsonpTemplatePlugin.js +37 -0
  590. package/lib/webpack.js +227 -0
  591. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +110 -0
  592. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +231 -0
  593. package/lib/webworker/WebWorkerTemplatePlugin.js +26 -0
  594. package/module.d.ts +238 -0
  595. package/package.json +258 -0
  596. package/schemas/WebpackOptions.check.d.ts +7 -0
  597. package/schemas/WebpackOptions.check.js +6 -0
  598. package/schemas/WebpackOptions.json +6179 -0
  599. package/schemas/_container.json +155 -0
  600. package/schemas/_sharing.json +118 -0
  601. package/schemas/plugins/BannerPlugin.check.d.ts +7 -0
  602. package/schemas/plugins/BannerPlugin.check.js +6 -0
  603. package/schemas/plugins/BannerPlugin.json +115 -0
  604. package/schemas/plugins/DllPlugin.check.d.ts +7 -0
  605. package/schemas/plugins/DllPlugin.check.js +6 -0
  606. package/schemas/plugins/DllPlugin.json +36 -0
  607. package/schemas/plugins/DllReferencePlugin.check.d.ts +7 -0
  608. package/schemas/plugins/DllReferencePlugin.check.js +6 -0
  609. package/schemas/plugins/DllReferencePlugin.json +206 -0
  610. package/schemas/plugins/IgnorePlugin.check.d.ts +7 -0
  611. package/schemas/plugins/IgnorePlugin.check.js +6 -0
  612. package/schemas/plugins/IgnorePlugin.json +34 -0
  613. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +7 -0
  614. package/schemas/plugins/LoaderOptionsPlugin.check.js +6 -0
  615. package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
  616. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  617. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  618. package/schemas/plugins/ManifestPlugin.json +98 -0
  619. package/schemas/plugins/ProgressPlugin.check.d.ts +7 -0
  620. package/schemas/plugins/ProgressPlugin.check.js +6 -0
  621. package/schemas/plugins/ProgressPlugin.json +65 -0
  622. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +7 -0
  623. package/schemas/plugins/SourceMapDevToolPlugin.check.js +6 -0
  624. package/schemas/plugins/SourceMapDevToolPlugin.json +168 -0
  625. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +7 -0
  626. package/schemas/plugins/WatchIgnorePlugin.check.js +6 -0
  627. package/schemas/plugins/WatchIgnorePlugin.json +25 -0
  628. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +7 -0
  629. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +6 -0
  630. package/schemas/plugins/asset/AssetGeneratorOptions.json +3 -0
  631. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +7 -0
  632. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +6 -0
  633. package/schemas/plugins/asset/AssetInlineGeneratorOptions.json +3 -0
  634. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +7 -0
  635. package/schemas/plugins/asset/AssetParserOptions.check.js +6 -0
  636. package/schemas/plugins/asset/AssetParserOptions.json +3 -0
  637. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +7 -0
  638. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +6 -0
  639. package/schemas/plugins/asset/AssetResourceGeneratorOptions.json +3 -0
  640. package/schemas/plugins/container/ContainerPlugin.check.d.ts +7 -0
  641. package/schemas/plugins/container/ContainerPlugin.check.js +6 -0
  642. package/schemas/plugins/container/ContainerPlugin.json +294 -0
  643. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +7 -0
  644. package/schemas/plugins/container/ContainerReferencePlugin.check.js +6 -0
  645. package/schemas/plugins/container/ContainerReferencePlugin.json +132 -0
  646. package/schemas/plugins/container/ExternalsType.check.d.ts +7 -0
  647. package/schemas/plugins/container/ExternalsType.check.js +6 -0
  648. package/schemas/plugins/container/ExternalsType.json +3 -0
  649. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +7 -0
  650. package/schemas/plugins/container/ModuleFederationPlugin.check.js +6 -0
  651. package/schemas/plugins/container/ModuleFederationPlugin.json +525 -0
  652. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  653. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  654. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  655. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  656. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  657. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  658. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  659. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  660. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  661. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  662. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  663. package/schemas/plugins/css/CssParserOptions.json +3 -0
  664. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +7 -0
  665. package/schemas/plugins/debug/ProfilingPlugin.check.js +6 -0
  666. package/schemas/plugins/debug/ProfilingPlugin.json +12 -0
  667. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  668. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  669. package/schemas/plugins/ids/HashedModuleIdsPlugin.json +57 -0
  670. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +7 -0
  671. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +6 -0
  672. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.json +11 -0
  673. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +7 -0
  674. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +6 -0
  675. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.json +11 -0
  676. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  677. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
  678. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  679. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  680. package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
  681. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  682. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +7 -0
  683. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +6 -0
  684. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
  685. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +7 -0
  686. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +6 -0
  687. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +21 -0
  688. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +7 -0
  689. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +6 -0
  690. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.json +11 -0
  691. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +7 -0
  692. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +6 -0
  693. package/schemas/plugins/optimize/MinChunkSizePlugin.json +20 -0
  694. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
  695. package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
  696. package/schemas/plugins/schemes/HttpUriPlugin.json +74 -0
  697. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  698. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  699. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  700. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +7 -0
  701. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +6 -0
  702. package/schemas/plugins/sharing/ConsumeSharedPlugin.json +120 -0
  703. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +7 -0
  704. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +6 -0
  705. package/schemas/plugins/sharing/ProvideSharedPlugin.json +94 -0
  706. package/schemas/plugins/sharing/SharePlugin.check.d.ts +7 -0
  707. package/schemas/plugins/sharing/SharePlugin.check.js +6 -0
  708. package/schemas/plugins/sharing/SharePlugin.json +133 -0
  709. package/types.d.ts +20217 -0
@@ -0,0 +1,4131 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const nodeModule = require("module");
9
+ const { isAbsolute } = require("path");
10
+ const { create: createResolver } = require("enhanced-resolve");
11
+ const asyncLib = require("neo-async");
12
+ const { DEFAULTS } = require("./config/defaults");
13
+ const AsyncQueue = require("./util/AsyncQueue");
14
+ const StackedCacheMap = require("./util/StackedCacheMap");
15
+ const createHash = require("./util/createHash");
16
+ const { dirname, join, lstatReadlinkAbsolute, relative } = require("./util/fs");
17
+ const makeSerializable = require("./util/makeSerializable");
18
+ const memoize = require("./util/memoize");
19
+ const processAsyncTree = require("./util/processAsyncTree");
20
+
21
+ /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
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
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
28
+ /** @typedef {import("./util/fs").JsonObject} JsonObject */
29
+ /** @typedef {import("./util/fs").IStats} IStats */
30
+ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
31
+ /**
32
+ * @template T
33
+ * @typedef {import("./util/AsyncQueue").Callback<T>} ProcessorCallback
34
+ */
35
+ /**
36
+ * @template T, R
37
+ * @typedef {import("./util/AsyncQueue").Processor<T, R>} Processor
38
+ */
39
+
40
+ const supportsEsm = Number(process.versions.modules) >= 83;
41
+
42
+ /** @type {Set<string>} */
43
+ const builtinModules = new Set(nodeModule.builtinModules);
44
+
45
+ let FS_ACCURACY = 2000;
46
+
47
+ /** @type {Set<string>} */
48
+ const EMPTY_SET = new Set();
49
+
50
+ const RBDT_RESOLVE_INITIAL = 0;
51
+ const RBDT_RESOLVE_FILE = 1;
52
+ const RBDT_RESOLVE_DIRECTORY = 2;
53
+ const RBDT_RESOLVE_CJS_FILE = 3;
54
+ const RBDT_RESOLVE_CJS_FILE_AS_CHILD = 4;
55
+ const RBDT_RESOLVE_ESM_FILE = 5;
56
+ const RBDT_DIRECTORY = 6;
57
+ const RBDT_FILE = 7;
58
+ const RBDT_DIRECTORY_DEPENDENCIES = 8;
59
+ const RBDT_FILE_DEPENDENCIES = 9;
60
+
61
+ /** @typedef {RBDT_RESOLVE_INITIAL | RBDT_RESOLVE_FILE | RBDT_RESOLVE_DIRECTORY | RBDT_RESOLVE_CJS_FILE | RBDT_RESOLVE_CJS_FILE_AS_CHILD | RBDT_RESOLVE_ESM_FILE | RBDT_DIRECTORY | RBDT_FILE | RBDT_DIRECTORY_DEPENDENCIES | RBDT_FILE_DEPENDENCIES} JobType */
62
+
63
+ const INVALID = Symbol("invalid");
64
+
65
+ // eslint-disable-next-line jsdoc/ts-no-empty-object-type
66
+ /** @typedef {{ }} ExistenceOnlyTimeEntry */
67
+
68
+ /**
69
+ * @typedef {object} FileSystemInfoEntry
70
+ * @property {number} safeTime
71
+ * @property {number=} timestamp
72
+ */
73
+
74
+ /**
75
+ * @typedef {object} ResolvedContextFileSystemInfoEntry
76
+ * @property {number} safeTime
77
+ * @property {string=} timestampHash
78
+ */
79
+
80
+ /** @typedef {Set<string>} Symlinks */
81
+
82
+ /**
83
+ * @typedef {object} ContextFileSystemInfoEntry
84
+ * @property {number} safeTime
85
+ * @property {string=} timestampHash
86
+ * @property {ResolvedContextFileSystemInfoEntry=} resolved
87
+ * @property {Symlinks=} symlinks
88
+ */
89
+
90
+ /**
91
+ * @typedef {object} TimestampAndHash
92
+ * @property {number} safeTime
93
+ * @property {number=} timestamp
94
+ * @property {string} hash
95
+ */
96
+
97
+ /**
98
+ * @typedef {object} ResolvedContextTimestampAndHash
99
+ * @property {number} safeTime
100
+ * @property {string=} timestampHash
101
+ * @property {string} hash
102
+ */
103
+
104
+ /**
105
+ * @typedef {object} ContextTimestampAndHash
106
+ * @property {number} safeTime
107
+ * @property {string=} timestampHash
108
+ * @property {string} hash
109
+ * @property {ResolvedContextTimestampAndHash=} resolved
110
+ * @property {Symlinks=} symlinks
111
+ */
112
+
113
+ /**
114
+ * @typedef {object} ContextHash
115
+ * @property {string} hash
116
+ * @property {string=} resolved
117
+ * @property {Symlinks=} symlinks
118
+ */
119
+
120
+ /** @typedef {Set<string>} SnapshotContent */
121
+
122
+ /**
123
+ * @typedef {object} SnapshotOptimizationEntry
124
+ * @property {Snapshot} snapshot
125
+ * @property {number} shared
126
+ * @property {SnapshotContent | undefined} snapshotContent
127
+ * @property {Set<SnapshotOptimizationEntry> | undefined} children
128
+ */
129
+
130
+ /** @typedef {Map<string, string | false | undefined>} ResolveResults */
131
+
132
+ /** @typedef {Set<string>} Files */
133
+ /** @typedef {Set<string>} Directories */
134
+ /** @typedef {Set<string>} Missing */
135
+
136
+ /**
137
+ * @typedef {object} ResolveDependencies
138
+ * @property {Files} files list of files
139
+ * @property {Directories} directories list of directories
140
+ * @property {Missing} missing list of missing entries
141
+ */
142
+
143
+ /**
144
+ * @typedef {object} ResolveBuildDependenciesResult
145
+ * @property {Files} files list of files
146
+ * @property {Directories} directories list of directories
147
+ * @property {Missing} missing list of missing entries
148
+ * @property {ResolveResults} resolveResults stored resolve results
149
+ * @property {ResolveDependencies} resolveDependencies dependencies of the resolving
150
+ */
151
+
152
+ /**
153
+ * @typedef {object} SnapshotOptions
154
+ * @property {boolean=} hash should use hash to snapshot
155
+ * @property {boolean=} timestamp should use timestamp to snapshot
156
+ */
157
+
158
+ const DONE_ITERATOR_RESULT = new Set().keys().next();
159
+
160
+ // cspell:word tshs
161
+ // Tsh = Timestamp + Hash
162
+ // Tshs = Timestamp + Hash combinations
163
+
164
+ class SnapshotIterator {
165
+ /**
166
+ * @param {() => IteratorResult<string>} next next
167
+ */
168
+ constructor(next) {
169
+ this.next = next;
170
+ }
171
+ }
172
+
173
+ /**
174
+ * @template T
175
+ * @typedef {(snapshot: Snapshot) => T[]} GetMapsFunction
176
+ */
177
+
178
+ /**
179
+ * @template T
180
+ */
181
+ class SnapshotIterable {
182
+ /**
183
+ * @param {Snapshot} snapshot snapshot
184
+ * @param {GetMapsFunction<T>} getMaps get maps function
185
+ */
186
+ constructor(snapshot, getMaps) {
187
+ this.snapshot = snapshot;
188
+ this.getMaps = getMaps;
189
+ }
190
+
191
+ [Symbol.iterator]() {
192
+ let state = 0;
193
+ /** @type {IterableIterator<string>} */
194
+ let it;
195
+ /** @type {GetMapsFunction<T>} */
196
+ let getMaps;
197
+ /** @type {T[]} */
198
+ let maps;
199
+ /** @type {Snapshot} */
200
+ let snapshot;
201
+ /** @type {Snapshot[] | undefined} */
202
+ let queue;
203
+ return new SnapshotIterator(() => {
204
+ for (;;) {
205
+ switch (state) {
206
+ case 0:
207
+ snapshot = this.snapshot;
208
+ getMaps = this.getMaps;
209
+ maps = getMaps(snapshot);
210
+ state = 1;
211
+ /* falls through */
212
+ case 1:
213
+ if (maps.length > 0) {
214
+ const map = maps.pop();
215
+ if (map !== undefined) {
216
+ it =
217
+ /** @type {Set<EXPECTED_ANY> | Map<string, EXPECTED_ANY>} */
218
+ (map).keys();
219
+ state = 2;
220
+ } else {
221
+ break;
222
+ }
223
+ } else {
224
+ state = 3;
225
+ break;
226
+ }
227
+ /* falls through */
228
+ case 2: {
229
+ const result = it.next();
230
+ if (!result.done) return result;
231
+ state = 1;
232
+ break;
233
+ }
234
+ case 3: {
235
+ const children = snapshot.children;
236
+ if (children !== undefined) {
237
+ if (children.size === 1) {
238
+ // shortcut for a single child
239
+ // avoids allocation of queue
240
+ for (const child of children) snapshot = child;
241
+ maps = getMaps(snapshot);
242
+ state = 1;
243
+ break;
244
+ }
245
+ if (queue === undefined) queue = [];
246
+ for (const child of children) {
247
+ queue.push(child);
248
+ }
249
+ }
250
+ if (queue !== undefined && queue.length > 0) {
251
+ snapshot = /** @type {Snapshot} */ (queue.pop());
252
+ maps = getMaps(snapshot);
253
+ state = 1;
254
+ break;
255
+ } else {
256
+ state = 4;
257
+ }
258
+ }
259
+ /* falls through */
260
+ case 4:
261
+ return DONE_ITERATOR_RESULT;
262
+ }
263
+ }
264
+ });
265
+ }
266
+ }
267
+
268
+ /** @typedef {Map<string, FileSystemInfoEntry | null>} FileTimestamps */
269
+ /** @typedef {Map<string, string | null>} FileHashes */
270
+ /** @typedef {Map<string, TimestampAndHash | string | null>} FileTshs */
271
+ /** @typedef {Map<string, ResolvedContextFileSystemInfoEntry | null>} ContextTimestamps */
272
+ /** @typedef {Map<string, string | null>} ContextHashes */
273
+ /** @typedef {Map<string, ResolvedContextTimestampAndHash | null>} ContextTshs */
274
+ /** @typedef {Map<string, boolean>} MissingExistence */
275
+ /** @typedef {Map<string, string>} ManagedItemInfo */
276
+ /** @typedef {Set<string>} ManagedFiles */
277
+ /** @typedef {Set<string>} ManagedContexts */
278
+ /** @typedef {Set<string>} ManagedMissing */
279
+ /** @typedef {Set<Snapshot>} Children */
280
+
281
+ class Snapshot {
282
+ constructor() {
283
+ this._flags = 0;
284
+ /** @type {Iterable<string> | undefined} */
285
+ this._cachedFileIterable = undefined;
286
+ /** @type {Iterable<string> | undefined} */
287
+ this._cachedContextIterable = undefined;
288
+ /** @type {Iterable<string> | undefined} */
289
+ this._cachedMissingIterable = undefined;
290
+ /** @type {number | undefined} */
291
+ this.startTime = undefined;
292
+ /** @type {FileTimestamps | undefined} */
293
+ this.fileTimestamps = undefined;
294
+ /** @type {FileHashes | undefined} */
295
+ this.fileHashes = undefined;
296
+ /** @type {FileTshs | undefined} */
297
+ this.fileTshs = undefined;
298
+ /** @type {ContextTimestamps | undefined} */
299
+ this.contextTimestamps = undefined;
300
+ /** @type {ContextHashes | undefined} */
301
+ this.contextHashes = undefined;
302
+ /** @type {ContextTshs | undefined} */
303
+ this.contextTshs = undefined;
304
+ /** @type {MissingExistence | undefined} */
305
+ this.missingExistence = undefined;
306
+ /** @type {ManagedItemInfo | undefined} */
307
+ this.managedItemInfo = undefined;
308
+ /** @type {ManagedFiles | undefined} */
309
+ this.managedFiles = undefined;
310
+ /** @type {ManagedContexts | undefined} */
311
+ this.managedContexts = undefined;
312
+ /** @type {ManagedMissing | undefined} */
313
+ this.managedMissing = undefined;
314
+ /** @type {Children | undefined} */
315
+ this.children = undefined;
316
+ }
317
+
318
+ hasStartTime() {
319
+ return (this._flags & 1) !== 0;
320
+ }
321
+
322
+ /**
323
+ * @param {number} value start value
324
+ */
325
+ setStartTime(value) {
326
+ this._flags |= 1;
327
+ this.startTime = value;
328
+ }
329
+
330
+ /**
331
+ * @param {number | undefined} value value
332
+ * @param {Snapshot} snapshot snapshot
333
+ */
334
+ setMergedStartTime(value, snapshot) {
335
+ if (value) {
336
+ if (snapshot.hasStartTime()) {
337
+ this.setStartTime(
338
+ Math.min(
339
+ value,
340
+ /** @type {NonNullable<Snapshot["startTime"]>} */
341
+ (snapshot.startTime)
342
+ )
343
+ );
344
+ } else {
345
+ this.setStartTime(value);
346
+ }
347
+ } else if (snapshot.hasStartTime()) {
348
+ this.setStartTime(
349
+ /** @type {NonNullable<Snapshot["startTime"]>} */
350
+ (snapshot.startTime)
351
+ );
352
+ }
353
+ }
354
+
355
+ hasFileTimestamps() {
356
+ return (this._flags & 2) !== 0;
357
+ }
358
+
359
+ /**
360
+ * @param {FileTimestamps} value file timestamps
361
+ */
362
+ setFileTimestamps(value) {
363
+ this._flags |= 2;
364
+ this.fileTimestamps = value;
365
+ }
366
+
367
+ hasFileHashes() {
368
+ return (this._flags & 4) !== 0;
369
+ }
370
+
371
+ /**
372
+ * @param {FileHashes} value file hashes
373
+ */
374
+ setFileHashes(value) {
375
+ this._flags |= 4;
376
+ this.fileHashes = value;
377
+ }
378
+
379
+ hasFileTshs() {
380
+ return (this._flags & 8) !== 0;
381
+ }
382
+
383
+ /**
384
+ * @param {FileTshs} value file tshs
385
+ */
386
+ setFileTshs(value) {
387
+ this._flags |= 8;
388
+ this.fileTshs = value;
389
+ }
390
+
391
+ hasContextTimestamps() {
392
+ return (this._flags & 0x10) !== 0;
393
+ }
394
+
395
+ /**
396
+ * @param {ContextTimestamps} value context timestamps
397
+ */
398
+ setContextTimestamps(value) {
399
+ this._flags |= 0x10;
400
+ this.contextTimestamps = value;
401
+ }
402
+
403
+ hasContextHashes() {
404
+ return (this._flags & 0x20) !== 0;
405
+ }
406
+
407
+ /**
408
+ * @param {ContextHashes} value context hashes
409
+ */
410
+ setContextHashes(value) {
411
+ this._flags |= 0x20;
412
+ this.contextHashes = value;
413
+ }
414
+
415
+ hasContextTshs() {
416
+ return (this._flags & 0x40) !== 0;
417
+ }
418
+
419
+ /**
420
+ * @param {ContextTshs} value context tshs
421
+ */
422
+ setContextTshs(value) {
423
+ this._flags |= 0x40;
424
+ this.contextTshs = value;
425
+ }
426
+
427
+ hasMissingExistence() {
428
+ return (this._flags & 0x80) !== 0;
429
+ }
430
+
431
+ /**
432
+ * @param {MissingExistence} value context tshs
433
+ */
434
+ setMissingExistence(value) {
435
+ this._flags |= 0x80;
436
+ this.missingExistence = value;
437
+ }
438
+
439
+ hasManagedItemInfo() {
440
+ return (this._flags & 0x100) !== 0;
441
+ }
442
+
443
+ /**
444
+ * @param {ManagedItemInfo} value managed item info
445
+ */
446
+ setManagedItemInfo(value) {
447
+ this._flags |= 0x100;
448
+ this.managedItemInfo = value;
449
+ }
450
+
451
+ hasManagedFiles() {
452
+ return (this._flags & 0x200) !== 0;
453
+ }
454
+
455
+ /**
456
+ * @param {ManagedFiles} value managed files
457
+ */
458
+ setManagedFiles(value) {
459
+ this._flags |= 0x200;
460
+ this.managedFiles = value;
461
+ }
462
+
463
+ hasManagedContexts() {
464
+ return (this._flags & 0x400) !== 0;
465
+ }
466
+
467
+ /**
468
+ * @param {ManagedContexts} value managed contexts
469
+ */
470
+ setManagedContexts(value) {
471
+ this._flags |= 0x400;
472
+ this.managedContexts = value;
473
+ }
474
+
475
+ hasManagedMissing() {
476
+ return (this._flags & 0x800) !== 0;
477
+ }
478
+
479
+ /**
480
+ * @param {ManagedMissing} value managed missing
481
+ */
482
+ setManagedMissing(value) {
483
+ this._flags |= 0x800;
484
+ this.managedMissing = value;
485
+ }
486
+
487
+ hasChildren() {
488
+ return (this._flags & 0x1000) !== 0;
489
+ }
490
+
491
+ /**
492
+ * @param {Children} value children
493
+ */
494
+ setChildren(value) {
495
+ this._flags |= 0x1000;
496
+ this.children = value;
497
+ }
498
+
499
+ /**
500
+ * @param {Snapshot} child children
501
+ */
502
+ addChild(child) {
503
+ if (!this.hasChildren()) {
504
+ this.setChildren(new Set());
505
+ }
506
+ /** @type {Children} */
507
+ (this.children).add(child);
508
+ }
509
+
510
+ /**
511
+ * @param {ObjectSerializerContext} context context
512
+ */
513
+ serialize({ write }) {
514
+ write(this._flags);
515
+ if (this.hasStartTime()) write(this.startTime);
516
+ if (this.hasFileTimestamps()) write(this.fileTimestamps);
517
+ if (this.hasFileHashes()) write(this.fileHashes);
518
+ if (this.hasFileTshs()) write(this.fileTshs);
519
+ if (this.hasContextTimestamps()) write(this.contextTimestamps);
520
+ if (this.hasContextHashes()) write(this.contextHashes);
521
+ if (this.hasContextTshs()) write(this.contextTshs);
522
+ if (this.hasMissingExistence()) write(this.missingExistence);
523
+ if (this.hasManagedItemInfo()) write(this.managedItemInfo);
524
+ if (this.hasManagedFiles()) write(this.managedFiles);
525
+ if (this.hasManagedContexts()) write(this.managedContexts);
526
+ if (this.hasManagedMissing()) write(this.managedMissing);
527
+ if (this.hasChildren()) write(this.children);
528
+ }
529
+
530
+ /**
531
+ * @param {ObjectDeserializerContext} context context
532
+ */
533
+ deserialize({ read }) {
534
+ this._flags = read();
535
+ if (this.hasStartTime()) this.startTime = read();
536
+ if (this.hasFileTimestamps()) this.fileTimestamps = read();
537
+ if (this.hasFileHashes()) this.fileHashes = read();
538
+ if (this.hasFileTshs()) this.fileTshs = read();
539
+ if (this.hasContextTimestamps()) this.contextTimestamps = read();
540
+ if (this.hasContextHashes()) this.contextHashes = read();
541
+ if (this.hasContextTshs()) this.contextTshs = read();
542
+ if (this.hasMissingExistence()) this.missingExistence = read();
543
+ if (this.hasManagedItemInfo()) this.managedItemInfo = read();
544
+ if (this.hasManagedFiles()) this.managedFiles = read();
545
+ if (this.hasManagedContexts()) this.managedContexts = read();
546
+ if (this.hasManagedMissing()) this.managedMissing = read();
547
+ if (this.hasChildren()) this.children = read();
548
+ }
549
+
550
+ /**
551
+ * @template T
552
+ * @param {GetMapsFunction<T>} getMaps first
553
+ * @returns {SnapshotIterable<T>} iterable
554
+ */
555
+ _createIterable(getMaps) {
556
+ return new SnapshotIterable(this, getMaps);
557
+ }
558
+
559
+ /**
560
+ * @returns {Iterable<string>} iterable
561
+ */
562
+ getFileIterable() {
563
+ if (this._cachedFileIterable === undefined) {
564
+ this._cachedFileIterable = this._createIterable((s) => [
565
+ s.fileTimestamps,
566
+ s.fileHashes,
567
+ s.fileTshs,
568
+ s.managedFiles
569
+ ]);
570
+ }
571
+ return this._cachedFileIterable;
572
+ }
573
+
574
+ /**
575
+ * @returns {Iterable<string>} iterable
576
+ */
577
+ getContextIterable() {
578
+ if (this._cachedContextIterable === undefined) {
579
+ this._cachedContextIterable = this._createIterable((s) => [
580
+ s.contextTimestamps,
581
+ s.contextHashes,
582
+ s.contextTshs,
583
+ s.managedContexts
584
+ ]);
585
+ }
586
+ return this._cachedContextIterable;
587
+ }
588
+
589
+ /**
590
+ * @returns {Iterable<string>} iterable
591
+ */
592
+ getMissingIterable() {
593
+ if (this._cachedMissingIterable === undefined) {
594
+ this._cachedMissingIterable = this._createIterable((s) => [
595
+ s.missingExistence,
596
+ s.managedMissing
597
+ ]);
598
+ }
599
+ return this._cachedMissingIterable;
600
+ }
601
+ }
602
+
603
+ makeSerializable(Snapshot, "webpack/lib/FileSystemInfo", "Snapshot");
604
+
605
+ const MIN_COMMON_SNAPSHOT_SIZE = 3;
606
+
607
+ /**
608
+ * @template U, T
609
+ * @typedef {U extends true ? Set<string> : Map<string, T>} SnapshotOptimizationValue
610
+ */
611
+
612
+ /**
613
+ * @template T
614
+ * @template {boolean} [U=false]
615
+ */
616
+ class SnapshotOptimization {
617
+ /**
618
+ * @param {(snapshot: Snapshot) => boolean} has has value
619
+ * @param {(snapshot: Snapshot) => SnapshotOptimizationValue<U, T> | undefined} get get value
620
+ * @param {(snapshot: Snapshot, value: SnapshotOptimizationValue<U, T>) => void} set set value
621
+ * @param {boolean=} useStartTime use the start time of snapshots
622
+ * @param {U=} isSet value is an Set instead of a Map
623
+ */
624
+ constructor(
625
+ has,
626
+ get,
627
+ set,
628
+ useStartTime = true,
629
+ isSet = /** @type {U} */ (false)
630
+ ) {
631
+ this._has = has;
632
+ this._get = get;
633
+ this._set = set;
634
+ this._useStartTime = useStartTime;
635
+ /** @type {U} */
636
+ this._isSet = isSet;
637
+ /** @type {Map<string, SnapshotOptimizationEntry>} */
638
+ this._map = new Map();
639
+ this._statItemsShared = 0;
640
+ this._statItemsUnshared = 0;
641
+ this._statSharedSnapshots = 0;
642
+ this._statReusedSharedSnapshots = 0;
643
+ }
644
+
645
+ getStatisticMessage() {
646
+ const total = this._statItemsShared + this._statItemsUnshared;
647
+ if (total === 0) return;
648
+ return `${
649
+ this._statItemsShared && Math.round((this._statItemsShared * 100) / total)
650
+ }% (${this._statItemsShared}/${total}) entries shared via ${
651
+ this._statSharedSnapshots
652
+ } shared snapshots (${
653
+ this._statReusedSharedSnapshots + this._statSharedSnapshots
654
+ } times referenced)`;
655
+ }
656
+
657
+ clear() {
658
+ this._map.clear();
659
+ this._statItemsShared = 0;
660
+ this._statItemsUnshared = 0;
661
+ this._statSharedSnapshots = 0;
662
+ this._statReusedSharedSnapshots = 0;
663
+ }
664
+
665
+ /**
666
+ * @param {Snapshot} newSnapshot snapshot
667
+ * @param {Set<string>} capturedFiles files to snapshot/share
668
+ * @returns {void}
669
+ */
670
+ optimize(newSnapshot, capturedFiles) {
671
+ if (capturedFiles.size === 0) {
672
+ return;
673
+ }
674
+ /**
675
+ * @param {SnapshotOptimizationEntry} entry optimization entry
676
+ * @returns {void}
677
+ */
678
+ const increaseSharedAndStoreOptimizationEntry = (entry) => {
679
+ if (entry.children !== undefined) {
680
+ for (const child of entry.children) {
681
+ increaseSharedAndStoreOptimizationEntry(child);
682
+ }
683
+ }
684
+ entry.shared++;
685
+ storeOptimizationEntry(entry);
686
+ };
687
+ /**
688
+ * @param {SnapshotOptimizationEntry} entry optimization entry
689
+ * @returns {void}
690
+ */
691
+ const storeOptimizationEntry = (entry) => {
692
+ for (const path of /** @type {SnapshotContent} */ (
693
+ entry.snapshotContent
694
+ )) {
695
+ const old =
696
+ /** @type {SnapshotOptimizationEntry} */
697
+ (this._map.get(path));
698
+ if (old.shared < entry.shared) {
699
+ this._map.set(path, entry);
700
+ }
701
+ capturedFiles.delete(path);
702
+ }
703
+ };
704
+
705
+ /** @type {SnapshotOptimizationEntry | undefined} */
706
+ let newOptimizationEntry;
707
+
708
+ const capturedFilesSize = capturedFiles.size;
709
+
710
+ /** @type {Set<SnapshotOptimizationEntry> | undefined} */
711
+ const optimizationEntries = new Set();
712
+
713
+ for (const path of capturedFiles) {
714
+ const optimizationEntry = this._map.get(path);
715
+ if (optimizationEntry === undefined) {
716
+ if (newOptimizationEntry === undefined) {
717
+ newOptimizationEntry = {
718
+ snapshot: newSnapshot,
719
+ shared: 0,
720
+ snapshotContent: undefined,
721
+ children: undefined
722
+ };
723
+ }
724
+ this._map.set(path, newOptimizationEntry);
725
+ } else {
726
+ optimizationEntries.add(optimizationEntry);
727
+ }
728
+ }
729
+
730
+ optimizationEntriesLabel: for (const optimizationEntry of optimizationEntries) {
731
+ const snapshot = optimizationEntry.snapshot;
732
+ if (optimizationEntry.shared > 0) {
733
+ // It's a shared snapshot
734
+ // We can't change it, so we can only use it when all files match
735
+ // and startTime is compatible
736
+ if (
737
+ this._useStartTime &&
738
+ newSnapshot.startTime &&
739
+ (!snapshot.startTime || snapshot.startTime > newSnapshot.startTime)
740
+ ) {
741
+ continue;
742
+ }
743
+ /** @type {Set<string>} */
744
+ const nonSharedFiles = new Set();
745
+ const snapshotContent =
746
+ /** @type {NonNullable<SnapshotOptimizationEntry["snapshotContent"]>} */
747
+ (optimizationEntry.snapshotContent);
748
+ const snapshotEntries =
749
+ /** @type {SnapshotOptimizationValue<U, T>} */
750
+ (this._get(snapshot));
751
+ for (const path of snapshotContent) {
752
+ if (!capturedFiles.has(path)) {
753
+ if (!snapshotEntries.has(path)) {
754
+ // File is not shared and can't be removed from the snapshot
755
+ // because it's in a child of the snapshot
756
+ continue optimizationEntriesLabel;
757
+ }
758
+ nonSharedFiles.add(path);
759
+ }
760
+ }
761
+ if (nonSharedFiles.size === 0) {
762
+ // The complete snapshot is shared
763
+ // add it as child
764
+ newSnapshot.addChild(snapshot);
765
+ increaseSharedAndStoreOptimizationEntry(optimizationEntry);
766
+ this._statReusedSharedSnapshots++;
767
+ } else {
768
+ // Only a part of the snapshot is shared
769
+ const sharedCount = snapshotContent.size - nonSharedFiles.size;
770
+ if (sharedCount < MIN_COMMON_SNAPSHOT_SIZE) {
771
+ // Common part it too small
772
+ continue;
773
+ }
774
+ // Extract common timestamps from both snapshots
775
+ /** @type {Set<string> | Map<string, T>} */
776
+ let commonMap;
777
+ if (this._isSet) {
778
+ commonMap = new Set();
779
+ for (const path of /** @type {Set<string>} */ (snapshotEntries)) {
780
+ if (nonSharedFiles.has(path)) continue;
781
+ commonMap.add(path);
782
+ snapshotEntries.delete(path);
783
+ }
784
+ } else {
785
+ commonMap = new Map();
786
+ const map = /** @type {Map<string, T>} */ (snapshotEntries);
787
+ for (const [path, value] of map) {
788
+ if (nonSharedFiles.has(path)) continue;
789
+ commonMap.set(path, value);
790
+ snapshotEntries.delete(path);
791
+ }
792
+ }
793
+ // Create and attach snapshot
794
+ const commonSnapshot = new Snapshot();
795
+ if (this._useStartTime) {
796
+ commonSnapshot.setMergedStartTime(newSnapshot.startTime, snapshot);
797
+ }
798
+ this._set(
799
+ commonSnapshot,
800
+ /** @type {SnapshotOptimizationValue<U, T>} */ (commonMap)
801
+ );
802
+ newSnapshot.addChild(commonSnapshot);
803
+ snapshot.addChild(commonSnapshot);
804
+ // Create optimization entry
805
+ const newEntry = {
806
+ snapshot: commonSnapshot,
807
+ shared: optimizationEntry.shared + 1,
808
+ snapshotContent: new Set(commonMap.keys()),
809
+ children: undefined
810
+ };
811
+ if (optimizationEntry.children === undefined) {
812
+ optimizationEntry.children = new Set();
813
+ }
814
+ optimizationEntry.children.add(newEntry);
815
+ storeOptimizationEntry(newEntry);
816
+ this._statSharedSnapshots++;
817
+ }
818
+ } else {
819
+ // It's a unshared snapshot
820
+ // We can extract a common shared snapshot
821
+ // with all common files
822
+ const snapshotEntries = this._get(snapshot);
823
+ if (snapshotEntries === undefined) {
824
+ // Incomplete snapshot, that can't be used
825
+ continue;
826
+ }
827
+ /** @type {Set<string> | Map<string, T>} */
828
+ let commonMap;
829
+ if (this._isSet) {
830
+ commonMap = new Set();
831
+ const set = /** @type {Set<string>} */ (snapshotEntries);
832
+ if (capturedFiles.size < set.size) {
833
+ for (const path of capturedFiles) {
834
+ if (set.has(path)) commonMap.add(path);
835
+ }
836
+ } else {
837
+ for (const path of set) {
838
+ if (capturedFiles.has(path)) commonMap.add(path);
839
+ }
840
+ }
841
+ } else {
842
+ commonMap = new Map();
843
+ const map = /** @type {Map<string, T>} */ (snapshotEntries);
844
+ for (const path of capturedFiles) {
845
+ const ts = map.get(path);
846
+ if (ts === undefined) continue;
847
+ commonMap.set(path, ts);
848
+ }
849
+ }
850
+
851
+ if (commonMap.size < MIN_COMMON_SNAPSHOT_SIZE) {
852
+ // Common part it too small
853
+ continue;
854
+ }
855
+ // Create and attach snapshot
856
+ const commonSnapshot = new Snapshot();
857
+ if (this._useStartTime) {
858
+ commonSnapshot.setMergedStartTime(newSnapshot.startTime, snapshot);
859
+ }
860
+ this._set(
861
+ commonSnapshot,
862
+ /** @type {SnapshotOptimizationValue<U, T>} */
863
+ (commonMap)
864
+ );
865
+ newSnapshot.addChild(commonSnapshot);
866
+ snapshot.addChild(commonSnapshot);
867
+ // Remove files from snapshot
868
+ for (const path of commonMap.keys()) snapshotEntries.delete(path);
869
+ const sharedCount = commonMap.size;
870
+ this._statItemsUnshared -= sharedCount;
871
+ this._statItemsShared += sharedCount;
872
+ // Create optimization entry
873
+ storeOptimizationEntry({
874
+ snapshot: commonSnapshot,
875
+ shared: 2,
876
+ snapshotContent: new Set(commonMap.keys()),
877
+ children: undefined
878
+ });
879
+ this._statSharedSnapshots++;
880
+ }
881
+ }
882
+ const unshared = capturedFiles.size;
883
+ this._statItemsUnshared += unshared;
884
+ this._statItemsShared += capturedFilesSize - unshared;
885
+ }
886
+ }
887
+
888
+ /**
889
+ * @param {string} str input
890
+ * @returns {string} result
891
+ */
892
+ const parseString = (str) => {
893
+ if (str[0] === "'" || str[0] === "`") {
894
+ str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
895
+ }
896
+ return JSON.parse(str);
897
+ };
898
+
899
+ /* istanbul ignore next */
900
+ /**
901
+ * @param {number} mtime mtime
902
+ */
903
+ const applyMtime = (mtime) => {
904
+ if (FS_ACCURACY > 1 && mtime % 2 !== 0) FS_ACCURACY = 1;
905
+ else if (FS_ACCURACY > 10 && mtime % 20 !== 0) FS_ACCURACY = 10;
906
+ else if (FS_ACCURACY > 100 && mtime % 200 !== 0) FS_ACCURACY = 100;
907
+ else if (FS_ACCURACY > 1000 && mtime % 2000 !== 0) FS_ACCURACY = 1000;
908
+ };
909
+
910
+ /**
911
+ * @template T
912
+ * @template K
913
+ * @param {Map<T, K> | undefined} a source map
914
+ * @param {Map<T, K> | undefined} b joining map
915
+ * @returns {Map<T, K>} joined map
916
+ */
917
+ const mergeMaps = (a, b) => {
918
+ if (!b || b.size === 0) return /** @type {Map<T, K>} */ (a);
919
+ if (!a || a.size === 0) return /** @type {Map<T, K>} */ (b);
920
+ /** @type {Map<T, K>} */
921
+ const map = new Map(a);
922
+ for (const [key, value] of b) {
923
+ map.set(key, value);
924
+ }
925
+ return map;
926
+ };
927
+
928
+ /**
929
+ * @template T
930
+ * @param {Set<T> | undefined} a source map
931
+ * @param {Set<T> | undefined} b joining map
932
+ * @returns {Set<T>} joined map
933
+ */
934
+ const mergeSets = (a, b) => {
935
+ if (!b || b.size === 0) return /** @type {Set<T>} */ (a);
936
+ if (!a || a.size === 0) return /** @type {Set<T>} */ (b);
937
+ /** @type {Set<T>} */
938
+ const map = new Set(a);
939
+ for (const item of b) {
940
+ map.add(item);
941
+ }
942
+ return map;
943
+ };
944
+
945
+ /**
946
+ * Finding file or directory to manage
947
+ * @param {string} managedPath path that is managing by {@link FileSystemInfo}
948
+ * @param {string} path path to file or directory
949
+ * @returns {string | null} managed item
950
+ * @example
951
+ * getManagedItem(
952
+ * '/Users/user/my-project/node_modules/',
953
+ * '/Users/user/my-project/node_modules/package/index.js'
954
+ * ) === '/Users/user/my-project/node_modules/package'
955
+ * getManagedItem(
956
+ * '/Users/user/my-project/node_modules/',
957
+ * '/Users/user/my-project/node_modules/package1/node_modules/package2'
958
+ * ) === '/Users/user/my-project/node_modules/package1/node_modules/package2'
959
+ * getManagedItem(
960
+ * '/Users/user/my-project/node_modules/',
961
+ * '/Users/user/my-project/node_modules/.bin/script.js'
962
+ * ) === null // hidden files are disallowed as managed items
963
+ * getManagedItem(
964
+ * '/Users/user/my-project/node_modules/',
965
+ * '/Users/user/my-project/node_modules/package'
966
+ * ) === '/Users/user/my-project/node_modules/package'
967
+ */
968
+ const getManagedItem = (managedPath, path) => {
969
+ let i = managedPath.length;
970
+ let slashes = 1;
971
+ let startingPosition = true;
972
+ loop: while (i < path.length) {
973
+ switch (path.charCodeAt(i)) {
974
+ case 47: // slash
975
+ case 92: // backslash
976
+ if (--slashes === 0) break loop;
977
+ startingPosition = true;
978
+ break;
979
+ case 46: // .
980
+ // hidden files are disallowed as managed items
981
+ // it's probably .yarn-integrity or .cache
982
+ if (startingPosition) return null;
983
+ break;
984
+ case 64: // @
985
+ if (!startingPosition) return null;
986
+ slashes++;
987
+ break;
988
+ default:
989
+ startingPosition = false;
990
+ break;
991
+ }
992
+ i++;
993
+ }
994
+ if (i === path.length) slashes--;
995
+ // return null when path is incomplete
996
+ if (slashes !== 0) return null;
997
+ // if (path.slice(i + 1, i + 13) === "node_modules")
998
+ if (
999
+ path.length >= i + 13 &&
1000
+ path.charCodeAt(i + 1) === 110 &&
1001
+ path.charCodeAt(i + 2) === 111 &&
1002
+ path.charCodeAt(i + 3) === 100 &&
1003
+ path.charCodeAt(i + 4) === 101 &&
1004
+ path.charCodeAt(i + 5) === 95 &&
1005
+ path.charCodeAt(i + 6) === 109 &&
1006
+ path.charCodeAt(i + 7) === 111 &&
1007
+ path.charCodeAt(i + 8) === 100 &&
1008
+ path.charCodeAt(i + 9) === 117 &&
1009
+ path.charCodeAt(i + 10) === 108 &&
1010
+ path.charCodeAt(i + 11) === 101 &&
1011
+ path.charCodeAt(i + 12) === 115
1012
+ ) {
1013
+ // if this is the end of the path
1014
+ if (path.length === i + 13) {
1015
+ // return the node_modules directory
1016
+ // it's special
1017
+ return path;
1018
+ }
1019
+ const c = path.charCodeAt(i + 13);
1020
+ // if next symbol is slash or backslash
1021
+ if (c === 47 || c === 92) {
1022
+ // Managed subpath
1023
+ return getManagedItem(path.slice(0, i + 14), path);
1024
+ }
1025
+ }
1026
+ return path.slice(0, i);
1027
+ };
1028
+
1029
+ /**
1030
+ * @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
1031
+ * @param {T | null} entry entry
1032
+ * @returns {T["resolved"] | null | undefined} the resolved entry
1033
+ */
1034
+ const getResolvedTimestamp = (entry) => {
1035
+ if (entry === null) return null;
1036
+ if (entry.resolved !== undefined) return entry.resolved;
1037
+ return entry.symlinks === undefined ? entry : undefined;
1038
+ };
1039
+
1040
+ /**
1041
+ * @param {ContextHash | null} entry entry
1042
+ * @returns {string | null | undefined} the resolved entry
1043
+ */
1044
+ const getResolvedHash = (entry) => {
1045
+ if (entry === null) return null;
1046
+ if (entry.resolved !== undefined) return entry.resolved;
1047
+ return entry.symlinks === undefined ? entry.hash : undefined;
1048
+ };
1049
+
1050
+ /**
1051
+ * @template T
1052
+ * @param {Set<T>} source source
1053
+ * @param {Set<T>} target target
1054
+ */
1055
+ const addAll = (source, target) => {
1056
+ for (const key of source) target.add(key);
1057
+ };
1058
+
1059
+ const getEsModuleLexer = memoize(() => require("es-module-lexer"));
1060
+
1061
+ /** @typedef {Set<string>} LoggedPaths */
1062
+
1063
+ /** @typedef {FileSystemInfoEntry | "ignore" | null} FileTimestamp */
1064
+ /** @typedef {ContextFileSystemInfoEntry | "ignore" | null} ContextTimestamp */
1065
+ /** @typedef {ResolvedContextFileSystemInfoEntry | "ignore" | null} ResolvedContextTimestamp */
1066
+
1067
+ /** @typedef {(err?: WebpackError | null, result?: boolean) => void} CheckSnapshotValidCallback */
1068
+
1069
+ /**
1070
+ * Used to access information about the filesystem in a cached way
1071
+ */
1072
+ class FileSystemInfo {
1073
+ /**
1074
+ * @param {InputFileSystem} fs file system
1075
+ * @param {object} options options
1076
+ * @param {Iterable<string | RegExp>=} options.unmanagedPaths paths that are not managed by a package manager and the contents are subject to change
1077
+ * @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
1078
+ * @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
1079
+ * @param {Logger=} options.logger logger used to log invalid snapshots
1080
+ * @param {HashFunction=} options.hashFunction the hash function to use
1081
+ */
1082
+ constructor(
1083
+ fs,
1084
+ {
1085
+ unmanagedPaths = [],
1086
+ managedPaths = [],
1087
+ immutablePaths = [],
1088
+ logger,
1089
+ hashFunction = DEFAULTS.HASH_FUNCTION
1090
+ } = {}
1091
+ ) {
1092
+ this.fs = fs;
1093
+ this.logger = logger;
1094
+ this._remainingLogs = logger ? 40 : 0;
1095
+ /** @type {LoggedPaths | undefined} */
1096
+ this._loggedPaths = logger ? new Set() : undefined;
1097
+ this._hashFunction = hashFunction;
1098
+ /** @type {WeakMap<Snapshot, boolean | CheckSnapshotValidCallback[]>} */
1099
+ this._snapshotCache = new WeakMap();
1100
+ this._fileTimestampsOptimization = new SnapshotOptimization(
1101
+ (s) => s.hasFileTimestamps(),
1102
+ (s) => s.fileTimestamps,
1103
+ (s, v) => s.setFileTimestamps(v)
1104
+ );
1105
+ this._fileHashesOptimization = new SnapshotOptimization(
1106
+ (s) => s.hasFileHashes(),
1107
+ (s) => s.fileHashes,
1108
+ (s, v) => s.setFileHashes(v),
1109
+ false
1110
+ );
1111
+ this._fileTshsOptimization = new SnapshotOptimization(
1112
+ (s) => s.hasFileTshs(),
1113
+ (s) => s.fileTshs,
1114
+ (s, v) => s.setFileTshs(v)
1115
+ );
1116
+ this._contextTimestampsOptimization = new SnapshotOptimization(
1117
+ (s) => s.hasContextTimestamps(),
1118
+ (s) => s.contextTimestamps,
1119
+ (s, v) => s.setContextTimestamps(v)
1120
+ );
1121
+ this._contextHashesOptimization = new SnapshotOptimization(
1122
+ (s) => s.hasContextHashes(),
1123
+ (s) => s.contextHashes,
1124
+ (s, v) => s.setContextHashes(v),
1125
+ false
1126
+ );
1127
+ this._contextTshsOptimization = new SnapshotOptimization(
1128
+ (s) => s.hasContextTshs(),
1129
+ (s) => s.contextTshs,
1130
+ (s, v) => s.setContextTshs(v)
1131
+ );
1132
+ this._missingExistenceOptimization = new SnapshotOptimization(
1133
+ (s) => s.hasMissingExistence(),
1134
+ (s) => s.missingExistence,
1135
+ (s, v) => s.setMissingExistence(v),
1136
+ false
1137
+ );
1138
+ this._managedItemInfoOptimization = new SnapshotOptimization(
1139
+ (s) => s.hasManagedItemInfo(),
1140
+ (s) => s.managedItemInfo,
1141
+ (s, v) => s.setManagedItemInfo(v),
1142
+ false
1143
+ );
1144
+ this._managedFilesOptimization = new SnapshotOptimization(
1145
+ (s) => s.hasManagedFiles(),
1146
+ (s) => s.managedFiles,
1147
+ (s, v) => s.setManagedFiles(v),
1148
+ false,
1149
+ true
1150
+ );
1151
+ this._managedContextsOptimization = new SnapshotOptimization(
1152
+ (s) => s.hasManagedContexts(),
1153
+ (s) => s.managedContexts,
1154
+ (s, v) => s.setManagedContexts(v),
1155
+ false,
1156
+ true
1157
+ );
1158
+ this._managedMissingOptimization = new SnapshotOptimization(
1159
+ (s) => s.hasManagedMissing(),
1160
+ (s) => s.managedMissing,
1161
+ (s, v) => s.setManagedMissing(v),
1162
+ false,
1163
+ true
1164
+ );
1165
+ /** @type {StackedCacheMap<string, FileTimestamp>} */
1166
+ this._fileTimestamps = new StackedCacheMap();
1167
+ /** @type {Map<string, string | null>} */
1168
+ this._fileHashes = new Map();
1169
+ /** @type {Map<string, TimestampAndHash | string>} */
1170
+ this._fileTshs = new Map();
1171
+ /** @type {StackedCacheMap<string, ContextTimestamp>} */
1172
+ this._contextTimestamps = new StackedCacheMap();
1173
+ /** @type {Map<string, ContextHash>} */
1174
+ this._contextHashes = new Map();
1175
+ /** @type {Map<string, ContextTimestampAndHash>} */
1176
+ this._contextTshs = new Map();
1177
+ /** @type {Map<string, string>} */
1178
+ this._managedItems = new Map();
1179
+ /** @type {AsyncQueue<string, string, FileSystemInfoEntry>} */
1180
+ this.fileTimestampQueue = new AsyncQueue({
1181
+ name: "file timestamp",
1182
+ parallelism: 30,
1183
+ processor: this._readFileTimestamp.bind(this)
1184
+ });
1185
+ /** @type {AsyncQueue<string, string, string>} */
1186
+ this.fileHashQueue = new AsyncQueue({
1187
+ name: "file hash",
1188
+ parallelism: 10,
1189
+ processor: this._readFileHash.bind(this)
1190
+ });
1191
+ /** @type {AsyncQueue<string, string, ContextFileSystemInfoEntry>} */
1192
+ this.contextTimestampQueue = new AsyncQueue({
1193
+ name: "context timestamp",
1194
+ parallelism: 2,
1195
+ processor: this._readContextTimestamp.bind(this)
1196
+ });
1197
+ /** @type {AsyncQueue<string, string, ContextHash>} */
1198
+ this.contextHashQueue = new AsyncQueue({
1199
+ name: "context hash",
1200
+ parallelism: 2,
1201
+ processor: this._readContextHash.bind(this)
1202
+ });
1203
+ /** @type {AsyncQueue<string, string, ContextTimestampAndHash>} */
1204
+ this.contextTshQueue = new AsyncQueue({
1205
+ name: "context hash and timestamp",
1206
+ parallelism: 2,
1207
+ processor: this._readContextTimestampAndHash.bind(this)
1208
+ });
1209
+ /** @type {AsyncQueue<string, string, string>} */
1210
+ this.managedItemQueue = new AsyncQueue({
1211
+ name: "managed item info",
1212
+ parallelism: 10,
1213
+ processor: this._getManagedItemInfo.bind(this)
1214
+ });
1215
+ /** @type {AsyncQueue<string, string, Set<string>>} */
1216
+ this.managedItemDirectoryQueue = new AsyncQueue({
1217
+ name: "managed item directory info",
1218
+ parallelism: 10,
1219
+ processor: this._getManagedItemDirectoryInfo.bind(this)
1220
+ });
1221
+ const _unmanagedPaths = [...unmanagedPaths];
1222
+ /** @type {string[]} */
1223
+ this.unmanagedPathsWithSlash = _unmanagedPaths
1224
+ .filter((p) => typeof p === "string")
1225
+ .map((p) => join(fs, p, "_").slice(0, -1));
1226
+ /** @type {RegExp[]} */
1227
+ this.unmanagedPathsRegExps = _unmanagedPaths.filter(
1228
+ (p) => typeof p !== "string"
1229
+ );
1230
+
1231
+ this.managedPaths = [...managedPaths];
1232
+ /** @type {string[]} */
1233
+ this.managedPathsWithSlash = this.managedPaths
1234
+ .filter((p) => typeof p === "string")
1235
+ .map((p) => join(fs, p, "_").slice(0, -1));
1236
+ /** @type {RegExp[]} */
1237
+ this.managedPathsRegExps = this.managedPaths.filter(
1238
+ (p) => typeof p !== "string"
1239
+ );
1240
+
1241
+ this.immutablePaths = [...immutablePaths];
1242
+ /** @type {string[]} */
1243
+ this.immutablePathsWithSlash = this.immutablePaths
1244
+ .filter((p) => typeof p === "string")
1245
+ .map((p) => join(fs, p, "_").slice(0, -1));
1246
+ /** @type {RegExp[]} */
1247
+ this.immutablePathsRegExps = this.immutablePaths.filter(
1248
+ (p) => typeof p !== "string"
1249
+ );
1250
+
1251
+ this._cachedDeprecatedFileTimestamps = undefined;
1252
+ this._cachedDeprecatedContextTimestamps = undefined;
1253
+
1254
+ this._warnAboutExperimentalEsmTracking = false;
1255
+
1256
+ this._statCreatedSnapshots = 0;
1257
+ this._statTestedSnapshotsCached = 0;
1258
+ this._statTestedSnapshotsNotCached = 0;
1259
+ this._statTestedChildrenCached = 0;
1260
+ this._statTestedChildrenNotCached = 0;
1261
+ this._statTestedEntries = 0;
1262
+ }
1263
+
1264
+ logStatistics() {
1265
+ const logger = /** @type {Logger} */ (this.logger);
1266
+ /**
1267
+ * @param {string} header header
1268
+ * @param {string | undefined} message message
1269
+ */
1270
+ const logWhenMessage = (header, message) => {
1271
+ if (message) {
1272
+ logger.log(`${header}: ${message}`);
1273
+ }
1274
+ };
1275
+ logger.log(`${this._statCreatedSnapshots} new snapshots created`);
1276
+ logger.log(
1277
+ `${
1278
+ this._statTestedSnapshotsNotCached &&
1279
+ Math.round(
1280
+ (this._statTestedSnapshotsNotCached * 100) /
1281
+ (this._statTestedSnapshotsCached +
1282
+ this._statTestedSnapshotsNotCached)
1283
+ )
1284
+ }% root snapshot uncached (${this._statTestedSnapshotsNotCached} / ${
1285
+ this._statTestedSnapshotsCached + this._statTestedSnapshotsNotCached
1286
+ })`
1287
+ );
1288
+ logger.log(
1289
+ `${
1290
+ this._statTestedChildrenNotCached &&
1291
+ Math.round(
1292
+ (this._statTestedChildrenNotCached * 100) /
1293
+ (this._statTestedChildrenCached + this._statTestedChildrenNotCached)
1294
+ )
1295
+ }% children snapshot uncached (${this._statTestedChildrenNotCached} / ${
1296
+ this._statTestedChildrenCached + this._statTestedChildrenNotCached
1297
+ })`
1298
+ );
1299
+ logger.log(`${this._statTestedEntries} entries tested`);
1300
+ logger.log(
1301
+ `File info in cache: ${this._fileTimestamps.size} timestamps ${this._fileHashes.size} hashes ${this._fileTshs.size} timestamp hash combinations`
1302
+ );
1303
+ logWhenMessage(
1304
+ "File timestamp snapshot optimization",
1305
+ this._fileTimestampsOptimization.getStatisticMessage()
1306
+ );
1307
+ logWhenMessage(
1308
+ "File hash snapshot optimization",
1309
+ this._fileHashesOptimization.getStatisticMessage()
1310
+ );
1311
+ logWhenMessage(
1312
+ "File timestamp hash combination snapshot optimization",
1313
+ this._fileTshsOptimization.getStatisticMessage()
1314
+ );
1315
+ logger.log(
1316
+ `Directory info in cache: ${this._contextTimestamps.size} timestamps ${this._contextHashes.size} hashes ${this._contextTshs.size} timestamp hash combinations`
1317
+ );
1318
+ logWhenMessage(
1319
+ "Directory timestamp snapshot optimization",
1320
+ this._contextTimestampsOptimization.getStatisticMessage()
1321
+ );
1322
+ logWhenMessage(
1323
+ "Directory hash snapshot optimization",
1324
+ this._contextHashesOptimization.getStatisticMessage()
1325
+ );
1326
+ logWhenMessage(
1327
+ "Directory timestamp hash combination snapshot optimization",
1328
+ this._contextTshsOptimization.getStatisticMessage()
1329
+ );
1330
+ logWhenMessage(
1331
+ "Missing items snapshot optimization",
1332
+ this._missingExistenceOptimization.getStatisticMessage()
1333
+ );
1334
+ logger.log(`Managed items info in cache: ${this._managedItems.size} items`);
1335
+ logWhenMessage(
1336
+ "Managed items snapshot optimization",
1337
+ this._managedItemInfoOptimization.getStatisticMessage()
1338
+ );
1339
+ logWhenMessage(
1340
+ "Managed files snapshot optimization",
1341
+ this._managedFilesOptimization.getStatisticMessage()
1342
+ );
1343
+ logWhenMessage(
1344
+ "Managed contexts snapshot optimization",
1345
+ this._managedContextsOptimization.getStatisticMessage()
1346
+ );
1347
+ logWhenMessage(
1348
+ "Managed missing snapshot optimization",
1349
+ this._managedMissingOptimization.getStatisticMessage()
1350
+ );
1351
+ }
1352
+
1353
+ /**
1354
+ * @private
1355
+ * @param {string} path path
1356
+ * @param {string} reason reason
1357
+ * @param {EXPECTED_ANY[]} args arguments
1358
+ */
1359
+ _log(path, reason, ...args) {
1360
+ const key = path + reason;
1361
+ const loggedPaths = /** @type {LoggedPaths} */ (this._loggedPaths);
1362
+ if (loggedPaths.has(key)) return;
1363
+ loggedPaths.add(key);
1364
+ /** @type {Logger} */
1365
+ (this.logger).debug(`${path} invalidated because ${reason}`, ...args);
1366
+ if (--this._remainingLogs === 0) {
1367
+ /** @type {Logger} */
1368
+ (this.logger).debug(
1369
+ "Logging limit has been reached and no further logging will be emitted by FileSystemInfo"
1370
+ );
1371
+ }
1372
+ }
1373
+
1374
+ clear() {
1375
+ this._remainingLogs = this.logger ? 40 : 0;
1376
+ if (this._loggedPaths !== undefined) this._loggedPaths.clear();
1377
+
1378
+ this._snapshotCache = new WeakMap();
1379
+ this._fileTimestampsOptimization.clear();
1380
+ this._fileHashesOptimization.clear();
1381
+ this._fileTshsOptimization.clear();
1382
+ this._contextTimestampsOptimization.clear();
1383
+ this._contextHashesOptimization.clear();
1384
+ this._contextTshsOptimization.clear();
1385
+ this._missingExistenceOptimization.clear();
1386
+ this._managedItemInfoOptimization.clear();
1387
+ this._managedFilesOptimization.clear();
1388
+ this._managedContextsOptimization.clear();
1389
+ this._managedMissingOptimization.clear();
1390
+ this._fileTimestamps.clear();
1391
+ this._fileHashes.clear();
1392
+ this._fileTshs.clear();
1393
+ this._contextTimestamps.clear();
1394
+ this._contextHashes.clear();
1395
+ this._contextTshs.clear();
1396
+ this._managedItems.clear();
1397
+ this._managedItems.clear();
1398
+
1399
+ this._cachedDeprecatedFileTimestamps = undefined;
1400
+ this._cachedDeprecatedContextTimestamps = undefined;
1401
+
1402
+ this._statCreatedSnapshots = 0;
1403
+ this._statTestedSnapshotsCached = 0;
1404
+ this._statTestedSnapshotsNotCached = 0;
1405
+ this._statTestedChildrenCached = 0;
1406
+ this._statTestedChildrenNotCached = 0;
1407
+ this._statTestedEntries = 0;
1408
+ }
1409
+
1410
+ /**
1411
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | ExistenceOnlyTimeEntry | "ignore" | null>} map timestamps
1412
+ * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1413
+ * @returns {void}
1414
+ */
1415
+ addFileTimestamps(map, immutable) {
1416
+ this._fileTimestamps.addAll(
1417
+ /** @type {ReadonlyMap<string, FileTimestamp>} */
1418
+ (map),
1419
+ immutable
1420
+ );
1421
+ this._cachedDeprecatedFileTimestamps = undefined;
1422
+ }
1423
+
1424
+ /**
1425
+ * @param {ReadonlyMap<string, ContextFileSystemInfoEntry | ExistenceOnlyTimeEntry | "ignore" | null>} map timestamps
1426
+ * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1427
+ * @returns {void}
1428
+ */
1429
+ addContextTimestamps(map, immutable) {
1430
+ this._contextTimestamps.addAll(
1431
+ /** @type {ReadonlyMap<string, ContextTimestamp>} */
1432
+ (map),
1433
+ immutable
1434
+ );
1435
+ this._cachedDeprecatedContextTimestamps = undefined;
1436
+ }
1437
+
1438
+ /**
1439
+ * @param {string} path file path
1440
+ * @param {(err?: WebpackError | null, fileTimestamp?: FileTimestamp) => void} callback callback function
1441
+ * @returns {void}
1442
+ */
1443
+ getFileTimestamp(path, callback) {
1444
+ const cache = this._fileTimestamps.get(path);
1445
+ if (cache !== undefined) return callback(null, cache);
1446
+ this.fileTimestampQueue.add(path, callback);
1447
+ }
1448
+
1449
+ /**
1450
+ * @param {string} path context path
1451
+ * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback function
1452
+ * @returns {void}
1453
+ */
1454
+ getContextTimestamp(path, callback) {
1455
+ const cache = this._contextTimestamps.get(path);
1456
+ if (cache !== undefined) {
1457
+ if (cache === "ignore") return callback(null, "ignore");
1458
+ const resolved = getResolvedTimestamp(cache);
1459
+ if (resolved !== undefined) return callback(null, resolved);
1460
+ return this._resolveContextTimestamp(
1461
+ /** @type {ResolvedContextFileSystemInfoEntry} */
1462
+ (cache),
1463
+ callback
1464
+ );
1465
+ }
1466
+ this.contextTimestampQueue.add(path, (err, _entry) => {
1467
+ if (err) return callback(err);
1468
+ const entry = /** @type {ContextFileSystemInfoEntry} */ (_entry);
1469
+ const resolved = getResolvedTimestamp(entry);
1470
+ if (resolved !== undefined) return callback(null, resolved);
1471
+ this._resolveContextTimestamp(entry, callback);
1472
+ });
1473
+ }
1474
+
1475
+ /**
1476
+ * @private
1477
+ * @param {string} path context path
1478
+ * @param {(err?: WebpackError | null, contextTimestamp?: ContextTimestamp) => void} callback callback function
1479
+ * @returns {void}
1480
+ */
1481
+ _getUnresolvedContextTimestamp(path, callback) {
1482
+ const cache = this._contextTimestamps.get(path);
1483
+ if (cache !== undefined) return callback(null, cache);
1484
+ this.contextTimestampQueue.add(path, callback);
1485
+ }
1486
+
1487
+ /**
1488
+ * @param {string} path file path
1489
+ * @param {(err?: WebpackError | null, hash?: string | null) => void} callback callback function
1490
+ * @returns {void}
1491
+ */
1492
+ getFileHash(path, callback) {
1493
+ const cache = this._fileHashes.get(path);
1494
+ if (cache !== undefined) return callback(null, cache);
1495
+ this.fileHashQueue.add(path, callback);
1496
+ }
1497
+
1498
+ /**
1499
+ * @param {string} path context path
1500
+ * @param {(err?: WebpackError | null, contextHash?: string) => void} callback callback function
1501
+ * @returns {void}
1502
+ */
1503
+ getContextHash(path, callback) {
1504
+ const cache = this._contextHashes.get(path);
1505
+ if (cache !== undefined) {
1506
+ const resolved = getResolvedHash(cache);
1507
+ if (resolved !== undefined) {
1508
+ return callback(null, /** @type {string} */ (resolved));
1509
+ }
1510
+ return this._resolveContextHash(cache, callback);
1511
+ }
1512
+ this.contextHashQueue.add(path, (err, _entry) => {
1513
+ if (err) return callback(err);
1514
+ const entry = /** @type {ContextHash} */ (_entry);
1515
+ const resolved = getResolvedHash(entry);
1516
+ if (resolved !== undefined) {
1517
+ return callback(null, /** @type {string} */ (resolved));
1518
+ }
1519
+ this._resolveContextHash(entry, callback);
1520
+ });
1521
+ }
1522
+
1523
+ /**
1524
+ * @private
1525
+ * @param {string} path context path
1526
+ * @param {(err?: WebpackError | null, contextHash?: ContextHash | null) => void} callback callback function
1527
+ * @returns {void}
1528
+ */
1529
+ _getUnresolvedContextHash(path, callback) {
1530
+ const cache = this._contextHashes.get(path);
1531
+ if (cache !== undefined) return callback(null, cache);
1532
+ this.contextHashQueue.add(path, callback);
1533
+ }
1534
+
1535
+ /**
1536
+ * @param {string} path context path
1537
+ * @param {(err?: WebpackError | null, resolvedContextTimestampAndHash?: ResolvedContextTimestampAndHash | null) => void} callback callback function
1538
+ * @returns {void}
1539
+ */
1540
+ getContextTsh(path, callback) {
1541
+ const cache = this._contextTshs.get(path);
1542
+ if (cache !== undefined) {
1543
+ const resolved = getResolvedTimestamp(cache);
1544
+ if (resolved !== undefined) return callback(null, resolved);
1545
+ return this._resolveContextTsh(cache, callback);
1546
+ }
1547
+ this.contextTshQueue.add(path, (err, _entry) => {
1548
+ if (err) return callback(err);
1549
+ const entry = /** @type {ContextTimestampAndHash} */ (_entry);
1550
+ const resolved = getResolvedTimestamp(entry);
1551
+ if (resolved !== undefined) return callback(null, resolved);
1552
+ this._resolveContextTsh(entry, callback);
1553
+ });
1554
+ }
1555
+
1556
+ /**
1557
+ * @private
1558
+ * @param {string} path context path
1559
+ * @param {(err?: WebpackError | null, contextTimestampAndHash?: ContextTimestampAndHash | null) => void} callback callback function
1560
+ * @returns {void}
1561
+ */
1562
+ _getUnresolvedContextTsh(path, callback) {
1563
+ const cache = this._contextTshs.get(path);
1564
+ if (cache !== undefined) return callback(null, cache);
1565
+ this.contextTshQueue.add(path, callback);
1566
+ }
1567
+
1568
+ _createBuildDependenciesResolvers() {
1569
+ const resolveContext = createResolver({
1570
+ resolveToContext: true,
1571
+ exportsFields: [],
1572
+ fileSystem: this.fs
1573
+ });
1574
+ const resolveCjs = createResolver({
1575
+ extensions: [".js", ".json", ".node"],
1576
+ conditionNames: ["require", "node"],
1577
+ exportsFields: ["exports"],
1578
+ fileSystem: this.fs
1579
+ });
1580
+ const resolveCjsAsChild = createResolver({
1581
+ extensions: [".js", ".json", ".node"],
1582
+ conditionNames: ["require", "node"],
1583
+ exportsFields: [],
1584
+ fileSystem: this.fs
1585
+ });
1586
+ const resolveEsm = createResolver({
1587
+ extensions: [".js", ".json", ".node"],
1588
+ fullySpecified: true,
1589
+ conditionNames: ["import", "node"],
1590
+ exportsFields: ["exports"],
1591
+ fileSystem: this.fs
1592
+ });
1593
+ return { resolveContext, resolveEsm, resolveCjs, resolveCjsAsChild };
1594
+ }
1595
+
1596
+ /**
1597
+ * @param {string} context context directory
1598
+ * @param {Iterable<string>} deps dependencies
1599
+ * @param {(err?: Error | null, resolveBuildDependenciesResult?: ResolveBuildDependenciesResult) => void} callback callback function
1600
+ * @returns {void}
1601
+ */
1602
+ resolveBuildDependencies(context, deps, callback) {
1603
+ const { resolveContext, resolveEsm, resolveCjs, resolveCjsAsChild } =
1604
+ this._createBuildDependenciesResolvers();
1605
+
1606
+ /** @type {Files} */
1607
+ const files = new Set();
1608
+ /** @type {Symlinks} */
1609
+ const fileSymlinks = new Set();
1610
+ /** @type {Directories} */
1611
+ const directories = new Set();
1612
+ /** @type {Symlinks} */
1613
+ const directorySymlinks = new Set();
1614
+ /** @type {Missing} */
1615
+ const missing = new Set();
1616
+ /** @type {ResolveDependencies["files"]} */
1617
+ const resolveFiles = new Set();
1618
+ /** @type {ResolveDependencies["directories"]} */
1619
+ const resolveDirectories = new Set();
1620
+ /** @type {ResolveDependencies["missing"]} */
1621
+ const resolveMissing = new Set();
1622
+ /** @type {ResolveResults} */
1623
+ const resolveResults = new Map();
1624
+ /** @type {Set<string>} */
1625
+ const invalidResolveResults = new Set();
1626
+ const resolverContext = {
1627
+ fileDependencies: resolveFiles,
1628
+ contextDependencies: resolveDirectories,
1629
+ missingDependencies: resolveMissing
1630
+ };
1631
+ /**
1632
+ * @param {undefined | boolean | string} expected expected result
1633
+ * @returns {string} expected result
1634
+ */
1635
+ const expectedToString = (expected) =>
1636
+ expected ? ` (expected ${expected})` : "";
1637
+ /** @typedef {{ type: JobType, context: string | undefined, path: string, issuer: Job | undefined, expected: undefined | boolean | string }} Job */
1638
+
1639
+ /**
1640
+ * @param {Job} job job
1641
+ * @returns {string} result
1642
+ */
1643
+ const jobToString = (job) => {
1644
+ switch (job.type) {
1645
+ case RBDT_RESOLVE_FILE:
1646
+ return `resolve file ${job.path}${expectedToString(job.expected)}`;
1647
+ case RBDT_RESOLVE_DIRECTORY:
1648
+ return `resolve directory ${job.path}`;
1649
+ case RBDT_RESOLVE_CJS_FILE:
1650
+ return `resolve commonjs file ${job.path}${expectedToString(
1651
+ job.expected
1652
+ )}`;
1653
+ case RBDT_RESOLVE_ESM_FILE:
1654
+ return `resolve esm file ${job.path}${expectedToString(
1655
+ job.expected
1656
+ )}`;
1657
+ case RBDT_DIRECTORY:
1658
+ return `directory ${job.path}`;
1659
+ case RBDT_FILE:
1660
+ return `file ${job.path}`;
1661
+ case RBDT_DIRECTORY_DEPENDENCIES:
1662
+ return `directory dependencies ${job.path}`;
1663
+ case RBDT_FILE_DEPENDENCIES:
1664
+ return `file dependencies ${job.path}`;
1665
+ }
1666
+ return `unknown ${job.type} ${job.path}`;
1667
+ };
1668
+ /**
1669
+ * @param {Job} job job
1670
+ * @returns {string} string value
1671
+ */
1672
+ const pathToString = (job) => {
1673
+ let result = ` at ${jobToString(job)}`;
1674
+ /** @type {Job | undefined} */
1675
+ (job) = job.issuer;
1676
+ while (job !== undefined) {
1677
+ result += `\n at ${jobToString(job)}`;
1678
+ job = /** @type {Job} */ (job.issuer);
1679
+ }
1680
+ return result;
1681
+ };
1682
+ const logger = /** @type {Logger} */ (this.logger);
1683
+ processAsyncTree(
1684
+ Array.from(
1685
+ deps,
1686
+ (dep) =>
1687
+ /** @type {Job} */ ({
1688
+ type: RBDT_RESOLVE_INITIAL,
1689
+ context,
1690
+ path: dep,
1691
+ expected: undefined,
1692
+ issuer: undefined
1693
+ })
1694
+ ),
1695
+ 20,
1696
+ (job, push, callback) => {
1697
+ const { type, context, path, expected } = job;
1698
+ /**
1699
+ * @param {string} path path
1700
+ * @returns {void}
1701
+ */
1702
+ const resolveDirectory = (path) => {
1703
+ const key = `d\n${context}\n${path}`;
1704
+ if (resolveResults.has(key)) {
1705
+ return callback();
1706
+ }
1707
+ resolveResults.set(key, undefined);
1708
+ resolveContext(
1709
+ /** @type {string} */ (context),
1710
+ path,
1711
+ resolverContext,
1712
+ (err, _, result) => {
1713
+ if (err) {
1714
+ if (expected === false) {
1715
+ resolveResults.set(key, false);
1716
+ return callback();
1717
+ }
1718
+ invalidResolveResults.add(key);
1719
+ err.message += `\nwhile resolving '${path}' in ${context} to a directory`;
1720
+ return callback(err);
1721
+ }
1722
+ const resultPath = /** @type {ResolveRequest} */ (result).path;
1723
+ resolveResults.set(key, resultPath);
1724
+ push({
1725
+ type: RBDT_DIRECTORY,
1726
+ context: undefined,
1727
+ path: /** @type {string} */ (resultPath),
1728
+ expected: undefined,
1729
+ issuer: job
1730
+ });
1731
+ callback();
1732
+ }
1733
+ );
1734
+ };
1735
+ /**
1736
+ * @param {string} path path
1737
+ * @param {("f" | "c" | "e")=} symbol symbol
1738
+ * @param {(ResolveFunctionAsync)=} resolve resolve fn
1739
+ * @returns {void}
1740
+ */
1741
+ const resolveFile = (path, symbol, resolve) => {
1742
+ const key = `${symbol}\n${context}\n${path}`;
1743
+ if (resolveResults.has(key)) {
1744
+ return callback();
1745
+ }
1746
+ resolveResults.set(key, undefined);
1747
+ /** @type {ResolveFunctionAsync} */
1748
+ (resolve)(
1749
+ /** @type {string} */ (context),
1750
+ path,
1751
+ resolverContext,
1752
+ (err, _, result) => {
1753
+ if (typeof expected === "string") {
1754
+ if (!err && result && result.path === expected) {
1755
+ resolveResults.set(key, result.path);
1756
+ } else {
1757
+ invalidResolveResults.add(key);
1758
+ logger.warn(
1759
+ `Resolving '${path}' in ${context} for build dependencies doesn't lead to expected result '${expected}', but to '${
1760
+ err || (result && result.path)
1761
+ }' instead. Resolving dependencies are ignored for this path.\n${pathToString(
1762
+ job
1763
+ )}`
1764
+ );
1765
+ }
1766
+ } else {
1767
+ if (err) {
1768
+ if (expected === false) {
1769
+ resolveResults.set(key, false);
1770
+ return callback();
1771
+ }
1772
+ invalidResolveResults.add(key);
1773
+ err.message += `\nwhile resolving '${path}' in ${context} as file\n${pathToString(
1774
+ job
1775
+ )}`;
1776
+ return callback(err);
1777
+ }
1778
+ const resultPath = /** @type {ResolveRequest} */ (result).path;
1779
+ resolveResults.set(key, resultPath);
1780
+ push({
1781
+ type: RBDT_FILE,
1782
+ context: undefined,
1783
+ path: /** @type {string} */ (resultPath),
1784
+ expected: undefined,
1785
+ issuer: job
1786
+ });
1787
+ }
1788
+ callback();
1789
+ }
1790
+ );
1791
+ };
1792
+ const resolvedType =
1793
+ type === RBDT_RESOLVE_INITIAL
1794
+ ? /[\\/]$/.test(path)
1795
+ ? RBDT_RESOLVE_DIRECTORY
1796
+ : RBDT_RESOLVE_FILE
1797
+ : type;
1798
+ switch (resolvedType) {
1799
+ case RBDT_RESOLVE_FILE: {
1800
+ resolveFile(
1801
+ path,
1802
+ "f",
1803
+ /\.mjs$/.test(path) ? resolveEsm : resolveCjs
1804
+ );
1805
+ break;
1806
+ }
1807
+ case RBDT_RESOLVE_DIRECTORY: {
1808
+ resolveDirectory(RBDT_RESOLVE_INITIAL ? path.slice(0, -1) : path);
1809
+ break;
1810
+ }
1811
+ case RBDT_RESOLVE_CJS_FILE: {
1812
+ resolveFile(path, "f", resolveCjs);
1813
+ break;
1814
+ }
1815
+ case RBDT_RESOLVE_CJS_FILE_AS_CHILD: {
1816
+ resolveFile(path, "c", resolveCjsAsChild);
1817
+ break;
1818
+ }
1819
+ case RBDT_RESOLVE_ESM_FILE: {
1820
+ resolveFile(path, "e", resolveEsm);
1821
+ break;
1822
+ }
1823
+ case RBDT_FILE: {
1824
+ if (files.has(path)) {
1825
+ callback();
1826
+ break;
1827
+ }
1828
+ files.add(path);
1829
+ /** @type {NonNullable<InputFileSystem["realpath"]>} */
1830
+ (this.fs.realpath)(path, (err, _realPath) => {
1831
+ if (err) return callback(err);
1832
+ const realPath = /** @type {string} */ (_realPath);
1833
+ if (realPath !== path) {
1834
+ fileSymlinks.add(path);
1835
+ resolveFiles.add(path);
1836
+ if (files.has(realPath)) return callback();
1837
+ files.add(realPath);
1838
+ }
1839
+ push({
1840
+ type: RBDT_FILE_DEPENDENCIES,
1841
+ context: undefined,
1842
+ path: realPath,
1843
+ expected: undefined,
1844
+ issuer: job
1845
+ });
1846
+ callback();
1847
+ });
1848
+ break;
1849
+ }
1850
+ case RBDT_DIRECTORY: {
1851
+ if (directories.has(path)) {
1852
+ callback();
1853
+ break;
1854
+ }
1855
+ directories.add(path);
1856
+ /** @type {NonNullable<InputFileSystem["realpath"]>} */
1857
+ (this.fs.realpath)(path, (err, _realPath) => {
1858
+ if (err) return callback(err);
1859
+ const realPath = /** @type {string} */ (_realPath);
1860
+ if (realPath !== path) {
1861
+ directorySymlinks.add(path);
1862
+ resolveFiles.add(path);
1863
+ if (directories.has(realPath)) return callback();
1864
+ directories.add(realPath);
1865
+ }
1866
+ push({
1867
+ type: RBDT_DIRECTORY_DEPENDENCIES,
1868
+ context: undefined,
1869
+ path: realPath,
1870
+ expected: undefined,
1871
+ issuer: job
1872
+ });
1873
+ callback();
1874
+ });
1875
+ break;
1876
+ }
1877
+ case RBDT_FILE_DEPENDENCIES: {
1878
+ // Check for known files without dependencies
1879
+ if (/\.json5?$|\.yarn-integrity$|yarn\.lock$|\.ya?ml/.test(path)) {
1880
+ process.nextTick(callback);
1881
+ break;
1882
+ }
1883
+ // Check commonjs cache for the module
1884
+ /** @type {NodeModule | undefined} */
1885
+ const module = require.cache[path];
1886
+ if (
1887
+ module &&
1888
+ Array.isArray(module.children) &&
1889
+ // https://github.com/nodejs/node/issues/59868
1890
+ // Force use `es-module-lexer` for mjs
1891
+ !/\.mjs$/.test(path)
1892
+ ) {
1893
+ children: for (const child of module.children) {
1894
+ const childPath = child.filename;
1895
+ if (childPath) {
1896
+ push({
1897
+ type: RBDT_FILE,
1898
+ context: undefined,
1899
+ path: childPath,
1900
+ expected: undefined,
1901
+ issuer: job
1902
+ });
1903
+ const context = dirname(this.fs, path);
1904
+ for (const modulePath of module.paths) {
1905
+ if (childPath.startsWith(modulePath)) {
1906
+ const subPath = childPath.slice(modulePath.length + 1);
1907
+ const packageMatch = /^@[^\\/]+[\\/][^\\/]+/.exec(
1908
+ subPath
1909
+ );
1910
+ if (packageMatch) {
1911
+ push({
1912
+ type: RBDT_FILE,
1913
+ context: undefined,
1914
+ path: `${
1915
+ modulePath +
1916
+ childPath[modulePath.length] +
1917
+ packageMatch[0] +
1918
+ childPath[modulePath.length]
1919
+ }package.json`,
1920
+ expected: false,
1921
+ issuer: job
1922
+ });
1923
+ }
1924
+ let request = subPath.replace(/\\/g, "/");
1925
+ if (request.endsWith(".js")) {
1926
+ request = request.slice(0, -3);
1927
+ }
1928
+ push({
1929
+ type: RBDT_RESOLVE_CJS_FILE_AS_CHILD,
1930
+ context,
1931
+ path: request,
1932
+ expected: child.filename,
1933
+ issuer: job
1934
+ });
1935
+ continue children;
1936
+ }
1937
+ }
1938
+ let request = relative(this.fs, context, childPath);
1939
+ if (request.endsWith(".js")) request = request.slice(0, -3);
1940
+ request = request.replace(/\\/g, "/");
1941
+ if (!request.startsWith("../") && !isAbsolute(request)) {
1942
+ request = `./${request}`;
1943
+ }
1944
+ push({
1945
+ type: RBDT_RESOLVE_CJS_FILE,
1946
+ context,
1947
+ path: request,
1948
+ expected: child.filename,
1949
+ issuer: job
1950
+ });
1951
+ }
1952
+ }
1953
+ } else if (supportsEsm && /\.m?js$/.test(path)) {
1954
+ if (!this._warnAboutExperimentalEsmTracking) {
1955
+ logger.log(
1956
+ "Node.js doesn't offer a (nice) way to introspect the ESM dependency graph yet.\n" +
1957
+ "Until a full solution is available webpack uses an experimental ESM tracking based on parsing.\n" +
1958
+ "As best effort webpack parses the ESM files to guess dependencies. But this can lead to expensive and incorrect tracking."
1959
+ );
1960
+ this._warnAboutExperimentalEsmTracking = true;
1961
+ }
1962
+
1963
+ const lexer = getEsModuleLexer();
1964
+
1965
+ lexer.init.then(() => {
1966
+ this.fs.readFile(path, (err, content) => {
1967
+ if (err) return callback(err);
1968
+ try {
1969
+ const context = dirname(this.fs, path);
1970
+ const source = /** @type {Buffer} */ (content).toString();
1971
+ const [imports] = lexer.parse(source);
1972
+ /** @type {Set<string>} */
1973
+ const added = new Set();
1974
+ for (const imp of imports) {
1975
+ try {
1976
+ /** @type {string} */
1977
+ let dependency;
1978
+ if (imp.d === -1) {
1979
+ // import ... from "..."
1980
+ dependency = parseString(
1981
+ source.slice(imp.s - 1, imp.e + 1)
1982
+ );
1983
+ } else if (imp.d > -1) {
1984
+ // import()
1985
+ const expr = source.slice(imp.s, imp.e).trim();
1986
+ dependency = parseString(expr);
1987
+ } else {
1988
+ // e.g. import.meta
1989
+ continue;
1990
+ }
1991
+
1992
+ // We should not track Node.js build dependencies
1993
+ if (dependency.startsWith("node:")) continue;
1994
+ if (builtinModules.has(dependency)) continue;
1995
+ // Avoid extra jobs for identical imports
1996
+ if (added.has(dependency)) continue;
1997
+
1998
+ push({
1999
+ type: RBDT_RESOLVE_ESM_FILE,
2000
+ context,
2001
+ path: dependency,
2002
+ expected: imp.d > -1 ? false : undefined,
2003
+ issuer: job
2004
+ });
2005
+ added.add(dependency);
2006
+ } catch (err1) {
2007
+ logger.warn(
2008
+ `Parsing of ${path} for build dependencies failed at 'import(${source.slice(
2009
+ imp.s,
2010
+ imp.e
2011
+ )})'.\n` +
2012
+ "Build dependencies behind this expression are ignored and might cause incorrect cache invalidation."
2013
+ );
2014
+ logger.debug(pathToString(job));
2015
+ logger.debug(/** @type {Error} */ (err1).stack);
2016
+ }
2017
+ }
2018
+ } catch (err2) {
2019
+ logger.warn(
2020
+ `Parsing of ${path} for build dependencies failed and all dependencies of this file are ignored, which might cause incorrect cache invalidation..`
2021
+ );
2022
+ logger.debug(pathToString(job));
2023
+ logger.debug(/** @type {Error} */ (err2).stack);
2024
+ }
2025
+ process.nextTick(callback);
2026
+ });
2027
+ }, callback);
2028
+ break;
2029
+ } else {
2030
+ logger.log(
2031
+ `Assuming ${path} has no dependencies as we were unable to assign it to any module system.`
2032
+ );
2033
+ logger.debug(pathToString(job));
2034
+ }
2035
+ process.nextTick(callback);
2036
+ break;
2037
+ }
2038
+ case RBDT_DIRECTORY_DEPENDENCIES: {
2039
+ const match =
2040
+ /(^.+[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+)/.exec(path);
2041
+ const packagePath = match ? match[1] : path;
2042
+ const packageJson = join(this.fs, packagePath, "package.json");
2043
+ this.fs.readFile(packageJson, (err, content) => {
2044
+ if (err) {
2045
+ if (err.code === "ENOENT") {
2046
+ resolveMissing.add(packageJson);
2047
+ const parent = dirname(this.fs, packagePath);
2048
+ if (parent !== packagePath) {
2049
+ push({
2050
+ type: RBDT_DIRECTORY_DEPENDENCIES,
2051
+ context: undefined,
2052
+ path: parent,
2053
+ expected: undefined,
2054
+ issuer: job
2055
+ });
2056
+ }
2057
+ callback();
2058
+ return;
2059
+ }
2060
+ return callback(err);
2061
+ }
2062
+ resolveFiles.add(packageJson);
2063
+ /** @type {JsonObject} */
2064
+ let packageData;
2065
+ try {
2066
+ packageData = JSON.parse(
2067
+ /** @type {Buffer} */
2068
+ (content).toString("utf8")
2069
+ );
2070
+ } catch (parseErr) {
2071
+ return callback(/** @type {Error} */ (parseErr));
2072
+ }
2073
+ const depsObject = packageData.dependencies;
2074
+ const optionalDepsObject = packageData.optionalDependencies;
2075
+ /** @type {Set<string>} */
2076
+ const allDeps = new Set();
2077
+ /** @type {Set<string>} */
2078
+ const optionalDeps = new Set();
2079
+ if (typeof depsObject === "object" && depsObject) {
2080
+ for (const dep of Object.keys(depsObject)) {
2081
+ allDeps.add(dep);
2082
+ }
2083
+ }
2084
+ if (
2085
+ typeof optionalDepsObject === "object" &&
2086
+ optionalDepsObject
2087
+ ) {
2088
+ for (const dep of Object.keys(optionalDepsObject)) {
2089
+ allDeps.add(dep);
2090
+ optionalDeps.add(dep);
2091
+ }
2092
+ }
2093
+ for (const dep of allDeps) {
2094
+ push({
2095
+ type: RBDT_RESOLVE_DIRECTORY,
2096
+ context: packagePath,
2097
+ path: dep,
2098
+ expected: !optionalDeps.has(dep),
2099
+ issuer: job
2100
+ });
2101
+ }
2102
+ callback();
2103
+ });
2104
+ break;
2105
+ }
2106
+ }
2107
+ },
2108
+ (err) => {
2109
+ if (err) return callback(err);
2110
+ for (const l of fileSymlinks) files.delete(l);
2111
+ for (const l of directorySymlinks) directories.delete(l);
2112
+ for (const k of invalidResolveResults) resolveResults.delete(k);
2113
+ callback(null, {
2114
+ files,
2115
+ directories,
2116
+ missing,
2117
+ resolveResults,
2118
+ resolveDependencies: {
2119
+ files: resolveFiles,
2120
+ directories: resolveDirectories,
2121
+ missing: resolveMissing
2122
+ }
2123
+ });
2124
+ }
2125
+ );
2126
+ }
2127
+
2128
+ /**
2129
+ * @param {ResolveResults} resolveResults results from resolving
2130
+ * @param {(err?: Error | null, result?: boolean) => void} callback callback with true when resolveResults resolve the same way
2131
+ * @returns {void}
2132
+ */
2133
+ checkResolveResultsValid(resolveResults, callback) {
2134
+ const { resolveCjs, resolveCjsAsChild, resolveEsm, resolveContext } =
2135
+ this._createBuildDependenciesResolvers();
2136
+ asyncLib.eachLimit(
2137
+ resolveResults,
2138
+ 20,
2139
+ ([key, expectedResult], callback) => {
2140
+ const [type, context, path] = key.split("\n");
2141
+ switch (type) {
2142
+ case "d":
2143
+ resolveContext(context, path, {}, (err, _, result) => {
2144
+ if (expectedResult === false) {
2145
+ return callback(err ? undefined : INVALID);
2146
+ }
2147
+ if (err) return callback(err);
2148
+ const resultPath = /** @type {ResolveRequest} */ (result).path;
2149
+ if (resultPath !== expectedResult) return callback(INVALID);
2150
+ callback();
2151
+ });
2152
+ break;
2153
+ case "f":
2154
+ resolveCjs(context, path, {}, (err, _, result) => {
2155
+ if (expectedResult === false) {
2156
+ return callback(err ? undefined : INVALID);
2157
+ }
2158
+ if (err) return callback(err);
2159
+ const resultPath = /** @type {ResolveRequest} */ (result).path;
2160
+ if (resultPath !== expectedResult) return callback(INVALID);
2161
+ callback();
2162
+ });
2163
+ break;
2164
+ case "c":
2165
+ resolveCjsAsChild(context, path, {}, (err, _, result) => {
2166
+ if (expectedResult === false) {
2167
+ return callback(err ? undefined : INVALID);
2168
+ }
2169
+ if (err) return callback(err);
2170
+ const resultPath = /** @type {ResolveRequest} */ (result).path;
2171
+ if (resultPath !== expectedResult) return callback(INVALID);
2172
+ callback();
2173
+ });
2174
+ break;
2175
+ case "e":
2176
+ resolveEsm(context, path, {}, (err, _, result) => {
2177
+ if (expectedResult === false) {
2178
+ return callback(err ? undefined : INVALID);
2179
+ }
2180
+ if (err) return callback(err);
2181
+ const resultPath = /** @type {ResolveRequest} */ (result).path;
2182
+ if (resultPath !== expectedResult) return callback(INVALID);
2183
+ callback();
2184
+ });
2185
+ break;
2186
+ default:
2187
+ callback(new Error("Unexpected type in resolve result key"));
2188
+ break;
2189
+ }
2190
+ },
2191
+ /**
2192
+ * @param {Error | typeof INVALID=} err error or invalid flag
2193
+ * @returns {void}
2194
+ */
2195
+ /** @type {import("neo-async").ErrorCallback<Error | typeof INVALID>} */ (
2196
+ (err) => {
2197
+ if (err === INVALID) {
2198
+ return callback(null, false);
2199
+ }
2200
+ if (err) {
2201
+ return callback(err);
2202
+ }
2203
+ return callback(null, true);
2204
+ }
2205
+ )
2206
+ );
2207
+ }
2208
+
2209
+ /**
2210
+ * @param {number | null | undefined} startTime when processing the files has started
2211
+ * @param {Iterable<string> | null | undefined} files all files
2212
+ * @param {Iterable<string> | null | undefined} directories all directories
2213
+ * @param {Iterable<string> | null | undefined} missing all missing files or directories
2214
+ * @param {SnapshotOptions | null | undefined} options options object (for future extensions)
2215
+ * @param {(err: WebpackError | null, snapshot: Snapshot | null) => void} callback callback function
2216
+ * @returns {void}
2217
+ */
2218
+ createSnapshot(startTime, files, directories, missing, options, callback) {
2219
+ /** @type {FileTimestamps} */
2220
+ const fileTimestamps = new Map();
2221
+ /** @type {FileHashes} */
2222
+ const fileHashes = new Map();
2223
+ /** @type {FileTshs} */
2224
+ const fileTshs = new Map();
2225
+ /** @type {ContextTimestamps} */
2226
+ const contextTimestamps = new Map();
2227
+ /** @type {ContextHashes} */
2228
+ const contextHashes = new Map();
2229
+ /** @type {ContextTshs} */
2230
+ const contextTshs = new Map();
2231
+ /** @type {MissingExistence} */
2232
+ const missingExistence = new Map();
2233
+ /** @type {ManagedItemInfo} */
2234
+ const managedItemInfo = new Map();
2235
+ /** @type {ManagedFiles} */
2236
+ const managedFiles = new Set();
2237
+ /** @type {ManagedContexts} */
2238
+ const managedContexts = new Set();
2239
+ /** @type {ManagedMissing} */
2240
+ const managedMissing = new Set();
2241
+ /** @type {Children} */
2242
+ const children = new Set();
2243
+
2244
+ const snapshot = new Snapshot();
2245
+ if (startTime) snapshot.setStartTime(startTime);
2246
+
2247
+ /** @type {Set<string>} */
2248
+ const managedItems = new Set();
2249
+
2250
+ /** 1 = timestamp, 2 = hash, 3 = timestamp + hash */
2251
+ const mode = options && options.hash ? (options.timestamp ? 3 : 2) : 1;
2252
+
2253
+ let jobs = 1;
2254
+ const jobDone = () => {
2255
+ if (--jobs === 0) {
2256
+ if (fileTimestamps.size !== 0) {
2257
+ snapshot.setFileTimestamps(fileTimestamps);
2258
+ }
2259
+ if (fileHashes.size !== 0) {
2260
+ snapshot.setFileHashes(fileHashes);
2261
+ }
2262
+ if (fileTshs.size !== 0) {
2263
+ snapshot.setFileTshs(fileTshs);
2264
+ }
2265
+ if (contextTimestamps.size !== 0) {
2266
+ snapshot.setContextTimestamps(contextTimestamps);
2267
+ }
2268
+ if (contextHashes.size !== 0) {
2269
+ snapshot.setContextHashes(contextHashes);
2270
+ }
2271
+ if (contextTshs.size !== 0) {
2272
+ snapshot.setContextTshs(contextTshs);
2273
+ }
2274
+ if (missingExistence.size !== 0) {
2275
+ snapshot.setMissingExistence(missingExistence);
2276
+ }
2277
+ if (managedItemInfo.size !== 0) {
2278
+ snapshot.setManagedItemInfo(managedItemInfo);
2279
+ }
2280
+ this._managedFilesOptimization.optimize(snapshot, managedFiles);
2281
+ if (managedFiles.size !== 0) {
2282
+ snapshot.setManagedFiles(managedFiles);
2283
+ }
2284
+ this._managedContextsOptimization.optimize(snapshot, managedContexts);
2285
+ if (managedContexts.size !== 0) {
2286
+ snapshot.setManagedContexts(managedContexts);
2287
+ }
2288
+ this._managedMissingOptimization.optimize(snapshot, managedMissing);
2289
+ if (managedMissing.size !== 0) {
2290
+ snapshot.setManagedMissing(managedMissing);
2291
+ }
2292
+ if (children.size !== 0) {
2293
+ snapshot.setChildren(children);
2294
+ }
2295
+ this._snapshotCache.set(snapshot, true);
2296
+ this._statCreatedSnapshots++;
2297
+
2298
+ callback(null, snapshot);
2299
+ }
2300
+ };
2301
+ const jobError = () => {
2302
+ if (jobs > 0) {
2303
+ // large negative number instead of NaN or something else to keep jobs to stay a SMI (v8)
2304
+ jobs = -100000000;
2305
+ callback(null, null);
2306
+ }
2307
+ };
2308
+ /**
2309
+ * @param {string} path path
2310
+ * @param {ManagedFiles} managedSet managed set
2311
+ * @returns {boolean} true when managed
2312
+ */
2313
+ const checkManaged = (path, managedSet) => {
2314
+ for (const unmanagedPath of this.unmanagedPathsRegExps) {
2315
+ if (unmanagedPath.test(path)) return false;
2316
+ }
2317
+ for (const unmanagedPath of this.unmanagedPathsWithSlash) {
2318
+ if (path.startsWith(unmanagedPath)) return false;
2319
+ }
2320
+ for (const immutablePath of this.immutablePathsRegExps) {
2321
+ if (immutablePath.test(path)) {
2322
+ managedSet.add(path);
2323
+ return true;
2324
+ }
2325
+ }
2326
+ for (const immutablePath of this.immutablePathsWithSlash) {
2327
+ if (path.startsWith(immutablePath)) {
2328
+ managedSet.add(path);
2329
+ return true;
2330
+ }
2331
+ }
2332
+ for (const managedPath of this.managedPathsRegExps) {
2333
+ const match = managedPath.exec(path);
2334
+ if (match) {
2335
+ const managedItem = getManagedItem(match[1], path);
2336
+ if (managedItem) {
2337
+ managedItems.add(managedItem);
2338
+ managedSet.add(path);
2339
+ return true;
2340
+ }
2341
+ }
2342
+ }
2343
+ for (const managedPath of this.managedPathsWithSlash) {
2344
+ if (path.startsWith(managedPath)) {
2345
+ const managedItem = getManagedItem(managedPath, path);
2346
+ if (managedItem) {
2347
+ managedItems.add(managedItem);
2348
+ managedSet.add(path);
2349
+ return true;
2350
+ }
2351
+ }
2352
+ }
2353
+ return false;
2354
+ };
2355
+ /**
2356
+ * @param {Iterable<string>} items items
2357
+ * @param {Set<string>} managedSet managed set
2358
+ * @returns {Set<string>} result
2359
+ */
2360
+ const captureNonManaged = (items, managedSet) => {
2361
+ /** @type {Set<string>} */
2362
+ const capturedItems = new Set();
2363
+ for (const path of items) {
2364
+ if (!checkManaged(path, managedSet)) capturedItems.add(path);
2365
+ }
2366
+ return capturedItems;
2367
+ };
2368
+ /**
2369
+ * @param {ManagedFiles} capturedFiles captured files
2370
+ */
2371
+ const processCapturedFiles = (capturedFiles) => {
2372
+ if (capturedFiles.size === 0) {
2373
+ return;
2374
+ }
2375
+ switch (mode) {
2376
+ case 3:
2377
+ this._fileTshsOptimization.optimize(snapshot, capturedFiles);
2378
+ for (const path of capturedFiles) {
2379
+ const cache = this._fileTshs.get(path);
2380
+ if (cache !== undefined) {
2381
+ fileTshs.set(path, cache);
2382
+ } else {
2383
+ jobs++;
2384
+ this._getFileTimestampAndHash(path, (err, entry) => {
2385
+ if (err) {
2386
+ if (this.logger) {
2387
+ this.logger.debug(
2388
+ `Error snapshotting file timestamp hash combination of ${path}: ${err.stack}`
2389
+ );
2390
+ }
2391
+ jobError();
2392
+ } else {
2393
+ fileTshs.set(path, /** @type {TimestampAndHash} */ (entry));
2394
+ jobDone();
2395
+ }
2396
+ });
2397
+ }
2398
+ }
2399
+ break;
2400
+ case 2:
2401
+ this._fileHashesOptimization.optimize(snapshot, capturedFiles);
2402
+ for (const path of capturedFiles) {
2403
+ const cache = this._fileHashes.get(path);
2404
+ if (cache !== undefined) {
2405
+ fileHashes.set(path, cache);
2406
+ } else {
2407
+ jobs++;
2408
+ this.fileHashQueue.add(path, (err, entry) => {
2409
+ if (err) {
2410
+ if (this.logger) {
2411
+ this.logger.debug(
2412
+ `Error snapshotting file hash of ${path}: ${err.stack}`
2413
+ );
2414
+ }
2415
+ jobError();
2416
+ } else {
2417
+ fileHashes.set(path, /** @type {string} */ (entry));
2418
+ jobDone();
2419
+ }
2420
+ });
2421
+ }
2422
+ }
2423
+ break;
2424
+ case 1:
2425
+ this._fileTimestampsOptimization.optimize(snapshot, capturedFiles);
2426
+ for (const path of capturedFiles) {
2427
+ const cache = this._fileTimestamps.get(path);
2428
+ if (cache !== undefined) {
2429
+ if (cache !== "ignore") {
2430
+ fileTimestamps.set(path, cache);
2431
+ }
2432
+ } else {
2433
+ jobs++;
2434
+ this.fileTimestampQueue.add(path, (err, entry) => {
2435
+ if (err) {
2436
+ if (this.logger) {
2437
+ this.logger.debug(
2438
+ `Error snapshotting file timestamp of ${path}: ${err.stack}`
2439
+ );
2440
+ }
2441
+ jobError();
2442
+ } else {
2443
+ fileTimestamps.set(
2444
+ path,
2445
+ /** @type {FileSystemInfoEntry} */
2446
+ (entry)
2447
+ );
2448
+ jobDone();
2449
+ }
2450
+ });
2451
+ }
2452
+ }
2453
+ break;
2454
+ }
2455
+ };
2456
+ if (files) {
2457
+ processCapturedFiles(captureNonManaged(files, managedFiles));
2458
+ }
2459
+ /**
2460
+ * @param {ManagedContexts} capturedDirectories captured directories
2461
+ */
2462
+ const processCapturedDirectories = (capturedDirectories) => {
2463
+ if (capturedDirectories.size === 0) {
2464
+ return;
2465
+ }
2466
+ switch (mode) {
2467
+ case 3:
2468
+ this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
2469
+ for (const path of capturedDirectories) {
2470
+ const cache = this._contextTshs.get(path);
2471
+ /** @type {ResolvedContextTimestampAndHash | null | undefined} */
2472
+ let resolved;
2473
+ if (
2474
+ cache !== undefined &&
2475
+ (resolved = getResolvedTimestamp(cache)) !== undefined
2476
+ ) {
2477
+ contextTshs.set(path, resolved);
2478
+ } else {
2479
+ jobs++;
2480
+ /**
2481
+ * @param {(WebpackError | null)=} err error
2482
+ * @param {(ResolvedContextTimestampAndHash | null)=} entry entry
2483
+ * @returns {void}
2484
+ */
2485
+ const callback = (err, entry) => {
2486
+ if (err) {
2487
+ if (this.logger) {
2488
+ this.logger.debug(
2489
+ `Error snapshotting context timestamp hash combination of ${path}: ${err.stack}`
2490
+ );
2491
+ }
2492
+ jobError();
2493
+ } else {
2494
+ contextTshs.set(
2495
+ path,
2496
+ /** @type {ResolvedContextTimestampAndHash | null} */
2497
+ (entry)
2498
+ );
2499
+ jobDone();
2500
+ }
2501
+ };
2502
+ if (cache !== undefined) {
2503
+ this._resolveContextTsh(cache, callback);
2504
+ } else {
2505
+ this.getContextTsh(path, callback);
2506
+ }
2507
+ }
2508
+ }
2509
+ break;
2510
+ case 2:
2511
+ this._contextHashesOptimization.optimize(
2512
+ snapshot,
2513
+ capturedDirectories
2514
+ );
2515
+ for (const path of capturedDirectories) {
2516
+ const cache = this._contextHashes.get(path);
2517
+ /** @type {undefined | null | string} */
2518
+ let resolved;
2519
+ if (
2520
+ cache !== undefined &&
2521
+ (resolved = getResolvedHash(cache)) !== undefined
2522
+ ) {
2523
+ contextHashes.set(path, resolved);
2524
+ } else {
2525
+ jobs++;
2526
+ /**
2527
+ * @param {(WebpackError | null)=} err err
2528
+ * @param {string=} entry entry
2529
+ */
2530
+ const callback = (err, entry) => {
2531
+ if (err) {
2532
+ if (this.logger) {
2533
+ this.logger.debug(
2534
+ `Error snapshotting context hash of ${path}: ${err.stack}`
2535
+ );
2536
+ }
2537
+ jobError();
2538
+ } else {
2539
+ contextHashes.set(path, /** @type {string} */ (entry));
2540
+ jobDone();
2541
+ }
2542
+ };
2543
+ if (cache !== undefined) {
2544
+ this._resolveContextHash(cache, callback);
2545
+ } else {
2546
+ this.getContextHash(path, callback);
2547
+ }
2548
+ }
2549
+ }
2550
+ break;
2551
+ case 1:
2552
+ this._contextTimestampsOptimization.optimize(
2553
+ snapshot,
2554
+ capturedDirectories
2555
+ );
2556
+ for (const path of capturedDirectories) {
2557
+ const cache = this._contextTimestamps.get(path);
2558
+ if (cache === "ignore") continue;
2559
+ /** @type {undefined | null | ResolvedContextFileSystemInfoEntry} */
2560
+ let resolved;
2561
+ if (
2562
+ cache !== undefined &&
2563
+ (resolved = getResolvedTimestamp(cache)) !== undefined
2564
+ ) {
2565
+ contextTimestamps.set(path, resolved);
2566
+ } else {
2567
+ jobs++;
2568
+ /**
2569
+ * @param {(Error | null)=} err error
2570
+ * @param {FileTimestamp=} entry entry
2571
+ * @returns {void}
2572
+ */
2573
+ const callback = (err, entry) => {
2574
+ if (err) {
2575
+ if (this.logger) {
2576
+ this.logger.debug(
2577
+ `Error snapshotting context timestamp of ${path}: ${err.stack}`
2578
+ );
2579
+ }
2580
+ jobError();
2581
+ } else {
2582
+ contextTimestamps.set(
2583
+ path,
2584
+ /** @type {FileSystemInfoEntry | null} */
2585
+ (entry)
2586
+ );
2587
+ jobDone();
2588
+ }
2589
+ };
2590
+ if (cache !== undefined) {
2591
+ this._resolveContextTimestamp(
2592
+ /** @type {ContextFileSystemInfoEntry} */
2593
+ (cache),
2594
+ callback
2595
+ );
2596
+ } else {
2597
+ this.getContextTimestamp(path, callback);
2598
+ }
2599
+ }
2600
+ }
2601
+ break;
2602
+ }
2603
+ };
2604
+ if (directories) {
2605
+ processCapturedDirectories(
2606
+ captureNonManaged(directories, managedContexts)
2607
+ );
2608
+ }
2609
+ /**
2610
+ * @param {ManagedMissing} capturedMissing captured missing
2611
+ */
2612
+ const processCapturedMissing = (capturedMissing) => {
2613
+ if (capturedMissing.size === 0) {
2614
+ return;
2615
+ }
2616
+ this._missingExistenceOptimization.optimize(snapshot, capturedMissing);
2617
+ for (const path of capturedMissing) {
2618
+ const cache = this._fileTimestamps.get(path);
2619
+ if (cache !== undefined) {
2620
+ if (cache !== "ignore") {
2621
+ missingExistence.set(path, Boolean(cache));
2622
+ }
2623
+ } else {
2624
+ jobs++;
2625
+ this.fileTimestampQueue.add(path, (err, entry) => {
2626
+ if (err) {
2627
+ if (this.logger) {
2628
+ this.logger.debug(
2629
+ `Error snapshotting missing timestamp of ${path}: ${err.stack}`
2630
+ );
2631
+ }
2632
+ jobError();
2633
+ } else {
2634
+ missingExistence.set(path, Boolean(entry));
2635
+ jobDone();
2636
+ }
2637
+ });
2638
+ }
2639
+ }
2640
+ };
2641
+ if (missing) {
2642
+ processCapturedMissing(captureNonManaged(missing, managedMissing));
2643
+ }
2644
+ this._managedItemInfoOptimization.optimize(snapshot, managedItems);
2645
+ for (const path of managedItems) {
2646
+ const cache = this._managedItems.get(path);
2647
+ if (cache !== undefined) {
2648
+ if (!cache.startsWith("*")) {
2649
+ managedFiles.add(join(this.fs, path, "package.json"));
2650
+ } else if (cache === "*nested") {
2651
+ managedMissing.add(join(this.fs, path, "package.json"));
2652
+ }
2653
+ managedItemInfo.set(path, cache);
2654
+ } else {
2655
+ jobs++;
2656
+ this.managedItemQueue.add(path, (err, entry) => {
2657
+ if (err) {
2658
+ if (this.logger) {
2659
+ this.logger.debug(
2660
+ `Error snapshotting managed item ${path}: ${err.stack}`
2661
+ );
2662
+ }
2663
+ jobError();
2664
+ } else if (entry) {
2665
+ if (!entry.startsWith("*")) {
2666
+ managedFiles.add(join(this.fs, path, "package.json"));
2667
+ } else if (cache === "*nested") {
2668
+ managedMissing.add(join(this.fs, path, "package.json"));
2669
+ }
2670
+ managedItemInfo.set(path, entry);
2671
+ jobDone();
2672
+ } else {
2673
+ // Fallback to normal snapshotting
2674
+ /**
2675
+ * @param {Set<string>} set set
2676
+ * @param {(set: Set<string>) => void} fn fn
2677
+ */
2678
+ const process = (set, fn) => {
2679
+ if (set.size === 0) return;
2680
+ /** @type {Set<string>} */
2681
+ const captured = new Set();
2682
+ for (const file of set) {
2683
+ if (file.startsWith(path)) captured.add(file);
2684
+ }
2685
+ if (captured.size > 0) fn(captured);
2686
+ };
2687
+ process(managedFiles, processCapturedFiles);
2688
+ process(managedContexts, processCapturedDirectories);
2689
+ process(managedMissing, processCapturedMissing);
2690
+ jobDone();
2691
+ }
2692
+ });
2693
+ }
2694
+ }
2695
+ jobDone();
2696
+ }
2697
+
2698
+ /**
2699
+ * @param {Snapshot} snapshot1 a snapshot
2700
+ * @param {Snapshot} snapshot2 a snapshot
2701
+ * @returns {Snapshot} merged snapshot
2702
+ */
2703
+ mergeSnapshots(snapshot1, snapshot2) {
2704
+ const snapshot = new Snapshot();
2705
+ if (snapshot1.hasStartTime() && snapshot2.hasStartTime()) {
2706
+ snapshot.setStartTime(
2707
+ Math.min(
2708
+ /** @type {NonNullable<Snapshot["startTime"]>} */
2709
+ (snapshot1.startTime),
2710
+ /** @type {NonNullable<Snapshot["startTime"]>} */
2711
+ (snapshot2.startTime)
2712
+ )
2713
+ );
2714
+ } else if (snapshot2.hasStartTime()) {
2715
+ snapshot.startTime = snapshot2.startTime;
2716
+ } else if (snapshot1.hasStartTime()) {
2717
+ snapshot.startTime = snapshot1.startTime;
2718
+ }
2719
+ if (snapshot1.hasFileTimestamps() || snapshot2.hasFileTimestamps()) {
2720
+ snapshot.setFileTimestamps(
2721
+ mergeMaps(snapshot1.fileTimestamps, snapshot2.fileTimestamps)
2722
+ );
2723
+ }
2724
+ if (snapshot1.hasFileHashes() || snapshot2.hasFileHashes()) {
2725
+ snapshot.setFileHashes(
2726
+ mergeMaps(snapshot1.fileHashes, snapshot2.fileHashes)
2727
+ );
2728
+ }
2729
+ if (snapshot1.hasFileTshs() || snapshot2.hasFileTshs()) {
2730
+ snapshot.setFileTshs(mergeMaps(snapshot1.fileTshs, snapshot2.fileTshs));
2731
+ }
2732
+ if (snapshot1.hasContextTimestamps() || snapshot2.hasContextTimestamps()) {
2733
+ snapshot.setContextTimestamps(
2734
+ mergeMaps(snapshot1.contextTimestamps, snapshot2.contextTimestamps)
2735
+ );
2736
+ }
2737
+ if (snapshot1.hasContextHashes() || snapshot2.hasContextHashes()) {
2738
+ snapshot.setContextHashes(
2739
+ mergeMaps(snapshot1.contextHashes, snapshot2.contextHashes)
2740
+ );
2741
+ }
2742
+ if (snapshot1.hasContextTshs() || snapshot2.hasContextTshs()) {
2743
+ snapshot.setContextTshs(
2744
+ mergeMaps(snapshot1.contextTshs, snapshot2.contextTshs)
2745
+ );
2746
+ }
2747
+ if (snapshot1.hasMissingExistence() || snapshot2.hasMissingExistence()) {
2748
+ snapshot.setMissingExistence(
2749
+ mergeMaps(snapshot1.missingExistence, snapshot2.missingExistence)
2750
+ );
2751
+ }
2752
+ if (snapshot1.hasManagedItemInfo() || snapshot2.hasManagedItemInfo()) {
2753
+ snapshot.setManagedItemInfo(
2754
+ mergeMaps(snapshot1.managedItemInfo, snapshot2.managedItemInfo)
2755
+ );
2756
+ }
2757
+ if (snapshot1.hasManagedFiles() || snapshot2.hasManagedFiles()) {
2758
+ snapshot.setManagedFiles(
2759
+ mergeSets(snapshot1.managedFiles, snapshot2.managedFiles)
2760
+ );
2761
+ }
2762
+ if (snapshot1.hasManagedContexts() || snapshot2.hasManagedContexts()) {
2763
+ snapshot.setManagedContexts(
2764
+ mergeSets(snapshot1.managedContexts, snapshot2.managedContexts)
2765
+ );
2766
+ }
2767
+ if (snapshot1.hasManagedMissing() || snapshot2.hasManagedMissing()) {
2768
+ snapshot.setManagedMissing(
2769
+ mergeSets(snapshot1.managedMissing, snapshot2.managedMissing)
2770
+ );
2771
+ }
2772
+ if (snapshot1.hasChildren() || snapshot2.hasChildren()) {
2773
+ snapshot.setChildren(mergeSets(snapshot1.children, snapshot2.children));
2774
+ }
2775
+ if (
2776
+ this._snapshotCache.get(snapshot1) === true &&
2777
+ this._snapshotCache.get(snapshot2) === true
2778
+ ) {
2779
+ this._snapshotCache.set(snapshot, true);
2780
+ }
2781
+ return snapshot;
2782
+ }
2783
+
2784
+ /**
2785
+ * @param {Snapshot} snapshot the snapshot made
2786
+ * @param {CheckSnapshotValidCallback} callback callback function
2787
+ * @returns {void}
2788
+ */
2789
+ checkSnapshotValid(snapshot, callback) {
2790
+ const cachedResult = this._snapshotCache.get(snapshot);
2791
+ if (cachedResult !== undefined) {
2792
+ this._statTestedSnapshotsCached++;
2793
+ if (typeof cachedResult === "boolean") {
2794
+ callback(null, cachedResult);
2795
+ } else {
2796
+ cachedResult.push(callback);
2797
+ }
2798
+ return;
2799
+ }
2800
+ this._statTestedSnapshotsNotCached++;
2801
+ this._checkSnapshotValidNoCache(snapshot, callback);
2802
+ }
2803
+
2804
+ /**
2805
+ * @private
2806
+ * @param {Snapshot} snapshot the snapshot made
2807
+ * @param {CheckSnapshotValidCallback} callback callback function
2808
+ * @returns {void}
2809
+ */
2810
+ _checkSnapshotValidNoCache(snapshot, callback) {
2811
+ /** @type {number | undefined} */
2812
+ let startTime;
2813
+ if (snapshot.hasStartTime()) {
2814
+ startTime = snapshot.startTime;
2815
+ }
2816
+ let jobs = 1;
2817
+ const jobDone = () => {
2818
+ if (--jobs === 0) {
2819
+ this._snapshotCache.set(snapshot, true);
2820
+ callback(null, true);
2821
+ }
2822
+ };
2823
+ const invalid = () => {
2824
+ if (jobs > 0) {
2825
+ // large negative number instead of NaN or something else to keep jobs to stay a SMI (v8)
2826
+ jobs = -100000000;
2827
+ this._snapshotCache.set(snapshot, false);
2828
+ callback(null, false);
2829
+ }
2830
+ };
2831
+ /**
2832
+ * @param {string} path path
2833
+ * @param {WebpackError} err err
2834
+ */
2835
+ const invalidWithError = (path, err) => {
2836
+ if (this._remainingLogs > 0) {
2837
+ this._log(path, "error occurred: %s", err);
2838
+ }
2839
+ invalid();
2840
+ };
2841
+ /**
2842
+ * @param {string} path file path
2843
+ * @param {string | null} current current hash
2844
+ * @param {string | null} snap snapshot hash
2845
+ * @returns {boolean} true, if ok
2846
+ */
2847
+ const checkHash = (path, current, snap) => {
2848
+ if (current !== snap) {
2849
+ // If hash differ it's invalid
2850
+ if (this._remainingLogs > 0) {
2851
+ this._log(path, "hashes differ (%s != %s)", current, snap);
2852
+ }
2853
+ return false;
2854
+ }
2855
+ return true;
2856
+ };
2857
+ /**
2858
+ * @param {string} path file path
2859
+ * @param {boolean} current current entry
2860
+ * @param {boolean} snap entry from snapshot
2861
+ * @returns {boolean} true, if ok
2862
+ */
2863
+ const checkExistence = (path, current, snap) => {
2864
+ if (!current !== !snap) {
2865
+ // If existence of item differs
2866
+ // it's invalid
2867
+ if (this._remainingLogs > 0) {
2868
+ this._log(
2869
+ path,
2870
+ current ? "it didn't exist before" : "it does no longer exist"
2871
+ );
2872
+ }
2873
+ return false;
2874
+ }
2875
+ return true;
2876
+ };
2877
+ /**
2878
+ * @param {string} path file path
2879
+ * @param {FileSystemInfoEntry | null} c current entry
2880
+ * @param {FileSystemInfoEntry | null} s entry from snapshot
2881
+ * @param {boolean} log log reason
2882
+ * @returns {boolean} true, if ok
2883
+ */
2884
+ const checkFile = (path, c, s, log = true) => {
2885
+ if (c === s) return true;
2886
+ if (!checkExistence(path, Boolean(c), Boolean(s))) return false;
2887
+ if (c) {
2888
+ // For existing items only
2889
+ if (typeof startTime === "number" && c.safeTime > startTime) {
2890
+ // If a change happened after starting reading the item
2891
+ // this may no longer be valid
2892
+ if (log && this._remainingLogs > 0) {
2893
+ this._log(
2894
+ path,
2895
+ "it may have changed (%d) after the start time of the snapshot (%d)",
2896
+ c.safeTime,
2897
+ startTime
2898
+ );
2899
+ }
2900
+ return false;
2901
+ }
2902
+ const snap = /** @type {FileSystemInfoEntry} */ (s);
2903
+ if (snap.timestamp !== undefined && c.timestamp !== snap.timestamp) {
2904
+ // If we have a timestamp (it was a file or symlink) and it differs from current timestamp
2905
+ // it's invalid
2906
+ if (log && this._remainingLogs > 0) {
2907
+ this._log(
2908
+ path,
2909
+ "timestamps differ (%d != %d)",
2910
+ c.timestamp,
2911
+ snap.timestamp
2912
+ );
2913
+ }
2914
+ return false;
2915
+ }
2916
+ }
2917
+ return true;
2918
+ };
2919
+ /**
2920
+ * @param {string} path file path
2921
+ * @param {ResolvedContextFileSystemInfoEntry | null} c current entry
2922
+ * @param {ResolvedContextFileSystemInfoEntry | null} s entry from snapshot
2923
+ * @param {boolean} log log reason
2924
+ * @returns {boolean} true, if ok
2925
+ */
2926
+ const checkContext = (path, c, s, log = true) => {
2927
+ if (c === s) return true;
2928
+ if (!checkExistence(path, Boolean(c), Boolean(s))) return false;
2929
+ if (c) {
2930
+ // For existing items only
2931
+ if (typeof startTime === "number" && c.safeTime > startTime) {
2932
+ // If a change happened after starting reading the item
2933
+ // this may no longer be valid
2934
+ if (log && this._remainingLogs > 0) {
2935
+ this._log(
2936
+ path,
2937
+ "it may have changed (%d) after the start time of the snapshot (%d)",
2938
+ c.safeTime,
2939
+ startTime
2940
+ );
2941
+ }
2942
+ return false;
2943
+ }
2944
+ const snap = /** @type {ResolvedContextFileSystemInfoEntry} */ (s);
2945
+ if (
2946
+ snap.timestampHash !== undefined &&
2947
+ c.timestampHash !== snap.timestampHash
2948
+ ) {
2949
+ // If we have a timestampHash (it was a directory) and it differs from current timestampHash
2950
+ // it's invalid
2951
+ if (log && this._remainingLogs > 0) {
2952
+ this._log(
2953
+ path,
2954
+ "timestamps hashes differ (%s != %s)",
2955
+ c.timestampHash,
2956
+ snap.timestampHash
2957
+ );
2958
+ }
2959
+ return false;
2960
+ }
2961
+ }
2962
+ return true;
2963
+ };
2964
+ if (snapshot.hasChildren()) {
2965
+ /**
2966
+ * @param {(WebpackError | null)=} err err
2967
+ * @param {boolean=} result result
2968
+ * @returns {void}
2969
+ */
2970
+ const childCallback = (err, result) => {
2971
+ if (err || !result) return invalid();
2972
+ jobDone();
2973
+ };
2974
+ for (const child of /** @type {Children} */ (snapshot.children)) {
2975
+ const cache = this._snapshotCache.get(child);
2976
+ if (cache !== undefined) {
2977
+ this._statTestedChildrenCached++;
2978
+ /* istanbul ignore else */
2979
+ if (typeof cache === "boolean") {
2980
+ if (cache === false) {
2981
+ invalid();
2982
+ return;
2983
+ }
2984
+ } else {
2985
+ jobs++;
2986
+ cache.push(childCallback);
2987
+ }
2988
+ } else {
2989
+ this._statTestedChildrenNotCached++;
2990
+ jobs++;
2991
+ this._checkSnapshotValidNoCache(child, childCallback);
2992
+ }
2993
+ }
2994
+ }
2995
+ if (snapshot.hasFileTimestamps()) {
2996
+ const fileTimestamps =
2997
+ /** @type {FileTimestamps} */
2998
+ (snapshot.fileTimestamps);
2999
+ this._statTestedEntries += fileTimestamps.size;
3000
+ for (const [path, ts] of fileTimestamps) {
3001
+ const cache = this._fileTimestamps.get(path);
3002
+ if (cache !== undefined) {
3003
+ if (cache !== "ignore" && !checkFile(path, cache, ts)) {
3004
+ invalid();
3005
+ return;
3006
+ }
3007
+ } else {
3008
+ jobs++;
3009
+ this.fileTimestampQueue.add(path, (err, entry) => {
3010
+ if (err) return invalidWithError(path, err);
3011
+ if (
3012
+ !checkFile(
3013
+ path,
3014
+ /** @type {FileSystemInfoEntry | null} */ (entry),
3015
+ ts
3016
+ )
3017
+ ) {
3018
+ invalid();
3019
+ } else {
3020
+ jobDone();
3021
+ }
3022
+ });
3023
+ }
3024
+ }
3025
+ }
3026
+ /**
3027
+ * @param {string} path file path
3028
+ * @param {string | null} hash hash
3029
+ */
3030
+ const processFileHashSnapshot = (path, hash) => {
3031
+ const cache = this._fileHashes.get(path);
3032
+ if (cache !== undefined) {
3033
+ if (cache !== "ignore" && !checkHash(path, cache, hash)) {
3034
+ invalid();
3035
+ }
3036
+ } else {
3037
+ jobs++;
3038
+ this.fileHashQueue.add(path, (err, entry) => {
3039
+ if (err) return invalidWithError(path, err);
3040
+ if (!checkHash(path, /** @type {string} */ (entry), hash)) {
3041
+ invalid();
3042
+ } else {
3043
+ jobDone();
3044
+ }
3045
+ });
3046
+ }
3047
+ };
3048
+ if (snapshot.hasFileHashes()) {
3049
+ const fileHashes = /** @type {FileHashes} */ (snapshot.fileHashes);
3050
+ this._statTestedEntries += fileHashes.size;
3051
+ for (const [path, hash] of fileHashes) {
3052
+ processFileHashSnapshot(path, hash);
3053
+ }
3054
+ }
3055
+ if (snapshot.hasFileTshs()) {
3056
+ const fileTshs = /** @type {FileTshs} */ (snapshot.fileTshs);
3057
+ this._statTestedEntries += fileTshs.size;
3058
+ for (const [path, tsh] of fileTshs) {
3059
+ if (typeof tsh === "string") {
3060
+ processFileHashSnapshot(path, tsh);
3061
+ } else {
3062
+ const cache = this._fileTimestamps.get(path);
3063
+ if (cache !== undefined) {
3064
+ if (cache === "ignore" || !checkFile(path, cache, tsh, false)) {
3065
+ processFileHashSnapshot(path, tsh && tsh.hash);
3066
+ }
3067
+ } else {
3068
+ jobs++;
3069
+ this.fileTimestampQueue.add(path, (err, entry) => {
3070
+ if (err) return invalidWithError(path, err);
3071
+ if (
3072
+ !checkFile(
3073
+ path,
3074
+ /** @type {FileSystemInfoEntry | null} */
3075
+ (entry),
3076
+ tsh,
3077
+ false
3078
+ )
3079
+ ) {
3080
+ processFileHashSnapshot(path, tsh && tsh.hash);
3081
+ }
3082
+ jobDone();
3083
+ });
3084
+ }
3085
+ }
3086
+ }
3087
+ }
3088
+ if (snapshot.hasContextTimestamps()) {
3089
+ const contextTimestamps =
3090
+ /** @type {ContextTimestamps} */
3091
+ (snapshot.contextTimestamps);
3092
+ this._statTestedEntries += contextTimestamps.size;
3093
+ for (const [path, ts] of contextTimestamps) {
3094
+ const cache = this._contextTimestamps.get(path);
3095
+ if (cache === "ignore") continue;
3096
+ /** @type {undefined | null | ResolvedContextFileSystemInfoEntry} */
3097
+ let resolved;
3098
+ if (
3099
+ cache !== undefined &&
3100
+ (resolved = getResolvedTimestamp(cache)) !== undefined
3101
+ ) {
3102
+ if (!checkContext(path, resolved, ts)) {
3103
+ invalid();
3104
+ return;
3105
+ }
3106
+ } else {
3107
+ jobs++;
3108
+ /**
3109
+ * @param {(WebpackError | null)=} err error
3110
+ * @param {ResolvedContextTimestamp=} entry entry
3111
+ * @returns {void}
3112
+ */
3113
+ const callback = (err, entry) => {
3114
+ if (err) return invalidWithError(path, err);
3115
+ if (
3116
+ !checkContext(
3117
+ path,
3118
+ /** @type {ResolvedContextFileSystemInfoEntry | null} */
3119
+ (entry),
3120
+ ts
3121
+ )
3122
+ ) {
3123
+ invalid();
3124
+ } else {
3125
+ jobDone();
3126
+ }
3127
+ };
3128
+ if (cache !== undefined) {
3129
+ this._resolveContextTimestamp(
3130
+ /** @type {ContextFileSystemInfoEntry} */
3131
+ (cache),
3132
+ callback
3133
+ );
3134
+ } else {
3135
+ this.getContextTimestamp(path, callback);
3136
+ }
3137
+ }
3138
+ }
3139
+ }
3140
+ /**
3141
+ * @param {string} path path
3142
+ * @param {string | null} hash hash
3143
+ */
3144
+ const processContextHashSnapshot = (path, hash) => {
3145
+ const cache = this._contextHashes.get(path);
3146
+ /** @type {undefined | null | string} */
3147
+ let resolved;
3148
+ if (
3149
+ cache !== undefined &&
3150
+ (resolved = getResolvedHash(cache)) !== undefined
3151
+ ) {
3152
+ if (!checkHash(path, resolved, hash)) {
3153
+ invalid();
3154
+ }
3155
+ } else {
3156
+ jobs++;
3157
+ /**
3158
+ * @param {(WebpackError | null)=} err err
3159
+ * @param {string=} entry entry
3160
+ * @returns {void}
3161
+ */
3162
+ const callback = (err, entry) => {
3163
+ if (err) return invalidWithError(path, err);
3164
+ if (!checkHash(path, /** @type {string} */ (entry), hash)) {
3165
+ invalid();
3166
+ } else {
3167
+ jobDone();
3168
+ }
3169
+ };
3170
+ if (cache !== undefined) {
3171
+ this._resolveContextHash(cache, callback);
3172
+ } else {
3173
+ this.getContextHash(path, callback);
3174
+ }
3175
+ }
3176
+ };
3177
+ if (snapshot.hasContextHashes()) {
3178
+ const contextHashes =
3179
+ /** @type {ContextHashes} */
3180
+ (snapshot.contextHashes);
3181
+ this._statTestedEntries += contextHashes.size;
3182
+ for (const [path, hash] of contextHashes) {
3183
+ processContextHashSnapshot(path, hash);
3184
+ }
3185
+ }
3186
+ if (snapshot.hasContextTshs()) {
3187
+ const contextTshs = /** @type {ContextTshs} */ (snapshot.contextTshs);
3188
+ this._statTestedEntries += contextTshs.size;
3189
+ for (const [path, tsh] of contextTshs) {
3190
+ if (typeof tsh === "string") {
3191
+ processContextHashSnapshot(path, tsh);
3192
+ } else {
3193
+ const cache = this._contextTimestamps.get(path);
3194
+ if (cache === "ignore") continue;
3195
+ /** @type {undefined | null | ResolvedContextFileSystemInfoEntry} */
3196
+ let resolved;
3197
+ if (
3198
+ cache !== undefined &&
3199
+ (resolved = getResolvedTimestamp(cache)) !== undefined
3200
+ ) {
3201
+ if (!checkContext(path, resolved, tsh, false)) {
3202
+ processContextHashSnapshot(path, tsh && tsh.hash);
3203
+ }
3204
+ } else {
3205
+ jobs++;
3206
+ /**
3207
+ * @param {(WebpackError | null)=} err error
3208
+ * @param {ResolvedContextTimestamp=} entry entry
3209
+ * @returns {void}
3210
+ */
3211
+ const callback = (err, entry) => {
3212
+ if (err) return invalidWithError(path, err);
3213
+ if (
3214
+ !checkContext(
3215
+ path,
3216
+ // TODO: test with `"ignore"`
3217
+ /** @type {ResolvedContextFileSystemInfoEntry | null} */
3218
+ (entry),
3219
+ tsh,
3220
+ false
3221
+ )
3222
+ ) {
3223
+ processContextHashSnapshot(path, tsh && tsh.hash);
3224
+ }
3225
+ jobDone();
3226
+ };
3227
+ if (cache !== undefined) {
3228
+ this._resolveContextTimestamp(
3229
+ /** @type {ContextFileSystemInfoEntry} */
3230
+ (cache),
3231
+ callback
3232
+ );
3233
+ } else {
3234
+ this.getContextTimestamp(path, callback);
3235
+ }
3236
+ }
3237
+ }
3238
+ }
3239
+ }
3240
+ if (snapshot.hasMissingExistence()) {
3241
+ const missingExistence =
3242
+ /** @type {MissingExistence} */
3243
+ (snapshot.missingExistence);
3244
+ this._statTestedEntries += missingExistence.size;
3245
+ for (const [path, existence] of missingExistence) {
3246
+ const cache = this._fileTimestamps.get(path);
3247
+ if (cache !== undefined) {
3248
+ if (
3249
+ cache !== "ignore" &&
3250
+ !checkExistence(path, Boolean(cache), Boolean(existence))
3251
+ ) {
3252
+ invalid();
3253
+ return;
3254
+ }
3255
+ } else {
3256
+ jobs++;
3257
+ this.fileTimestampQueue.add(path, (err, entry) => {
3258
+ if (err) return invalidWithError(path, err);
3259
+ if (!checkExistence(path, Boolean(entry), Boolean(existence))) {
3260
+ invalid();
3261
+ } else {
3262
+ jobDone();
3263
+ }
3264
+ });
3265
+ }
3266
+ }
3267
+ }
3268
+ if (snapshot.hasManagedItemInfo()) {
3269
+ const managedItemInfo =
3270
+ /** @type {ManagedItemInfo} */
3271
+ (snapshot.managedItemInfo);
3272
+ this._statTestedEntries += managedItemInfo.size;
3273
+ for (const [path, info] of managedItemInfo) {
3274
+ const cache = this._managedItems.get(path);
3275
+ if (cache !== undefined) {
3276
+ if (!checkHash(path, cache, info)) {
3277
+ invalid();
3278
+ return;
3279
+ }
3280
+ } else {
3281
+ jobs++;
3282
+ this.managedItemQueue.add(path, (err, entry) => {
3283
+ if (err) return invalidWithError(path, err);
3284
+ if (!checkHash(path, /** @type {string} */ (entry), info)) {
3285
+ invalid();
3286
+ } else {
3287
+ jobDone();
3288
+ }
3289
+ });
3290
+ }
3291
+ }
3292
+ }
3293
+ jobDone();
3294
+
3295
+ // if there was an async action
3296
+ // try to join multiple concurrent request for this snapshot
3297
+ if (jobs > 0) {
3298
+ const callbacks = [callback];
3299
+ callback = (err, result) => {
3300
+ for (const callback of callbacks) callback(err, result);
3301
+ };
3302
+ this._snapshotCache.set(snapshot, callbacks);
3303
+ }
3304
+ }
3305
+
3306
+ /**
3307
+ * @private
3308
+ * @type {Processor<string, FileSystemInfoEntry>}
3309
+ */
3310
+ _readFileTimestamp(path, callback) {
3311
+ this.fs.stat(path, (err, _stat) => {
3312
+ if (err) {
3313
+ if (err.code === "ENOENT") {
3314
+ this._fileTimestamps.set(path, null);
3315
+ this._cachedDeprecatedFileTimestamps = undefined;
3316
+ return callback(null, null);
3317
+ }
3318
+ return callback(/** @type {WebpackError} */ (err));
3319
+ }
3320
+ const stat = /** @type {IStats} */ (_stat);
3321
+ /** @type {FileSystemInfoEntry} */
3322
+ let ts;
3323
+ if (stat.isDirectory()) {
3324
+ ts = {
3325
+ safeTime: 0,
3326
+ timestamp: undefined
3327
+ };
3328
+ } else {
3329
+ const mtime = Number(stat.mtime);
3330
+
3331
+ if (mtime) applyMtime(mtime);
3332
+
3333
+ ts = {
3334
+ safeTime: mtime ? mtime + FS_ACCURACY : Infinity,
3335
+ timestamp: mtime
3336
+ };
3337
+ }
3338
+
3339
+ this._fileTimestamps.set(path, ts);
3340
+ this._cachedDeprecatedFileTimestamps = undefined;
3341
+
3342
+ callback(null, ts);
3343
+ });
3344
+ }
3345
+
3346
+ /**
3347
+ * @private
3348
+ * @type {Processor<string, string>}
3349
+ */
3350
+ _readFileHash(path, callback) {
3351
+ this.fs.readFile(path, (err, content) => {
3352
+ if (err) {
3353
+ if (err.code === "EISDIR") {
3354
+ this._fileHashes.set(path, "directory");
3355
+ return callback(null, "directory");
3356
+ }
3357
+ if (err.code === "ENOENT") {
3358
+ this._fileHashes.set(path, null);
3359
+ return callback(null, null);
3360
+ }
3361
+ if (err.code === "ERR_FS_FILE_TOO_LARGE") {
3362
+ /** @type {Logger} */
3363
+ (this.logger).warn(`Ignoring ${path} for hashing as it's very large`);
3364
+ this._fileHashes.set(path, "too large");
3365
+ return callback(null, "too large");
3366
+ }
3367
+ return callback(/** @type {WebpackError} */ (err));
3368
+ }
3369
+
3370
+ const hash = createHash(this._hashFunction);
3371
+
3372
+ hash.update(/** @type {string | Buffer} */ (content));
3373
+
3374
+ const digest = hash.digest("hex");
3375
+
3376
+ this._fileHashes.set(path, digest);
3377
+
3378
+ callback(null, digest);
3379
+ });
3380
+ }
3381
+
3382
+ /**
3383
+ * @private
3384
+ * @param {string} path path
3385
+ * @param {(err: WebpackError | null, timestampAndHash?: TimestampAndHash | string) => void} callback callback
3386
+ */
3387
+ _getFileTimestampAndHash(path, callback) {
3388
+ /**
3389
+ * @param {string} hash hash
3390
+ * @returns {void}
3391
+ */
3392
+ const continueWithHash = (hash) => {
3393
+ const cache = this._fileTimestamps.get(path);
3394
+ if (cache !== undefined) {
3395
+ if (cache !== "ignore") {
3396
+ /** @type {TimestampAndHash} */
3397
+ const result = {
3398
+ .../** @type {FileSystemInfoEntry} */ (cache),
3399
+ hash
3400
+ };
3401
+ this._fileTshs.set(path, result);
3402
+ return callback(null, result);
3403
+ }
3404
+ this._fileTshs.set(path, hash);
3405
+ return callback(null, hash);
3406
+ }
3407
+ this.fileTimestampQueue.add(path, (err, entry) => {
3408
+ if (err) {
3409
+ return callback(err);
3410
+ }
3411
+ /** @type {TimestampAndHash} */
3412
+ const result = {
3413
+ .../** @type {FileSystemInfoEntry} */ (entry),
3414
+ hash
3415
+ };
3416
+ this._fileTshs.set(path, result);
3417
+ return callback(null, result);
3418
+ });
3419
+ };
3420
+
3421
+ const cache = this._fileHashes.get(path);
3422
+ if (cache !== undefined) {
3423
+ continueWithHash(/** @type {string} */ (cache));
3424
+ } else {
3425
+ this.fileHashQueue.add(path, (err, entry) => {
3426
+ if (err) {
3427
+ return callback(err);
3428
+ }
3429
+ continueWithHash(/** @type {string} */ (entry));
3430
+ });
3431
+ }
3432
+ }
3433
+
3434
+ /**
3435
+ * @private
3436
+ * @template T
3437
+ * @template ItemType
3438
+ * @param {object} options options
3439
+ * @param {string} options.path path
3440
+ * @param {(value: string) => ItemType} options.fromImmutablePath called when context item is an immutable path
3441
+ * @param {(value: string) => ItemType} options.fromManagedItem called when context item is a managed path
3442
+ * @param {(value: string, result: string, callback: (err?: WebpackError | null, itemType?: ItemType) => void) => void} options.fromSymlink called when context item is a symlink
3443
+ * @param {(value: string, stats: IStats, callback: (err?: WebpackError | null, itemType?: ItemType | null) => void) => void} options.fromFile called when context item is a file
3444
+ * @param {(value: string, stats: IStats, callback: (err?: WebpackError | null, itemType?: ItemType) => void) => void} options.fromDirectory called when context item is a directory
3445
+ * @param {(arr: string[], arr1: ItemType[]) => T} options.reduce called from all context items
3446
+ * @param {(err?: Error | null, result?: T | null) => void} callback callback
3447
+ */
3448
+ _readContext(
3449
+ {
3450
+ path,
3451
+ fromImmutablePath,
3452
+ fromManagedItem,
3453
+ fromSymlink,
3454
+ fromFile,
3455
+ fromDirectory,
3456
+ reduce
3457
+ },
3458
+ callback
3459
+ ) {
3460
+ this.fs.readdir(path, (err, _files) => {
3461
+ if (err) {
3462
+ if (err.code === "ENOENT") {
3463
+ return callback(null, null);
3464
+ }
3465
+ return callback(err);
3466
+ }
3467
+ const files = /** @type {string[]} */ (_files)
3468
+ .map((file) => file.normalize("NFC"))
3469
+ .filter((file) => !/^\./.test(file))
3470
+ .sort();
3471
+ asyncLib.map(
3472
+ files,
3473
+ (file, callback) => {
3474
+ const child = join(this.fs, path, file);
3475
+ for (const immutablePath of this.immutablePathsRegExps) {
3476
+ if (immutablePath.test(path)) {
3477
+ // ignore any immutable path for timestamping
3478
+ return callback(null, fromImmutablePath(path));
3479
+ }
3480
+ }
3481
+ for (const immutablePath of this.immutablePathsWithSlash) {
3482
+ if (path.startsWith(immutablePath)) {
3483
+ // ignore any immutable path for timestamping
3484
+ return callback(null, fromImmutablePath(path));
3485
+ }
3486
+ }
3487
+ for (const managedPath of this.managedPathsRegExps) {
3488
+ const match = managedPath.exec(path);
3489
+ if (match) {
3490
+ const managedItem = getManagedItem(match[1], path);
3491
+ if (managedItem) {
3492
+ // construct timestampHash from managed info
3493
+ return this.managedItemQueue.add(managedItem, (err, info) => {
3494
+ if (err) return callback(err);
3495
+ return callback(
3496
+ null,
3497
+ fromManagedItem(/** @type {string} */ (info))
3498
+ );
3499
+ });
3500
+ }
3501
+ }
3502
+ }
3503
+ for (const managedPath of this.managedPathsWithSlash) {
3504
+ if (path.startsWith(managedPath)) {
3505
+ const managedItem = getManagedItem(managedPath, child);
3506
+ if (managedItem) {
3507
+ // construct timestampHash from managed info
3508
+ return this.managedItemQueue.add(managedItem, (err, info) => {
3509
+ if (err) return callback(err);
3510
+ return callback(
3511
+ null,
3512
+ fromManagedItem(/** @type {string} */ (info))
3513
+ );
3514
+ });
3515
+ }
3516
+ }
3517
+ }
3518
+
3519
+ lstatReadlinkAbsolute(this.fs, child, (err, _stat) => {
3520
+ if (err) return callback(err);
3521
+
3522
+ const stat = /** @type {IStats | string} */ (_stat);
3523
+
3524
+ if (typeof stat === "string") {
3525
+ return fromSymlink(child, stat, callback);
3526
+ }
3527
+
3528
+ if (stat.isFile()) {
3529
+ return fromFile(child, stat, callback);
3530
+ }
3531
+ if (stat.isDirectory()) {
3532
+ return fromDirectory(child, stat, callback);
3533
+ }
3534
+ callback(null, null);
3535
+ });
3536
+ },
3537
+ (err, results) => {
3538
+ if (err) return callback(err);
3539
+ const result = reduce(files, /** @type {ItemType[]} */ (results));
3540
+ callback(null, result);
3541
+ }
3542
+ );
3543
+ });
3544
+ }
3545
+
3546
+ /**
3547
+ * @private
3548
+ * @type {Processor<string, ContextFileSystemInfoEntry>}
3549
+ */
3550
+ _readContextTimestamp(path, callback) {
3551
+ this._readContext(
3552
+ {
3553
+ path,
3554
+ fromImmutablePath: () =>
3555
+ /** @type {ContextFileSystemInfoEntry | FileSystemInfoEntry | "ignore" | null} */
3556
+ (null),
3557
+ fromManagedItem: (info) => ({
3558
+ safeTime: 0,
3559
+ timestampHash: info
3560
+ }),
3561
+ fromSymlink: (file, target, callback) => {
3562
+ callback(
3563
+ null,
3564
+ /** @type {ContextFileSystemInfoEntry} */
3565
+ ({
3566
+ timestampHash: target,
3567
+ symlinks: new Set([target])
3568
+ })
3569
+ );
3570
+ },
3571
+ fromFile: (file, stat, callback) => {
3572
+ // Prefer the cached value over our new stat to report consistent results
3573
+ const cache = this._fileTimestamps.get(file);
3574
+ if (cache !== undefined) {
3575
+ return callback(null, cache === "ignore" ? null : cache);
3576
+ }
3577
+
3578
+ const mtime = Number(stat.mtime);
3579
+
3580
+ if (mtime) applyMtime(mtime);
3581
+
3582
+ /** @type {FileSystemInfoEntry} */
3583
+ const ts = {
3584
+ safeTime: mtime ? mtime + FS_ACCURACY : Infinity,
3585
+ timestamp: mtime
3586
+ };
3587
+
3588
+ this._fileTimestamps.set(file, ts);
3589
+ this._cachedDeprecatedFileTimestamps = undefined;
3590
+ callback(null, ts);
3591
+ },
3592
+ fromDirectory: (directory, stat, callback) => {
3593
+ this.contextTimestampQueue.increaseParallelism();
3594
+ this._getUnresolvedContextTimestamp(directory, (err, tsEntry) => {
3595
+ this.contextTimestampQueue.decreaseParallelism();
3596
+ callback(err, tsEntry);
3597
+ });
3598
+ },
3599
+ reduce: (files, tsEntries) => {
3600
+ /** @type {undefined | Symlinks} */
3601
+ let symlinks;
3602
+
3603
+ const hash = createHash(this._hashFunction);
3604
+
3605
+ for (const file of files) hash.update(file);
3606
+ let safeTime = 0;
3607
+ for (const _e of tsEntries) {
3608
+ if (!_e) {
3609
+ hash.update("n");
3610
+ continue;
3611
+ }
3612
+ const entry =
3613
+ /** @type {FileSystemInfoEntry | ContextFileSystemInfoEntry} */
3614
+ (_e);
3615
+ if (/** @type {FileSystemInfoEntry} */ (entry).timestamp) {
3616
+ hash.update("f");
3617
+ hash.update(
3618
+ `${/** @type {FileSystemInfoEntry} */ (entry).timestamp}`
3619
+ );
3620
+ } else if (
3621
+ /** @type {ContextFileSystemInfoEntry} */ (entry).timestampHash
3622
+ ) {
3623
+ hash.update("d");
3624
+ hash.update(
3625
+ `${/** @type {ContextFileSystemInfoEntry} */ (entry).timestampHash}`
3626
+ );
3627
+ }
3628
+ if (
3629
+ /** @type {ContextFileSystemInfoEntry} */
3630
+ (entry).symlinks !== undefined
3631
+ ) {
3632
+ if (symlinks === undefined) symlinks = new Set();
3633
+ addAll(
3634
+ /** @type {ContextFileSystemInfoEntry} */ (entry).symlinks,
3635
+ symlinks
3636
+ );
3637
+ }
3638
+ if (entry.safeTime) {
3639
+ safeTime = Math.max(safeTime, entry.safeTime);
3640
+ }
3641
+ }
3642
+
3643
+ const digest = hash.digest("hex");
3644
+ /** @type {ContextFileSystemInfoEntry} */
3645
+ const result = {
3646
+ safeTime,
3647
+ timestampHash: digest
3648
+ };
3649
+ if (symlinks) result.symlinks = symlinks;
3650
+ return result;
3651
+ }
3652
+ },
3653
+ (err, result) => {
3654
+ if (err) return callback(/** @type {WebpackError} */ (err));
3655
+ this._contextTimestamps.set(path, result);
3656
+ this._cachedDeprecatedContextTimestamps = undefined;
3657
+
3658
+ callback(null, result);
3659
+ }
3660
+ );
3661
+ }
3662
+
3663
+ /**
3664
+ * @private
3665
+ * @param {ContextFileSystemInfoEntry} entry entry
3666
+ * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback
3667
+ * @returns {void}
3668
+ */
3669
+ _resolveContextTimestamp(entry, callback) {
3670
+ /** @type {string[]} */
3671
+ const hashes = [];
3672
+ let safeTime = 0;
3673
+ processAsyncTree(
3674
+ /** @type {NonNullable<ContextHash["symlinks"]>} */ (entry.symlinks),
3675
+ 10,
3676
+ (target, push, callback) => {
3677
+ this._getUnresolvedContextTimestamp(target, (err, entry) => {
3678
+ if (err) return callback(err);
3679
+ if (entry && entry !== "ignore") {
3680
+ hashes.push(/** @type {string} */ (entry.timestampHash));
3681
+ if (entry.safeTime) {
3682
+ safeTime = Math.max(safeTime, entry.safeTime);
3683
+ }
3684
+ if (entry.symlinks !== undefined) {
3685
+ for (const target of entry.symlinks) push(target);
3686
+ }
3687
+ }
3688
+ callback();
3689
+ });
3690
+ },
3691
+ (err) => {
3692
+ if (err) return callback(/** @type {WebpackError} */ (err));
3693
+ const hash = createHash(this._hashFunction);
3694
+ hash.update(/** @type {string} */ (entry.timestampHash));
3695
+ if (entry.safeTime) {
3696
+ safeTime = Math.max(safeTime, entry.safeTime);
3697
+ }
3698
+ hashes.sort();
3699
+ for (const h of hashes) {
3700
+ hash.update(h);
3701
+ }
3702
+ callback(
3703
+ null,
3704
+ (entry.resolved = {
3705
+ safeTime,
3706
+ timestampHash: hash.digest("hex")
3707
+ })
3708
+ );
3709
+ }
3710
+ );
3711
+ }
3712
+
3713
+ /**
3714
+ * @private
3715
+ * @type {Processor<string, ContextHash>}
3716
+ */
3717
+ _readContextHash(path, callback) {
3718
+ this._readContext(
3719
+ {
3720
+ path,
3721
+ fromImmutablePath: () => /** @type {ContextHash | ""} */ (""),
3722
+ fromManagedItem: (info) => info || "",
3723
+ fromSymlink: (file, target, callback) => {
3724
+ callback(
3725
+ null,
3726
+ /** @type {ContextHash} */
3727
+ ({
3728
+ hash: target,
3729
+ symlinks: new Set([target])
3730
+ })
3731
+ );
3732
+ },
3733
+ fromFile: (file, stat, callback) =>
3734
+ this.getFileHash(file, (err, hash) => {
3735
+ callback(err, hash || "");
3736
+ }),
3737
+ fromDirectory: (directory, stat, callback) => {
3738
+ this.contextHashQueue.increaseParallelism();
3739
+ this._getUnresolvedContextHash(directory, (err, hash) => {
3740
+ this.contextHashQueue.decreaseParallelism();
3741
+ callback(err, hash || "");
3742
+ });
3743
+ },
3744
+ /**
3745
+ * @param {string[]} files files
3746
+ * @param {(string | ContextHash)[]} fileHashes hashes
3747
+ * @returns {ContextHash} reduced hash
3748
+ */
3749
+ reduce: (files, fileHashes) => {
3750
+ /** @type {undefined | Symlinks} */
3751
+ let symlinks;
3752
+ const hash = createHash(this._hashFunction);
3753
+
3754
+ for (const file of files) hash.update(file);
3755
+ for (const entry of fileHashes) {
3756
+ if (typeof entry === "string") {
3757
+ hash.update(entry);
3758
+ } else {
3759
+ hash.update(entry.hash);
3760
+ if (entry.symlinks) {
3761
+ if (symlinks === undefined) symlinks = new Set();
3762
+ addAll(entry.symlinks, symlinks);
3763
+ }
3764
+ }
3765
+ }
3766
+
3767
+ /** @type {ContextHash} */
3768
+ const result = {
3769
+ hash: hash.digest("hex")
3770
+ };
3771
+ if (symlinks) result.symlinks = symlinks;
3772
+ return result;
3773
+ }
3774
+ },
3775
+ (err, _result) => {
3776
+ if (err) return callback(/** @type {WebpackError} */ (err));
3777
+ const result = /** @type {ContextHash} */ (_result);
3778
+ this._contextHashes.set(path, result);
3779
+ return callback(null, result);
3780
+ }
3781
+ );
3782
+ }
3783
+
3784
+ /**
3785
+ * @private
3786
+ * @param {ContextHash} entry context hash
3787
+ * @param {(err: WebpackError | null, contextHash?: string) => void} callback callback
3788
+ * @returns {void}
3789
+ */
3790
+ _resolveContextHash(entry, callback) {
3791
+ /** @type {string[]} */
3792
+ const hashes = [];
3793
+ processAsyncTree(
3794
+ /** @type {NonNullable<ContextHash["symlinks"]>} */ (entry.symlinks),
3795
+ 10,
3796
+ (target, push, callback) => {
3797
+ this._getUnresolvedContextHash(target, (err, hash) => {
3798
+ if (err) return callback(err);
3799
+ if (hash) {
3800
+ hashes.push(hash.hash);
3801
+ if (hash.symlinks !== undefined) {
3802
+ for (const target of hash.symlinks) push(target);
3803
+ }
3804
+ }
3805
+ callback();
3806
+ });
3807
+ },
3808
+ (err) => {
3809
+ if (err) return callback(/** @type {WebpackError} */ (err));
3810
+ const hash = createHash(this._hashFunction);
3811
+ hash.update(entry.hash);
3812
+ hashes.sort();
3813
+ for (const h of hashes) {
3814
+ hash.update(h);
3815
+ }
3816
+ callback(null, (entry.resolved = hash.digest("hex")));
3817
+ }
3818
+ );
3819
+ }
3820
+
3821
+ /**
3822
+ * @private
3823
+ * @type {Processor<string, ContextTimestampAndHash>}
3824
+ */
3825
+ _readContextTimestampAndHash(path, callback) {
3826
+ /**
3827
+ * @param {ContextTimestamp} timestamp timestamp
3828
+ * @param {ContextHash} hash hash
3829
+ */
3830
+ const finalize = (timestamp, hash) => {
3831
+ const result =
3832
+ /** @type {ContextTimestampAndHash} */
3833
+ (timestamp === "ignore" ? hash : { ...timestamp, ...hash });
3834
+ this._contextTshs.set(path, result);
3835
+ callback(null, result);
3836
+ };
3837
+ const cachedHash = this._contextHashes.get(path);
3838
+ const cachedTimestamp = this._contextTimestamps.get(path);
3839
+ if (cachedHash !== undefined) {
3840
+ if (cachedTimestamp !== undefined) {
3841
+ finalize(cachedTimestamp, cachedHash);
3842
+ } else {
3843
+ this.contextTimestampQueue.add(path, (err, entry) => {
3844
+ if (err) return callback(err);
3845
+ finalize(
3846
+ /** @type {ContextFileSystemInfoEntry} */
3847
+ (entry),
3848
+ cachedHash
3849
+ );
3850
+ });
3851
+ }
3852
+ } else if (cachedTimestamp !== undefined) {
3853
+ this.contextHashQueue.add(path, (err, entry) => {
3854
+ if (err) return callback(err);
3855
+ finalize(cachedTimestamp, /** @type {ContextHash} */ (entry));
3856
+ });
3857
+ } else {
3858
+ this._readContext(
3859
+ {
3860
+ path,
3861
+ fromImmutablePath: () =>
3862
+ /** @type {ContextTimestampAndHash | Omit<ContextTimestampAndHash, "safeTime"> | string | null} */ (
3863
+ null
3864
+ ),
3865
+ fromManagedItem: (info) => ({
3866
+ safeTime: 0,
3867
+ timestampHash: info,
3868
+ hash: info || ""
3869
+ }),
3870
+ fromSymlink: (file, target, callback) => {
3871
+ callback(null, {
3872
+ timestampHash: target,
3873
+ hash: target,
3874
+ symlinks: new Set([target])
3875
+ });
3876
+ },
3877
+ fromFile: (file, stat, callback) => {
3878
+ this._getFileTimestampAndHash(file, callback);
3879
+ },
3880
+ fromDirectory: (directory, stat, callback) => {
3881
+ this.contextTshQueue.increaseParallelism();
3882
+ this.contextTshQueue.add(directory, (err, result) => {
3883
+ this.contextTshQueue.decreaseParallelism();
3884
+ callback(err, result);
3885
+ });
3886
+ },
3887
+ /**
3888
+ * @param {string[]} files files
3889
+ * @param {(Partial<TimestampAndHash> & Partial<ContextTimestampAndHash> | string | null)[]} results results
3890
+ * @returns {ContextTimestampAndHash} tsh
3891
+ */
3892
+ reduce: (files, results) => {
3893
+ /** @type {undefined | Symlinks} */
3894
+ let symlinks;
3895
+
3896
+ const tsHash = createHash(this._hashFunction);
3897
+ const hash = createHash(this._hashFunction);
3898
+
3899
+ for (const file of files) {
3900
+ tsHash.update(file);
3901
+ hash.update(file);
3902
+ }
3903
+ let safeTime = 0;
3904
+ for (const entry of results) {
3905
+ if (!entry) {
3906
+ tsHash.update("n");
3907
+ continue;
3908
+ }
3909
+ if (typeof entry === "string") {
3910
+ tsHash.update("n");
3911
+ hash.update(entry);
3912
+ continue;
3913
+ }
3914
+ if (entry.timestamp) {
3915
+ tsHash.update("f");
3916
+ tsHash.update(`${entry.timestamp}`);
3917
+ } else if (entry.timestampHash) {
3918
+ tsHash.update("d");
3919
+ tsHash.update(`${entry.timestampHash}`);
3920
+ }
3921
+ if (entry.symlinks !== undefined) {
3922
+ if (symlinks === undefined) symlinks = new Set();
3923
+ addAll(entry.symlinks, symlinks);
3924
+ }
3925
+ if (entry.safeTime) {
3926
+ safeTime = Math.max(safeTime, entry.safeTime);
3927
+ }
3928
+ hash.update(/** @type {string} */ (entry.hash));
3929
+ }
3930
+
3931
+ /** @type {ContextTimestampAndHash} */
3932
+ const result = {
3933
+ safeTime,
3934
+ timestampHash: tsHash.digest("hex"),
3935
+ hash: hash.digest("hex")
3936
+ };
3937
+ if (symlinks) result.symlinks = symlinks;
3938
+ return result;
3939
+ }
3940
+ },
3941
+ (err, _result) => {
3942
+ if (err) return callback(/** @type {WebpackError} */ (err));
3943
+ const result = /** @type {ContextTimestampAndHash} */ (_result);
3944
+ this._contextTshs.set(path, result);
3945
+ return callback(null, result);
3946
+ }
3947
+ );
3948
+ }
3949
+ }
3950
+
3951
+ /**
3952
+ * @private
3953
+ * @param {ContextTimestampAndHash} entry entry
3954
+ * @param {ProcessorCallback<ResolvedContextTimestampAndHash>} callback callback
3955
+ * @returns {void}
3956
+ */
3957
+ _resolveContextTsh(entry, callback) {
3958
+ /** @type {string[]} */
3959
+ const hashes = [];
3960
+ /** @type {string[]} */
3961
+ const tsHashes = [];
3962
+ let safeTime = 0;
3963
+ processAsyncTree(
3964
+ /** @type {NonNullable<ContextHash["symlinks"]>} */ (entry.symlinks),
3965
+ 10,
3966
+ (target, push, callback) => {
3967
+ this._getUnresolvedContextTsh(target, (err, entry) => {
3968
+ if (err) return callback(err);
3969
+ if (entry) {
3970
+ hashes.push(entry.hash);
3971
+ if (entry.timestampHash) tsHashes.push(entry.timestampHash);
3972
+ if (entry.safeTime) {
3973
+ safeTime = Math.max(safeTime, entry.safeTime);
3974
+ }
3975
+ if (entry.symlinks !== undefined) {
3976
+ for (const target of entry.symlinks) push(target);
3977
+ }
3978
+ }
3979
+ callback();
3980
+ });
3981
+ },
3982
+ (err) => {
3983
+ if (err) return callback(/** @type {WebpackError} */ (err));
3984
+ const hash = createHash(this._hashFunction);
3985
+ const tsHash = createHash(this._hashFunction);
3986
+ hash.update(entry.hash);
3987
+ if (entry.timestampHash) tsHash.update(entry.timestampHash);
3988
+ if (entry.safeTime) {
3989
+ safeTime = Math.max(safeTime, entry.safeTime);
3990
+ }
3991
+ hashes.sort();
3992
+ for (const h of hashes) {
3993
+ hash.update(h);
3994
+ }
3995
+ tsHashes.sort();
3996
+ for (const h of tsHashes) {
3997
+ tsHash.update(h);
3998
+ }
3999
+ callback(
4000
+ null,
4001
+ (entry.resolved = {
4002
+ safeTime,
4003
+ timestampHash: tsHash.digest("hex"),
4004
+ hash: hash.digest("hex")
4005
+ })
4006
+ );
4007
+ }
4008
+ );
4009
+ }
4010
+
4011
+ /**
4012
+ * @private
4013
+ * @type {Processor<string, Set<string>>}
4014
+ */
4015
+ _getManagedItemDirectoryInfo(path, callback) {
4016
+ this.fs.readdir(path, (err, elements) => {
4017
+ if (err) {
4018
+ if (err.code === "ENOENT" || err.code === "ENOTDIR") {
4019
+ return callback(null, EMPTY_SET);
4020
+ }
4021
+ return callback(/** @type {WebpackError} */ (err));
4022
+ }
4023
+ const set = new Set(
4024
+ /** @type {string[]} */
4025
+ (elements).map((element) => join(this.fs, path, element))
4026
+ );
4027
+ callback(null, set);
4028
+ });
4029
+ }
4030
+
4031
+ /**
4032
+ * @private
4033
+ * @type {Processor<string, string>}
4034
+ */
4035
+ _getManagedItemInfo(path, callback) {
4036
+ const dir = dirname(this.fs, path);
4037
+ this.managedItemDirectoryQueue.add(dir, (err, elements) => {
4038
+ if (err) {
4039
+ return callback(err);
4040
+ }
4041
+ if (!(/** @type {Set<string>} */ (elements).has(path))) {
4042
+ // file or directory doesn't exist
4043
+ this._managedItems.set(path, "*missing");
4044
+ return callback(null, "*missing");
4045
+ }
4046
+ // something exists
4047
+ // it may be a file or directory
4048
+ if (
4049
+ path.endsWith("node_modules") &&
4050
+ (path.endsWith("/node_modules") || path.endsWith("\\node_modules"))
4051
+ ) {
4052
+ // we are only interested in existence of this special directory
4053
+ this._managedItems.set(path, "*node_modules");
4054
+ return callback(null, "*node_modules");
4055
+ }
4056
+
4057
+ // we assume it's a directory, as files shouldn't occur in managed paths
4058
+ const packageJsonPath = join(this.fs, path, "package.json");
4059
+ this.fs.readFile(packageJsonPath, (err, content) => {
4060
+ if (err) {
4061
+ if (err.code === "ENOENT" || err.code === "ENOTDIR") {
4062
+ // no package.json or path is not a directory
4063
+ this.fs.readdir(path, (err, elements) => {
4064
+ if (
4065
+ !err &&
4066
+ /** @type {string[]} */ (elements).length === 1 &&
4067
+ /** @type {string[]} */ (elements)[0] === "node_modules"
4068
+ ) {
4069
+ // This is only a grouping folder e.g. used by yarn
4070
+ // we are only interested in existence of this special directory
4071
+ this._managedItems.set(path, "*nested");
4072
+ return callback(null, "*nested");
4073
+ }
4074
+ /** @type {Logger} */
4075
+ (this.logger).warn(
4076
+ `Managed item ${path} isn't a directory or doesn't contain a package.json (see snapshot.managedPaths option)`
4077
+ );
4078
+ return callback();
4079
+ });
4080
+ return;
4081
+ }
4082
+ return callback(/** @type {WebpackError} */ (err));
4083
+ }
4084
+ /** @type {JsonObject} */
4085
+ let data;
4086
+ try {
4087
+ data = JSON.parse(/** @type {Buffer} */ (content).toString("utf8"));
4088
+ } catch (parseErr) {
4089
+ return callback(/** @type {WebpackError} */ (parseErr));
4090
+ }
4091
+ if (!data.name) {
4092
+ /** @type {Logger} */
4093
+ (this.logger).warn(
4094
+ `${packageJsonPath} doesn't contain a "name" property (see snapshot.managedPaths option)`
4095
+ );
4096
+ return callback();
4097
+ }
4098
+ const info = `${data.name || ""}@${data.version || ""}`;
4099
+ this._managedItems.set(path, info);
4100
+ callback(null, info);
4101
+ });
4102
+ });
4103
+ }
4104
+
4105
+ getDeprecatedFileTimestamps() {
4106
+ if (this._cachedDeprecatedFileTimestamps !== undefined) {
4107
+ return this._cachedDeprecatedFileTimestamps;
4108
+ }
4109
+ /** @type {Map<string, number | null>} */
4110
+ const map = new Map();
4111
+ for (const [path, info] of this._fileTimestamps) {
4112
+ if (info) map.set(path, typeof info === "object" ? info.safeTime : null);
4113
+ }
4114
+ return (this._cachedDeprecatedFileTimestamps = map);
4115
+ }
4116
+
4117
+ getDeprecatedContextTimestamps() {
4118
+ if (this._cachedDeprecatedContextTimestamps !== undefined) {
4119
+ return this._cachedDeprecatedContextTimestamps;
4120
+ }
4121
+ /** @type {Map<string, number | null>} */
4122
+ const map = new Map();
4123
+ for (const [path, info] of this._contextTimestamps) {
4124
+ if (info) map.set(path, typeof info === "object" ? info.safeTime : null);
4125
+ }
4126
+ return (this._cachedDeprecatedContextTimestamps = map);
4127
+ }
4128
+ }
4129
+
4130
+ module.exports = FileSystemInfo;
4131
+ module.exports.Snapshot = Snapshot;