webpack 5.97.1 → 5.104.1

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 (610) hide show
  1. package/README.md +368 -434
  2. package/bin/webpack.js +15 -9
  3. package/hot/dev-server.js +18 -3
  4. package/hot/emitter-event-target.js +7 -0
  5. package/hot/lazy-compilation-node.js +45 -29
  6. package/hot/lazy-compilation-universal.js +18 -0
  7. package/hot/lazy-compilation-web.js +15 -5
  8. package/hot/load-http.js +7 -0
  9. package/hot/log.js +15 -15
  10. package/hot/only-dev-server.js +19 -4
  11. package/hot/poll.js +1 -0
  12. package/lib/APIPlugin.js +48 -50
  13. package/lib/AbstractMethodError.js +1 -0
  14. package/lib/AsyncDependenciesBlock.js +4 -5
  15. package/lib/AutomaticPrefetchPlugin.js +22 -22
  16. package/lib/BannerPlugin.js +35 -40
  17. package/lib/Cache.js +12 -9
  18. package/lib/CacheFacade.js +13 -13
  19. package/lib/CaseSensitiveModulesWarning.js +6 -6
  20. package/lib/Chunk.js +68 -47
  21. package/lib/ChunkGraph.js +174 -95
  22. package/lib/ChunkGroup.js +32 -24
  23. package/lib/ChunkTemplate.js +8 -8
  24. package/lib/CleanPlugin.js +90 -42
  25. package/lib/CodeGenerationResults.js +12 -9
  26. package/lib/CompatibilityPlugin.js +70 -21
  27. package/lib/Compilation.js +827 -550
  28. package/lib/Compiler.js +137 -109
  29. package/lib/ConcatenationScope.js +45 -8
  30. package/lib/ConditionalInitFragment.js +1 -1
  31. package/lib/ConstPlugin.js +89 -59
  32. package/lib/ContextExclusionPlugin.js +5 -4
  33. package/lib/ContextModule.js +66 -51
  34. package/lib/ContextModuleFactory.js +51 -30
  35. package/lib/ContextReplacementPlugin.js +89 -34
  36. package/lib/CssModule.js +8 -4
  37. package/lib/DefinePlugin.js +209 -57
  38. package/lib/DelegatedModule.js +34 -23
  39. package/lib/DelegatedModuleFactoryPlugin.js +27 -24
  40. package/lib/DelegatedPlugin.js +4 -2
  41. package/lib/DependenciesBlock.js +0 -2
  42. package/lib/Dependency.js +37 -19
  43. package/lib/DependencyTemplate.js +2 -0
  44. package/lib/DependencyTemplates.js +5 -6
  45. package/lib/DllEntryPlugin.js +8 -4
  46. package/lib/DllModule.js +11 -12
  47. package/lib/DllModuleFactory.js +2 -2
  48. package/lib/DllPlugin.js +9 -6
  49. package/lib/DllReferencePlugin.js +60 -65
  50. package/lib/DotenvPlugin.js +462 -0
  51. package/lib/DynamicEntryPlugin.js +8 -8
  52. package/lib/EntryOptionPlugin.js +8 -6
  53. package/lib/EntryPlugin.js +5 -3
  54. package/lib/Entrypoint.js +19 -0
  55. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  56. package/lib/EnvironmentPlugin.js +26 -19
  57. package/lib/ErrorHelpers.js +6 -6
  58. package/lib/EvalDevToolModulePlugin.js +17 -14
  59. package/lib/EvalSourceMapDevToolPlugin.js +156 -142
  60. package/lib/ExportsInfo.js +180 -115
  61. package/lib/ExportsInfoApiPlugin.js +2 -2
  62. package/lib/ExternalModule.js +256 -102
  63. package/lib/ExternalModuleFactoryPlugin.js +66 -29
  64. package/lib/ExternalsPlugin.js +57 -2
  65. package/lib/FileSystemInfo.js +313 -247
  66. package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
  67. package/lib/FlagDependencyExportsPlugin.js +29 -19
  68. package/lib/FlagDependencyUsagePlugin.js +9 -10
  69. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  70. package/lib/Generator.js +43 -10
  71. package/lib/GraphHelpers.js +11 -3
  72. package/lib/HookWebpackError.js +35 -7
  73. package/lib/HotModuleReplacementPlugin.js +149 -108
  74. package/lib/HotUpdateChunk.js +0 -3
  75. package/lib/IgnoreErrorModuleFactory.js +2 -2
  76. package/lib/IgnorePlugin.js +16 -13
  77. package/lib/IgnoreWarningsPlugin.js +6 -4
  78. package/lib/InitFragment.js +41 -23
  79. package/lib/InvalidDependenciesModuleWarning.js +2 -3
  80. package/lib/JavascriptMetaInfoPlugin.js +2 -4
  81. package/lib/LibManifestPlugin.js +12 -13
  82. package/lib/LoaderOptionsPlugin.js +12 -14
  83. package/lib/LoaderTargetPlugin.js +5 -3
  84. package/lib/MainTemplate.js +18 -29
  85. package/lib/ManifestPlugin.js +235 -0
  86. package/lib/Module.js +138 -60
  87. package/lib/ModuleBuildError.js +4 -2
  88. package/lib/ModuleDependencyError.js +4 -3
  89. package/lib/ModuleDependencyWarning.js +4 -3
  90. package/lib/ModuleError.js +1 -1
  91. package/lib/ModuleFactory.js +10 -3
  92. package/lib/ModuleFilenameHelpers.js +63 -60
  93. package/lib/ModuleGraph.js +195 -70
  94. package/lib/ModuleGraphConnection.js +14 -20
  95. package/lib/ModuleInfoHeaderPlugin.js +15 -16
  96. package/lib/ModuleNotFoundError.js +1 -1
  97. package/lib/ModuleParseError.js +8 -4
  98. package/lib/ModuleSourceTypeConstants.js +189 -0
  99. package/lib/ModuleTemplate.js +7 -8
  100. package/lib/ModuleTypeConstants.js +37 -15
  101. package/lib/ModuleWarning.js +1 -1
  102. package/lib/MultiCompiler.js +64 -49
  103. package/lib/MultiStats.js +19 -14
  104. package/lib/MultiWatching.js +7 -11
  105. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  106. package/lib/NodeStuffPlugin.js +438 -126
  107. package/lib/NormalModule.js +322 -201
  108. package/lib/NormalModuleFactory.js +230 -117
  109. package/lib/NormalModuleReplacementPlugin.js +37 -39
  110. package/lib/NullFactory.js +3 -2
  111. package/lib/OptimizationStages.js +1 -1
  112. package/lib/OptionsApply.js +1 -1
  113. package/lib/Parser.js +5 -3
  114. package/lib/PlatformPlugin.js +3 -1
  115. package/lib/PrefetchPlugin.js +6 -4
  116. package/lib/ProgressPlugin.js +48 -49
  117. package/lib/ProvidePlugin.js +7 -5
  118. package/lib/RawModule.js +26 -12
  119. package/lib/RecordIdsPlugin.js +88 -110
  120. package/lib/RequestShortener.js +3 -1
  121. package/lib/ResolverFactory.js +15 -14
  122. package/lib/RuntimeGlobals.js +216 -153
  123. package/lib/RuntimeModule.js +7 -6
  124. package/lib/RuntimePlugin.js +115 -62
  125. package/lib/RuntimeTemplate.js +248 -76
  126. package/lib/SelfModuleFactory.js +2 -2
  127. package/lib/SizeFormatHelpers.js +2 -2
  128. package/lib/SourceMapDevToolModuleOptionsPlugin.js +17 -27
  129. package/lib/SourceMapDevToolPlugin.js +72 -59
  130. package/lib/Stats.js +2 -3
  131. package/lib/Template.js +31 -24
  132. package/lib/TemplatedPathPlugin.js +24 -21
  133. package/lib/UseStrictPlugin.js +1 -1
  134. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  135. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  136. package/lib/WarnNoModeSetPlugin.js +3 -1
  137. package/lib/WatchIgnorePlugin.js +11 -9
  138. package/lib/Watching.js +27 -29
  139. package/lib/WebpackError.js +10 -3
  140. package/lib/WebpackIsIncludedPlugin.js +4 -5
  141. package/lib/WebpackOptionsApply.js +263 -135
  142. package/lib/asset/AssetBytesGenerator.js +171 -0
  143. package/lib/asset/AssetBytesParser.js +37 -0
  144. package/lib/asset/AssetGenerator.js +285 -223
  145. package/lib/asset/AssetModulesPlugin.js +103 -41
  146. package/lib/asset/AssetParser.js +7 -3
  147. package/lib/asset/AssetSourceGenerator.js +41 -17
  148. package/lib/asset/RawDataUrlModule.js +17 -9
  149. package/lib/async-modules/AsyncModuleHelpers.js +52 -0
  150. package/lib/async-modules/AwaitDependenciesInitFragment.js +39 -24
  151. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  152. package/lib/buildChunkGraph.js +36 -17
  153. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  154. package/lib/cache/IdleFileCachePlugin.js +22 -20
  155. package/lib/cache/MemoryCachePlugin.js +3 -3
  156. package/lib/cache/MemoryWithGcCachePlugin.js +17 -11
  157. package/lib/cache/PackFileCacheStrategy.js +198 -170
  158. package/lib/cache/ResolverCachePlugin.js +58 -48
  159. package/lib/cache/getLazyHashedEtag.js +5 -4
  160. package/lib/cli.js +197 -39
  161. package/lib/config/browserslistTargetHandler.js +110 -85
  162. package/lib/config/defaults.js +514 -113
  163. package/lib/config/normalization.js +91 -64
  164. package/lib/config/target.js +30 -18
  165. package/lib/container/ContainerEntryDependency.js +0 -1
  166. package/lib/container/ContainerEntryModule.js +16 -15
  167. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  168. package/lib/container/ContainerPlugin.js +5 -6
  169. package/lib/container/ContainerReferencePlugin.js +27 -30
  170. package/lib/container/FallbackDependency.js +2 -1
  171. package/lib/container/FallbackModule.js +19 -14
  172. package/lib/container/FallbackModuleFactory.js +2 -2
  173. package/lib/container/HoistContainerReferencesPlugin.js +7 -7
  174. package/lib/container/ModuleFederationPlugin.js +4 -4
  175. package/lib/container/RemoteModule.js +14 -14
  176. package/lib/container/RemoteRuntimeModule.js +2 -2
  177. package/lib/container/options.js +9 -9
  178. package/lib/css/CssGenerator.js +366 -74
  179. package/lib/css/CssLoadingRuntimeModule.js +26 -16
  180. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  181. package/lib/css/CssModulesPlugin.js +191 -142
  182. package/lib/css/CssParser.js +1756 -740
  183. package/lib/css/walkCssTokens.js +180 -67
  184. package/lib/debug/ProfilingPlugin.js +135 -51
  185. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +29 -28
  186. package/lib/dependencies/AMDPlugin.js +18 -11
  187. package/lib/dependencies/AMDRequireArrayDependency.js +5 -4
  188. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  189. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +35 -26
  190. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  191. package/lib/dependencies/CachedConstDependency.js +24 -18
  192. package/lib/dependencies/CommonJsExportRequireDependency.js +31 -24
  193. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  194. package/lib/dependencies/CommonJsExportsParserPlugin.js +50 -36
  195. package/lib/dependencies/CommonJsFullRequireDependency.js +7 -13
  196. package/lib/dependencies/CommonJsImportsParserPlugin.js +146 -127
  197. package/lib/dependencies/CommonJsPlugin.js +29 -18
  198. package/lib/dependencies/CommonJsRequireContextDependency.js +4 -3
  199. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  200. package/lib/dependencies/ConstDependency.js +2 -2
  201. package/lib/dependencies/ContextDependency.js +10 -5
  202. package/lib/dependencies/ContextDependencyHelpers.js +21 -13
  203. package/lib/dependencies/ContextDependencyTemplateAsId.js +10 -9
  204. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +13 -10
  205. package/lib/dependencies/ContextElementDependency.js +23 -12
  206. package/lib/dependencies/CssIcssExportDependency.js +402 -22
  207. package/lib/dependencies/CssIcssImportDependency.js +116 -51
  208. package/lib/dependencies/CssIcssSymbolDependency.js +33 -35
  209. package/lib/dependencies/CssImportDependency.js +17 -14
  210. package/lib/dependencies/CssUrlDependency.js +8 -13
  211. package/lib/dependencies/DynamicExports.js +19 -19
  212. package/lib/dependencies/ExportsInfoDependency.js +13 -10
  213. package/lib/dependencies/ExternalModuleDependency.js +7 -7
  214. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  215. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  216. package/lib/dependencies/HarmonyAcceptDependency.js +96 -5
  217. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -5
  218. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  219. package/lib/dependencies/HarmonyDetectionParserPlugin.js +10 -30
  220. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +19 -8
  221. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +136 -99
  222. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  223. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +152 -61
  224. package/lib/dependencies/HarmonyExportInitFragment.js +2 -2
  225. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  226. package/lib/dependencies/HarmonyExports.js +5 -5
  227. package/lib/dependencies/HarmonyImportDependency.js +92 -45
  228. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +201 -163
  229. package/lib/dependencies/HarmonyImportSideEffectDependency.js +5 -6
  230. package/lib/dependencies/HarmonyImportSpecifierDependency.js +69 -42
  231. package/lib/dependencies/HarmonyModulesPlugin.js +16 -11
  232. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  233. package/lib/dependencies/ImportContextDependency.js +15 -1
  234. package/lib/dependencies/ImportDependency.js +25 -7
  235. package/lib/dependencies/ImportEagerDependency.js +7 -5
  236. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +23 -13
  237. package/lib/dependencies/ImportMetaContextPlugin.js +2 -2
  238. package/lib/dependencies/ImportMetaPlugin.js +172 -20
  239. package/lib/dependencies/ImportParserPlugin.js +327 -49
  240. package/lib/dependencies/ImportPhase.js +121 -0
  241. package/lib/dependencies/ImportPlugin.js +3 -1
  242. package/lib/dependencies/ImportWeakDependency.js +7 -5
  243. package/lib/dependencies/JsonExportsDependency.js +54 -28
  244. package/lib/dependencies/LoaderDependency.js +0 -3
  245. package/lib/dependencies/LoaderImportDependency.js +0 -3
  246. package/lib/dependencies/LoaderPlugin.js +24 -25
  247. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  248. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  249. package/lib/dependencies/ModuleDependency.js +14 -13
  250. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  251. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  252. package/lib/dependencies/NullDependency.js +2 -0
  253. package/lib/dependencies/ProvidedDependency.js +8 -10
  254. package/lib/dependencies/PureExpressionDependency.js +1 -2
  255. package/lib/dependencies/RequireContextDependency.js +2 -1
  256. package/lib/dependencies/RequireContextDependencyParserPlugin.js +47 -44
  257. package/lib/dependencies/RequireContextPlugin.js +5 -2
  258. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -3
  259. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +101 -99
  260. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  261. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  262. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  263. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  264. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  265. package/lib/dependencies/RequireResolveDependency.js +3 -3
  266. package/lib/dependencies/RuntimeRequirementsDependency.js +3 -4
  267. package/lib/dependencies/StaticExportsDependency.js +3 -5
  268. package/lib/dependencies/SystemPlugin.js +4 -4
  269. package/lib/dependencies/URLContextDependency.js +65 -0
  270. package/lib/dependencies/URLDependency.js +3 -8
  271. package/lib/dependencies/URLPlugin.js +18 -159
  272. package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -3
  273. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  274. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  275. package/lib/dependencies/WorkerDependency.js +8 -6
  276. package/lib/dependencies/WorkerPlugin.js +131 -67
  277. package/lib/dependencies/getFunctionExpression.js +2 -2
  278. package/lib/dependencies/processExportInfo.js +4 -4
  279. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  280. package/lib/esm/ModuleChunkFormatPlugin.js +232 -179
  281. package/lib/esm/ModuleChunkLoadingPlugin.js +112 -57
  282. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +102 -28
  283. package/lib/formatLocation.js +2 -2
  284. package/lib/hmr/HotModuleReplacement.runtime.js +41 -29
  285. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  286. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -33
  287. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  288. package/lib/hmr/LazyCompilationPlugin.js +67 -54
  289. package/lib/hmr/lazyCompilationBackend.js +23 -18
  290. package/lib/ids/ChunkModuleIdRangePlugin.js +14 -11
  291. package/lib/ids/DeterministicChunkIdsPlugin.js +32 -37
  292. package/lib/ids/DeterministicModuleIdsPlugin.js +52 -52
  293. package/lib/ids/HashedModuleIdsPlugin.js +15 -13
  294. package/lib/ids/IdHelpers.js +66 -49
  295. package/lib/ids/NamedChunkIdsPlugin.js +14 -17
  296. package/lib/ids/NamedModuleIdsPlugin.js +12 -14
  297. package/lib/ids/NaturalChunkIdsPlugin.js +6 -4
  298. package/lib/ids/NaturalModuleIdsPlugin.js +4 -3
  299. package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -5
  300. package/lib/ids/OccurrenceModuleIdsPlugin.js +8 -7
  301. package/lib/ids/SyncModuleIdsPlugin.js +18 -13
  302. package/lib/index.js +54 -14
  303. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +116 -119
  304. package/lib/javascript/BasicEvaluatedExpression.js +26 -18
  305. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  306. package/lib/javascript/ChunkHelpers.js +17 -5
  307. package/lib/javascript/CommonJsChunkFormatPlugin.js +114 -141
  308. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -4
  309. package/lib/javascript/JavascriptGenerator.js +122 -100
  310. package/lib/javascript/JavascriptModulesPlugin.js +332 -152
  311. package/lib/javascript/JavascriptParser.js +1488 -1052
  312. package/lib/javascript/JavascriptParserHelpers.js +48 -47
  313. package/lib/javascript/StartupHelpers.js +23 -22
  314. package/lib/json/JsonData.js +4 -4
  315. package/lib/json/JsonGenerator.js +66 -32
  316. package/lib/json/JsonModulesPlugin.js +16 -6
  317. package/lib/json/JsonParser.js +23 -8
  318. package/lib/library/AbstractLibraryPlugin.js +45 -10
  319. package/lib/library/AmdLibraryPlugin.js +7 -5
  320. package/lib/library/AssignLibraryPlugin.js +71 -17
  321. package/lib/library/EnableLibraryPlugin.js +51 -25
  322. package/lib/library/ExportPropertyLibraryPlugin.js +12 -18
  323. package/lib/library/JsonpLibraryPlugin.js +5 -2
  324. package/lib/library/ModuleLibraryPlugin.js +230 -18
  325. package/lib/library/SystemLibraryPlugin.js +29 -11
  326. package/lib/library/UmdLibraryPlugin.js +35 -32
  327. package/lib/logging/Logger.js +18 -15
  328. package/lib/logging/createConsoleLogger.js +27 -27
  329. package/lib/logging/runtime.js +11 -11
  330. package/lib/logging/truncateArgs.js +5 -5
  331. package/lib/node/CommonJsChunkLoadingPlugin.js +72 -75
  332. package/lib/node/NodeEnvironmentPlugin.js +9 -3
  333. package/lib/node/NodeTargetPlugin.js +9 -1
  334. package/lib/node/NodeTemplatePlugin.js +2 -2
  335. package/lib/node/NodeWatchFileSystem.js +4 -4
  336. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -38
  337. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +10 -11
  338. package/lib/node/ReadFileCompileWasmPlugin.js +11 -14
  339. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -30
  340. package/lib/node/nodeConsole.js +12 -7
  341. package/lib/optimize/AggressiveMergingPlugin.js +46 -47
  342. package/lib/optimize/AggressiveSplittingPlugin.js +233 -238
  343. package/lib/optimize/ConcatenatedModule.js +620 -251
  344. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  345. package/lib/optimize/FlagIncludedChunksPlugin.js +93 -96
  346. package/lib/optimize/InnerGraph.js +139 -124
  347. package/lib/optimize/InnerGraphPlugin.js +29 -24
  348. package/lib/optimize/LimitChunkCountPlugin.js +32 -8
  349. package/lib/optimize/MangleExportsPlugin.js +22 -22
  350. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  351. package/lib/optimize/MinChunkSizePlugin.js +12 -7
  352. package/lib/optimize/ModuleConcatenationPlugin.js +92 -71
  353. package/lib/optimize/RealContentHashPlugin.js +58 -44
  354. package/lib/optimize/RemoveEmptyChunksPlugin.js +8 -5
  355. package/lib/optimize/RemoveParentModulesPlugin.js +7 -4
  356. package/lib/optimize/RuntimeChunkPlugin.js +22 -25
  357. package/lib/optimize/SideEffectsFlagPlugin.js +44 -26
  358. package/lib/optimize/SplitChunksPlugin.js +209 -158
  359. package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
  360. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  361. package/lib/performance/SizeLimitsPlugin.js +8 -5
  362. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  363. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -64
  364. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -4
  365. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  366. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  367. package/lib/rules/BasicEffectRulePlugin.js +14 -5
  368. package/lib/rules/BasicMatcherRulePlugin.js +18 -7
  369. package/lib/rules/ObjectMatcherRulePlugin.js +17 -6
  370. package/lib/rules/RuleSetCompiler.js +73 -32
  371. package/lib/rules/UseEffectRulePlugin.js +61 -25
  372. package/lib/runtime/AsyncModuleRuntimeModule.js +74 -9
  373. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -4
  374. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  375. package/lib/runtime/CompatRuntimeModule.js +0 -1
  376. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  377. package/lib/runtime/GetChunkFilenameRuntimeModule.js +34 -35
  378. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  379. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  380. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  381. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +248 -0
  382. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  383. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  384. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  385. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +10 -9
  386. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  387. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  388. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  389. package/lib/schemes/DataUriPlugin.js +9 -31
  390. package/lib/schemes/FileUriPlugin.js +11 -6
  391. package/lib/schemes/HttpUriPlugin.js +381 -261
  392. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  393. package/lib/serialization/AggregateErrorSerializer.js +41 -0
  394. package/lib/serialization/BinaryMiddleware.js +51 -33
  395. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  396. package/lib/serialization/FileMiddleware.js +101 -71
  397. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  398. package/lib/serialization/ObjectMiddleware.js +130 -54
  399. package/lib/serialization/PlainObjectSerializer.js +1 -1
  400. package/lib/serialization/Serializer.js +38 -20
  401. package/lib/serialization/SerializerMiddleware.js +121 -49
  402. package/lib/serialization/SingleItemMiddleware.js +9 -7
  403. package/lib/serialization/types.js +1 -1
  404. package/lib/sharing/ConsumeSharedModule.js +9 -9
  405. package/lib/sharing/ConsumeSharedPlugin.js +14 -14
  406. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -8
  407. package/lib/sharing/ProvideSharedModule.js +9 -11
  408. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  409. package/lib/sharing/ProvideSharedPlugin.js +15 -10
  410. package/lib/sharing/SharePlugin.js +3 -4
  411. package/lib/sharing/ShareRuntimeModule.js +7 -6
  412. package/lib/sharing/resolveMatchedConfigs.js +27 -13
  413. package/lib/sharing/utils.js +37 -43
  414. package/lib/stats/DefaultStatsFactoryPlugin.js +455 -286
  415. package/lib/stats/DefaultStatsPresetPlugin.js +77 -46
  416. package/lib/stats/DefaultStatsPrinterPlugin.js +583 -419
  417. package/lib/stats/StatsFactory.js +75 -32
  418. package/lib/stats/StatsPrinter.js +71 -51
  419. package/lib/url/URLParserPlugin.js +264 -0
  420. package/lib/util/ArrayHelpers.js +6 -8
  421. package/lib/util/ArrayQueue.js +1 -1
  422. package/lib/util/AsyncQueue.js +11 -10
  423. package/lib/util/Hash.js +37 -5
  424. package/lib/util/IterableHelpers.js +4 -4
  425. package/lib/util/LazyBucketSortedSet.js +46 -27
  426. package/lib/util/LazySet.js +16 -10
  427. package/lib/util/MapHelpers.js +1 -1
  428. package/lib/util/ParallelismFactorCalculator.js +2 -2
  429. package/lib/util/Semaphore.js +3 -3
  430. package/lib/util/SetHelpers.js +6 -6
  431. package/lib/util/SortableSet.js +11 -9
  432. package/lib/util/StackedCacheMap.js +2 -2
  433. package/lib/util/StackedMap.js +3 -3
  434. package/lib/util/StringXor.js +2 -1
  435. package/lib/util/TupleQueue.js +11 -8
  436. package/lib/util/TupleSet.js +44 -19
  437. package/lib/util/URLAbsoluteSpecifier.js +3 -4
  438. package/lib/util/WeakTupleMap.js +56 -42
  439. package/lib/util/binarySearchBounds.js +4 -3
  440. package/lib/util/chainedImports.js +3 -1
  441. package/lib/util/cleverMerge.js +171 -107
  442. package/lib/util/comparators.js +265 -162
  443. package/lib/util/compileBooleanMatcher.js +120 -41
  444. package/lib/util/concatenate.js +20 -16
  445. package/lib/util/conventions.js +73 -74
  446. package/lib/util/create-schema-validation.js +8 -8
  447. package/lib/util/createHash.js +32 -135
  448. package/lib/util/dataURL.js +39 -0
  449. package/lib/util/deprecation.js +119 -116
  450. package/lib/util/deterministicGrouping.js +56 -47
  451. package/lib/util/extractSourceMap.js +319 -0
  452. package/lib/util/extractUrlAndGlobal.js +1 -1
  453. package/lib/util/findGraphRoots.js +19 -9
  454. package/lib/util/fs.js +169 -141
  455. package/lib/util/hash/BatchedHash.js +50 -10
  456. package/lib/util/hash/BulkUpdateHash.js +138 -0
  457. package/lib/util/hash/DebugHash.js +75 -0
  458. package/lib/util/hash/hash-digest.js +216 -0
  459. package/lib/util/hash/md4.js +2 -2
  460. package/lib/util/hash/wasm-hash.js +59 -17
  461. package/lib/util/identifier.js +124 -61
  462. package/lib/util/internalSerializables.js +4 -6
  463. package/lib/util/magicComment.js +9 -5
  464. package/lib/util/makeSerializable.js +2 -2
  465. package/lib/util/memoize.js +5 -2
  466. package/lib/util/objectToMap.js +3 -2
  467. package/lib/util/processAsyncTree.js +5 -5
  468. package/lib/util/propertyAccess.js +1 -1
  469. package/lib/util/propertyName.js +2 -3
  470. package/lib/util/registerExternalSerializer.js +16 -20
  471. package/lib/util/removeBOM.js +25 -0
  472. package/lib/util/runtime.js +72 -56
  473. package/lib/util/semver.js +44 -33
  474. package/lib/util/serialization.js +56 -56
  475. package/lib/util/smartGrouping.js +42 -27
  476. package/lib/util/source.js +5 -4
  477. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  478. package/lib/validateSchema.js +7 -9
  479. package/lib/wasm/EnableWasmLoadingPlugin.js +22 -12
  480. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -5
  481. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +15 -3
  482. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +28 -22
  483. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +47 -57
  484. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -10
  485. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +8 -4
  486. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +23 -17
  487. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  488. package/lib/wasm-sync/WebAssemblyGenerator.js +56 -41
  489. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +6 -3
  490. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +25 -10
  491. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +11 -12
  492. package/lib/wasm-sync/WebAssemblyParser.js +10 -17
  493. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  494. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
  495. package/lib/web/FetchCompileWasmPlugin.js +6 -8
  496. package/lib/web/JsonpChunkLoadingPlugin.js +74 -74
  497. package/lib/web/JsonpChunkLoadingRuntimeModule.js +10 -26
  498. package/lib/web/JsonpTemplatePlugin.js +0 -1
  499. package/lib/webpack.js +107 -87
  500. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +79 -75
  501. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +38 -51
  502. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  503. package/module.d.ts +5 -0
  504. package/package.json +149 -129
  505. package/schemas/WebpackOptions.check.d.ts +1 -1
  506. package/schemas/WebpackOptions.check.js +2 -2
  507. package/schemas/WebpackOptions.json +543 -190
  508. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  509. package/schemas/plugins/BannerPlugin.check.js +2 -2
  510. package/schemas/plugins/BannerPlugin.json +4 -0
  511. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  512. package/schemas/plugins/DllPlugin.check.js +1 -1
  513. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  514. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  515. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  516. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  517. package/schemas/plugins/IgnorePlugin.json +1 -1
  518. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  519. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  520. package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +2 -2
  521. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  522. package/schemas/plugins/ManifestPlugin.json +98 -0
  523. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  524. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  525. package/schemas/plugins/ProgressPlugin.json +1 -1
  526. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  527. package/schemas/plugins/SourceMapDevToolPlugin.check.js +2 -2
  528. package/schemas/plugins/SourceMapDevToolPlugin.json +23 -6
  529. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  530. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  531. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  532. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  533. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  534. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  535. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  536. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  537. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  538. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  539. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  540. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  541. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  542. package/schemas/plugins/container/ContainerReferencePlugin.check.js +2 -2
  543. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  544. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  545. package/schemas/plugins/container/ExternalsType.check.js +2 -2
  546. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  547. package/schemas/plugins/container/ModuleFederationPlugin.check.js +2 -2
  548. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  549. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  550. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  551. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  552. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +2 -2
  553. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  554. package/schemas/plugins/css/CssModuleParserOptions.check.js +2 -2
  555. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  556. package/schemas/plugins/css/CssParserOptions.check.js +2 -2
  557. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  558. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  559. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  560. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  561. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  562. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  563. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  564. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  565. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  566. package/schemas/plugins/{css/CssGlobalParserOptions.check.d.ts → json/JsonModulesPluginGenerator.check.d.ts} +1 -1
  567. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
  568. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  569. package/schemas/plugins/{css/CssGlobalGeneratorOptions.check.d.ts → json/JsonModulesPluginParser.check.d.ts} +1 -1
  570. package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
  571. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  572. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  573. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  574. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  575. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  576. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  577. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  578. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  579. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  580. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  581. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  582. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  583. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  584. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  585. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  586. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  587. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  588. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  589. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  590. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  591. package/types.d.ts +5115 -1863
  592. package/SECURITY.md +0 -9
  593. package/lib/ModuleSourceTypesConstants.js +0 -112
  594. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  595. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -111
  596. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
  597. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
  598. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  599. package/schemas/plugins/JsonModulesPluginParser.check.js +0 -6
  600. package/schemas/plugins/JsonModulesPluginParser.json +0 -12
  601. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  602. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  603. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  604. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  605. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  606. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  607. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  608. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  609. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  610. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -5,29 +5,28 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { create: createResolver } = require("enhanced-resolve");
9
8
  const nodeModule = require("module");
10
- const asyncLib = require("neo-async");
11
9
  const { isAbsolute } = require("path");
10
+ const { create: createResolver } = require("enhanced-resolve");
11
+ const asyncLib = require("neo-async");
12
+ const { DEFAULTS } = require("./config/defaults");
12
13
  const AsyncQueue = require("./util/AsyncQueue");
13
14
  const StackedCacheMap = require("./util/StackedCacheMap");
14
15
  const createHash = require("./util/createHash");
15
- const { join, dirname, relative, lstatReadlinkAbsolute } = require("./util/fs");
16
+ const { dirname, join, lstatReadlinkAbsolute, relative } = require("./util/fs");
16
17
  const makeSerializable = require("./util/makeSerializable");
18
+ const memoize = require("./util/memoize");
17
19
  const processAsyncTree = require("./util/processAsyncTree");
18
20
 
19
- /** @typedef {import("enhanced-resolve").Resolver} Resolver */
20
21
  /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
21
22
  /** @typedef {import("enhanced-resolve").ResolveFunctionAsync} ResolveFunctionAsync */
22
23
  /** @typedef {import("./WebpackError")} WebpackError */
23
24
  /** @typedef {import("./logging/Logger").Logger} Logger */
24
25
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
25
26
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
26
- /** @typedef {typeof import("./util/Hash")} Hash */
27
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
27
28
  /** @typedef {import("./util/fs").IStats} IStats */
28
29
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
29
- /** @typedef {import("./util/fs").PathLike} PathLike */
30
- /** @typedef {import("./util/fs").StringCallback} StringCallback */
31
30
  /**
32
31
  * @template T
33
32
  * @typedef {import("./util/AsyncQueue").Callback<T>} ProcessorCallback
@@ -46,8 +45,8 @@ let FS_ACCURACY = 2000;
46
45
 
47
46
  const EMPTY_SET = new Set();
48
47
 
49
- const RBDT_RESOLVE_CJS = 0;
50
- const RBDT_RESOLVE_ESM = 1;
48
+ const RBDT_RESOLVE_INITIAL = 0;
49
+ const RBDT_RESOLVE_FILE = 1;
51
50
  const RBDT_RESOLVE_DIRECTORY = 2;
52
51
  const RBDT_RESOLVE_CJS_FILE = 3;
53
52
  const RBDT_RESOLVE_CJS_FILE_AS_CHILD = 4;
@@ -57,7 +56,7 @@ const RBDT_FILE = 7;
57
56
  const RBDT_DIRECTORY_DEPENDENCIES = 8;
58
57
  const RBDT_FILE_DEPENDENCIES = 9;
59
58
 
60
- /** @typedef {RBDT_RESOLVE_CJS | RBDT_RESOLVE_ESM | 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 */
59
+ /** @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 */
61
60
 
62
61
  const INVALID = Symbol("invalid");
63
62
 
@@ -73,12 +72,14 @@ const INVALID = Symbol("invalid");
73
72
  * @property {string=} timestampHash
74
73
  */
75
74
 
75
+ /** @typedef {Set<string>} Symlinks */
76
+
76
77
  /**
77
78
  * @typedef {object} ContextFileSystemInfoEntry
78
79
  * @property {number} safeTime
79
80
  * @property {string=} timestampHash
80
81
  * @property {ResolvedContextFileSystemInfoEntry=} resolved
81
- * @property {Set<string>=} symlinks
82
+ * @property {Symlinks=} symlinks
82
83
  */
83
84
 
84
85
  /**
@@ -95,8 +96,6 @@ const INVALID = Symbol("invalid");
95
96
  * @property {string} hash
96
97
  */
97
98
 
98
- /** @typedef {Set<string>} Symlinks */
99
-
100
99
  /**
101
100
  * @typedef {object} ContextTimestampAndHash
102
101
  * @property {number} safeTime
@@ -123,16 +122,26 @@ const INVALID = Symbol("invalid");
123
122
  * @property {Set<SnapshotOptimizationEntry> | undefined} children
124
123
  */
125
124
 
125
+ /** @typedef {Map<string, string | false | undefined>} ResolveResults */
126
+
127
+ /** @typedef {Set<string>} Files */
128
+ /** @typedef {Set<string>} Directories */
129
+ /** @typedef {Set<string>} Missing */
130
+
131
+ /**
132
+ * @typedef {object} ResolveDependencies
133
+ * @property {Files} files list of files
134
+ * @property {Directories} directories list of directories
135
+ * @property {Missing} missing list of missing entries
136
+ */
137
+
126
138
  /**
127
139
  * @typedef {object} ResolveBuildDependenciesResult
128
- * @property {Set<string>} files list of files
129
- * @property {Set<string>} directories list of directories
130
- * @property {Set<string>} missing list of missing entries
131
- * @property {Map<string, string | false | undefined>} resolveResults stored resolve results
132
- * @property {object} resolveDependencies dependencies of the resolving
133
- * @property {Set<string>} resolveDependencies.files list of files
134
- * @property {Set<string>} resolveDependencies.directories list of directories
135
- * @property {Set<string>} resolveDependencies.missing list of missing entries
140
+ * @property {Files} files list of files
141
+ * @property {Directories} directories list of directories
142
+ * @property {Missing} missing list of missing entries
143
+ * @property {ResolveResults} resolveResults stored resolve results
144
+ * @property {ResolveDependencies} resolveDependencies dependencies of the resolving
136
145
  */
137
146
 
138
147
  /**
@@ -157,13 +166,17 @@ class SnapshotIterator {
157
166
  }
158
167
 
159
168
  /**
160
- * @typedef {(snapshot: Snapshot) => (Map<string, any> | Set<string> | undefined)[]} GetMapsFunction
169
+ * @template T
170
+ * @typedef {(snapshot: Snapshot) => T[]} GetMapsFunction
161
171
  */
162
172
 
173
+ /**
174
+ * @template T
175
+ */
163
176
  class SnapshotIterable {
164
177
  /**
165
178
  * @param {Snapshot} snapshot snapshot
166
- * @param {GetMapsFunction} getMaps get maps function
179
+ * @param {GetMapsFunction<T>} getMaps get maps function
167
180
  */
168
181
  constructor(snapshot, getMaps) {
169
182
  this.snapshot = snapshot;
@@ -174,9 +187,9 @@ class SnapshotIterable {
174
187
  let state = 0;
175
188
  /** @type {IterableIterator<string>} */
176
189
  let it;
177
- /** @type {(snapshot: Snapshot) => (Map<string, any> | Set<string> | undefined)[]} */
190
+ /** @type {GetMapsFunction<T>} */
178
191
  let getMaps;
179
- /** @type {(Map<string, any> | Set<string> | undefined)[]} */
192
+ /** @type {T[]} */
180
193
  let maps;
181
194
  /** @type {Snapshot} */
182
195
  let snapshot;
@@ -195,7 +208,9 @@ class SnapshotIterable {
195
208
  if (maps.length > 0) {
196
209
  const map = maps.pop();
197
210
  if (map !== undefined) {
198
- it = map.keys();
211
+ it =
212
+ /** @type {Set<EXPECTED_ANY> | Map<string, EXPECTED_ANY>} */
213
+ (map).keys();
199
214
  state = 2;
200
215
  } else {
201
216
  break;
@@ -303,7 +318,7 @@ class Snapshot {
303
318
  * @param {number} value start value
304
319
  */
305
320
  setStartTime(value) {
306
- this._flags = this._flags | 1;
321
+ this._flags |= 1;
307
322
  this.startTime = value;
308
323
  }
309
324
 
@@ -340,7 +355,7 @@ class Snapshot {
340
355
  * @param {FileTimestamps} value file timestamps
341
356
  */
342
357
  setFileTimestamps(value) {
343
- this._flags = this._flags | 2;
358
+ this._flags |= 2;
344
359
  this.fileTimestamps = value;
345
360
  }
346
361
 
@@ -352,7 +367,7 @@ class Snapshot {
352
367
  * @param {FileHashes} value file hashes
353
368
  */
354
369
  setFileHashes(value) {
355
- this._flags = this._flags | 4;
370
+ this._flags |= 4;
356
371
  this.fileHashes = value;
357
372
  }
358
373
 
@@ -364,7 +379,7 @@ class Snapshot {
364
379
  * @param {FileTshs} value file tshs
365
380
  */
366
381
  setFileTshs(value) {
367
- this._flags = this._flags | 8;
382
+ this._flags |= 8;
368
383
  this.fileTshs = value;
369
384
  }
370
385
 
@@ -376,7 +391,7 @@ class Snapshot {
376
391
  * @param {ContextTimestamps} value context timestamps
377
392
  */
378
393
  setContextTimestamps(value) {
379
- this._flags = this._flags | 0x10;
394
+ this._flags |= 0x10;
380
395
  this.contextTimestamps = value;
381
396
  }
382
397
 
@@ -388,7 +403,7 @@ class Snapshot {
388
403
  * @param {ContextHashes} value context hashes
389
404
  */
390
405
  setContextHashes(value) {
391
- this._flags = this._flags | 0x20;
406
+ this._flags |= 0x20;
392
407
  this.contextHashes = value;
393
408
  }
394
409
 
@@ -400,7 +415,7 @@ class Snapshot {
400
415
  * @param {ContextTshs} value context tshs
401
416
  */
402
417
  setContextTshs(value) {
403
- this._flags = this._flags | 0x40;
418
+ this._flags |= 0x40;
404
419
  this.contextTshs = value;
405
420
  }
406
421
 
@@ -412,7 +427,7 @@ class Snapshot {
412
427
  * @param {MissingExistence} value context tshs
413
428
  */
414
429
  setMissingExistence(value) {
415
- this._flags = this._flags | 0x80;
430
+ this._flags |= 0x80;
416
431
  this.missingExistence = value;
417
432
  }
418
433
 
@@ -424,7 +439,7 @@ class Snapshot {
424
439
  * @param {ManagedItemInfo} value managed item info
425
440
  */
426
441
  setManagedItemInfo(value) {
427
- this._flags = this._flags | 0x100;
442
+ this._flags |= 0x100;
428
443
  this.managedItemInfo = value;
429
444
  }
430
445
 
@@ -436,7 +451,7 @@ class Snapshot {
436
451
  * @param {ManagedFiles} value managed files
437
452
  */
438
453
  setManagedFiles(value) {
439
- this._flags = this._flags | 0x200;
454
+ this._flags |= 0x200;
440
455
  this.managedFiles = value;
441
456
  }
442
457
 
@@ -448,7 +463,7 @@ class Snapshot {
448
463
  * @param {ManagedContexts} value managed contexts
449
464
  */
450
465
  setManagedContexts(value) {
451
- this._flags = this._flags | 0x400;
466
+ this._flags |= 0x400;
452
467
  this.managedContexts = value;
453
468
  }
454
469
 
@@ -460,7 +475,7 @@ class Snapshot {
460
475
  * @param {ManagedMissing} value managed missing
461
476
  */
462
477
  setManagedMissing(value) {
463
- this._flags = this._flags | 0x800;
478
+ this._flags |= 0x800;
464
479
  this.managedMissing = value;
465
480
  }
466
481
 
@@ -472,7 +487,7 @@ class Snapshot {
472
487
  * @param {Children} value children
473
488
  */
474
489
  setChildren(value) {
475
- this._flags = this._flags | 0x1000;
490
+ this._flags |= 0x1000;
476
491
  this.children = value;
477
492
  }
478
493
 
@@ -528,8 +543,9 @@ class Snapshot {
528
543
  }
529
544
 
530
545
  /**
531
- * @param {GetMapsFunction} getMaps first
532
- * @returns {Iterable<string>} iterable
546
+ * @template T
547
+ * @param {GetMapsFunction<T>} getMaps first
548
+ * @returns {SnapshotIterable<T>} iterable
533
549
  */
534
550
  _createIterable(getMaps) {
535
551
  return new SnapshotIterable(this, getMaps);
@@ -540,7 +556,7 @@ class Snapshot {
540
556
  */
541
557
  getFileIterable() {
542
558
  if (this._cachedFileIterable === undefined) {
543
- this._cachedFileIterable = this._createIterable(s => [
559
+ this._cachedFileIterable = this._createIterable((s) => [
544
560
  s.fileTimestamps,
545
561
  s.fileHashes,
546
562
  s.fileTshs,
@@ -555,7 +571,7 @@ class Snapshot {
555
571
  */
556
572
  getContextIterable() {
557
573
  if (this._cachedContextIterable === undefined) {
558
- this._cachedContextIterable = this._createIterable(s => [
574
+ this._cachedContextIterable = this._createIterable((s) => [
559
575
  s.contextTimestamps,
560
576
  s.contextHashes,
561
577
  s.contextTshs,
@@ -570,7 +586,7 @@ class Snapshot {
570
586
  */
571
587
  getMissingIterable() {
572
588
  if (this._cachedMissingIterable === undefined) {
573
- this._cachedMissingIterable = this._createIterable(s => [
589
+ this._cachedMissingIterable = this._createIterable((s) => [
574
590
  s.missingExistence,
575
591
  s.managedMissing
576
592
  ]);
@@ -594,9 +610,9 @@ const MIN_COMMON_SNAPSHOT_SIZE = 3;
594
610
  */
595
611
  class SnapshotOptimization {
596
612
  /**
597
- * @param {function(Snapshot): boolean} has has value
598
- * @param {function(Snapshot): SnapshotOptimizationValue<U, T> | undefined} get get value
599
- * @param {function(Snapshot, SnapshotOptimizationValue<U, T>): void} set set value
613
+ * @param {(snapshot: Snapshot) => boolean} has has value
614
+ * @param {(snapshot: Snapshot) => SnapshotOptimizationValue<U, T> | undefined} get get value
615
+ * @param {(snapshot: Snapshot, value: SnapshotOptimizationValue<U, T>) => void} set set value
600
616
  * @param {boolean=} useStartTime use the start time of snapshots
601
617
  * @param {U=} isSet value is an Set instead of a Map
602
618
  */
@@ -647,11 +663,14 @@ class SnapshotOptimization {
647
663
  * @returns {void}
648
664
  */
649
665
  optimize(newSnapshot, capturedFiles) {
666
+ if (capturedFiles.size === 0) {
667
+ return;
668
+ }
650
669
  /**
651
670
  * @param {SnapshotOptimizationEntry} entry optimization entry
652
671
  * @returns {void}
653
672
  */
654
- const increaseSharedAndStoreOptimizationEntry = entry => {
673
+ const increaseSharedAndStoreOptimizationEntry = (entry) => {
655
674
  if (entry.children !== undefined) {
656
675
  for (const child of entry.children) {
657
676
  increaseSharedAndStoreOptimizationEntry(child);
@@ -664,7 +683,7 @@ class SnapshotOptimization {
664
683
  * @param {SnapshotOptimizationEntry} entry optimization entry
665
684
  * @returns {void}
666
685
  */
667
- const storeOptimizationEntry = entry => {
686
+ const storeOptimizationEntry = (entry) => {
668
687
  for (const path of /** @type {SnapshotContent} */ (
669
688
  entry.snapshotContent
670
689
  )) {
@@ -698,7 +717,6 @@ class SnapshotOptimization {
698
717
  };
699
718
  }
700
719
  this._map.set(path, newOptimizationEntry);
701
- continue;
702
720
  } else {
703
721
  optimizationEntries.add(optimizationEntry);
704
722
  }
@@ -717,6 +735,7 @@ class SnapshotOptimization {
717
735
  ) {
718
736
  continue;
719
737
  }
738
+ /** @type {Set<string>} */
720
739
  const nonSharedFiles = new Set();
721
740
  const snapshotContent =
722
741
  /** @type {NonNullable<SnapshotOptimizationEntry["snapshotContent"]>} */
@@ -732,7 +751,6 @@ class SnapshotOptimization {
732
751
  continue optimizationEntriesLabel;
733
752
  }
734
753
  nonSharedFiles.add(path);
735
- continue;
736
754
  }
737
755
  }
738
756
  if (nonSharedFiles.size === 0) {
@@ -784,8 +802,9 @@ class SnapshotOptimization {
784
802
  snapshotContent: new Set(commonMap.keys()),
785
803
  children: undefined
786
804
  };
787
- if (optimizationEntry.children === undefined)
805
+ if (optimizationEntry.children === undefined) {
788
806
  optimizationEntry.children = new Set();
807
+ }
789
808
  optimizationEntry.children.add(newEntry);
790
809
  storeOptimizationEntry(newEntry);
791
810
  this._statSharedSnapshots++;
@@ -863,9 +882,10 @@ class SnapshotOptimization {
863
882
  * @param {string} str input
864
883
  * @returns {string} result
865
884
  */
866
- const parseString = str => {
867
- if (str[0] === "'" || str[0] === "`")
885
+ const parseString = (str) => {
886
+ if (str[0] === "'" || str[0] === "`") {
868
887
  str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
888
+ }
869
889
  return JSON.parse(str);
870
890
  };
871
891
 
@@ -873,7 +893,7 @@ const parseString = str => {
873
893
  /**
874
894
  * @param {number} mtime mtime
875
895
  */
876
- const applyMtime = mtime => {
896
+ const applyMtime = (mtime) => {
877
897
  if (FS_ACCURACY > 1 && mtime % 2 !== 0) FS_ACCURACY = 1;
878
898
  else if (FS_ACCURACY > 10 && mtime % 20 !== 0) FS_ACCURACY = 10;
879
899
  else if (FS_ACCURACY > 100 && mtime % 200 !== 0) FS_ACCURACY = 100;
@@ -919,7 +939,7 @@ const mergeSets = (a, b) => {
919
939
  * Finding file or directory to manage
920
940
  * @param {string} managedPath path that is managing by {@link FileSystemInfo}
921
941
  * @param {string} path path to file or directory
922
- * @returns {string|null} managed item
942
+ * @returns {string | null} managed item
923
943
  * @example
924
944
  * getManagedItem(
925
945
  * '/Users/user/my-project/node_modules/',
@@ -1004,7 +1024,7 @@ const getManagedItem = (managedPath, path) => {
1004
1024
  * @param {T | null} entry entry
1005
1025
  * @returns {T["resolved"] | null | undefined} the resolved entry
1006
1026
  */
1007
- const getResolvedTimestamp = entry => {
1027
+ const getResolvedTimestamp = (entry) => {
1008
1028
  if (entry === null) return null;
1009
1029
  if (entry.resolved !== undefined) return entry.resolved;
1010
1030
  return entry.symlinks === undefined ? entry : undefined;
@@ -1014,7 +1034,7 @@ const getResolvedTimestamp = entry => {
1014
1034
  * @param {ContextHash | null} entry entry
1015
1035
  * @returns {string | null | undefined} the resolved entry
1016
1036
  */
1017
- const getResolvedHash = entry => {
1037
+ const getResolvedHash = (entry) => {
1018
1038
  if (entry === null) return null;
1019
1039
  if (entry.resolved !== undefined) return entry.resolved;
1020
1040
  return entry.symlinks === undefined ? entry.hash : undefined;
@@ -1029,8 +1049,16 @@ const addAll = (source, target) => {
1029
1049
  for (const key of source) target.add(key);
1030
1050
  };
1031
1051
 
1052
+ const getEsModuleLexer = memoize(() => require("es-module-lexer"));
1053
+
1032
1054
  /** @typedef {Set<string>} LoggedPaths */
1033
1055
 
1056
+ /** @typedef {FileSystemInfoEntry | "ignore" | null} FileTimestamp */
1057
+ /** @typedef {ContextFileSystemInfoEntry | "ignore" | null} ContextTimestamp */
1058
+ /** @typedef {ResolvedContextFileSystemInfoEntry | "ignore" | null} ResolvedContextTimestamp */
1059
+
1060
+ /** @typedef {(err?: WebpackError | null, result?: boolean) => void} CheckSnapshotValidCallback */
1061
+
1034
1062
  /**
1035
1063
  * Used to access information about the filesystem in a cached way
1036
1064
  */
@@ -1042,7 +1070,7 @@ class FileSystemInfo {
1042
1070
  * @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
1043
1071
  * @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
1044
1072
  * @param {Logger=} options.logger logger used to log invalid snapshots
1045
- * @param {string | Hash=} options.hashFunction the hash function to use
1073
+ * @param {HashFunction=} options.hashFunction the hash function to use
1046
1074
  */
1047
1075
  constructor(
1048
1076
  fs,
@@ -1051,7 +1079,7 @@ class FileSystemInfo {
1051
1079
  managedPaths = [],
1052
1080
  immutablePaths = [],
1053
1081
  logger,
1054
- hashFunction = "md4"
1082
+ hashFunction = DEFAULTS.HASH_FUNCTION
1055
1083
  } = {}
1056
1084
  ) {
1057
1085
  this.fs = fs;
@@ -1060,80 +1088,80 @@ class FileSystemInfo {
1060
1088
  /** @type {LoggedPaths | undefined} */
1061
1089
  this._loggedPaths = logger ? new Set() : undefined;
1062
1090
  this._hashFunction = hashFunction;
1063
- /** @type {WeakMap<Snapshot, boolean | (function((WebpackError | null)=, boolean=): void)[]>} */
1091
+ /** @type {WeakMap<Snapshot, boolean | CheckSnapshotValidCallback[]>} */
1064
1092
  this._snapshotCache = new WeakMap();
1065
1093
  this._fileTimestampsOptimization = new SnapshotOptimization(
1066
- s => s.hasFileTimestamps(),
1067
- s => s.fileTimestamps,
1094
+ (s) => s.hasFileTimestamps(),
1095
+ (s) => s.fileTimestamps,
1068
1096
  (s, v) => s.setFileTimestamps(v)
1069
1097
  );
1070
1098
  this._fileHashesOptimization = new SnapshotOptimization(
1071
- s => s.hasFileHashes(),
1072
- s => s.fileHashes,
1099
+ (s) => s.hasFileHashes(),
1100
+ (s) => s.fileHashes,
1073
1101
  (s, v) => s.setFileHashes(v),
1074
1102
  false
1075
1103
  );
1076
1104
  this._fileTshsOptimization = new SnapshotOptimization(
1077
- s => s.hasFileTshs(),
1078
- s => s.fileTshs,
1105
+ (s) => s.hasFileTshs(),
1106
+ (s) => s.fileTshs,
1079
1107
  (s, v) => s.setFileTshs(v)
1080
1108
  );
1081
1109
  this._contextTimestampsOptimization = new SnapshotOptimization(
1082
- s => s.hasContextTimestamps(),
1083
- s => s.contextTimestamps,
1110
+ (s) => s.hasContextTimestamps(),
1111
+ (s) => s.contextTimestamps,
1084
1112
  (s, v) => s.setContextTimestamps(v)
1085
1113
  );
1086
1114
  this._contextHashesOptimization = new SnapshotOptimization(
1087
- s => s.hasContextHashes(),
1088
- s => s.contextHashes,
1115
+ (s) => s.hasContextHashes(),
1116
+ (s) => s.contextHashes,
1089
1117
  (s, v) => s.setContextHashes(v),
1090
1118
  false
1091
1119
  );
1092
1120
  this._contextTshsOptimization = new SnapshotOptimization(
1093
- s => s.hasContextTshs(),
1094
- s => s.contextTshs,
1121
+ (s) => s.hasContextTshs(),
1122
+ (s) => s.contextTshs,
1095
1123
  (s, v) => s.setContextTshs(v)
1096
1124
  );
1097
1125
  this._missingExistenceOptimization = new SnapshotOptimization(
1098
- s => s.hasMissingExistence(),
1099
- s => s.missingExistence,
1126
+ (s) => s.hasMissingExistence(),
1127
+ (s) => s.missingExistence,
1100
1128
  (s, v) => s.setMissingExistence(v),
1101
1129
  false
1102
1130
  );
1103
1131
  this._managedItemInfoOptimization = new SnapshotOptimization(
1104
- s => s.hasManagedItemInfo(),
1105
- s => s.managedItemInfo,
1132
+ (s) => s.hasManagedItemInfo(),
1133
+ (s) => s.managedItemInfo,
1106
1134
  (s, v) => s.setManagedItemInfo(v),
1107
1135
  false
1108
1136
  );
1109
1137
  this._managedFilesOptimization = new SnapshotOptimization(
1110
- s => s.hasManagedFiles(),
1111
- s => s.managedFiles,
1138
+ (s) => s.hasManagedFiles(),
1139
+ (s) => s.managedFiles,
1112
1140
  (s, v) => s.setManagedFiles(v),
1113
1141
  false,
1114
1142
  true
1115
1143
  );
1116
1144
  this._managedContextsOptimization = new SnapshotOptimization(
1117
- s => s.hasManagedContexts(),
1118
- s => s.managedContexts,
1145
+ (s) => s.hasManagedContexts(),
1146
+ (s) => s.managedContexts,
1119
1147
  (s, v) => s.setManagedContexts(v),
1120
1148
  false,
1121
1149
  true
1122
1150
  );
1123
1151
  this._managedMissingOptimization = new SnapshotOptimization(
1124
- s => s.hasManagedMissing(),
1125
- s => s.managedMissing,
1152
+ (s) => s.hasManagedMissing(),
1153
+ (s) => s.managedMissing,
1126
1154
  (s, v) => s.setManagedMissing(v),
1127
1155
  false,
1128
1156
  true
1129
1157
  );
1130
- /** @type {StackedCacheMap<string, FileSystemInfoEntry | "ignore" | null>} */
1158
+ /** @type {StackedCacheMap<string, FileTimestamp>} */
1131
1159
  this._fileTimestamps = new StackedCacheMap();
1132
1160
  /** @type {Map<string, string | null>} */
1133
1161
  this._fileHashes = new Map();
1134
1162
  /** @type {Map<string, TimestampAndHash | string>} */
1135
1163
  this._fileTshs = new Map();
1136
- /** @type {StackedCacheMap<string, ContextFileSystemInfoEntry | "ignore" | null>} */
1164
+ /** @type {StackedCacheMap<string, ContextTimestamp>} */
1137
1165
  this._contextTimestamps = new StackedCacheMap();
1138
1166
  /** @type {Map<string, ContextHash>} */
1139
1167
  this._contextHashes = new Map();
@@ -1183,28 +1211,34 @@ class FileSystemInfo {
1183
1211
  parallelism: 10,
1184
1212
  processor: this._getManagedItemDirectoryInfo.bind(this)
1185
1213
  });
1186
- const _unmanagedPaths = Array.from(unmanagedPaths);
1187
- this.unmanagedPathsWithSlash = /** @type {string[]} */ (
1188
- _unmanagedPaths.filter(p => typeof p === "string")
1189
- ).map(p => join(fs, p, "_").slice(0, -1));
1190
- this.unmanagedPathsRegExps = /** @type {RegExp[]} */ (
1191
- _unmanagedPaths.filter(p => typeof p !== "string")
1214
+ const _unmanagedPaths = [...unmanagedPaths];
1215
+ /** @type {string[]} */
1216
+ this.unmanagedPathsWithSlash = _unmanagedPaths
1217
+ .filter((p) => typeof p === "string")
1218
+ .map((p) => join(fs, p, "_").slice(0, -1));
1219
+ /** @type {RegExp[]} */
1220
+ this.unmanagedPathsRegExps = _unmanagedPaths.filter(
1221
+ (p) => typeof p !== "string"
1192
1222
  );
1193
1223
 
1194
- this.managedPaths = Array.from(managedPaths);
1195
- this.managedPathsWithSlash = /** @type {string[]} */ (
1196
- this.managedPaths.filter(p => typeof p === "string")
1197
- ).map(p => join(fs, p, "_").slice(0, -1));
1198
-
1199
- this.managedPathsRegExps = /** @type {RegExp[]} */ (
1200
- this.managedPaths.filter(p => typeof p !== "string")
1224
+ this.managedPaths = [...managedPaths];
1225
+ /** @type {string[]} */
1226
+ this.managedPathsWithSlash = this.managedPaths
1227
+ .filter((p) => typeof p === "string")
1228
+ .map((p) => join(fs, p, "_").slice(0, -1));
1229
+ /** @type {RegExp[]} */
1230
+ this.managedPathsRegExps = this.managedPaths.filter(
1231
+ (p) => typeof p !== "string"
1201
1232
  );
1202
- this.immutablePaths = Array.from(immutablePaths);
1203
- this.immutablePathsWithSlash = /** @type {string[]} */ (
1204
- this.immutablePaths.filter(p => typeof p === "string")
1205
- ).map(p => join(fs, p, "_").slice(0, -1));
1206
- this.immutablePathsRegExps = /** @type {RegExp[]} */ (
1207
- this.immutablePaths.filter(p => typeof p !== "string")
1233
+
1234
+ this.immutablePaths = [...immutablePaths];
1235
+ /** @type {string[]} */
1236
+ this.immutablePathsWithSlash = this.immutablePaths
1237
+ .filter((p) => typeof p === "string")
1238
+ .map((p) => join(fs, p, "_").slice(0, -1));
1239
+ /** @type {RegExp[]} */
1240
+ this.immutablePathsRegExps = this.immutablePaths.filter(
1241
+ (p) => typeof p !== "string"
1208
1242
  );
1209
1243
 
1210
1244
  this._cachedDeprecatedFileTimestamps = undefined;
@@ -1310,9 +1344,10 @@ class FileSystemInfo {
1310
1344
  }
1311
1345
 
1312
1346
  /**
1347
+ * @private
1313
1348
  * @param {string} path path
1314
1349
  * @param {string} reason reason
1315
- * @param {any[]} args arguments
1350
+ * @param {EXPECTED_ANY[]} args arguments
1316
1351
  */
1317
1352
  _log(path, reason, ...args) {
1318
1353
  const key = path + reason;
@@ -1366,7 +1401,7 @@ class FileSystemInfo {
1366
1401
  }
1367
1402
 
1368
1403
  /**
1369
- * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
1404
+ * @param {ReadonlyMap<string, FileTimestamp>} map timestamps
1370
1405
  * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1371
1406
  * @returns {void}
1372
1407
  */
@@ -1376,7 +1411,7 @@ class FileSystemInfo {
1376
1411
  }
1377
1412
 
1378
1413
  /**
1379
- * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} map timestamps
1414
+ * @param {ReadonlyMap<string, ContextTimestamp>} map timestamps
1380
1415
  * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it
1381
1416
  * @returns {void}
1382
1417
  */
@@ -1387,7 +1422,7 @@ class FileSystemInfo {
1387
1422
 
1388
1423
  /**
1389
1424
  * @param {string} path file path
1390
- * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1425
+ * @param {(err?: WebpackError | null, fileTimestamp?: FileTimestamp) => void} callback callback function
1391
1426
  * @returns {void}
1392
1427
  */
1393
1428
  getFileTimestamp(path, callback) {
@@ -1398,7 +1433,7 @@ class FileSystemInfo {
1398
1433
 
1399
1434
  /**
1400
1435
  * @param {string} path context path
1401
- * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1436
+ * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback function
1402
1437
  * @returns {void}
1403
1438
  */
1404
1439
  getContextTimestamp(path, callback) {
@@ -1423,8 +1458,9 @@ class FileSystemInfo {
1423
1458
  }
1424
1459
 
1425
1460
  /**
1461
+ * @private
1426
1462
  * @param {string} path context path
1427
- * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function
1463
+ * @param {(err?: WebpackError | null, contextTimestamp?: ContextTimestamp) => void} callback callback function
1428
1464
  * @returns {void}
1429
1465
  */
1430
1466
  _getUnresolvedContextTimestamp(path, callback) {
@@ -1435,7 +1471,7 @@ class FileSystemInfo {
1435
1471
 
1436
1472
  /**
1437
1473
  * @param {string} path file path
1438
- * @param {function((WebpackError | null)=, (string | null)=): void} callback callback function
1474
+ * @param {(err?: WebpackError | null, hash?: string | null) => void} callback callback function
1439
1475
  * @returns {void}
1440
1476
  */
1441
1477
  getFileHash(path, callback) {
@@ -1446,30 +1482,33 @@ class FileSystemInfo {
1446
1482
 
1447
1483
  /**
1448
1484
  * @param {string} path context path
1449
- * @param {function((WebpackError | null)=, string=): void} callback callback function
1485
+ * @param {(err?: WebpackError | null, contextHash?: string) => void} callback callback function
1450
1486
  * @returns {void}
1451
1487
  */
1452
1488
  getContextHash(path, callback) {
1453
1489
  const cache = this._contextHashes.get(path);
1454
1490
  if (cache !== undefined) {
1455
1491
  const resolved = getResolvedHash(cache);
1456
- if (resolved !== undefined)
1492
+ if (resolved !== undefined) {
1457
1493
  return callback(null, /** @type {string} */ (resolved));
1494
+ }
1458
1495
  return this._resolveContextHash(cache, callback);
1459
1496
  }
1460
1497
  this.contextHashQueue.add(path, (err, _entry) => {
1461
1498
  if (err) return callback(err);
1462
1499
  const entry = /** @type {ContextHash} */ (_entry);
1463
1500
  const resolved = getResolvedHash(entry);
1464
- if (resolved !== undefined)
1501
+ if (resolved !== undefined) {
1465
1502
  return callback(null, /** @type {string} */ (resolved));
1503
+ }
1466
1504
  this._resolveContextHash(entry, callback);
1467
1505
  });
1468
1506
  }
1469
1507
 
1470
1508
  /**
1509
+ * @private
1471
1510
  * @param {string} path context path
1472
- * @param {function((WebpackError | null)=, (ContextHash | null)=): void} callback callback function
1511
+ * @param {(err?: WebpackError | null, contextHash?: ContextHash | null) => void} callback callback function
1473
1512
  * @returns {void}
1474
1513
  */
1475
1514
  _getUnresolvedContextHash(path, callback) {
@@ -1480,7 +1519,7 @@ class FileSystemInfo {
1480
1519
 
1481
1520
  /**
1482
1521
  * @param {string} path context path
1483
- * @param {function((WebpackError | null)=, (ResolvedContextTimestampAndHash | null)=): void} callback callback function
1522
+ * @param {(err?: WebpackError | null, resolvedContextTimestampAndHash?: ResolvedContextTimestampAndHash | null) => void} callback callback function
1484
1523
  * @returns {void}
1485
1524
  */
1486
1525
  getContextTsh(path, callback) {
@@ -1500,8 +1539,9 @@ class FileSystemInfo {
1500
1539
  }
1501
1540
 
1502
1541
  /**
1542
+ * @private
1503
1543
  * @param {string} path context path
1504
- * @param {function((WebpackError | null)=, (ContextTimestampAndHash | null)=): void} callback callback function
1544
+ * @param {(err?: WebpackError | null, contextTimestampAndHash?: ContextTimestampAndHash | null) => void} callback callback function
1505
1545
  * @returns {void}
1506
1546
  */
1507
1547
  _getUnresolvedContextTsh(path, callback) {
@@ -1541,31 +1581,32 @@ class FileSystemInfo {
1541
1581
  /**
1542
1582
  * @param {string} context context directory
1543
1583
  * @param {Iterable<string>} deps dependencies
1544
- * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function
1584
+ * @param {(err?: Error | null, resolveBuildDependenciesResult?: ResolveBuildDependenciesResult) => void} callback callback function
1545
1585
  * @returns {void}
1546
1586
  */
1547
1587
  resolveBuildDependencies(context, deps, callback) {
1548
1588
  const { resolveContext, resolveEsm, resolveCjs, resolveCjsAsChild } =
1549
1589
  this._createBuildDependenciesResolvers();
1550
1590
 
1551
- /** @type {Set<string>} */
1591
+ /** @type {Files} */
1552
1592
  const files = new Set();
1553
- /** @type {Set<string>} */
1593
+ /** @type {Symlinks} */
1554
1594
  const fileSymlinks = new Set();
1555
- /** @type {Set<string>} */
1595
+ /** @type {Directories} */
1556
1596
  const directories = new Set();
1557
- /** @type {Set<string>} */
1597
+ /** @type {Symlinks} */
1558
1598
  const directorySymlinks = new Set();
1559
- /** @type {Set<string>} */
1599
+ /** @type {Missing} */
1560
1600
  const missing = new Set();
1561
- /** @type {Set<string>} */
1601
+ /** @type {ResolveDependencies["files"]} */
1562
1602
  const resolveFiles = new Set();
1563
- /** @type {Set<string>} */
1603
+ /** @type {ResolveDependencies["directories"]} */
1564
1604
  const resolveDirectories = new Set();
1565
- /** @type {Set<string>} */
1605
+ /** @type {ResolveDependencies["missing"]} */
1566
1606
  const resolveMissing = new Set();
1567
- /** @type {Map<string, string | false | undefined>} */
1607
+ /** @type {ResolveResults} */
1568
1608
  const resolveResults = new Map();
1609
+ /** @type {Set<string>} */
1569
1610
  const invalidResolveResults = new Set();
1570
1611
  const resolverContext = {
1571
1612
  fileDependencies: resolveFiles,
@@ -1576,22 +1617,18 @@ class FileSystemInfo {
1576
1617
  * @param {undefined | boolean | string} expected expected result
1577
1618
  * @returns {string} expected result
1578
1619
  */
1579
- const expectedToString = expected =>
1620
+ const expectedToString = (expected) =>
1580
1621
  expected ? ` (expected ${expected})` : "";
1581
1622
  /** @typedef {{ type: JobType, context: string | undefined, path: string, issuer: Job | undefined, expected: undefined | boolean | string }} Job */
1582
1623
 
1583
1624
  /**
1584
1625
  * @param {Job} job job
1585
- * @returns {`resolve commonjs file ${string}${string}`|`resolve esm file ${string}${string}`|`resolve esm ${string}${string}`|`resolve directory ${string}`|`file ${string}`|`unknown ${string} ${string}`|`resolve commonjs ${string}${string}`|`directory ${string}`|`file dependencies ${string}`|`directory dependencies ${string}`} result
1626
+ * @returns {string} result
1586
1627
  */
1587
- const jobToString = job => {
1628
+ const jobToString = (job) => {
1588
1629
  switch (job.type) {
1589
- case RBDT_RESOLVE_CJS:
1590
- return `resolve commonjs ${job.path}${expectedToString(
1591
- job.expected
1592
- )}`;
1593
- case RBDT_RESOLVE_ESM:
1594
- return `resolve esm ${job.path}${expectedToString(job.expected)}`;
1630
+ case RBDT_RESOLVE_FILE:
1631
+ return `resolve file ${job.path}${expectedToString(job.expected)}`;
1595
1632
  case RBDT_RESOLVE_DIRECTORY:
1596
1633
  return `resolve directory ${job.path}`;
1597
1634
  case RBDT_RESOLVE_CJS_FILE:
@@ -1617,7 +1654,7 @@ class FileSystemInfo {
1617
1654
  * @param {Job} job job
1618
1655
  * @returns {string} string value
1619
1656
  */
1620
- const pathToString = job => {
1657
+ const pathToString = (job) => {
1621
1658
  let result = ` at ${jobToString(job)}`;
1622
1659
  /** @type {Job | undefined} */
1623
1660
  (job) = job.issuer;
@@ -1631,9 +1668,9 @@ class FileSystemInfo {
1631
1668
  processAsyncTree(
1632
1669
  Array.from(
1633
1670
  deps,
1634
- dep =>
1671
+ (dep) =>
1635
1672
  /** @type {Job} */ ({
1636
- type: RBDT_RESOLVE_CJS,
1673
+ type: RBDT_RESOLVE_INITIAL,
1637
1674
  context,
1638
1675
  path: dep,
1639
1676
  expected: undefined,
@@ -1647,7 +1684,7 @@ class FileSystemInfo {
1647
1684
  * @param {string} path path
1648
1685
  * @returns {void}
1649
1686
  */
1650
- const resolveDirectory = path => {
1687
+ const resolveDirectory = (path) => {
1651
1688
  const key = `d\n${context}\n${path}`;
1652
1689
  if (resolveResults.has(key)) {
1653
1690
  return callback();
@@ -1737,27 +1774,23 @@ class FileSystemInfo {
1737
1774
  }
1738
1775
  );
1739
1776
  };
1740
- switch (type) {
1741
- case RBDT_RESOLVE_CJS: {
1742
- const isDirectory = /[\\/]$/.test(path);
1743
- if (isDirectory) {
1744
- resolveDirectory(path.slice(0, -1));
1745
- } else {
1746
- resolveFile(path, "f", resolveCjs);
1747
- }
1748
- break;
1749
- }
1750
- case RBDT_RESOLVE_ESM: {
1751
- const isDirectory = /[\\/]$/.test(path);
1752
- if (isDirectory) {
1753
- resolveDirectory(path.slice(0, -1));
1754
- } else {
1755
- resolveFile(path);
1756
- }
1777
+ const resolvedType =
1778
+ type === RBDT_RESOLVE_INITIAL
1779
+ ? /[\\/]$/.test(path)
1780
+ ? RBDT_RESOLVE_DIRECTORY
1781
+ : RBDT_RESOLVE_FILE
1782
+ : type;
1783
+ switch (resolvedType) {
1784
+ case RBDT_RESOLVE_FILE: {
1785
+ resolveFile(
1786
+ path,
1787
+ "f",
1788
+ /\.mjs$/.test(path) ? resolveEsm : resolveCjs
1789
+ );
1757
1790
  break;
1758
1791
  }
1759
1792
  case RBDT_RESOLVE_DIRECTORY: {
1760
- resolveDirectory(path);
1793
+ resolveDirectory(RBDT_RESOLVE_INITIAL ? path.slice(0, -1) : path);
1761
1794
  break;
1762
1795
  }
1763
1796
  case RBDT_RESOLVE_CJS_FILE: {
@@ -1835,7 +1868,13 @@ class FileSystemInfo {
1835
1868
  // Check commonjs cache for the module
1836
1869
  /** @type {NodeModule | undefined} */
1837
1870
  const module = require.cache[path];
1838
- if (module && Array.isArray(module.children)) {
1871
+ if (
1872
+ module &&
1873
+ Array.isArray(module.children) &&
1874
+ // https://github.com/nodejs/node/issues/59868
1875
+ // Force use `es-module-lexer` for mjs
1876
+ !/\.mjs$/.test(path)
1877
+ ) {
1839
1878
  children: for (const child of module.children) {
1840
1879
  const childPath = child.filename;
1841
1880
  if (childPath) {
@@ -1868,8 +1907,9 @@ class FileSystemInfo {
1868
1907
  });
1869
1908
  }
1870
1909
  let request = subPath.replace(/\\/g, "/");
1871
- if (request.endsWith(".js"))
1910
+ if (request.endsWith(".js")) {
1872
1911
  request = request.slice(0, -3);
1912
+ }
1873
1913
  push({
1874
1914
  type: RBDT_RESOLVE_CJS_FILE_AS_CHILD,
1875
1915
  context,
@@ -1904,7 +1944,9 @@ class FileSystemInfo {
1904
1944
  );
1905
1945
  this._warnAboutExperimentalEsmTracking = true;
1906
1946
  }
1907
- const lexer = require("es-module-lexer");
1947
+
1948
+ const lexer = getEsModuleLexer();
1949
+
1908
1950
  lexer.init.then(() => {
1909
1951
  this.fs.readFile(path, (err, content) => {
1910
1952
  if (err) return callback(err);
@@ -1912,26 +1954,29 @@ class FileSystemInfo {
1912
1954
  const context = dirname(this.fs, path);
1913
1955
  const source = /** @type {Buffer} */ (content).toString();
1914
1956
  const [imports] = lexer.parse(source);
1957
+ const added = new Set();
1915
1958
  for (const imp of imports) {
1916
1959
  try {
1917
1960
  let dependency;
1918
1961
  if (imp.d === -1) {
1919
1962
  // import ... from "..."
1920
1963
  dependency = parseString(
1921
- source.substring(imp.s - 1, imp.e + 1)
1964
+ source.slice(imp.s - 1, imp.e + 1)
1922
1965
  );
1923
1966
  } else if (imp.d > -1) {
1924
1967
  // import()
1925
- const expr = source.substring(imp.s, imp.e).trim();
1968
+ const expr = source.slice(imp.s, imp.e).trim();
1926
1969
  dependency = parseString(expr);
1927
1970
  } else {
1928
1971
  // e.g. import.meta
1929
1972
  continue;
1930
1973
  }
1931
1974
 
1932
- // we should not track Node.js build dependencies
1975
+ // We should not track Node.js build dependencies
1933
1976
  if (dependency.startsWith("node:")) continue;
1934
1977
  if (builtinModules.has(dependency)) continue;
1978
+ // Avoid extra jobs for identical imports
1979
+ if (added.has(dependency)) continue;
1935
1980
 
1936
1981
  push({
1937
1982
  type: RBDT_RESOLVE_ESM_FILE,
@@ -1940,9 +1985,10 @@ class FileSystemInfo {
1940
1985
  expected: imp.d > -1 ? false : undefined,
1941
1986
  issuer: job
1942
1987
  });
1988
+ added.add(dependency);
1943
1989
  } catch (err1) {
1944
1990
  logger.warn(
1945
- `Parsing of ${path} for build dependencies failed at 'import(${source.substring(
1991
+ `Parsing of ${path} for build dependencies failed at 'import(${source.slice(
1946
1992
  imp.s,
1947
1993
  imp.e
1948
1994
  )})'.\n` +
@@ -2000,7 +2046,8 @@ class FileSystemInfo {
2000
2046
  let packageData;
2001
2047
  try {
2002
2048
  packageData = JSON.parse(
2003
- /** @type {Buffer} */ (content).toString("utf-8")
2049
+ /** @type {Buffer} */
2050
+ (content).toString("utf8")
2004
2051
  );
2005
2052
  } catch (parseErr) {
2006
2053
  return callback(/** @type {Error} */ (parseErr));
@@ -2038,7 +2085,7 @@ class FileSystemInfo {
2038
2085
  }
2039
2086
  }
2040
2087
  },
2041
- err => {
2088
+ (err) => {
2042
2089
  if (err) return callback(err);
2043
2090
  for (const l of fileSymlinks) files.delete(l);
2044
2091
  for (const l of directorySymlinks) directories.delete(l);
@@ -2059,8 +2106,8 @@ class FileSystemInfo {
2059
2106
  }
2060
2107
 
2061
2108
  /**
2062
- * @param {Map<string, string | false>} resolveResults results from resolving
2063
- * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way
2109
+ * @param {ResolveResults} resolveResults results from resolving
2110
+ * @param {(err?: Error | null, result?: boolean) => void} callback callback with true when resolveResults resolve the same way
2064
2111
  * @returns {void}
2065
2112
  */
2066
2113
  checkResolveResultsValid(resolveResults, callback) {
@@ -2074,8 +2121,9 @@ class FileSystemInfo {
2074
2121
  switch (type) {
2075
2122
  case "d":
2076
2123
  resolveContext(context, path, {}, (err, _, result) => {
2077
- if (expectedResult === false)
2124
+ if (expectedResult === false) {
2078
2125
  return callback(err ? undefined : INVALID);
2126
+ }
2079
2127
  if (err) return callback(err);
2080
2128
  const resultPath = /** @type {ResolveRequest} */ (result).path;
2081
2129
  if (resultPath !== expectedResult) return callback(INVALID);
@@ -2084,8 +2132,9 @@ class FileSystemInfo {
2084
2132
  break;
2085
2133
  case "f":
2086
2134
  resolveCjs(context, path, {}, (err, _, result) => {
2087
- if (expectedResult === false)
2135
+ if (expectedResult === false) {
2088
2136
  return callback(err ? undefined : INVALID);
2137
+ }
2089
2138
  if (err) return callback(err);
2090
2139
  const resultPath = /** @type {ResolveRequest} */ (result).path;
2091
2140
  if (resultPath !== expectedResult) return callback(INVALID);
@@ -2094,8 +2143,9 @@ class FileSystemInfo {
2094
2143
  break;
2095
2144
  case "c":
2096
2145
  resolveCjsAsChild(context, path, {}, (err, _, result) => {
2097
- if (expectedResult === false)
2146
+ if (expectedResult === false) {
2098
2147
  return callback(err ? undefined : INVALID);
2148
+ }
2099
2149
  if (err) return callback(err);
2100
2150
  const resultPath = /** @type {ResolveRequest} */ (result).path;
2101
2151
  if (resultPath !== expectedResult) return callback(INVALID);
@@ -2104,8 +2154,9 @@ class FileSystemInfo {
2104
2154
  break;
2105
2155
  case "e":
2106
2156
  resolveEsm(context, path, {}, (err, _, result) => {
2107
- if (expectedResult === false)
2157
+ if (expectedResult === false) {
2108
2158
  return callback(err ? undefined : INVALID);
2159
+ }
2109
2160
  if (err) return callback(err);
2110
2161
  const resultPath = /** @type {ResolveRequest} */ (result).path;
2111
2162
  if (resultPath !== expectedResult) return callback(INVALID);
@@ -2121,7 +2172,7 @@ class FileSystemInfo {
2121
2172
  * @param {Error | typeof INVALID=} err error or invalid flag
2122
2173
  * @returns {void}
2123
2174
  */
2124
- err => {
2175
+ (err) => {
2125
2176
  if (err === INVALID) {
2126
2177
  return callback(null, false);
2127
2178
  }
@@ -2135,11 +2186,11 @@ class FileSystemInfo {
2135
2186
 
2136
2187
  /**
2137
2188
  * @param {number | null | undefined} startTime when processing the files has started
2138
- * @param {Iterable<string> | null} files all files
2139
- * @param {Iterable<string> | null} directories all directories
2140
- * @param {Iterable<string> | null} missing all missing files or directories
2189
+ * @param {Iterable<string> | null | undefined} files all files
2190
+ * @param {Iterable<string> | null | undefined} directories all directories
2191
+ * @param {Iterable<string> | null | undefined} missing all missing files or directories
2141
2192
  * @param {SnapshotOptions | null | undefined} options options object (for future extensions)
2142
- * @param {function(WebpackError | null, Snapshot | null): void} callback callback function
2193
+ * @param {(err: WebpackError | null, snapshot: Snapshot | null) => void} callback callback function
2143
2194
  * @returns {void}
2144
2195
  */
2145
2196
  createSnapshot(startTime, files, directories, missing, options, callback) {
@@ -2234,7 +2285,7 @@ class FileSystemInfo {
2234
2285
  };
2235
2286
  /**
2236
2287
  * @param {string} path path
2237
- * @param {Set<string>} managedSet managed set
2288
+ * @param {ManagedFiles} managedSet managed set
2238
2289
  * @returns {boolean} true when managed
2239
2290
  */
2240
2291
  const checkManaged = (path, managedSet) => {
@@ -2285,6 +2336,7 @@ class FileSystemInfo {
2285
2336
  * @returns {Set<string>} result
2286
2337
  */
2287
2338
  const captureNonManaged = (items, managedSet) => {
2339
+ /** @type {Set<string>} */
2288
2340
  const capturedItems = new Set();
2289
2341
  for (const path of items) {
2290
2342
  if (!checkManaged(path, managedSet)) capturedItems.add(path);
@@ -2292,9 +2344,12 @@ class FileSystemInfo {
2292
2344
  return capturedItems;
2293
2345
  };
2294
2346
  /**
2295
- * @param {Set<string>} capturedFiles captured files
2347
+ * @param {ManagedFiles} capturedFiles captured files
2296
2348
  */
2297
- const processCapturedFiles = capturedFiles => {
2349
+ const processCapturedFiles = (capturedFiles) => {
2350
+ if (capturedFiles.size === 0) {
2351
+ return;
2352
+ }
2298
2353
  switch (mode) {
2299
2354
  case 3:
2300
2355
  this._fileTshsOptimization.optimize(snapshot, capturedFiles);
@@ -2380,9 +2435,12 @@ class FileSystemInfo {
2380
2435
  processCapturedFiles(captureNonManaged(files, managedFiles));
2381
2436
  }
2382
2437
  /**
2383
- * @param {Set<string>} capturedDirectories captured directories
2438
+ * @param {ManagedContexts} capturedDirectories captured directories
2384
2439
  */
2385
- const processCapturedDirectories = capturedDirectories => {
2440
+ const processCapturedDirectories = (capturedDirectories) => {
2441
+ if (capturedDirectories.size === 0) {
2442
+ return;
2443
+ }
2386
2444
  switch (mode) {
2387
2445
  case 3:
2388
2446
  this._contextTshsOptimization.optimize(snapshot, capturedDirectories);
@@ -2485,7 +2543,7 @@ class FileSystemInfo {
2485
2543
  jobs++;
2486
2544
  /**
2487
2545
  * @param {(Error | null)=} err error
2488
- * @param {(FileSystemInfoEntry | "ignore" | null)=} entry entry
2546
+ * @param {FileTimestamp=} entry entry
2489
2547
  * @returns {void}
2490
2548
  */
2491
2549
  const callback = (err, entry) => {
@@ -2525,9 +2583,12 @@ class FileSystemInfo {
2525
2583
  );
2526
2584
  }
2527
2585
  /**
2528
- * @param {Set<string>} capturedMissing captured missing
2586
+ * @param {ManagedMissing} capturedMissing captured missing
2529
2587
  */
2530
- const processCapturedMissing = capturedMissing => {
2588
+ const processCapturedMissing = (capturedMissing) => {
2589
+ if (capturedMissing.size === 0) {
2590
+ return;
2591
+ }
2531
2592
  this._missingExistenceOptimization.optimize(snapshot, capturedMissing);
2532
2593
  for (const path of capturedMissing) {
2533
2594
  const cache = this._fileTimestamps.get(path);
@@ -2588,7 +2649,7 @@ class FileSystemInfo {
2588
2649
  // Fallback to normal snapshotting
2589
2650
  /**
2590
2651
  * @param {Set<string>} set set
2591
- * @param {function(Set<string>): void} fn fn
2652
+ * @param {(set: Set<string>) => void} fn fn
2592
2653
  */
2593
2654
  const process = (set, fn) => {
2594
2655
  if (set.size === 0) return;
@@ -2697,7 +2758,7 @@ class FileSystemInfo {
2697
2758
 
2698
2759
  /**
2699
2760
  * @param {Snapshot} snapshot the snapshot made
2700
- * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2761
+ * @param {CheckSnapshotValidCallback} callback callback function
2701
2762
  * @returns {void}
2702
2763
  */
2703
2764
  checkSnapshotValid(snapshot, callback) {
@@ -2716,8 +2777,9 @@ class FileSystemInfo {
2716
2777
  }
2717
2778
 
2718
2779
  /**
2780
+ * @private
2719
2781
  * @param {Snapshot} snapshot the snapshot made
2720
- * @param {function((WebpackError | null)=, boolean=): void} callback callback function
2782
+ * @param {CheckSnapshotValidCallback} callback callback function
2721
2783
  * @returns {void}
2722
2784
  */
2723
2785
  _checkSnapshotValidNoCache(snapshot, callback) {
@@ -3019,7 +3081,7 @@ class FileSystemInfo {
3019
3081
  jobs++;
3020
3082
  /**
3021
3083
  * @param {(WebpackError | null)=} err error
3022
- * @param {(ResolvedContextFileSystemInfoEntry | "ignore" | null)=} entry entry
3084
+ * @param {ResolvedContextTimestamp=} entry entry
3023
3085
  * @returns {void}
3024
3086
  */
3025
3087
  const callback = (err, entry) => {
@@ -3123,7 +3185,7 @@ class FileSystemInfo {
3123
3185
  jobs++;
3124
3186
  /**
3125
3187
  * @param {(WebpackError | null)=} err error
3126
- * @param {(ResolvedContextFileSystemInfoEntry | "ignore" | null)=} entry entry
3188
+ * @param {ResolvedContextTimestamp=} entry entry
3127
3189
  * @returns {void}
3128
3190
  */
3129
3191
  const callback = (err, entry) => {
@@ -3222,8 +3284,8 @@ class FileSystemInfo {
3222
3284
  }
3223
3285
 
3224
3286
  /**
3225
- * @type {Processor<string, FileSystemInfoEntry>}
3226
3287
  * @private
3288
+ * @type {Processor<string, FileSystemInfoEntry>}
3227
3289
  */
3228
3290
  _readFileTimestamp(path, callback) {
3229
3291
  this.fs.stat(path, (err, _stat) => {
@@ -3261,8 +3323,8 @@ class FileSystemInfo {
3261
3323
  }
3262
3324
 
3263
3325
  /**
3264
- * @type {Processor<string, string>}
3265
3326
  * @private
3327
+ * @type {Processor<string, string>}
3266
3328
  */
3267
3329
  _readFileHash(path, callback) {
3268
3330
  this.fs.readFile(path, (err, content) => {
@@ -3288,7 +3350,7 @@ class FileSystemInfo {
3288
3350
 
3289
3351
  hash.update(/** @type {string | Buffer} */ (content));
3290
3352
 
3291
- const digest = /** @type {string} */ (hash.digest("hex"));
3353
+ const digest = hash.digest("hex");
3292
3354
 
3293
3355
  this._fileHashes.set(path, digest);
3294
3356
 
@@ -3297,16 +3359,16 @@ class FileSystemInfo {
3297
3359
  }
3298
3360
 
3299
3361
  /**
3300
- * @param {string} path path
3301
- * @param {function(WebpackError | null, TimestampAndHash=) : void} callback callback
3302
3362
  * @private
3363
+ * @param {string} path path
3364
+ * @param {(err: WebpackError | null, timestampAndHash?: TimestampAndHash | string) => void} callback callback
3303
3365
  */
3304
3366
  _getFileTimestampAndHash(path, callback) {
3305
3367
  /**
3306
3368
  * @param {string} hash hash
3307
3369
  * @returns {void}
3308
3370
  */
3309
- const continueWithHash = hash => {
3371
+ const continueWithHash = (hash) => {
3310
3372
  const cache = this._fileTimestamps.get(path);
3311
3373
  if (cache !== undefined) {
3312
3374
  if (cache !== "ignore") {
@@ -3319,7 +3381,7 @@ class FileSystemInfo {
3319
3381
  return callback(null, result);
3320
3382
  }
3321
3383
  this._fileTshs.set(path, hash);
3322
- return callback(null, /** @type {TODO} */ (hash));
3384
+ return callback(null, hash);
3323
3385
  }
3324
3386
  this.fileTimestampQueue.add(path, (err, entry) => {
3325
3387
  if (err) {
@@ -3349,17 +3411,18 @@ class FileSystemInfo {
3349
3411
  }
3350
3412
 
3351
3413
  /**
3414
+ * @private
3352
3415
  * @template T
3353
3416
  * @template ItemType
3354
3417
  * @param {object} options options
3355
3418
  * @param {string} options.path path
3356
- * @param {function(string): ItemType} options.fromImmutablePath called when context item is an immutable path
3357
- * @param {function(string): ItemType} options.fromManagedItem called when context item is a managed path
3358
- * @param {function(string, string, function((WebpackError | null)=, ItemType=): void): void} options.fromSymlink called when context item is a symlink
3359
- * @param {function(string, IStats, function((WebpackError | null)=, (ItemType | null)=): void): void} options.fromFile called when context item is a file
3360
- * @param {function(string, IStats, function((WebpackError | null)=, ItemType=): void): void} options.fromDirectory called when context item is a directory
3361
- * @param {function(string[], ItemType[]): T} options.reduce called from all context items
3362
- * @param {function((Error | null)=, (T | null)=): void} callback callback
3419
+ * @param {(value: string) => ItemType} options.fromImmutablePath called when context item is an immutable path
3420
+ * @param {(value: string) => ItemType} options.fromManagedItem called when context item is a managed path
3421
+ * @param {(value: string, result: string, callback: (err?: WebpackError | null, itemType?: ItemType) => void) => void} options.fromSymlink called when context item is a symlink
3422
+ * @param {(value: string, stats: IStats, callback: (err?: WebpackError | null, itemType?: ItemType | null) => void) => void} options.fromFile called when context item is a file
3423
+ * @param {(value: string, stats: IStats, callback: (err?: WebpackError | null, itemType?: ItemType) => void) => void} options.fromDirectory called when context item is a directory
3424
+ * @param {(arr: string[], arr1: ItemType[]) => T} options.reduce called from all context items
3425
+ * @param {(err?: Error | null, result?: T | null) => void} callback callback
3363
3426
  */
3364
3427
  _readContext(
3365
3428
  {
@@ -3381,8 +3444,8 @@ class FileSystemInfo {
3381
3444
  return callback(err);
3382
3445
  }
3383
3446
  const files = /** @type {string[]} */ (_files)
3384
- .map(file => file.normalize("NFC"))
3385
- .filter(file => !/^\./.test(file))
3447
+ .map((file) => file.normalize("NFC"))
3448
+ .filter((file) => !/^\./.test(file))
3386
3449
  .sort();
3387
3450
  asyncLib.map(
3388
3451
  files,
@@ -3460,8 +3523,8 @@ class FileSystemInfo {
3460
3523
  }
3461
3524
 
3462
3525
  /**
3463
- * @type {Processor<string, ContextFileSystemInfoEntry>}
3464
3526
  * @private
3527
+ * @type {Processor<string, ContextFileSystemInfoEntry>}
3465
3528
  */
3466
3529
  _readContextTimestamp(path, callback) {
3467
3530
  this._readContext(
@@ -3470,7 +3533,7 @@ class FileSystemInfo {
3470
3533
  fromImmutablePath: () =>
3471
3534
  /** @type {ContextFileSystemInfoEntry | FileSystemInfoEntry | "ignore" | null} */
3472
3535
  (null),
3473
- fromManagedItem: info => ({
3536
+ fromManagedItem: (info) => ({
3474
3537
  safeTime: 0,
3475
3538
  timestampHash: info
3476
3539
  }),
@@ -3487,8 +3550,9 @@ class FileSystemInfo {
3487
3550
  fromFile: (file, stat, callback) => {
3488
3551
  // Prefer the cached value over our new stat to report consistent results
3489
3552
  const cache = this._fileTimestamps.get(file);
3490
- if (cache !== undefined)
3553
+ if (cache !== undefined) {
3491
3554
  return callback(null, cache === "ignore" ? null : cache);
3555
+ }
3492
3556
 
3493
3557
  const mtime = Number(stat.mtime);
3494
3558
 
@@ -3554,7 +3618,7 @@ class FileSystemInfo {
3554
3618
  }
3555
3619
  }
3556
3620
 
3557
- const digest = /** @type {string} */ (hash.digest("hex"));
3621
+ const digest = hash.digest("hex");
3558
3622
  /** @type {ContextFileSystemInfoEntry} */
3559
3623
  const result = {
3560
3624
  safeTime,
@@ -3575,8 +3639,9 @@ class FileSystemInfo {
3575
3639
  }
3576
3640
 
3577
3641
  /**
3642
+ * @private
3578
3643
  * @param {ContextFileSystemInfoEntry} entry entry
3579
- * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback
3644
+ * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback
3580
3645
  * @returns {void}
3581
3646
  */
3582
3647
  _resolveContextTimestamp(entry, callback) {
@@ -3601,7 +3666,7 @@ class FileSystemInfo {
3601
3666
  callback();
3602
3667
  });
3603
3668
  },
3604
- err => {
3669
+ (err) => {
3605
3670
  if (err) return callback(/** @type {WebpackError} */ (err));
3606
3671
  const hash = createHash(this._hashFunction);
3607
3672
  hash.update(/** @type {string} */ (entry.timestampHash));
@@ -3616,7 +3681,7 @@ class FileSystemInfo {
3616
3681
  null,
3617
3682
  (entry.resolved = {
3618
3683
  safeTime,
3619
- timestampHash: /** @type {string} */ (hash.digest("hex"))
3684
+ timestampHash: hash.digest("hex")
3620
3685
  })
3621
3686
  );
3622
3687
  }
@@ -3624,15 +3689,15 @@ class FileSystemInfo {
3624
3689
  }
3625
3690
 
3626
3691
  /**
3627
- * @type {Processor<string, ContextHash>}
3628
3692
  * @private
3693
+ * @type {Processor<string, ContextHash>}
3629
3694
  */
3630
3695
  _readContextHash(path, callback) {
3631
3696
  this._readContext(
3632
3697
  {
3633
3698
  path,
3634
3699
  fromImmutablePath: () => /** @type {ContextHash | ""} */ (""),
3635
- fromManagedItem: info => info || "",
3700
+ fromManagedItem: (info) => info || "",
3636
3701
  fromSymlink: (file, target, callback) => {
3637
3702
  callback(
3638
3703
  null,
@@ -3678,7 +3743,7 @@ class FileSystemInfo {
3678
3743
 
3679
3744
  /** @type {ContextHash} */
3680
3745
  const result = {
3681
- hash: /** @type {string} */ (hash.digest("hex"))
3746
+ hash: hash.digest("hex")
3682
3747
  };
3683
3748
  if (symlinks) result.symlinks = symlinks;
3684
3749
  return result;
@@ -3694,8 +3759,9 @@ class FileSystemInfo {
3694
3759
  }
3695
3760
 
3696
3761
  /**
3762
+ * @private
3697
3763
  * @param {ContextHash} entry context hash
3698
- * @param {function(WebpackError | null, string=): void} callback callback
3764
+ * @param {(err: WebpackError | null, contextHash?: string) => void} callback callback
3699
3765
  * @returns {void}
3700
3766
  */
3701
3767
  _resolveContextHash(entry, callback) {
@@ -3716,7 +3782,7 @@ class FileSystemInfo {
3716
3782
  callback();
3717
3783
  });
3718
3784
  },
3719
- err => {
3785
+ (err) => {
3720
3786
  if (err) return callback(/** @type {WebpackError} */ (err));
3721
3787
  const hash = createHash(this._hashFunction);
3722
3788
  hash.update(entry.hash);
@@ -3724,21 +3790,18 @@ class FileSystemInfo {
3724
3790
  for (const h of hashes) {
3725
3791
  hash.update(h);
3726
3792
  }
3727
- callback(
3728
- null,
3729
- (entry.resolved = /** @type {string} */ (hash.digest("hex")))
3730
- );
3793
+ callback(null, (entry.resolved = hash.digest("hex")));
3731
3794
  }
3732
3795
  );
3733
3796
  }
3734
3797
 
3735
3798
  /**
3736
- * @type {Processor<string, ContextTimestampAndHash>}
3737
3799
  * @private
3800
+ * @type {Processor<string, ContextTimestampAndHash>}
3738
3801
  */
3739
3802
  _readContextTimestampAndHash(path, callback) {
3740
3803
  /**
3741
- * @param {ContextFileSystemInfoEntry | "ignore" | null} timestamp timestamp
3804
+ * @param {ContextTimestamp} timestamp timestamp
3742
3805
  * @param {ContextHash} hash hash
3743
3806
  */
3744
3807
  const finalize = (timestamp, hash) => {
@@ -3773,22 +3836,20 @@ class FileSystemInfo {
3773
3836
  {
3774
3837
  path,
3775
3838
  fromImmutablePath: () =>
3776
- /** @type {ContextTimestampAndHash | null} */ (null),
3777
- fromManagedItem: info => ({
3839
+ /** @type {ContextTimestampAndHash | Omit<ContextTimestampAndHash, "safeTime"> | string | null} */ (
3840
+ null
3841
+ ),
3842
+ fromManagedItem: (info) => ({
3778
3843
  safeTime: 0,
3779
3844
  timestampHash: info,
3780
3845
  hash: info || ""
3781
3846
  }),
3782
3847
  fromSymlink: (file, target, callback) => {
3783
- callback(
3784
- null,
3785
- /** @type {TODO} */
3786
- ({
3787
- timestampHash: target,
3788
- hash: target,
3789
- symlinks: new Set([target])
3790
- })
3791
- );
3848
+ callback(null, {
3849
+ timestampHash: target,
3850
+ hash: target,
3851
+ symlinks: new Set([target])
3852
+ });
3792
3853
  },
3793
3854
  fromFile: (file, stat, callback) => {
3794
3855
  this._getFileTimestampAndHash(file, callback);
@@ -3846,8 +3907,8 @@ class FileSystemInfo {
3846
3907
  /** @type {ContextTimestampAndHash} */
3847
3908
  const result = {
3848
3909
  safeTime,
3849
- timestampHash: /** @type {string} */ (tsHash.digest("hex")),
3850
- hash: /** @type {string} */ (hash.digest("hex"))
3910
+ timestampHash: tsHash.digest("hex"),
3911
+ hash: hash.digest("hex")
3851
3912
  };
3852
3913
  if (symlinks) result.symlinks = symlinks;
3853
3914
  return result;
@@ -3864,6 +3925,7 @@ class FileSystemInfo {
3864
3925
  }
3865
3926
 
3866
3927
  /**
3928
+ * @private
3867
3929
  * @param {ContextTimestampAndHash} entry entry
3868
3930
  * @param {ProcessorCallback<ResolvedContextTimestampAndHash>} callback callback
3869
3931
  * @returns {void}
@@ -3893,7 +3955,7 @@ class FileSystemInfo {
3893
3955
  callback();
3894
3956
  });
3895
3957
  },
3896
- err => {
3958
+ (err) => {
3897
3959
  if (err) return callback(/** @type {WebpackError} */ (err));
3898
3960
  const hash = createHash(this._hashFunction);
3899
3961
  const tsHash = createHash(this._hashFunction);
@@ -3914,8 +3976,8 @@ class FileSystemInfo {
3914
3976
  null,
3915
3977
  (entry.resolved = {
3916
3978
  safeTime,
3917
- timestampHash: /** @type {string} */ (tsHash.digest("hex")),
3918
- hash: /** @type {string} */ (hash.digest("hex"))
3979
+ timestampHash: tsHash.digest("hex"),
3980
+ hash: hash.digest("hex")
3919
3981
  })
3920
3982
  );
3921
3983
  }
@@ -3923,8 +3985,8 @@ class FileSystemInfo {
3923
3985
  }
3924
3986
 
3925
3987
  /**
3926
- * @type {Processor<string, Set<string>>}
3927
3988
  * @private
3989
+ * @type {Processor<string, Set<string>>}
3928
3990
  */
3929
3991
  _getManagedItemDirectoryInfo(path, callback) {
3930
3992
  this.fs.readdir(path, (err, elements) => {
@@ -3935,7 +3997,7 @@ class FileSystemInfo {
3935
3997
  return callback(/** @type {WebpackError} */ (err));
3936
3998
  }
3937
3999
  const set = new Set(
3938
- /** @type {string[]} */ (elements).map(element =>
4000
+ /** @type {string[]} */ (elements).map((element) =>
3939
4001
  join(this.fs, path, element)
3940
4002
  )
3941
4003
  );
@@ -3944,8 +4006,8 @@ class FileSystemInfo {
3944
4006
  }
3945
4007
 
3946
4008
  /**
3947
- * @type {Processor<string, string>}
3948
4009
  * @private
4010
+ * @type {Processor<string, string>}
3949
4011
  */
3950
4012
  _getManagedItemInfo(path, callback) {
3951
4013
  const dir = dirname(this.fs, path);
@@ -3998,7 +4060,7 @@ class FileSystemInfo {
3998
4060
  }
3999
4061
  let data;
4000
4062
  try {
4001
- data = JSON.parse(/** @type {Buffer} */ (content).toString("utf-8"));
4063
+ data = JSON.parse(/** @type {Buffer} */ (content).toString("utf8"));
4002
4064
  } catch (parseErr) {
4003
4065
  return callback(/** @type {WebpackError} */ (parseErr));
4004
4066
  }
@@ -4017,8 +4079,10 @@ class FileSystemInfo {
4017
4079
  }
4018
4080
 
4019
4081
  getDeprecatedFileTimestamps() {
4020
- if (this._cachedDeprecatedFileTimestamps !== undefined)
4082
+ if (this._cachedDeprecatedFileTimestamps !== undefined) {
4021
4083
  return this._cachedDeprecatedFileTimestamps;
4084
+ }
4085
+ /** @type {Map<string, number | null>} */
4022
4086
  const map = new Map();
4023
4087
  for (const [path, info] of this._fileTimestamps) {
4024
4088
  if (info) map.set(path, typeof info === "object" ? info.safeTime : null);
@@ -4027,8 +4091,10 @@ class FileSystemInfo {
4027
4091
  }
4028
4092
 
4029
4093
  getDeprecatedContextTimestamps() {
4030
- if (this._cachedDeprecatedContextTimestamps !== undefined)
4094
+ if (this._cachedDeprecatedContextTimestamps !== undefined) {
4031
4095
  return this._cachedDeprecatedContextTimestamps;
4096
+ }
4097
+ /** @type {Map<string, number | null>} */
4032
4098
  const map = new Map();
4033
4099
  for (const [path, info] of this._contextTimestamps) {
4034
4100
  if (info) map.set(path, typeof info === "object" ? info.safeTime : null);