@ohos-ports/rspack-core 1.7.11-beta.1 → 2.2.9-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/README.md +11 -1
  2. package/compiled/@rspack/lite-tapable/dist/index.d.ts +190 -0
  3. package/compiled/@rspack/lite-tapable/license +22 -0
  4. package/compiled/@rspack/lite-tapable/package.json +1 -0
  5. package/compiled/@swc/types/index.d.ts +161 -11
  6. package/compiled/@swc/types/package.json +1 -1
  7. package/compiled/connect-next/index.d.ts +57 -0
  8. package/compiled/connect-next/license +26 -0
  9. package/compiled/connect-next/package.json +1 -0
  10. package/compiled/http-proxy-middleware/index.d.ts +455 -0
  11. package/compiled/{browserslist-load-config → http-proxy-middleware}/license +3 -2
  12. package/compiled/http-proxy-middleware/package.json +1 -0
  13. package/compiled/open/index.d.ts +161 -0
  14. package/compiled/open/package.json +1 -0
  15. package/compiled/tinypool/README.md +196 -2
  16. package/compiled/tinypool/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
  17. package/compiled/tinypool/dist/entry/worker.js +1 -1
  18. package/compiled/tinypool/dist/index.d.ts +9 -4
  19. package/compiled/tinypool/dist/index.js +17 -53
  20. package/compiled/tinypool/package.json +22 -6
  21. package/compiled/watchpack/index.d.ts +3 -217
  22. package/compiled/watchpack/index.js +1778 -1091
  23. package/compiled/watchpack/package.json +8 -1
  24. package/compiled/watchpack/types/DirectoryWatcher.d.ts +335 -0
  25. package/compiled/watchpack/types/LinkResolver.d.ts +10 -0
  26. package/compiled/watchpack/types/getWatcherManager.d.ts +62 -0
  27. package/compiled/watchpack/types/index.d.ts +269 -0
  28. package/compiled/watchpack/types/reducePlan.d.ts +34 -0
  29. package/compiled/watchpack/types/util/globToRegExp.d.ts +2 -0
  30. package/compiled/watchpack/types/watchEventSource.d.ts +53 -0
  31. package/compiled/watchpack/types/watchpack.d.ts +2 -0
  32. package/compiled/webpack-sources/index.d.ts +61 -0
  33. package/compiled/webpack-sources/index.js +2370 -576
  34. package/compiled/webpack-sources/package.json +8 -1
  35. package/compiled/webpack-sources/types/CachedSource.d.ts +192 -0
  36. package/compiled/webpack-sources/types/CompatSource.d.ts +87 -0
  37. package/compiled/webpack-sources/types/ConcatSource.d.ts +75 -0
  38. package/compiled/webpack-sources/types/OriginalSource.d.ts +87 -0
  39. package/compiled/webpack-sources/types/PrefixSource.d.ts +59 -0
  40. package/compiled/webpack-sources/types/RawSource.d.ts +75 -0
  41. package/compiled/webpack-sources/types/ReplaceSource.d.ts +107 -0
  42. package/compiled/webpack-sources/types/SizeOnlySource.d.ts +24 -0
  43. package/compiled/webpack-sources/types/Source.d.ts +189 -0
  44. package/compiled/webpack-sources/types/SourceMapSource.d.ts +136 -0
  45. package/compiled/webpack-sources/types/helpers/createMappingsSerializer.d.ts +60 -0
  46. package/compiled/webpack-sources/types/helpers/getFromStreamChunks.d.ts +16 -0
  47. package/compiled/webpack-sources/types/helpers/getGeneratedSourceInfo.d.ts +31 -0
  48. package/compiled/webpack-sources/types/helpers/getName.d.ts +15 -0
  49. package/compiled/webpack-sources/types/helpers/getSource.d.ts +15 -0
  50. package/compiled/webpack-sources/types/helpers/readMappings.d.ts +19 -0
  51. package/compiled/webpack-sources/types/helpers/scopes.d.ts +119 -0
  52. package/compiled/webpack-sources/types/helpers/splitIntoLines.d.ts +6 -0
  53. package/compiled/webpack-sources/types/helpers/splitIntoPotentialTokens.d.ts +37 -0
  54. package/compiled/webpack-sources/types/helpers/streamAndGetSourceAndMap.d.ts +39 -0
  55. package/compiled/webpack-sources/types/helpers/streamChunks.d.ts +56 -0
  56. package/compiled/webpack-sources/types/helpers/streamChunksOfCombinedSourceMap.d.ts +42 -0
  57. package/compiled/webpack-sources/types/helpers/streamChunksOfRawSource.d.ts +16 -0
  58. package/compiled/webpack-sources/types/helpers/streamChunksOfSourceMap.d.ts +19 -0
  59. package/compiled/webpack-sources/types/helpers/stringBufferUtils.d.ts +55 -0
  60. package/compiled/webpack-sources/types/index.d.ts +50 -0
  61. package/dist/BuildInfo.d.ts +3 -1
  62. package/dist/ChunkGraph.d.ts +1 -1
  63. package/dist/CodeGenerationResults.d.ts +6 -1
  64. package/dist/Compilation.d.ts +60 -89
  65. package/dist/Compiler.d.ts +25 -22
  66. package/dist/ContextModuleFactory.d.ts +2 -2
  67. package/dist/Diagnostics.d.ts +2 -6
  68. package/dist/ExecuteModulePlugin.d.ts +1 -1
  69. package/dist/ExportsInfo.d.ts +1 -1
  70. package/dist/ExternalModule.d.ts +15 -1
  71. package/dist/FileSystem.d.ts +4 -2
  72. package/dist/FileSystemDependencies.d.ts +15 -0
  73. package/dist/Module.d.ts +9 -6
  74. package/dist/ModuleGraph.d.ts +11 -8
  75. package/dist/ModuleGraphConnection.d.ts +10 -0
  76. package/dist/Modules.d.ts +3 -0
  77. package/dist/MultiCompiler.d.ts +9 -9
  78. package/dist/MultiStats.d.ts +3 -3
  79. package/dist/MultiWatching.d.ts +3 -3
  80. package/dist/NativeWatchFileSystem.d.ts +31 -2
  81. package/dist/NormalModule.d.ts +4 -5
  82. package/dist/NormalModuleFactory.d.ts +5 -4
  83. package/dist/Resolver.d.ts +10 -2
  84. package/dist/ResolverFactory.d.ts +2 -2
  85. package/dist/RuntimeGlobals.d.ts +61 -56
  86. package/dist/RuntimeModule.d.ts +3 -3
  87. package/dist/RuntimeTemplate.d.ts +151 -0
  88. package/dist/Stats.d.ts +4 -4
  89. package/dist/VirtualModulesPlugin.d.ts +1 -1
  90. package/dist/Watching.d.ts +5 -5
  91. package/dist/builtin-loader/lightningcss/index.d.ts +11 -14
  92. package/dist/builtin-loader/lightningcss/target.d.ts +4 -0
  93. package/dist/builtin-loader/swc/index.d.ts +3 -5
  94. package/dist/builtin-loader/swc/pluginImport.d.ts +1 -1
  95. package/dist/builtin-loader/swc/types.d.ts +36 -65
  96. package/dist/builtin-plugin/APIPlugin.d.ts +3 -3
  97. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +3 -3
  98. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +3 -3
  99. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +3 -3
  100. package/dist/builtin-plugin/BannerPlugin.d.ts +3 -3
  101. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +3 -3
  102. package/dist/builtin-plugin/CaseSensitivePlugin.d.ts +3 -3
  103. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +3 -3
  104. package/dist/builtin-plugin/CircularCheckRspackPlugin.d.ts +33 -0
  105. package/dist/builtin-plugin/CircularDependencyRspackPlugin.d.ts +10 -4
  106. package/dist/builtin-plugin/CircularModulesInfoPlugin.d.ts +7 -0
  107. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +3 -3
  108. package/dist/builtin-plugin/CompactHashedChunkIdsPlugin.d.ts +12 -0
  109. package/dist/builtin-plugin/CompactHashedModuleIdsPlugin.d.ts +12 -0
  110. package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +3 -3
  111. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +3 -3
  112. package/dist/builtin-plugin/CssChunkingPlugin.d.ts +3 -3
  113. package/dist/builtin-plugin/CssHttpExternalsRspackPlugin.d.ts +9 -0
  114. package/dist/builtin-plugin/CssModulesPlugin.d.ts +3 -3
  115. package/dist/builtin-plugin/DataUriPlugin.d.ts +3 -3
  116. package/dist/builtin-plugin/DefinePlugin.d.ts +3 -3
  117. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +2 -2
  118. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +13 -2
  119. package/dist/builtin-plugin/DllEntryPlugin.d.ts +3 -3
  120. package/dist/builtin-plugin/DllReferenceAgencyPlugin.d.ts +3 -3
  121. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +4 -4
  122. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +3 -3
  123. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
  124. package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +2 -2
  125. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +3 -3
  126. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +3 -3
  127. package/dist/builtin-plugin/EntryPlugin.d.ts +4 -4
  128. package/dist/builtin-plugin/EsmLibraryPlugin.d.ts +7 -2
  129. package/dist/builtin-plugin/EsmNodeTargetPlugin.d.ts +9 -0
  130. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +3 -3
  131. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +3 -3
  132. package/dist/builtin-plugin/ExternalsPlugin.d.ts +4 -3
  133. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +3 -3
  134. package/dist/builtin-plugin/FileUriPlugin.d.ts +3 -3
  135. package/dist/builtin-plugin/FlagAllModulesAsUsedPlugin.d.ts +3 -3
  136. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +3 -3
  137. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +2 -2
  138. package/dist/builtin-plugin/HashedModuleIdsPlugin.d.ts +10 -0
  139. package/dist/builtin-plugin/HotModuleReplacementPlugin.d.ts +2 -2
  140. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +5 -5
  141. package/dist/builtin-plugin/HttpUriPlugin.d.ts +7 -3
  142. package/dist/builtin-plugin/IgnorePlugin.d.ts +3 -3
  143. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +3 -3
  144. package/dist/builtin-plugin/InlineExportsPlugin.d.ts +3 -3
  145. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +21 -6
  146. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +2 -2
  147. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +3 -3
  148. package/dist/builtin-plugin/LibManifestPlugin.d.ts +3 -3
  149. package/dist/builtin-plugin/LightningCssMinimizerRspackPlugin.d.ts +7 -11
  150. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +3 -3
  151. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +2 -2
  152. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +3 -3
  153. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +3 -3
  154. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +2 -2
  155. package/dist/builtin-plugin/ModuleInfoHeaderPlugin.d.ts +3 -3
  156. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +3 -3
  157. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +3 -3
  158. package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +2 -2
  159. package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +2 -2
  160. package/dist/builtin-plugin/NoEmitOnErrorsPlugin.d.ts +3 -3
  161. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +3 -3
  162. package/dist/builtin-plugin/NormalModuleReplacementPlugin.d.ts +4 -4
  163. package/dist/builtin-plugin/OccurrenceChunkIdsPlugin.d.ts +3 -3
  164. package/dist/builtin-plugin/ProgressPlugin.d.ts +8 -7
  165. package/dist/builtin-plugin/ProvidePlugin.d.ts +3 -3
  166. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +15 -4
  167. package/dist/builtin-plugin/RemoveDuplicateModulesPlugin.d.ts +3 -3
  168. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +3 -3
  169. package/dist/builtin-plugin/RsdoctorPlugin.d.ts +8 -11
  170. package/dist/builtin-plugin/RslibPlugin.d.ts +5 -6
  171. package/dist/builtin-plugin/RstestPlugin.d.ts +3 -4
  172. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +3 -3
  173. package/dist/builtin-plugin/RuntimePlugin.d.ts +7 -11
  174. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +9 -9
  175. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +5 -5
  176. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +3 -3
  177. package/dist/builtin-plugin/SplitChunksPlugin.d.ts +6 -5
  178. package/dist/builtin-plugin/SubresourceIntegrityPlugin.d.ts +2 -2
  179. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +7 -6
  180. package/dist/builtin-plugin/SyncModuleIdsPlugin.d.ts +16 -0
  181. package/dist/builtin-plugin/URLPlugin.d.ts +3 -3
  182. package/dist/builtin-plugin/WorkerPlugin.d.ts +4 -4
  183. package/dist/builtin-plugin/base.d.ts +3 -3
  184. package/dist/builtin-plugin/css-extract/index.d.ts +3 -3
  185. package/dist/builtin-plugin/css-extract/loader.d.ts +1 -1
  186. package/dist/builtin-plugin/css-extract/utils.d.ts +8 -1
  187. package/dist/builtin-plugin/html-plugin/hooks.d.ts +3 -3
  188. package/dist/builtin-plugin/html-plugin/index.d.ts +2 -2
  189. package/dist/builtin-plugin/html-plugin/options.d.ts +2 -7
  190. package/dist/builtin-plugin/html-plugin/plugin.d.ts +5 -9
  191. package/dist/builtin-plugin/html-plugin/taps.d.ts +1 -1
  192. package/dist/builtin-plugin/index.d.ts +92 -84
  193. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +6 -6
  194. package/dist/builtin-plugin/lazy-compilation/middleware.d.ts +4 -4
  195. package/dist/builtin-plugin/rsc/Coordinator.d.ts +8 -0
  196. package/dist/builtin-plugin/rsc/RscClientPlugin.d.ts +13 -0
  197. package/dist/builtin-plugin/rsc/RscServerPlugin.d.ts +47 -0
  198. package/dist/builtin-plugin/rsc/index.d.ts +24 -0
  199. package/dist/checkNodeVersion.d.ts +1 -0
  200. package/dist/config/adapter.d.ts +4 -4
  201. package/dist/config/adapterRuleUse.d.ts +89 -55
  202. package/dist/config/browserslistTargetHandler.d.ts +1 -1
  203. package/dist/config/defaults.d.ts +5 -3
  204. package/dist/config/devServer.d.ts +103 -238
  205. package/dist/config/index.d.ts +5 -5
  206. package/dist/config/normalization.d.ts +26 -47
  207. package/dist/config/target.d.ts +19 -12
  208. package/dist/config/types.d.ts +615 -256
  209. package/dist/container/ContainerPlugin.d.ts +4 -4
  210. package/dist/container/ContainerReferencePlugin.d.ts +4 -4
  211. package/dist/container/ModuleFederationManifestPlugin.d.ts +12 -5
  212. package/dist/container/ModuleFederationPlugin.d.ts +22 -5
  213. package/dist/container/ModuleFederationPluginV1.d.ts +10 -6
  214. package/dist/container/ModuleFederationRuntimePlugin.d.ts +3 -3
  215. package/dist/cssExtractHmr.js +2 -27
  216. package/dist/cssExtractLoader.js +24 -65
  217. package/dist/exports.d.ts +98 -84
  218. package/dist/index.d.ts +4 -3
  219. package/dist/index.js +14201 -11810
  220. package/dist/lib/AbstractMethodError.d.ts +1 -1
  221. package/dist/lib/Cache.d.ts +5 -2
  222. package/dist/lib/CacheFacade.d.ts +4 -4
  223. package/dist/lib/DllPlugin.d.ts +2 -2
  224. package/dist/lib/DllReferencePlugin.d.ts +3 -3
  225. package/dist/lib/EntryOptionPlugin.d.ts +2 -2
  226. package/dist/lib/EnvironmentPlugin.d.ts +3 -3
  227. package/dist/lib/HookWebpackError.d.ts +2 -3
  228. package/dist/lib/IgnoreWarningsPlugin.d.ts +1 -1
  229. package/dist/lib/LoaderOptionsPlugin.d.ts +2 -2
  230. package/dist/lib/LoaderTargetPlugin.d.ts +2 -2
  231. package/dist/lib/WebpackError.d.ts +2 -2
  232. package/dist/lib/cache/MemoryCachePlugin.d.ts +1 -1
  233. package/dist/lib/cache/getLazyHashedEtag.d.ts +2 -2
  234. package/dist/lib/cache/mergeEtags.d.ts +1 -2
  235. package/dist/loader-runner/ModuleError.d.ts +1 -1
  236. package/dist/loader-runner/cache.d.ts +27 -0
  237. package/dist/loader-runner/dependencies.d.ts +23 -0
  238. package/dist/loader-runner/index.d.ts +10 -11
  239. package/dist/loader-runner/loadLoader.d.ts +2 -2
  240. package/dist/loader-runner/service.d.ts +10 -1
  241. package/dist/loader-runner/utils.d.ts +3 -3
  242. package/dist/loader-runner/worker.d.ts +1 -1
  243. package/dist/logging/createConsoleLogger.d.ts +2 -2
  244. package/dist/l~0.js +34 -0
  245. package/dist/l~3.js +34 -0
  246. package/dist/moduleFederationDefaultRuntime.js +1 -1
  247. package/dist/node/NodeEnvironmentPlugin.d.ts +2 -2
  248. package/dist/node/NodeTemplatePlugin.d.ts +1 -1
  249. package/dist/node/NodeWatchFileSystem.d.ts +15 -3
  250. package/dist/node/nodeConsole.d.ts +1 -1
  251. package/dist/rspack.d.ts +7 -8
  252. package/dist/rspackOptionsApply.d.ts +1 -1
  253. package/dist/runtime/cssExtractHmr.d.ts +2 -2
  254. package/dist/runtime/moduleFederationDefaultRuntime.d.ts +1 -2
  255. package/dist/sharing/CollectSharedEntryPlugin.d.ts +22 -0
  256. package/dist/sharing/ConsumeSharedPlugin.d.ts +18 -6
  257. package/dist/sharing/IndependentSharedPlugin.d.ts +37 -0
  258. package/dist/sharing/ProvideSharedPlugin.d.ts +22 -3
  259. package/dist/sharing/SharePlugin.d.ts +51 -3
  260. package/dist/sharing/ShareRuntimePlugin.d.ts +2 -2
  261. package/dist/sharing/SharedContainerPlugin.d.ts +23 -0
  262. package/dist/sharing/SharedUsedExportsOptimizerPlugin.d.ts +14 -0
  263. package/dist/sharing/TreeShakingSharedPlugin.d.ts +19 -0
  264. package/dist/sharing/utils.d.ts +1 -0
  265. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +1 -1
  266. package/dist/stats/DefaultStatsPresetPlugin.d.ts +1 -1
  267. package/dist/stats/DefaultStatsPrinterPlugin.d.ts +1 -1
  268. package/dist/stats/StatsFactory.d.ts +7 -5
  269. package/dist/stats/StatsPrinter.d.ts +7 -7
  270. package/dist/stats/statsFactoryUtils.d.ts +15 -19
  271. package/dist/swc.d.ts +2 -2
  272. package/dist/taps/compilation.d.ts +1 -1
  273. package/dist/taps/compiler.d.ts +1 -1
  274. package/dist/taps/contextModuleFactory.d.ts +1 -1
  275. package/dist/taps/externalModule.d.ts +2 -0
  276. package/dist/taps/index.d.ts +7 -6
  277. package/dist/taps/javascriptModules.d.ts +1 -1
  278. package/dist/taps/normalModuleFactory.d.ts +1 -1
  279. package/dist/taps/types.d.ts +2 -2
  280. package/dist/trace/index.d.ts +1 -0
  281. package/dist/trace/traceHookPlugin.d.ts +1 -1
  282. package/dist/util/bindingHelpers.d.ts +7 -0
  283. package/dist/util/comparators.d.ts +1 -1
  284. package/dist/util/createHash.d.ts +2 -2
  285. package/dist/util/fs.d.ts +19 -18
  286. package/dist/util/hash/md4.d.ts +1 -1
  287. package/dist/util/hash/xxhash64.d.ts +1 -1
  288. package/dist/util/identifier.d.ts +35 -9
  289. package/dist/util/index.d.ts +2 -2
  290. package/dist/util/source.d.ts +3 -3
  291. package/dist/util/supportsColor.d.ts +6 -0
  292. package/dist/util/targetsVersion.d.ts +2 -0
  293. package/dist/util/validateConfig.d.ts +1 -1
  294. package/dist/util/watchTimeInfo.d.ts +7 -0
  295. package/dist/web/JsonpTemplatePlugin.d.ts +13 -0
  296. package/dist/webworker/WebWorkerTemplatePlugin.d.ts +13 -0
  297. package/dist/worker.js +935 -907
  298. package/hot/dev-server.js +12 -11
  299. package/hot/emitter.js +3 -1
  300. package/hot/lazy-compilation-node.js +4 -1
  301. package/hot/lazy-compilation-web.js +2 -3
  302. package/hot/log-apply-result.js +8 -5
  303. package/hot/log.js +18 -10
  304. package/hot/only-dev-server.js +13 -12
  305. package/hot/poll.js +10 -9
  306. package/hot/signal.js +12 -10
  307. package/module.d.ts +39 -2
  308. package/package.json +15 -39
  309. package/compiled/browserslist-load-config/index.d.ts +0 -21
  310. package/compiled/browserslist-load-config/index.js +0 -252
  311. package/compiled/browserslist-load-config/package.json +0 -1
  312. package/compiled/webpack-sources/types.d.ts +0 -458
  313. package/dist/builtin-loader/index.d.ts +0 -1
  314. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +0 -7
  315. package/dist/container/index.d.ts +0 -4
  316. package/dist/util/MergeCaller.d.ts +0 -10
  317. package/dist/util/fake.d.ts +0 -14
@@ -1,143 +1,6 @@
1
1
  /******/ (() => { // webpackBootstrap
2
2
  /******/ var __webpack_modules__ = ({
3
3
 
4
- /***/ 428:
5
- /***/ ((module) => {
6
-
7
- module.exports = function (glob, opts) {
8
- if (typeof glob !== 'string') {
9
- throw new TypeError('Expected a string');
10
- }
11
-
12
- var str = String(glob);
13
-
14
- // The regexp we are building, as a string.
15
- var reStr = "";
16
-
17
- // Whether we are matching so called "extended" globs (like bash) and should
18
- // support single character matching, matching ranges of characters, group
19
- // matching, etc.
20
- var extended = opts ? !!opts.extended : false;
21
-
22
- // When globstar is _false_ (default), '/foo/*' is translated a regexp like
23
- // '^\/foo\/.*$' which will match any string beginning with '/foo/'
24
- // When globstar is _true_, '/foo/*' is translated to regexp like
25
- // '^\/foo\/[^/]*$' which will match any string beginning with '/foo/' BUT
26
- // which does not have a '/' to the right of it.
27
- // E.g. with '/foo/*' these will match: '/foo/bar', '/foo/bar.txt' but
28
- // these will not '/foo/bar/baz', '/foo/bar/baz.txt'
29
- // Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
30
- // globstar is _false_
31
- var globstar = opts ? !!opts.globstar : false;
32
-
33
- // If we are doing extended matching, this boolean is true when we are inside
34
- // a group (eg {*.html,*.js}), and false otherwise.
35
- var inGroup = false;
36
-
37
- // RegExp flags (eg "i" ) to pass in to RegExp constructor.
38
- var flags = opts && typeof( opts.flags ) === "string" ? opts.flags : "";
39
-
40
- var c;
41
- for (var i = 0, len = str.length; i < len; i++) {
42
- c = str[i];
43
-
44
- switch (c) {
45
- case "/":
46
- case "$":
47
- case "^":
48
- case "+":
49
- case ".":
50
- case "(":
51
- case ")":
52
- case "=":
53
- case "!":
54
- case "|":
55
- reStr += "\\" + c;
56
- break;
57
-
58
- case "?":
59
- if (extended) {
60
- reStr += ".";
61
- break;
62
- }
63
-
64
- case "[":
65
- case "]":
66
- if (extended) {
67
- reStr += c;
68
- break;
69
- }
70
-
71
- case "{":
72
- if (extended) {
73
- inGroup = true;
74
- reStr += "(";
75
- break;
76
- }
77
-
78
- case "}":
79
- if (extended) {
80
- inGroup = false;
81
- reStr += ")";
82
- break;
83
- }
84
-
85
- case ",":
86
- if (inGroup) {
87
- reStr += "|";
88
- break;
89
- }
90
- reStr += "\\" + c;
91
- break;
92
-
93
- case "*":
94
- // Move over all consecutive "*"'s.
95
- // Also store the previous and next characters
96
- var prevChar = str[i - 1];
97
- var starCount = 1;
98
- while(str[i + 1] === "*") {
99
- starCount++;
100
- i++;
101
- }
102
- var nextChar = str[i + 1];
103
-
104
- if (!globstar) {
105
- // globstar is disabled, so treat any number of "*" as one
106
- reStr += ".*";
107
- } else {
108
- // globstar is enabled, so determine if this is a globstar segment
109
- var isGlobstar = starCount > 1 // multiple "*"'s
110
- && (prevChar === "/" || prevChar === undefined) // from the start of the segment
111
- && (nextChar === "/" || nextChar === undefined) // to the end of the segment
112
-
113
- if (isGlobstar) {
114
- // it's a globstar, so match zero or more path segments
115
- reStr += "((?:[^/]*(?:\/|$))*)";
116
- i++; // move over the "/"
117
- } else {
118
- // it's not a globstar, so only match one path segment
119
- reStr += "([^/]*)";
120
- }
121
- }
122
- break;
123
-
124
- default:
125
- reStr += c;
126
- }
127
- }
128
-
129
- // When regexp 'g' flag is specified don't
130
- // constrain the regular expression with ^ & $
131
- if (!flags || !~flags.indexOf('g')) {
132
- reStr = "^" + reStr + "$";
133
- }
134
-
135
- return new RegExp(reStr, flags);
136
- };
137
-
138
-
139
- /***/ }),
140
-
141
4
  /***/ 648:
142
5
  /***/ ((module) => {
143
6
 
@@ -1111,7 +974,7 @@ function patch (fs) {
1111
974
 
1112
975
  /***/ }),
1113
976
 
1114
- /***/ 40:
977
+ /***/ 409:
1115
978
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1116
979
 
1117
980
  "use strict";
@@ -1121,12 +984,23 @@ function patch (fs) {
1121
984
  */
1122
985
 
1123
986
 
1124
- const EventEmitter = (__nccwpck_require__(434).EventEmitter);
1125
- const fs = __nccwpck_require__(692);
987
+ const { EventEmitter } = __nccwpck_require__(434);
1126
988
  const path = __nccwpck_require__(928);
989
+ const fs = __nccwpck_require__(692);
990
+
991
+ const watchEventSource = __nccwpck_require__(92);
1127
992
 
1128
- const watchEventSource = __nccwpck_require__(729);
993
+ /** @typedef {import("./index").IgnoredFunction} IgnoredFunction */
994
+ /** @typedef {import("./index").EventType} EventType */
995
+ /** @typedef {import("./index").TimeInfoEntries} TimeInfoEntries */
996
+ /** @typedef {import("./index").Entry} Entry */
997
+ /** @typedef {import("./index").ExistenceOnlyTimeEntry} ExistenceOnlyTimeEntry */
998
+ /** @typedef {import("./index").OnlySafeTimeEntry} OnlySafeTimeEntry */
999
+ /** @typedef {import("./index").EventMap} EventMap */
1000
+ /** @typedef {import("./getWatcherManager").WatcherManager} WatcherManager */
1001
+ /** @typedef {import("./watchEventSource").Watcher} EventSourceWatcher */
1129
1002
 
1003
+ /** @type {ExistenceOnlyTimeEntry} */
1130
1004
  const EXISTANCE_ONLY_TIME_ENTRY = Object.freeze({});
1131
1005
 
1132
1006
  let FS_ACCURACY = 2000;
@@ -1134,45 +1008,177 @@ let FS_ACCURACY = 2000;
1134
1008
  const IS_OSX = (__nccwpck_require__(857).platform)() === "darwin";
1135
1009
  const IS_WIN = (__nccwpck_require__(857).platform)() === "win32";
1136
1010
 
1137
- const WATCHPACK_POLLING = process.env.WATCHPACK_POLLING;
1011
+ const { WATCHPACK_POLLING, WATCHPACK_RETRIES } = process.env;
1138
1012
  const FORCE_POLLING =
1013
+ // @ts-expect-error avoid additional checks
1139
1014
  `${+WATCHPACK_POLLING}` === WATCHPACK_POLLING
1140
1015
  ? +WATCHPACK_POLLING
1141
- : !!WATCHPACK_POLLING && WATCHPACK_POLLING !== "false";
1016
+ : Boolean(WATCHPACK_POLLING) && WATCHPACK_POLLING !== "false";
1017
+
1018
+ // Number of retries (and delay between retries, in ms) when an fs operation
1019
+ // returns EBUSY. EBUSY is transient on Windows when an AV scanner, indexer,
1020
+ // or another process briefly locks a file; retrying avoids incorrectly
1021
+ // reporting the file as removed (see webpack/watchpack#223, #44).
1022
+ //
1023
+ // Configurable via `WATCHPACK_RETRIES` env var: an integer >= 0, or "false"
1024
+ // to disable retries entirely. Unset / invalid values fall back to 3.
1025
+ const BUSY_RETRIES = (() => {
1026
+ if (WATCHPACK_RETRIES === undefined) return 3;
1027
+ if (WATCHPACK_RETRIES === "false") return 0;
1028
+ const n = Number(WATCHPACK_RETRIES);
1029
+ return Number.isFinite(n) && n >= 0 ? Math.floor(n) : 3;
1030
+ })();
1031
+ const BUSY_RETRY_DELAY = 100;
1142
1032
 
1033
+ /**
1034
+ * @param {string} str string
1035
+ * @returns {string} lower cased string
1036
+ */
1143
1037
  function withoutCase(str) {
1144
1038
  return str.toLowerCase();
1145
1039
  }
1146
1040
 
1041
+ /**
1042
+ * @param {number} times times
1043
+ * @param {() => void} callback callback
1044
+ * @returns {() => void} result
1045
+ */
1147
1046
  function needCalls(times, callback) {
1148
- return function() {
1047
+ return function needCallsCallback() {
1149
1048
  if (--times === 0) {
1150
1049
  return callback();
1151
1050
  }
1152
1051
  };
1153
1052
  }
1154
1053
 
1054
+ /**
1055
+ * @param {Entry} entry entry
1056
+ */
1057
+ function fixupEntryAccuracy(entry) {
1058
+ if (entry.accuracy > FS_ACCURACY) {
1059
+ entry.safeTime = entry.safeTime - entry.accuracy + FS_ACCURACY;
1060
+ entry.accuracy = FS_ACCURACY;
1061
+ }
1062
+ }
1063
+
1064
+ /**
1065
+ * @param {number=} mtime mtime
1066
+ */
1067
+ function ensureFsAccuracy(mtime) {
1068
+ if (!mtime) return;
1069
+ if (FS_ACCURACY > 1 && mtime % 1 !== 0) FS_ACCURACY = 1;
1070
+ else if (FS_ACCURACY > 10 && mtime % 10 !== 0) FS_ACCURACY = 10;
1071
+ else if (FS_ACCURACY > 100 && mtime % 100 !== 0) FS_ACCURACY = 100;
1072
+ else if (FS_ACCURACY > 1000 && mtime % 1000 !== 0) FS_ACCURACY = 1000;
1073
+ }
1074
+
1075
+ /**
1076
+ * Call `fs.lstat` with retries on EBUSY. Transient EBUSY errors are common
1077
+ * on Windows when another process (AV scanner, indexer, editor) holds an
1078
+ * open handle on the file. See webpack/watchpack#223, #44.
1079
+ *
1080
+ * The retry count is taken from the `WATCHPACK_RETRIES` env var (default
1081
+ * 3, set to "0" or "false" to disable retrying). The hot path is a single
1082
+ * `fs.lstat` call with one inline callback; the timer and the recursive
1083
+ * call are only scheduled when an EBUSY is actually observed.
1084
+ * @param {string} target target path
1085
+ * @param {{ closed: boolean }} watcher owning watcher (checked between retries)
1086
+ * @param {(err: NodeJS.ErrnoException | null, stats: import("fs").Stats) => void} callback callback
1087
+ * @param {number=} remaining retries remaining (defaults to `BUSY_RETRIES`)
1088
+ */
1089
+ function lstatWithRetry(target, watcher, callback, remaining = BUSY_RETRIES) {
1090
+ fs.lstat(target, (err, stats) => {
1091
+ if (
1092
+ err &&
1093
+ /** @type {NodeJS.ErrnoException} */ (err).code === "EBUSY" &&
1094
+ remaining > 0 &&
1095
+ !watcher.closed
1096
+ ) {
1097
+ setTimeout(
1098
+ () => lstatWithRetry(target, watcher, callback, remaining - 1),
1099
+ BUSY_RETRY_DELAY,
1100
+ );
1101
+ return;
1102
+ }
1103
+ callback(err, stats);
1104
+ });
1105
+ }
1106
+
1107
+ /**
1108
+ * @typedef {object} FileWatcherEvents
1109
+ * @property {(type: EventType) => void} initial-missing initial missing event
1110
+ * @property {(mtime: number, type: EventType, initial: boolean) => void} change change event
1111
+ * @property {(type: EventType) => void} remove remove event
1112
+ * @property {() => void} closed closed event
1113
+ */
1114
+
1115
+ /**
1116
+ * @typedef {object} DirectoryWatcherEvents
1117
+ * @property {(type: EventType) => void} initial-missing initial missing event
1118
+ * @property {((file: string, mtime: number, type: EventType, initial: boolean) => void)} change change event
1119
+ * @property {(type: EventType) => void} remove remove event
1120
+ * @property {() => void} closed closed event
1121
+ */
1122
+
1123
+ /**
1124
+ * @template {EventMap} T
1125
+ * @extends {EventEmitter<{ [K in keyof T]: Parameters<T[K]> }>}
1126
+ */
1155
1127
  class Watcher extends EventEmitter {
1156
- constructor(directoryWatcher, filePath, startTime) {
1128
+ /**
1129
+ * @param {DirectoryWatcher} directoryWatcher a directory watcher
1130
+ * @param {string} target a target to watch
1131
+ * @param {number=} startTime start time
1132
+ */
1133
+ constructor(directoryWatcher, target, startTime) {
1157
1134
  super();
1158
1135
  this.directoryWatcher = directoryWatcher;
1159
- this.path = filePath;
1136
+ this.path = target;
1160
1137
  this.startTime = startTime && +startTime;
1161
1138
  }
1162
1139
 
1140
+ /**
1141
+ * @param {number} mtime mtime
1142
+ * @param {boolean} initial true when initial, otherwise false
1143
+ * @returns {boolean} true of start time less than mtile, otherwise false
1144
+ */
1163
1145
  checkStartTime(mtime, initial) {
1164
- const startTime = this.startTime;
1146
+ const { startTime } = this;
1165
1147
  if (typeof startTime !== "number") return !initial;
1166
1148
  return startTime <= mtime;
1167
1149
  }
1168
1150
 
1169
1151
  close() {
1152
+ // @ts-expect-error bad typing in EventEmitter
1170
1153
  this.emit("closed");
1171
1154
  }
1172
1155
  }
1173
1156
 
1157
+ /** @typedef {Set<string>} InitialScanRemoved */
1158
+
1159
+ /**
1160
+ * @typedef {object} WatchpackEvents
1161
+ * @property {(target: string, mtime: string, type: EventType, initial: boolean) => void} change change event
1162
+ * @property {() => void} closed closed event
1163
+ */
1164
+
1165
+ /**
1166
+ * @typedef {object} DirectoryWatcherOptions
1167
+ * @property {boolean=} followSymlinks true when need to resolve symlinks and watch symlink and real file, otherwise false
1168
+ * @property {IgnoredFunction=} ignored ignore some files from watching (glob pattern or regexp)
1169
+ * @property {number | boolean=} poll true when need to enable polling mode for watching, otherwise false
1170
+ */
1171
+
1172
+ /**
1173
+ * @extends {EventEmitter<{ [K in keyof WatchpackEvents]: Parameters<WatchpackEvents[K]> }>}
1174
+ */
1174
1175
  class DirectoryWatcher extends EventEmitter {
1175
- constructor(watcherManager, directoryPath, options) {
1176
+ /**
1177
+ * @param {WatcherManager} watcherManager a watcher manager
1178
+ * @param {string} directoryPath directory path
1179
+ * @param {DirectoryWatcherOptions=} options options
1180
+ */
1181
+ constructor(watcherManager, directoryPath, options = {}) {
1176
1182
  super();
1177
1183
  if (FORCE_POLLING) {
1178
1184
  options.poll = FORCE_POLLING;
@@ -1182,28 +1188,37 @@ class DirectoryWatcher extends EventEmitter {
1182
1188
  this.path = directoryPath;
1183
1189
  // safeTime is the point in time after which reading is safe to be unchanged
1184
1190
  // timestamp is a value that should be compared with another timestamp (mtime)
1185
- /** @type {Map<string, { safeTime: number, timestamp: number }} */
1191
+ /** @type {Map<string, Entry>} */
1186
1192
  this.files = new Map();
1187
1193
  /** @type {Map<string, number>} */
1188
1194
  this.filesWithoutCase = new Map();
1195
+ /** @type {Map<string, Watcher<DirectoryWatcherEvents> | boolean>} */
1189
1196
  this.directories = new Map();
1197
+ /** @type {Map<string, Watcher<FileWatcherEvents>>} */
1198
+ this._symlinkTargetWatchers = new Map();
1190
1199
  this.lastWatchEvent = 0;
1191
1200
  this.initialScan = true;
1192
1201
  this.ignored = options.ignored || (() => false);
1193
1202
  this.nestedWatching = false;
1203
+ /** @type {number | false} */
1194
1204
  this.polledWatching =
1195
1205
  typeof options.poll === "number"
1196
1206
  ? options.poll
1197
1207
  : options.poll
1198
- ? 5007
1199
- : false;
1208
+ ? 5007
1209
+ : false;
1210
+ /** @type {undefined | NodeJS.Timeout} */
1200
1211
  this.timeout = undefined;
1212
+ /** @type {null | InitialScanRemoved} */
1201
1213
  this.initialScanRemoved = new Set();
1214
+ /** @type {undefined | number} */
1202
1215
  this.initialScanFinished = undefined;
1203
- /** @type {Map<string, Set<Watcher>>} */
1216
+ /** @type {Map<string, Set<Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>>>} */
1204
1217
  this.watchers = new Map();
1218
+ /** @type {Watcher<FileWatcherEvents> | null} */
1205
1219
  this.parentWatcher = null;
1206
1220
  this.refs = 0;
1221
+ /** @type {Map<string, boolean>} */
1207
1222
  this._activeEvents = new Map();
1208
1223
  this.closed = false;
1209
1224
  this.scanning = false;
@@ -1217,19 +1232,22 @@ class DirectoryWatcher extends EventEmitter {
1217
1232
  createWatcher() {
1218
1233
  try {
1219
1234
  if (this.polledWatching) {
1220
- this.watcher = {
1235
+ /** @type {EventSourceWatcher} */
1236
+ (this.watcher) = /** @type {EventSourceWatcher} */ ({
1221
1237
  close: () => {
1222
1238
  if (this.timeout) {
1223
1239
  clearTimeout(this.timeout);
1224
1240
  this.timeout = undefined;
1225
1241
  }
1226
- }
1227
- };
1242
+ },
1243
+ });
1228
1244
  } else {
1229
1245
  if (IS_OSX) {
1230
1246
  this.watchInParentDirectory();
1231
1247
  }
1232
- this.watcher = watchEventSource.watch(this.path);
1248
+ this.watcher =
1249
+ /** @type {EventSourceWatcher} */
1250
+ (watchEventSource.watch(this.path));
1233
1251
  this.watcher.on("change", this.onWatchEvent.bind(this));
1234
1252
  this.watcher.on("error", this.onWatcherError.bind(this));
1235
1253
  }
@@ -1238,6 +1256,11 @@ class DirectoryWatcher extends EventEmitter {
1238
1256
  }
1239
1257
  }
1240
1258
 
1259
+ /**
1260
+ * @template {(watcher: Watcher<EventMap>) => void} T
1261
+ * @param {string} path path
1262
+ * @param {T} fn function
1263
+ */
1241
1264
  forEachWatcher(path, fn) {
1242
1265
  const watchers = this.watchers.get(withoutCase(path));
1243
1266
  if (watchers !== undefined) {
@@ -1247,20 +1270,28 @@ class DirectoryWatcher extends EventEmitter {
1247
1270
  }
1248
1271
  }
1249
1272
 
1273
+ /**
1274
+ * @param {string} itemPath an item path
1275
+ * @param {boolean} initial true when initial, otherwise false
1276
+ * @param {EventType} type even type
1277
+ */
1250
1278
  setMissing(itemPath, initial, type) {
1251
1279
  if (this.initialScan) {
1252
- this.initialScanRemoved.add(itemPath);
1280
+ /** @type {InitialScanRemoved} */
1281
+ (this.initialScanRemoved).add(itemPath);
1253
1282
  }
1254
1283
 
1255
1284
  const oldDirectory = this.directories.get(itemPath);
1256
1285
  if (oldDirectory) {
1257
- if (this.nestedWatching) oldDirectory.close();
1286
+ if (this.nestedWatching) {
1287
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1288
+ (oldDirectory).close();
1289
+ }
1258
1290
  this.directories.delete(itemPath);
1259
-
1260
- this.forEachWatcher(itemPath, w => w.emit("remove", type));
1291
+ this.forEachWatcher(itemPath, (w) => w.emit("remove", type));
1261
1292
  if (!initial) {
1262
- this.forEachWatcher(this.path, w =>
1263
- w.emit("change", itemPath, null, type, initial)
1293
+ this.forEachWatcher(this.path, (w) =>
1294
+ w.emit("change", itemPath, null, type, initial),
1264
1295
  );
1265
1296
  }
1266
1297
  }
@@ -1269,30 +1300,38 @@ class DirectoryWatcher extends EventEmitter {
1269
1300
  if (oldFile) {
1270
1301
  this.files.delete(itemPath);
1271
1302
  const key = withoutCase(itemPath);
1272
- const count = this.filesWithoutCase.get(key) - 1;
1303
+ const count = /** @type {number} */ (this.filesWithoutCase.get(key)) - 1;
1273
1304
  if (count <= 0) {
1274
1305
  this.filesWithoutCase.delete(key);
1275
- this.forEachWatcher(itemPath, w => w.emit("remove", type));
1306
+ this.forEachWatcher(itemPath, (w) => w.emit("remove", type));
1276
1307
  } else {
1277
1308
  this.filesWithoutCase.set(key, count);
1278
1309
  }
1279
1310
 
1280
1311
  if (!initial) {
1281
- this.forEachWatcher(this.path, w =>
1282
- w.emit("change", itemPath, null, type, initial)
1312
+ this.forEachWatcher(this.path, (w) =>
1313
+ w.emit("change", itemPath, null, type, initial),
1283
1314
  );
1284
1315
  }
1285
1316
  }
1286
1317
  }
1287
1318
 
1288
- setFileTime(filePath, mtime, initial, ignoreWhenEqual, type) {
1319
+ /**
1320
+ * @param {string} target a target to set file time
1321
+ * @param {number} mtime mtime
1322
+ * @param {boolean} initial true when initial, otherwise false
1323
+ * @param {boolean} ignoreWhenEqual true to ignore when equal, otherwise false
1324
+ * @param {EventType} type type
1325
+ */
1326
+ setFileTime(target, mtime, initial, ignoreWhenEqual, type) {
1289
1327
  const now = Date.now();
1290
1328
 
1291
- if (this.ignored(filePath)) return;
1329
+ if (this.ignored(target)) return;
1292
1330
 
1293
- const old = this.files.get(filePath);
1331
+ const old = this.files.get(target);
1294
1332
 
1295
- let safeTime, accuracy;
1333
+ let safeTime;
1334
+ let accuracy;
1296
1335
  if (initial) {
1297
1336
  safeTime = Math.min(now, mtime) + FS_ACCURACY;
1298
1337
  accuracy = FS_ACCURACY;
@@ -1311,14 +1350,14 @@ class DirectoryWatcher extends EventEmitter {
1311
1350
 
1312
1351
  if (ignoreWhenEqual && old && old.timestamp === mtime) return;
1313
1352
 
1314
- this.files.set(filePath, {
1353
+ this.files.set(target, {
1315
1354
  safeTime,
1316
1355
  accuracy,
1317
- timestamp: mtime
1356
+ timestamp: mtime,
1318
1357
  });
1319
1358
 
1320
1359
  if (!old) {
1321
- const key = withoutCase(filePath);
1360
+ const key = withoutCase(target);
1322
1361
  const count = this.filesWithoutCase.get(key);
1323
1362
  this.filesWithoutCase.set(key, (count || 0) + 1);
1324
1363
  if (count !== undefined) {
@@ -1330,27 +1369,33 @@ class DirectoryWatcher extends EventEmitter {
1330
1369
  this.doScan(false);
1331
1370
  }
1332
1371
 
1333
- this.forEachWatcher(filePath, w => {
1372
+ this.forEachWatcher(target, (w) => {
1334
1373
  if (!initial || w.checkStartTime(safeTime, initial)) {
1335
1374
  w.emit("change", mtime, type);
1336
1375
  }
1337
1376
  });
1338
1377
  } else if (!initial) {
1339
- this.forEachWatcher(filePath, w => w.emit("change", mtime, type));
1378
+ this.forEachWatcher(target, (w) => w.emit("change", mtime, type));
1340
1379
  }
1341
- this.forEachWatcher(this.path, w => {
1380
+ this.forEachWatcher(this.path, (w) => {
1342
1381
  if (!initial || w.checkStartTime(safeTime, initial)) {
1343
- w.emit("change", filePath, safeTime, type, initial);
1382
+ w.emit("change", target, safeTime, type, initial);
1344
1383
  }
1345
1384
  });
1346
1385
  }
1347
1386
 
1387
+ /**
1388
+ * @param {string} directoryPath directory path
1389
+ * @param {number} birthtime birthtime
1390
+ * @param {boolean} initial true when initial, otherwise false
1391
+ * @param {EventType} type even type
1392
+ */
1348
1393
  setDirectory(directoryPath, birthtime, initial, type) {
1349
1394
  if (this.ignored(directoryPath)) return;
1350
1395
  if (directoryPath === this.path) {
1351
1396
  if (!initial) {
1352
- this.forEachWatcher(this.path, w =>
1353
- w.emit("change", directoryPath, birthtime, type, initial)
1397
+ this.forEachWatcher(this.path, (w) =>
1398
+ w.emit("change", directoryPath, birthtime, type, initial),
1354
1399
  );
1355
1400
  }
1356
1401
  } else {
@@ -1364,19 +1409,14 @@ class DirectoryWatcher extends EventEmitter {
1364
1409
  this.directories.set(directoryPath, true);
1365
1410
  }
1366
1411
 
1367
- let safeTime;
1368
- if (initial) {
1369
- safeTime = Math.min(now, birthtime) + FS_ACCURACY;
1370
- } else {
1371
- safeTime = now;
1372
- }
1412
+ const safeTime = initial ? Math.min(now, birthtime) + FS_ACCURACY : now;
1373
1413
 
1374
- this.forEachWatcher(directoryPath, w => {
1414
+ this.forEachWatcher(directoryPath, (w) => {
1375
1415
  if (!initial || w.checkStartTime(safeTime, false)) {
1376
1416
  w.emit("change", birthtime, type);
1377
1417
  }
1378
1418
  });
1379
- this.forEachWatcher(this.path, w => {
1419
+ this.forEachWatcher(this.path, (w) => {
1380
1420
  if (!initial || w.checkStartTime(safeTime, initial)) {
1381
1421
  w.emit("change", directoryPath, safeTime, type, initial);
1382
1422
  }
@@ -1385,43 +1425,61 @@ class DirectoryWatcher extends EventEmitter {
1385
1425
  }
1386
1426
  }
1387
1427
 
1428
+ /**
1429
+ * @param {string} directoryPath directory path
1430
+ */
1388
1431
  createNestedWatcher(directoryPath) {
1389
1432
  const watcher = this.watcherManager.watchDirectory(directoryPath, 1);
1390
- watcher.on("change", (filePath, mtime, type, initial) => {
1391
- this.forEachWatcher(this.path, w => {
1433
+ watcher.on("change", (target, mtime, type, initial) => {
1434
+ this.forEachWatcher(this.path, (w) => {
1392
1435
  if (!initial || w.checkStartTime(mtime, initial)) {
1393
- w.emit("change", filePath, mtime, type, initial);
1436
+ w.emit("change", target, mtime, type, initial);
1394
1437
  }
1395
1438
  });
1396
1439
  });
1397
1440
  this.directories.set(directoryPath, watcher);
1398
1441
  }
1399
1442
 
1443
+ /**
1444
+ * @param {boolean} flag true when nested, otherwise false
1445
+ */
1400
1446
  setNestedWatching(flag) {
1401
- if (this.nestedWatching !== !!flag) {
1402
- this.nestedWatching = !!flag;
1447
+ if (this.nestedWatching !== Boolean(flag)) {
1448
+ this.nestedWatching = Boolean(flag);
1403
1449
  if (this.nestedWatching) {
1404
1450
  for (const directory of this.directories.keys()) {
1405
1451
  this.createNestedWatcher(directory);
1406
1452
  }
1407
1453
  } else {
1408
1454
  for (const [directory, watcher] of this.directories) {
1409
- watcher.close();
1455
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1456
+ (watcher).close();
1410
1457
  this.directories.set(directory, true);
1411
1458
  }
1459
+ for (const w of this._symlinkTargetWatchers.values()) {
1460
+ w.close();
1461
+ }
1462
+ this._symlinkTargetWatchers.clear();
1412
1463
  }
1413
1464
  }
1414
1465
  }
1415
1466
 
1416
- watch(filePath, startTime) {
1417
- const key = withoutCase(filePath);
1467
+ /**
1468
+ * @param {string} target a target to watch
1469
+ * @param {number=} startTime start time
1470
+ * @returns {Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>} watcher
1471
+ */
1472
+ watch(target, startTime) {
1473
+ const key = withoutCase(target);
1418
1474
  let watchers = this.watchers.get(key);
1419
1475
  if (watchers === undefined) {
1420
1476
  watchers = new Set();
1421
1477
  this.watchers.set(key, watchers);
1422
1478
  }
1423
1479
  this.refs++;
1424
- const watcher = new Watcher(this, filePath, startTime);
1480
+ const watcher =
1481
+ /** @type {Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>} */
1482
+ (new Watcher(this, target, startTime));
1425
1483
  watcher.on("closed", () => {
1426
1484
  if (--this.refs <= 0) {
1427
1485
  this.close();
@@ -1430,12 +1488,12 @@ class DirectoryWatcher extends EventEmitter {
1430
1488
  watchers.delete(watcher);
1431
1489
  if (watchers.size === 0) {
1432
1490
  this.watchers.delete(key);
1433
- if (this.path === filePath) this.setNestedWatching(false);
1491
+ if (this.path === target) this.setNestedWatching(false);
1434
1492
  }
1435
1493
  });
1436
1494
  watchers.add(watcher);
1437
1495
  let safeTime;
1438
- if (filePath === this.path) {
1496
+ if (target === this.path) {
1439
1497
  this.setNestedWatching(true);
1440
1498
  safeTime = this.lastWatchEvent;
1441
1499
  for (const entry of this.files.values()) {
@@ -1443,7 +1501,7 @@ class DirectoryWatcher extends EventEmitter {
1443
1501
  safeTime = Math.max(safeTime, entry.safeTime);
1444
1502
  }
1445
1503
  } else {
1446
- const entry = this.files.get(filePath);
1504
+ const entry = this.files.get(target);
1447
1505
  if (entry) {
1448
1506
  fixupEntryAccuracy(entry);
1449
1507
  safeTime = entry.safeTime;
@@ -1452,38 +1510,47 @@ class DirectoryWatcher extends EventEmitter {
1452
1510
  }
1453
1511
  }
1454
1512
  if (safeTime) {
1455
- if (safeTime >= startTime) {
1513
+ if (startTime && safeTime >= startTime) {
1456
1514
  process.nextTick(() => {
1457
1515
  if (this.closed) return;
1458
- if (filePath === this.path) {
1459
- watcher.emit(
1516
+ if (target === this.path) {
1517
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1518
+ (watcher).emit(
1460
1519
  "change",
1461
- filePath,
1520
+ target,
1462
1521
  safeTime,
1463
1522
  "watch (outdated on attach)",
1464
- true
1523
+ true,
1465
1524
  );
1466
1525
  } else {
1467
- watcher.emit(
1526
+ /** @type {Watcher<FileWatcherEvents>} */
1527
+ (watcher).emit(
1468
1528
  "change",
1469
1529
  safeTime,
1470
1530
  "watch (outdated on attach)",
1471
- true
1531
+ true,
1472
1532
  );
1473
1533
  }
1474
1534
  });
1475
1535
  }
1476
1536
  } else if (this.initialScan) {
1477
- if (this.initialScanRemoved.has(filePath)) {
1537
+ if (
1538
+ /** @type {InitialScanRemoved} */
1539
+ (this.initialScanRemoved).has(target)
1540
+ ) {
1478
1541
  process.nextTick(() => {
1479
1542
  if (this.closed) return;
1480
1543
  watcher.emit("remove");
1481
1544
  });
1482
1545
  }
1483
1546
  } else if (
1484
- filePath !== this.path &&
1485
- !this.directories.has(filePath) &&
1486
- watcher.checkStartTime(this.initialScanFinished, false)
1547
+ target !== this.path &&
1548
+ !this.directories.has(target) &&
1549
+ watcher.checkStartTime(
1550
+ /** @type {number} */
1551
+ (this.initialScanFinished),
1552
+ false,
1553
+ )
1487
1554
  ) {
1488
1555
  process.nextTick(() => {
1489
1556
  if (this.closed) return;
@@ -1493,6 +1560,10 @@ class DirectoryWatcher extends EventEmitter {
1493
1560
  return watcher;
1494
1561
  }
1495
1562
 
1563
+ /**
1564
+ * @param {EventType} eventType event type
1565
+ * @param {string=} filename filename
1566
+ */
1496
1567
  onWatchEvent(eventType, filename) {
1497
1568
  if (this.closed) return;
1498
1569
  if (!filename) {
@@ -1504,15 +1575,15 @@ class DirectoryWatcher extends EventEmitter {
1504
1575
  return;
1505
1576
  }
1506
1577
 
1507
- const filePath = path.join(this.path, filename);
1508
- if (this.ignored(filePath)) return;
1578
+ const target = path.join(this.path, filename);
1579
+ if (this.ignored(target)) return;
1509
1580
 
1510
1581
  if (this._activeEvents.get(filename) === undefined) {
1511
1582
  this._activeEvents.set(filename, false);
1512
1583
  const checkStats = () => {
1513
1584
  if (this.closed) return;
1514
1585
  this._activeEvents.set(filename, false);
1515
- fs.lstat(filePath, (err, stats) => {
1586
+ lstatWithRetry(target, this, (err, stats) => {
1516
1587
  if (this.closed) return;
1517
1588
  if (this._activeEvents.get(filename) === true) {
1518
1589
  process.nextTick(checkStats);
@@ -1521,6 +1592,9 @@ class DirectoryWatcher extends EventEmitter {
1521
1592
  this._activeEvents.delete(filename);
1522
1593
  // ENOENT happens when the file/directory doesn't exist
1523
1594
  // EPERM happens when the containing directory doesn't exist
1595
+ // EBUSY happens when another process has the file locked (e.g.
1596
+ // Windows AV scanner). lstatWithRetry already retried before
1597
+ // giving up here.
1524
1598
  if (err) {
1525
1599
  if (
1526
1600
  err.code !== "ENOENT" &&
@@ -1528,35 +1602,35 @@ class DirectoryWatcher extends EventEmitter {
1528
1602
  err.code !== "EBUSY"
1529
1603
  ) {
1530
1604
  this.onStatsError(err);
1531
- } else {
1532
- if (filename === path.basename(this.path)) {
1533
- // This may indicate that the directory itself was removed
1534
- if (!fs.existsSync(this.path)) {
1535
- this.onDirectoryRemoved("stat failed");
1536
- }
1537
- }
1605
+ } else if (
1606
+ filename === path.basename(this.path) && // This may indicate that the directory itself was removed
1607
+ !fs.existsSync(this.path)
1608
+ ) {
1609
+ this.onDirectoryRemoved("stat failed");
1538
1610
  }
1539
1611
  }
1540
1612
  this.lastWatchEvent = Date.now();
1541
1613
  if (!stats) {
1542
- this.setMissing(filePath, false, eventType);
1614
+ // On EBUSY we keep the tracked state: the file is likely still
1615
+ // there and a later event or scan will reconcile. Emitting a
1616
+ // remove here would make the watch appear to stop after a
1617
+ // transient lock (webpack/watchpack#223, #44).
1618
+ if (err && err.code === "EBUSY" && BUSY_RETRIES > 0) {
1619
+ return;
1620
+ }
1621
+ this.setMissing(target, false, eventType);
1543
1622
  } else if (stats.isDirectory()) {
1544
- this.setDirectory(
1545
- filePath,
1546
- +stats.birthtime || 1,
1547
- false,
1548
- eventType
1549
- );
1623
+ this.setDirectory(target, +stats.birthtime || 1, false, eventType);
1550
1624
  } else if (stats.isFile() || stats.isSymbolicLink()) {
1551
1625
  if (stats.mtime) {
1552
- ensureFsAccuracy(stats.mtime);
1626
+ ensureFsAccuracy(+stats.mtime);
1553
1627
  }
1554
1628
  this.setFileTime(
1555
- filePath,
1629
+ target,
1556
1630
  +stats.mtime || +stats.ctime || 1,
1557
1631
  false,
1558
1632
  false,
1559
- eventType
1633
+ eventType,
1560
1634
  );
1561
1635
  }
1562
1636
  });
@@ -1567,25 +1641,42 @@ class DirectoryWatcher extends EventEmitter {
1567
1641
  }
1568
1642
  }
1569
1643
 
1644
+ /**
1645
+ * @param {unknown=} err error
1646
+ */
1570
1647
  onWatcherError(err) {
1571
1648
  if (this.closed) return;
1572
1649
  if (err) {
1573
- if (err.code !== "EPERM" && err.code !== "ENOENT") {
1574
- console.error("Watchpack Error (watcher): " + err);
1650
+ if (
1651
+ /** @type {NodeJS.ErrnoException} */
1652
+ (err).code !== "EPERM" &&
1653
+ /** @type {NodeJS.ErrnoException} */
1654
+ (err).code !== "ENOENT"
1655
+ ) {
1656
+ // eslint-disable-next-line no-console
1657
+ console.error(`Watchpack Error (watcher): ${err}`);
1575
1658
  }
1576
1659
  this.onDirectoryRemoved("watch error");
1577
1660
  }
1578
1661
  }
1579
1662
 
1663
+ /**
1664
+ * @param {Error | NodeJS.ErrnoException=} err error
1665
+ */
1580
1666
  onStatsError(err) {
1581
1667
  if (err) {
1582
- console.error("Watchpack Error (stats): " + err);
1668
+ // eslint-disable-next-line no-console
1669
+ console.error(`Watchpack Error (stats): ${err}`);
1583
1670
  }
1584
1671
  }
1585
1672
 
1673
+ /**
1674
+ * @param {Error | NodeJS.ErrnoException=} err error
1675
+ */
1586
1676
  onScanError(err) {
1587
1677
  if (err) {
1588
- console.error("Watchpack Error (initial scan): " + err);
1678
+ // eslint-disable-next-line no-console
1679
+ console.error(`Watchpack Error (initial scan): ${err}`);
1589
1680
  }
1590
1681
  this.onScanFinished();
1591
1682
  }
@@ -1599,18 +1690,21 @@ class DirectoryWatcher extends EventEmitter {
1599
1690
  }
1600
1691
  }
1601
1692
 
1693
+ /**
1694
+ * @param {string} reason a reason
1695
+ */
1602
1696
  onDirectoryRemoved(reason) {
1603
1697
  if (this.watcher) {
1604
1698
  this.watcher.close();
1605
1699
  this.watcher = null;
1606
1700
  }
1607
1701
  this.watchInParentDirectory();
1608
- const type = `directory-removed (${reason})`;
1702
+ const type = /** @type {EventType} */ (`directory-removed (${reason})`);
1609
1703
  for (const directory of this.directories.keys()) {
1610
- this.setMissing(directory, null, type);
1704
+ this.setMissing(directory, false, type);
1611
1705
  }
1612
1706
  for (const file of this.files.keys()) {
1613
- this.setMissing(file, null, type);
1707
+ this.setMissing(file, false, type);
1614
1708
  }
1615
1709
  }
1616
1710
 
@@ -1622,7 +1716,8 @@ class DirectoryWatcher extends EventEmitter {
1622
1716
  if (path.dirname(parentDir) === parentDir) return;
1623
1717
 
1624
1718
  this.parentWatcher = this.watcherManager.watchFile(this.path, 1);
1625
- this.parentWatcher.on("change", (mtime, type) => {
1719
+ /** @type {Watcher<FileWatcherEvents>} */
1720
+ (this.parentWatcher).on("change", (mtime, type) => {
1626
1721
  if (this.closed) return;
1627
1722
 
1628
1723
  // On non-osx platforms we don't need this watcher to detect
@@ -1637,17 +1732,21 @@ class DirectoryWatcher extends EventEmitter {
1637
1732
  this.doScan(false);
1638
1733
 
1639
1734
  // directory was created so we emit an event
1640
- this.forEachWatcher(this.path, w =>
1641
- w.emit("change", this.path, mtime, type, false)
1735
+ this.forEachWatcher(this.path, (w) =>
1736
+ w.emit("change", this.path, mtime, type, false),
1642
1737
  );
1643
1738
  }
1644
1739
  });
1645
- this.parentWatcher.on("remove", () => {
1740
+ /** @type {Watcher<FileWatcherEvents>} */
1741
+ (this.parentWatcher).on("remove", () => {
1646
1742
  this.onDirectoryRemoved("parent directory removed");
1647
1743
  });
1648
1744
  }
1649
1745
  }
1650
1746
 
1747
+ /**
1748
+ * @param {boolean} initial true when initial, otherwise false
1749
+ */
1651
1750
  doScan(initial) {
1652
1751
  if (this.scanning) {
1653
1752
  if (this.scanAgain) {
@@ -1668,7 +1767,20 @@ class DirectoryWatcher extends EventEmitter {
1668
1767
  fs.readdir(this.path, (err, items) => {
1669
1768
  if (this.closed) return;
1670
1769
  if (err) {
1671
- if (err.code === "ENOENT" || err.code === "EPERM") {
1770
+ // Mirror the lstat error handling below: treat permission /
1771
+ // invalid-argument / no-device errors on the directory itself
1772
+ // as removed rather than logging "Watchpack Error (initial
1773
+ // scan)". These surface for unreadable mounts (WSL `/mnt/c`,
1774
+ // fuse mounts), unmounted devices (`/efi`), and libuv's
1775
+ // post-Node 22.17 `EINVAL` on protected Windows paths
1776
+ // (see #187).
1777
+ if (
1778
+ err.code === "ENOENT" ||
1779
+ err.code === "EPERM" ||
1780
+ err.code === "EACCES" ||
1781
+ err.code === "ENODEV" ||
1782
+ (err.code === "EINVAL" && IS_WIN)
1783
+ ) {
1672
1784
  this.onDirectoryRemoved("scan readdir failed");
1673
1785
  } else {
1674
1786
  this.onScanError(err);
@@ -1681,7 +1793,7 @@ class DirectoryWatcher extends EventEmitter {
1681
1793
  if (watcher.checkStartTime(this.initialScanFinished, false)) {
1682
1794
  watcher.emit(
1683
1795
  "initial-missing",
1684
- "scan (parent directory missing in initial scan)"
1796
+ "scan (parent directory missing in initial scan)",
1685
1797
  );
1686
1798
  }
1687
1799
  }
@@ -1696,7 +1808,7 @@ class DirectoryWatcher extends EventEmitter {
1696
1808
  return;
1697
1809
  }
1698
1810
  const itemPaths = new Set(
1699
- items.map(item => path.join(this.path, item.normalize("NFC")))
1811
+ items.map((item) => path.join(this.path, item.normalize("NFC"))),
1700
1812
  );
1701
1813
  for (const file of this.files.keys()) {
1702
1814
  if (!itemPaths.has(file)) {
@@ -1730,7 +1842,7 @@ class DirectoryWatcher extends EventEmitter {
1730
1842
  if (watcher.checkStartTime(this.initialScanFinished, false)) {
1731
1843
  watcher.emit(
1732
1844
  "initial-missing",
1733
- "scan (missing in initial scan)"
1845
+ "scan (missing in initial scan)",
1734
1846
  );
1735
1847
  }
1736
1848
  }
@@ -1745,7 +1857,7 @@ class DirectoryWatcher extends EventEmitter {
1745
1857
  }
1746
1858
  });
1747
1859
  for (const itemPath of itemPaths) {
1748
- fs.lstat(itemPath, (err2, stats) => {
1860
+ lstatWithRetry(itemPath, this, (err2, stats) => {
1749
1861
  if (this.closed) return;
1750
1862
  if (err2) {
1751
1863
  if (
@@ -1753,37 +1865,115 @@ class DirectoryWatcher extends EventEmitter {
1753
1865
  err2.code === "EPERM" ||
1754
1866
  err2.code === "EACCES" ||
1755
1867
  err2.code === "EBUSY" ||
1868
+ err2.code === "ENODEV" ||
1756
1869
  // TODO https://github.com/libuv/libuv/pull/4566
1757
1870
  (err2.code === "EINVAL" && IS_WIN)
1758
1871
  ) {
1759
- this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
1872
+ // readdir saw the entry but we can't stat it due to a
1873
+ // transient lock — keep the previously-known entry instead
1874
+ // of incorrectly flagging it as missing.
1875
+ if (
1876
+ !(
1877
+ err2.code === "EBUSY" &&
1878
+ BUSY_RETRIES > 0 &&
1879
+ this.files.has(itemPath)
1880
+ )
1881
+ ) {
1882
+ this.setMissing(itemPath, initial, `scan (${err2.code})`);
1883
+ }
1760
1884
  } else {
1761
1885
  this.onScanError(err2);
1762
1886
  }
1763
1887
  itemFinished();
1764
1888
  return;
1765
1889
  }
1766
- if (stats.isFile() || stats.isSymbolicLink()) {
1767
- if (stats.mtime) {
1768
- ensureFsAccuracy(stats.mtime);
1769
- }
1770
- this.setFileTime(
1771
- itemPath,
1772
- +stats.mtime || +stats.ctime || 1,
1773
- initial,
1774
- true,
1775
- "scan (file)"
1776
- );
1777
- } else if (stats.isDirectory()) {
1778
- if (!initial || !this.directories.has(itemPath))
1890
+ /**
1891
+ * @param {string | null} realPath resolved real path for an outside-dir symlink target
1892
+ */
1893
+ const apply = (realPath) => {
1894
+ if (stats.isFile() || stats.isSymbolicLink()) {
1895
+ if (stats.mtime) ensureFsAccuracy(+stats.mtime);
1896
+ this.setFileTime(
1897
+ itemPath,
1898
+ +stats.mtime || +stats.ctime || 1,
1899
+ initial,
1900
+ true,
1901
+ "scan (file)",
1902
+ );
1903
+ if (realPath && !this._symlinkTargetWatchers.has(itemPath)) {
1904
+ const w = this.watcherManager.watchFile(realPath, Date.now());
1905
+ if (w) {
1906
+ w.on("change", (mtime, type, wInitial) => {
1907
+ if (wInitial) return;
1908
+ this.setFileTime(itemPath, mtime, false, false, type);
1909
+ });
1910
+ this._symlinkTargetWatchers.set(itemPath, w);
1911
+ }
1912
+ }
1913
+ } else if (
1914
+ stats.isDirectory() &&
1915
+ (!initial || !this.directories.has(itemPath))
1916
+ ) {
1779
1917
  this.setDirectory(
1780
1918
  itemPath,
1781
1919
  +stats.birthtime || 1,
1782
1920
  initial,
1783
- "scan (dir)"
1921
+ "scan (dir)",
1784
1922
  );
1923
+ }
1924
+ itemFinished();
1925
+ };
1926
+ if (
1927
+ this.options.followSymlinks &&
1928
+ this.nestedWatching &&
1929
+ stats.isSymbolicLink()
1930
+ ) {
1931
+ fs.realpath(itemPath, (err3, realPath) => {
1932
+ if (this.closed) return;
1933
+ if (
1934
+ err3 ||
1935
+ !realPath ||
1936
+ withoutCase(path.dirname(realPath)) === withoutCase(this.path)
1937
+ ) {
1938
+ apply(null);
1939
+ return;
1940
+ }
1941
+ // Cycle protection: when the symlink's target is the symlink
1942
+ // path itself or one of its ancestors, descending would
1943
+ // create an unbounded chain of `DirectoryWatcher`s as we walk
1944
+ // back into territory we are already watching. Treat the
1945
+ // symlink as a plain entry instead so the symlink itself is
1946
+ // still tracked but no recursion happens.
1947
+ const rel = path.relative(realPath, itemPath);
1948
+ if (!path.isAbsolute(rel) && !rel.startsWith("..")) {
1949
+ apply(null);
1950
+ return;
1951
+ }
1952
+ fs.stat(realPath, (err4, targetStats) => {
1953
+ if (this.closed) return;
1954
+ if (err4 || !targetStats) {
1955
+ apply(null);
1956
+ } else if (targetStats.isFile()) {
1957
+ apply(realPath);
1958
+ } else if (targetStats.isDirectory()) {
1959
+ // Treat a symlink whose target is a directory as a
1960
+ // nested watched directory so files inside the target
1961
+ // propagate change events to the symlink path.
1962
+ this.setDirectory(
1963
+ itemPath,
1964
+ +targetStats.birthtime || +stats.birthtime || 1,
1965
+ initial,
1966
+ "scan (dir)",
1967
+ );
1968
+ itemFinished();
1969
+ } else {
1970
+ apply(null);
1971
+ }
1972
+ });
1973
+ });
1974
+ return;
1785
1975
  }
1786
- itemFinished();
1976
+ apply(null);
1787
1977
  });
1788
1978
  }
1789
1979
  itemFinished();
@@ -1791,6 +1981,9 @@ class DirectoryWatcher extends EventEmitter {
1791
1981
  });
1792
1982
  }
1793
1983
 
1984
+ /**
1985
+ * @returns {Record<string, number>} times
1986
+ */
1794
1987
  getTimes() {
1795
1988
  const obj = Object.create(null);
1796
1989
  let safeTime = this.lastWatchEvent;
@@ -1801,7 +1994,9 @@ class DirectoryWatcher extends EventEmitter {
1801
1994
  }
1802
1995
  if (this.nestedWatching) {
1803
1996
  for (const w of this.directories.values()) {
1804
- const times = w.directoryWatcher.getTimes();
1997
+ const times =
1998
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1999
+ (w).directoryWatcher.getTimes();
1805
2000
  for (const file of Object.keys(times)) {
1806
2001
  const time = times[file];
1807
2002
  safeTime = Math.max(safeTime, time);
@@ -1813,7 +2008,7 @@ class DirectoryWatcher extends EventEmitter {
1813
2008
  if (!this.initialScan) {
1814
2009
  for (const watchers of this.watchers.values()) {
1815
2010
  for (const watcher of watchers) {
1816
- const path = watcher.path;
2011
+ const { path } = watcher;
1817
2012
  if (!Object.prototype.hasOwnProperty.call(obj, path)) {
1818
2013
  obj[path] = null;
1819
2014
  }
@@ -1823,6 +2018,11 @@ class DirectoryWatcher extends EventEmitter {
1823
2018
  return obj;
1824
2019
  }
1825
2020
 
2021
+ /**
2022
+ * @param {TimeInfoEntries} fileTimestamps file timestamps
2023
+ * @param {TimeInfoEntries} directoryTimestamps directory timestamps
2024
+ * @returns {number} safe time
2025
+ */
1826
2026
  collectTimeInfoEntries(fileTimestamps, directoryTimestamps) {
1827
2027
  let safeTime = this.lastWatchEvent;
1828
2028
  for (const [file, entry] of this.files) {
@@ -1834,23 +2034,25 @@ class DirectoryWatcher extends EventEmitter {
1834
2034
  for (const w of this.directories.values()) {
1835
2035
  safeTime = Math.max(
1836
2036
  safeTime,
1837
- w.directoryWatcher.collectTimeInfoEntries(
2037
+ /** @type {Watcher<DirectoryWatcherEvents>} */
2038
+ (w).directoryWatcher.collectTimeInfoEntries(
1838
2039
  fileTimestamps,
1839
- directoryTimestamps
1840
- )
2040
+ directoryTimestamps,
2041
+ ),
1841
2042
  );
1842
2043
  }
1843
2044
  fileTimestamps.set(this.path, EXISTANCE_ONLY_TIME_ENTRY);
1844
2045
  directoryTimestamps.set(this.path, {
1845
- safeTime
2046
+ safeTime,
1846
2047
  });
1847
2048
  } else {
1848
2049
  for (const dir of this.directories.keys()) {
1849
2050
  // No additional info about this directory
1850
2051
  // but maybe another DirectoryWatcher has info
1851
2052
  fileTimestamps.set(dir, EXISTANCE_ONLY_TIME_ENTRY);
1852
- if (!directoryTimestamps.has(dir))
2053
+ if (!directoryTimestamps.has(dir)) {
1853
2054
  directoryTimestamps.set(dir, EXISTANCE_ONLY_TIME_ENTRY);
2055
+ }
1854
2056
  }
1855
2057
  fileTimestamps.set(this.path, EXISTANCE_ONLY_TIME_ENTRY);
1856
2058
  directoryTimestamps.set(this.path, EXISTANCE_ONLY_TIME_ENTRY);
@@ -1858,7 +2060,7 @@ class DirectoryWatcher extends EventEmitter {
1858
2060
  if (!this.initialScan) {
1859
2061
  for (const watchers of this.watchers.values()) {
1860
2062
  for (const watcher of watchers) {
1861
- const path = watcher.path;
2063
+ const { path } = watcher;
1862
2064
  if (!fileTimestamps.has(path)) {
1863
2065
  fileTimestamps.set(path, null);
1864
2066
  }
@@ -1869,6 +2071,7 @@ class DirectoryWatcher extends EventEmitter {
1869
2071
  }
1870
2072
 
1871
2073
  close() {
2074
+ if (this.closed) return;
1872
2075
  this.closed = true;
1873
2076
  this.initialScan = false;
1874
2077
  if (this.watcher) {
@@ -1877,10 +2080,15 @@ class DirectoryWatcher extends EventEmitter {
1877
2080
  }
1878
2081
  if (this.nestedWatching) {
1879
2082
  for (const w of this.directories.values()) {
1880
- w.close();
2083
+ /** @type {Watcher<DirectoryWatcherEvents>} */
2084
+ (w).close();
1881
2085
  }
1882
2086
  this.directories.clear();
1883
2087
  }
2088
+ for (const w of this._symlinkTargetWatchers.values()) {
2089
+ w.close();
2090
+ }
2091
+ this._symlinkTargetWatchers.clear();
1884
2092
  if (this.parentWatcher) {
1885
2093
  this.parentWatcher.close();
1886
2094
  this.parentWatcher = null;
@@ -1891,26 +2099,12 @@ class DirectoryWatcher extends EventEmitter {
1891
2099
 
1892
2100
  module.exports = DirectoryWatcher;
1893
2101
  module.exports.EXISTANCE_ONLY_TIME_ENTRY = EXISTANCE_ONLY_TIME_ENTRY;
1894
-
1895
- function fixupEntryAccuracy(entry) {
1896
- if (entry.accuracy > FS_ACCURACY) {
1897
- entry.safeTime = entry.safeTime - entry.accuracy + FS_ACCURACY;
1898
- entry.accuracy = FS_ACCURACY;
1899
- }
1900
- }
1901
-
1902
- function ensureFsAccuracy(mtime) {
1903
- if (!mtime) return;
1904
- if (FS_ACCURACY > 1 && mtime % 1 !== 0) FS_ACCURACY = 1;
1905
- else if (FS_ACCURACY > 10 && mtime % 10 !== 0) FS_ACCURACY = 10;
1906
- else if (FS_ACCURACY > 100 && mtime % 100 !== 0) FS_ACCURACY = 100;
1907
- else if (FS_ACCURACY > 1000 && mtime % 1000 !== 0) FS_ACCURACY = 1000;
1908
- }
2102
+ module.exports.Watcher = Watcher;
1909
2103
 
1910
2104
 
1911
2105
  /***/ }),
1912
2106
 
1913
- /***/ 751:
2107
+ /***/ 366:
1914
2108
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1915
2109
 
1916
2110
  "use strict";
@@ -1931,12 +2125,13 @@ if (process.platform === "win32") EXPECTED_ERRORS.add("UNKNOWN");
1931
2125
 
1932
2126
  class LinkResolver {
1933
2127
  constructor() {
2128
+ /** @type {Map<string, readonly string[]>} */
1934
2129
  this.cache = new Map();
1935
2130
  }
1936
2131
 
1937
2132
  /**
1938
2133
  * @param {string} file path to file or directory
1939
- * @returns {string[]} array of file and all symlinks contributed in the resolving process (first item is the resolved file)
2134
+ * @returns {readonly string[]} array of file and all symlinks contributed in the resolving process (first item is the resolved file)
1940
2135
  */
1941
2136
  resolve(file) {
1942
2137
  const cacheEntry = this.cache.get(file);
@@ -1981,17 +2176,18 @@ class LinkResolver {
1981
2176
  for (let i = 1; i < parentResolved.length; i++) {
1982
2177
  resultSet.add(parentResolved[i]);
1983
2178
  }
1984
- result = Object.freeze(Array.from(resultSet));
2179
+ result = Object.freeze([...resultSet]);
1985
2180
  } else if (parentResolved.length > 1) {
1986
2181
  // we have links in the parent but not for the link content location
1987
- result = parentResolved.slice();
2182
+ result = [...parentResolved];
2183
+ // eslint-disable-next-line prefer-destructuring
1988
2184
  result[0] = linkResolved[0];
1989
2185
  // add the link
1990
2186
  result.push(realFile);
1991
2187
  Object.freeze(result);
1992
2188
  } else if (linkResolved.length > 1) {
1993
2189
  // we can return the link content location result
1994
- result = linkResolved.slice();
2190
+ result = [...linkResolved];
1995
2191
  // add the link
1996
2192
  result.push(realFile);
1997
2193
  Object.freeze(result);
@@ -2002,17 +2198,21 @@ class LinkResolver {
2002
2198
  // the resolve real location
2003
2199
  linkResolved[0],
2004
2200
  // add the link
2005
- realFile
2201
+ realFile,
2006
2202
  ]);
2007
2203
  }
2008
2204
  this.cache.set(file, result);
2009
2205
  return result;
2010
- } catch (e) {
2011
- if (!EXPECTED_ERRORS.has(e.code)) {
2012
- throw e;
2206
+ } catch (err) {
2207
+ if (
2208
+ /** @type {NodeJS.ErrnoException} */
2209
+ (err).code &&
2210
+ !EXPECTED_ERRORS.has(/** @type {NodeJS.ErrnoException} */ (err).code)
2211
+ ) {
2212
+ throw err;
2013
2213
  }
2014
2214
  // no link
2015
- const result = parentResolved.slice();
2215
+ const result = [...parentResolved];
2016
2216
  result[0] = realFile;
2017
2217
  Object.freeze(result);
2018
2218
  this.cache.set(file, result);
@@ -2020,12 +2220,13 @@ class LinkResolver {
2020
2220
  }
2021
2221
  }
2022
2222
  }
2223
+
2023
2224
  module.exports = LinkResolver;
2024
2225
 
2025
2226
 
2026
2227
  /***/ }),
2027
2228
 
2028
- /***/ 510:
2229
+ /***/ 213:
2029
2230
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2030
2231
 
2031
2232
  "use strict";
@@ -2036,14 +2237,31 @@ module.exports = LinkResolver;
2036
2237
 
2037
2238
 
2038
2239
  const path = __nccwpck_require__(928);
2039
- const DirectoryWatcher = __nccwpck_require__(40);
2240
+ const DirectoryWatcher = __nccwpck_require__(409);
2241
+
2242
+ /** @typedef {import("./index").EventMap} EventMap */
2243
+ /** @typedef {import("./DirectoryWatcher").DirectoryWatcherOptions} DirectoryWatcherOptions */
2244
+ /** @typedef {import("./DirectoryWatcher").DirectoryWatcherEvents} DirectoryWatcherEvents */
2245
+ /** @typedef {import("./DirectoryWatcher").FileWatcherEvents} FileWatcherEvents */
2246
+ /**
2247
+ * @template {EventMap} T
2248
+ * @typedef {import("./DirectoryWatcher").Watcher<T>} Watcher
2249
+ */
2040
2250
 
2041
2251
  class WatcherManager {
2042
- constructor(options) {
2252
+ /**
2253
+ * @param {DirectoryWatcherOptions=} options options
2254
+ */
2255
+ constructor(options = {}) {
2043
2256
  this.options = options;
2257
+ /** @type {Map<string, DirectoryWatcher>} */
2044
2258
  this.directoryWatchers = new Map();
2045
2259
  }
2046
2260
 
2261
+ /**
2262
+ * @param {string} directory a directory
2263
+ * @returns {DirectoryWatcher} a directory watcher
2264
+ */
2047
2265
  getDirectoryWatcher(directory) {
2048
2266
  const watcher = this.directoryWatchers.get(directory);
2049
2267
  if (watcher === undefined) {
@@ -2057,23 +2275,34 @@ class WatcherManager {
2057
2275
  return watcher;
2058
2276
  }
2059
2277
 
2060
- watchFile(p, startTime) {
2061
- const directory = path.dirname(p);
2062
- if (directory === p) return null;
2063
- return this.getDirectoryWatcher(directory).watch(p, startTime);
2278
+ /**
2279
+ * @param {string} file file
2280
+ * @param {number=} startTime start time
2281
+ * @returns {Watcher<FileWatcherEvents> | null} watcher or null if file has no directory
2282
+ */
2283
+ watchFile(file, startTime) {
2284
+ const directory = path.dirname(file);
2285
+ if (directory === file) return null;
2286
+ return this.getDirectoryWatcher(directory).watch(file, startTime);
2064
2287
  }
2065
2288
 
2289
+ /**
2290
+ * @param {string} directory directory
2291
+ * @param {number=} startTime start time
2292
+ * @returns {Watcher<DirectoryWatcherEvents>} watcher
2293
+ */
2066
2294
  watchDirectory(directory, startTime) {
2067
2295
  return this.getDirectoryWatcher(directory).watch(directory, startTime);
2068
2296
  }
2069
2297
  }
2070
2298
 
2071
2299
  const watcherManagers = new WeakMap();
2300
+
2072
2301
  /**
2073
- * @param {object} options options
2302
+ * @param {DirectoryWatcherOptions} options options
2074
2303
  * @returns {WatcherManager} the watcher manager
2075
2304
  */
2076
- module.exports = options => {
2305
+ module.exports = (options) => {
2077
2306
  const watcherManager = watcherManagers.get(options);
2078
2307
  if (watcherManager !== undefined) return watcherManager;
2079
2308
  const newWatcherManager = new WatcherManager(options);
@@ -2085,7 +2314,7 @@ module.exports.WatcherManager = WatcherManager;
2085
2314
 
2086
2315
  /***/ }),
2087
2316
 
2088
- /***/ 864:
2317
+ /***/ 934:
2089
2318
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2090
2319
 
2091
2320
  "use strict";
@@ -2095,144 +2324,600 @@ module.exports.WatcherManager = WatcherManager;
2095
2324
  */
2096
2325
 
2097
2326
 
2098
- const path = __nccwpck_require__(928);
2327
+ const { EventEmitter } = __nccwpck_require__(434);
2328
+ const LinkResolver = __nccwpck_require__(366);
2329
+ const getWatcherManager = __nccwpck_require__(213);
2330
+ const globToRegExp = __nccwpck_require__(737);
2331
+ const watchEventSource = __nccwpck_require__(92);
2332
+
2333
+ /** @typedef {import("./getWatcherManager").WatcherManager} WatcherManager */
2334
+ /** @typedef {import("./DirectoryWatcher")} DirectoryWatcher */
2335
+ /** @typedef {import("./DirectoryWatcher").DirectoryWatcherEvents} DirectoryWatcherEvents */
2336
+ /** @typedef {import("./DirectoryWatcher").FileWatcherEvents} FileWatcherEvents */
2337
+
2338
+ // eslint-disable-next-line jsdoc/reject-any-type
2339
+ /** @typedef {Record<string, (...args: any[]) => any>} EventMap */
2099
2340
 
2100
2341
  /**
2101
- * @template T
2102
- * @typedef {Object} TreeNode
2103
- * @property {string} filePath
2104
- * @property {TreeNode} parent
2105
- * @property {TreeNode[]} children
2106
- * @property {number} entries
2107
- * @property {boolean} active
2108
- * @property {T[] | T | undefined} value
2342
+ * @template {EventMap} T
2343
+ * @typedef {import("./DirectoryWatcher").Watcher<T>} Watcher
2109
2344
  */
2110
2345
 
2346
+ /** @typedef {(item: string) => boolean} IgnoredFunction */
2347
+ /** @typedef {string[] | RegExp | string | IgnoredFunction} Ignored */
2348
+
2111
2349
  /**
2112
- * @template T
2113
- * @param {Map<string, T[] | T} plan
2114
- * @param {number} limit
2115
- * @returns {Map<string, Map<T, string>>} the new plan
2350
+ * @typedef {object} WatcherOptions
2351
+ * @property {boolean=} followSymlinks true when need to resolve symlinks and watch symlink and real file, otherwise false
2352
+ * @property {Ignored=} ignored ignore some files from watching (glob pattern or regexp)
2353
+ * @property {number | boolean=} poll true when need to enable polling mode for watching, otherwise false
2116
2354
  */
2117
- module.exports = (plan, limit) => {
2118
- const treeMap = new Map();
2119
- // Convert to tree
2120
- for (const [filePath, value] of plan) {
2121
- treeMap.set(filePath, {
2122
- filePath,
2123
- parent: undefined,
2124
- children: undefined,
2125
- entries: 1,
2126
- active: true,
2127
- value
2128
- });
2129
- }
2130
- let currentCount = treeMap.size;
2131
- // Create parents and calculate sum of entries
2132
- for (const node of treeMap.values()) {
2133
- const parentPath = path.dirname(node.filePath);
2134
- if (parentPath !== node.filePath) {
2135
- let parent = treeMap.get(parentPath);
2136
- if (parent === undefined) {
2137
- parent = {
2138
- filePath: parentPath,
2139
- parent: undefined,
2140
- children: [node],
2141
- entries: node.entries,
2142
- active: false,
2143
- value: undefined
2144
- };
2145
- treeMap.set(parentPath, parent);
2146
- node.parent = parent;
2147
- } else {
2148
- node.parent = parent;
2149
- if (parent.children === undefined) {
2150
- parent.children = [node];
2151
- } else {
2152
- parent.children.push(node);
2153
- }
2154
- do {
2155
- parent.entries += node.entries;
2156
- parent = parent.parent;
2157
- } while (parent);
2158
- }
2159
- }
2355
+
2356
+ /** @typedef {WatcherOptions & { aggregateTimeout?: number }} WatchOptions */
2357
+
2358
+ /**
2359
+ * @typedef {object} NormalizedWatchOptions
2360
+ * @property {boolean} followSymlinks true when need to resolve symlinks and watch symlink and real file, otherwise false
2361
+ * @property {IgnoredFunction} ignored ignore some files from watching (glob pattern or regexp)
2362
+ * @property {number | boolean=} poll true when need to enable polling mode for watching, otherwise false
2363
+ */
2364
+
2365
+ /** @typedef {`scan (${string})` | "change" | "rename" | `watch ${string}` | `directory-removed ${string}`} EventType */
2366
+ /** @typedef {{ safeTime: number, timestamp: number, accuracy: number }} Entry */
2367
+ /** @typedef {{ safeTime: number }} OnlySafeTimeEntry */
2368
+
2369
+ // eslint-disable-next-line jsdoc/ts-no-empty-object-type
2370
+ /** @typedef {{ }} ExistenceOnlyTimeEntry */
2371
+ /** @typedef {Map<string, Entry | OnlySafeTimeEntry | ExistenceOnlyTimeEntry | null>} TimeInfoEntries */
2372
+ /** @typedef {Set<string>} Changes */
2373
+ /** @typedef {Set<string>} Removals */
2374
+ /** @typedef {{ changes: Changes, removals: Removals }} Aggregated */
2375
+ /** @typedef {{ files?: Iterable<string>, directories?: Iterable<string>, missing?: Iterable<string>, startTime?: number }} WatchMethodOptions */
2376
+ /** @typedef {Record<string, number>} Times */
2377
+
2378
+ /**
2379
+ * @param {MapIterator<WatchpackFileWatcher> | MapIterator<WatchpackDirectoryWatcher>} watchers watchers
2380
+ * @param {Set<DirectoryWatcher>} set set
2381
+ */
2382
+ function addWatchersToSet(watchers, set) {
2383
+ for (const ww of watchers) {
2384
+ // Set.add is already idempotent, so skip the redundant has() probe.
2385
+ set.add(ww.watcher.directoryWatcher);
2160
2386
  }
2161
- // Reduce until limit reached
2162
- while (currentCount > limit) {
2163
- // Select node that helps reaching the limit most effectively without overmerging
2164
- const overLimit = currentCount - limit;
2165
- let bestNode = undefined;
2166
- let bestCost = Infinity;
2167
- for (const node of treeMap.values()) {
2168
- if (node.entries <= 1 || !node.children || !node.parent) continue;
2169
- if (node.children.length === 0) continue;
2170
- if (node.children.length === 1 && !node.value) continue;
2171
- // Try to select the node with has just a bit more entries than we need to reduce
2172
- // When just a bit more is over 30% over the limit,
2173
- // also consider just a bit less entries then we need to reduce
2174
- const cost =
2175
- node.entries - 1 >= overLimit
2176
- ? node.entries - 1 - overLimit
2177
- : overLimit - node.entries + 1 + limit * 0.3;
2178
- if (cost < bestCost) {
2179
- bestNode = node;
2180
- bestCost = cost;
2181
- }
2182
- }
2183
- if (!bestNode) break;
2184
- // Merge all children
2185
- const reduction = bestNode.entries - 1;
2186
- bestNode.active = true;
2187
- bestNode.entries = 1;
2188
- currentCount -= reduction;
2189
- let parent = bestNode.parent;
2190
- while (parent) {
2191
- parent.entries -= reduction;
2192
- parent = parent.parent;
2193
- }
2194
- const queue = new Set(bestNode.children);
2195
- for (const node of queue) {
2196
- node.active = false;
2197
- node.entries = 0;
2198
- if (node.children) {
2199
- for (const child of node.children) queue.add(child);
2200
- }
2201
- }
2387
+ }
2388
+
2389
+ /**
2390
+ * @param {string} ignored ignored
2391
+ * @returns {string | undefined} resolved global to regexp
2392
+ */
2393
+ const stringToRegexp = (ignored) => {
2394
+ if (ignored.length === 0) {
2395
+ return;
2202
2396
  }
2203
- // Write down new plan
2204
- const newPlan = new Map();
2205
- for (const rootNode of treeMap.values()) {
2206
- if (!rootNode.active) continue;
2207
- const map = new Map();
2208
- const queue = new Set([rootNode]);
2209
- for (const node of queue) {
2210
- if (node.active && node !== rootNode) continue;
2211
- if (node.value) {
2212
- if (Array.isArray(node.value)) {
2213
- for (const item of node.value) {
2214
- map.set(item, node.filePath);
2397
+ return `^${globToRegExp(ignored)}(?:$|\\/)`;
2398
+ };
2399
+
2400
+ /**
2401
+ * Normalizes path separators for regex testing. `String.prototype.replace`
2402
+ * always allocates a new string, even when the pattern finds nothing; for
2403
+ * POSIX paths (the common case) that allocation is pure overhead. Check for
2404
+ * a backslash with `indexOf` first so we skip the copy on paths that are
2405
+ * already normalized.
2406
+ * @param {string} item item
2407
+ * @returns {string} item with backslashes normalized to forward slashes
2408
+ */
2409
+ const normalizeSeparators = (item) =>
2410
+ item.includes("\\") ? item.replace(/\\/g, "/") : item;
2411
+
2412
+ /**
2413
+ * @param {Ignored=} ignored ignored
2414
+ * @returns {(item: string) => boolean} ignored to function
2415
+ */
2416
+ const ignoredToFunction = (ignored) => {
2417
+ if (Array.isArray(ignored)) {
2418
+ const stringRegexps =
2419
+ /** @type {string[]} */
2420
+ (ignored.map((i) => stringToRegexp(i)).filter(Boolean));
2421
+ if (stringRegexps.length === 0) {
2422
+ return () => false;
2423
+ }
2424
+ const regexp =
2425
+ stringRegexps.length === 1
2426
+ ? new RegExp(stringRegexps[0])
2427
+ : new RegExp(stringRegexps.join("|"));
2428
+ return (item) => regexp.test(normalizeSeparators(item));
2429
+ } else if (typeof ignored === "string") {
2430
+ const stringRegexp = stringToRegexp(ignored);
2431
+ if (!stringRegexp) {
2432
+ return () => false;
2433
+ }
2434
+ const regexp = new RegExp(stringRegexp);
2435
+ return (item) => regexp.test(normalizeSeparators(item));
2436
+ } else if (ignored instanceof RegExp) {
2437
+ return (item) => ignored.test(normalizeSeparators(item));
2438
+ } else if (typeof ignored === "function") {
2439
+ return ignored;
2440
+ } else if (ignored) {
2441
+ throw new Error(`Invalid option for 'ignored': ${ignored}`);
2442
+ } else {
2443
+ return () => false;
2444
+ }
2445
+ };
2446
+
2447
+ /**
2448
+ * @param {WatchOptions} options options
2449
+ * @returns {NormalizedWatchOptions} normalized options
2450
+ */
2451
+ const normalizeOptions = (options) => ({
2452
+ followSymlinks: Boolean(options.followSymlinks),
2453
+ ignored: ignoredToFunction(options.ignored),
2454
+ poll: options.poll,
2455
+ });
2456
+
2457
+ const normalizeCache = new WeakMap();
2458
+ /**
2459
+ * @param {WatchOptions} options options
2460
+ * @returns {NormalizedWatchOptions} normalized options
2461
+ */
2462
+ const cachedNormalizeOptions = (options) => {
2463
+ const cacheEntry = normalizeCache.get(options);
2464
+ if (cacheEntry !== undefined) return cacheEntry;
2465
+ const normalized = normalizeOptions(options);
2466
+ normalizeCache.set(options, normalized);
2467
+ return normalized;
2468
+ };
2469
+
2470
+ class WatchpackFileWatcher {
2471
+ /**
2472
+ * @param {Watchpack} watchpack watchpack
2473
+ * @param {Watcher<FileWatcherEvents>} watcher watcher
2474
+ * @param {string | string[]} files files
2475
+ */
2476
+ constructor(watchpack, watcher, files) {
2477
+ /** @type {string[]} */
2478
+ this.files = Array.isArray(files) ? files : [files];
2479
+ this.watcher = watcher;
2480
+ watcher.on("initial-missing", (type) => {
2481
+ for (const file of this.files) {
2482
+ if (!watchpack._missing.has(file)) {
2483
+ watchpack._onRemove(file, file, type);
2484
+ }
2485
+ }
2486
+ });
2487
+ watcher.on("change", (mtime, type, _initial) => {
2488
+ for (const file of this.files) {
2489
+ watchpack._onChange(file, mtime, file, type);
2490
+ }
2491
+ });
2492
+ watcher.on("remove", (type) => {
2493
+ for (const file of this.files) {
2494
+ watchpack._onRemove(file, file, type);
2495
+ }
2496
+ });
2497
+ }
2498
+
2499
+ /**
2500
+ * @param {string | string[]} files files
2501
+ */
2502
+ update(files) {
2503
+ if (!Array.isArray(files)) {
2504
+ if (this.files.length !== 1) {
2505
+ this.files = [files];
2506
+ } else if (this.files[0] !== files) {
2507
+ this.files[0] = files;
2508
+ }
2509
+ } else {
2510
+ this.files = files;
2511
+ }
2512
+ }
2513
+
2514
+ close() {
2515
+ this.watcher.close();
2516
+ }
2517
+ }
2518
+
2519
+ class WatchpackDirectoryWatcher {
2520
+ /**
2521
+ * @param {Watchpack} watchpack watchpack
2522
+ * @param {Watcher<DirectoryWatcherEvents>} watcher watcher
2523
+ * @param {string} directories directories
2524
+ */
2525
+ constructor(watchpack, watcher, directories) {
2526
+ /** @type {string[]} */
2527
+ this.directories = Array.isArray(directories) ? directories : [directories];
2528
+ this.watcher = watcher;
2529
+ watcher.on("initial-missing", (type) => {
2530
+ for (const item of this.directories) {
2531
+ watchpack._onRemove(item, item, type);
2532
+ }
2533
+ });
2534
+ watcher.on("change", (file, mtime, type, _initial) => {
2535
+ for (const item of this.directories) {
2536
+ watchpack._onChange(item, mtime, file, type);
2537
+ }
2538
+ });
2539
+ watcher.on("remove", (type) => {
2540
+ for (const item of this.directories) {
2541
+ watchpack._onRemove(item, item, type);
2542
+ }
2543
+ });
2544
+ }
2545
+
2546
+ /**
2547
+ * @param {string | string[]} directories directories
2548
+ */
2549
+ update(directories) {
2550
+ if (!Array.isArray(directories)) {
2551
+ if (this.directories.length !== 1) {
2552
+ this.directories = [directories];
2553
+ } else if (this.directories[0] !== directories) {
2554
+ this.directories[0] = directories;
2555
+ }
2556
+ } else {
2557
+ this.directories = directories;
2558
+ }
2559
+ }
2560
+
2561
+ close() {
2562
+ this.watcher.close();
2563
+ }
2564
+ }
2565
+
2566
+ /**
2567
+ * @typedef {object} WatchpackEvents
2568
+ * @property {(file: string, mtime: number, type: EventType) => void} change change event
2569
+ * @property {(file: string, type: EventType) => void} remove remove event
2570
+ * @property {(changes: Changes, removals: Removals) => void} aggregated aggregated event
2571
+ */
2572
+
2573
+ /**
2574
+ * @extends {EventEmitter<{ [K in keyof WatchpackEvents]: Parameters<WatchpackEvents[K]> }>}
2575
+ */
2576
+ class Watchpack extends EventEmitter {
2577
+ /**
2578
+ * @param {WatchOptions=} options options
2579
+ */
2580
+ constructor(options = {}) {
2581
+ super();
2582
+ if (!options) options = {};
2583
+ /** @type {WatchOptions} */
2584
+ this.options = options;
2585
+ this.aggregateTimeout =
2586
+ typeof options.aggregateTimeout === "number"
2587
+ ? options.aggregateTimeout
2588
+ : 200;
2589
+ /** @type {NormalizedWatchOptions} */
2590
+ this.watcherOptions = cachedNormalizeOptions(options);
2591
+ /** @type {WatcherManager} */
2592
+ this.watcherManager = getWatcherManager(this.watcherOptions);
2593
+ /** @type {Map<string, WatchpackFileWatcher>} */
2594
+ this.fileWatchers = new Map();
2595
+ /** @type {Map<string, WatchpackDirectoryWatcher>} */
2596
+ this.directoryWatchers = new Map();
2597
+ /** @type {Set<string>} */
2598
+ this._missing = new Set();
2599
+ this.startTime = undefined;
2600
+ this.paused = false;
2601
+ /** @type {Changes} */
2602
+ this.aggregatedChanges = new Set();
2603
+ /** @type {Removals} */
2604
+ this.aggregatedRemovals = new Set();
2605
+ /** @type {undefined | NodeJS.Timeout} */
2606
+ this.aggregateTimer = undefined;
2607
+ this._onTimeout = this._onTimeout.bind(this);
2608
+ }
2609
+
2610
+ /**
2611
+ * @overload
2612
+ * @param {Iterable<string>} arg1 files
2613
+ * @param {Iterable<string>} arg2 directories
2614
+ * @param {number=} arg3 startTime
2615
+ * @returns {void}
2616
+ */
2617
+ /**
2618
+ * @overload
2619
+ * @param {WatchMethodOptions} arg1 watch options
2620
+ * @returns {void}
2621
+ */
2622
+ /**
2623
+ * @param {Iterable<string> | WatchMethodOptions} arg1 files
2624
+ * @param {Iterable<string>=} arg2 directories
2625
+ * @param {number=} arg3 startTime
2626
+ * @returns {void}
2627
+ */
2628
+ watch(arg1, arg2, arg3) {
2629
+ /** @type {Iterable<string> | undefined} */
2630
+ let files;
2631
+ /** @type {Iterable<string> | undefined} */
2632
+ let directories;
2633
+ /** @type {Iterable<string> | undefined} */
2634
+ let missing;
2635
+ /** @type {number | undefined} */
2636
+ let startTime;
2637
+ if (!arg2) {
2638
+ ({
2639
+ files = [],
2640
+ directories = [],
2641
+ missing = [],
2642
+ startTime,
2643
+ } = /** @type {WatchMethodOptions} */ (arg1));
2644
+ } else {
2645
+ files = /** @type {Iterable<string>} */ (arg1);
2646
+ directories = /** @type {Iterable<string>} */ (arg2);
2647
+ missing = [];
2648
+ startTime = /** @type {number} */ (arg3);
2649
+ }
2650
+ this.paused = false;
2651
+ const { fileWatchers, directoryWatchers } = this;
2652
+ const { ignored } = this.watcherOptions;
2653
+ /**
2654
+ * @param {string} path path
2655
+ * @returns {boolean} true when need to filter, otherwise false
2656
+ */
2657
+ const filter = (path) => !ignored(path);
2658
+ /**
2659
+ * @template K, V
2660
+ * @param {Map<K, V | V[]>} map map
2661
+ * @param {K} key key
2662
+ * @param {V} item item
2663
+ */
2664
+ const addToMap = (map, key, item) => {
2665
+ const list = map.get(key);
2666
+ if (list === undefined) {
2667
+ map.set(key, item);
2668
+ } else if (Array.isArray(list)) {
2669
+ list.push(item);
2670
+ } else {
2671
+ map.set(key, [list, item]);
2672
+ }
2673
+ };
2674
+ const fileWatchersNeeded = new Map();
2675
+ const directoryWatchersNeeded = new Map();
2676
+ /** @type {Set<string>} */
2677
+ const missingFiles = new Set();
2678
+ if (this.watcherOptions.followSymlinks) {
2679
+ const resolver = new LinkResolver();
2680
+ for (const file of files) {
2681
+ if (filter(file)) {
2682
+ for (const innerFile of resolver.resolve(file)) {
2683
+ if (file === innerFile || filter(innerFile)) {
2684
+ addToMap(fileWatchersNeeded, innerFile, file);
2685
+ }
2215
2686
  }
2216
- } else {
2217
- map.set(node.value, node.filePath);
2218
2687
  }
2219
2688
  }
2220
- if (node.children) {
2221
- for (const child of node.children) {
2222
- queue.add(child);
2689
+ for (const file of missing) {
2690
+ if (filter(file)) {
2691
+ for (const innerFile of resolver.resolve(file)) {
2692
+ if (file === innerFile || filter(innerFile)) {
2693
+ missingFiles.add(file);
2694
+ addToMap(fileWatchersNeeded, innerFile, file);
2695
+ }
2696
+ }
2223
2697
  }
2224
2698
  }
2699
+ for (const dir of directories) {
2700
+ if (filter(dir)) {
2701
+ let first = true;
2702
+ for (const innerItem of resolver.resolve(dir)) {
2703
+ if (filter(innerItem)) {
2704
+ addToMap(
2705
+ first ? directoryWatchersNeeded : fileWatchersNeeded,
2706
+ innerItem,
2707
+ dir,
2708
+ );
2709
+ }
2710
+ first = false;
2711
+ }
2712
+ }
2713
+ }
2714
+ } else {
2715
+ for (const file of files) {
2716
+ if (filter(file)) {
2717
+ addToMap(fileWatchersNeeded, file, file);
2718
+ }
2719
+ }
2720
+ for (const file of missing) {
2721
+ if (filter(file)) {
2722
+ missingFiles.add(file);
2723
+ addToMap(fileWatchersNeeded, file, file);
2724
+ }
2725
+ }
2726
+ for (const dir of directories) {
2727
+ if (filter(dir)) {
2728
+ addToMap(directoryWatchersNeeded, dir, dir);
2729
+ }
2730
+ }
2731
+ }
2732
+ // Close unneeded old watchers
2733
+ // and update existing watchers
2734
+ for (const [key, w] of fileWatchers) {
2735
+ const needed = fileWatchersNeeded.get(key);
2736
+ if (needed === undefined) {
2737
+ w.close();
2738
+ fileWatchers.delete(key);
2739
+ } else {
2740
+ w.update(needed);
2741
+ fileWatchersNeeded.delete(key);
2742
+ }
2743
+ }
2744
+ for (const [key, w] of directoryWatchers) {
2745
+ const needed = directoryWatchersNeeded.get(key);
2746
+ if (needed === undefined) {
2747
+ w.close();
2748
+ directoryWatchers.delete(key);
2749
+ } else {
2750
+ w.update(needed);
2751
+ directoryWatchersNeeded.delete(key);
2752
+ }
2753
+ }
2754
+ // Create new watchers and install handlers on these watchers
2755
+ watchEventSource.batch(() => {
2756
+ for (const [key, files] of fileWatchersNeeded) {
2757
+ const watcher = this.watcherManager.watchFile(key, startTime);
2758
+ if (watcher) {
2759
+ fileWatchers.set(key, new WatchpackFileWatcher(this, watcher, files));
2760
+ }
2761
+ }
2762
+ for (const [key, directories] of directoryWatchersNeeded) {
2763
+ const watcher = this.watcherManager.watchDirectory(key, startTime);
2764
+ if (watcher) {
2765
+ directoryWatchers.set(
2766
+ key,
2767
+ new WatchpackDirectoryWatcher(this, watcher, directories),
2768
+ );
2769
+ }
2770
+ }
2771
+ });
2772
+ this._missing = missingFiles;
2773
+ this.startTime = startTime;
2774
+ }
2775
+
2776
+ close() {
2777
+ this.paused = true;
2778
+ if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2779
+ for (const w of this.fileWatchers.values()) w.close();
2780
+ for (const w of this.directoryWatchers.values()) w.close();
2781
+ this.fileWatchers.clear();
2782
+ this.directoryWatchers.clear();
2783
+ }
2784
+
2785
+ pause() {
2786
+ this.paused = true;
2787
+ if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2788
+ }
2789
+
2790
+ /**
2791
+ * @returns {Record<string, number>} times
2792
+ */
2793
+ getTimes() {
2794
+ /** @type {Set<DirectoryWatcher>} */
2795
+ const directoryWatchers = new Set();
2796
+ addWatchersToSet(this.fileWatchers.values(), directoryWatchers);
2797
+ addWatchersToSet(this.directoryWatchers.values(), directoryWatchers);
2798
+ /** @type {Record<string, number>} */
2799
+ const obj = Object.create(null);
2800
+ for (const w of directoryWatchers) {
2801
+ // getTimes() returns a prototype-less object, so for...in is safe
2802
+ // and avoids the throwaway array that Object.keys would allocate.
2803
+ const times = w.getTimes();
2804
+ for (const file in times) obj[file] = times[file];
2805
+ }
2806
+ return obj;
2807
+ }
2808
+
2809
+ /**
2810
+ * @returns {TimeInfoEntries} time info entries
2811
+ */
2812
+ getTimeInfoEntries() {
2813
+ /** @type {TimeInfoEntries} */
2814
+ const map = new Map();
2815
+ this.collectTimeInfoEntries(map, map);
2816
+ return map;
2817
+ }
2818
+
2819
+ /**
2820
+ * @param {TimeInfoEntries} fileTimestamps file timestamps
2821
+ * @param {TimeInfoEntries} directoryTimestamps directory timestamps
2822
+ */
2823
+ collectTimeInfoEntries(fileTimestamps, directoryTimestamps) {
2824
+ /** @type {Set<DirectoryWatcher>} */
2825
+ const allWatchers = new Set();
2826
+ addWatchersToSet(this.fileWatchers.values(), allWatchers);
2827
+ addWatchersToSet(this.directoryWatchers.values(), allWatchers);
2828
+ for (const w of allWatchers) {
2829
+ w.collectTimeInfoEntries(fileTimestamps, directoryTimestamps);
2225
2830
  }
2226
- newPlan.set(rootNode.filePath, map);
2227
2831
  }
2228
- return newPlan;
2832
+
2833
+ /**
2834
+ * @returns {Aggregated} aggregated info
2835
+ */
2836
+ getAggregated() {
2837
+ if (this.aggregateTimer) {
2838
+ clearTimeout(this.aggregateTimer);
2839
+ this.aggregateTimer = undefined;
2840
+ }
2841
+ const changes = this.aggregatedChanges;
2842
+ const removals = this.aggregatedRemovals;
2843
+ this.aggregatedChanges = new Set();
2844
+ this.aggregatedRemovals = new Set();
2845
+ return { changes, removals };
2846
+ }
2847
+
2848
+ /**
2849
+ * @param {string} item item
2850
+ * @param {number} mtime mtime
2851
+ * @param {string} file file
2852
+ * @param {EventType} type type
2853
+ */
2854
+ _onChange(item, mtime, file, type) {
2855
+ file = file || item;
2856
+ if (!this.paused) {
2857
+ this.emit("change", file, mtime, type);
2858
+ if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2859
+ this.aggregateTimer = setTimeout(this._onTimeout, this.aggregateTimeout);
2860
+ }
2861
+ this.aggregatedRemovals.delete(item);
2862
+ this.aggregatedChanges.add(item);
2863
+ }
2864
+
2865
+ /**
2866
+ * @param {string} item item
2867
+ * @param {string} file file
2868
+ * @param {EventType} type type
2869
+ */
2870
+ _onRemove(item, file, type) {
2871
+ file = file || item;
2872
+ if (!this.paused) {
2873
+ this.emit("remove", file, type);
2874
+ if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2875
+ this.aggregateTimer = setTimeout(this._onTimeout, this.aggregateTimeout);
2876
+ }
2877
+ this.aggregatedChanges.delete(item);
2878
+ this.aggregatedRemovals.add(item);
2879
+ }
2880
+
2881
+ _onTimeout() {
2882
+ this.aggregateTimer = undefined;
2883
+ const changes = this.aggregatedChanges;
2884
+ const removals = this.aggregatedRemovals;
2885
+ this.aggregatedChanges = new Set();
2886
+ this.aggregatedRemovals = new Set();
2887
+ this.emit("aggregated", changes, removals);
2888
+ }
2889
+ }
2890
+
2891
+ /**
2892
+ * @template A
2893
+ * @template B
2894
+ * @param {A} obj input a
2895
+ * @param {B} exports input b
2896
+ * @returns {A & B} merged
2897
+ */
2898
+ const mergeExports = (obj, exports) => {
2899
+ const descriptors = Object.getOwnPropertyDescriptors(exports);
2900
+ Object.defineProperties(obj, descriptors);
2901
+ return /** @type {A & B} */ (Object.freeze(obj));
2229
2902
  };
2230
2903
 
2904
+ /** @typedef {typeof Watchpack & { util: { readonly globToRegExp: typeof globToRegExp } }} WatchpackExports */
2905
+
2906
+ module.exports = /** @type {WatchpackExports} */ (
2907
+ mergeExports(Watchpack, {
2908
+ util: {
2909
+ get globToRegExp() {
2910
+ return globToRegExp;
2911
+ },
2912
+ },
2913
+ })
2914
+ );
2915
+
2231
2916
 
2232
2917
  /***/ }),
2233
2918
 
2234
- /***/ 729:
2235
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2919
+ /***/ 817:
2920
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2236
2921
 
2237
2922
  "use strict";
2238
2923
  /*
@@ -2241,376 +2926,314 @@ module.exports = (plan, limit) => {
2241
2926
  */
2242
2927
 
2243
2928
 
2244
- const fs = __nccwpck_require__(896);
2245
2929
  const path = __nccwpck_require__(928);
2246
- const { EventEmitter } = __nccwpck_require__(434);
2247
- const reducePlan = __nccwpck_require__(864);
2248
-
2249
- const IS_OSX = (__nccwpck_require__(857).platform)() === "darwin";
2250
- const IS_WIN = (__nccwpck_require__(857).platform)() === "win32";
2251
- const SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN;
2252
-
2253
- // Use 20 for OSX to make `FSWatcher.close` faster
2254
- // https://github.com/nodejs/node/issues/29949
2255
- const watcherLimit =
2256
- +process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 20 : 10000);
2257
-
2258
- const recursiveWatcherLogging = !!process.env
2259
- .WATCHPACK_RECURSIVE_WATCHER_LOGGING;
2260
-
2261
- let isBatch = false;
2262
- let watcherCount = 0;
2263
-
2264
- /** @type {Map<Watcher, string>} */
2265
- const pendingWatchers = new Map();
2266
-
2267
- /** @type {Map<string, RecursiveWatcher>} */
2268
- const recursiveWatchers = new Map();
2269
-
2270
- /** @type {Map<string, DirectWatcher>} */
2271
- const directWatchers = new Map();
2272
-
2273
- /** @type {Map<Watcher, RecursiveWatcher | DirectWatcher>} */
2274
- const underlyingWatcher = new Map();
2275
-
2276
- function createEPERMError(filePath) {
2277
- const error = new Error(`Operation not permitted: ${filePath}`);
2278
- error.code = "EPERM";
2279
- return error;
2280
- }
2281
-
2282
- function createHandleChangeEvent(watcher, filePath, handleChangeEvent) {
2283
- return (type, filename) => {
2284
- // TODO: After Node.js v22, fs.watch(dir) and deleting a dir will trigger the rename change event.
2285
- // Here we just ignore it and keep the same behavior as before v22
2286
- // https://github.com/libuv/libuv/pull/4376
2287
- if (
2288
- type === "rename" &&
2289
- path.isAbsolute(filename) &&
2290
- path.basename(filename) === path.basename(filePath)
2291
- ) {
2292
- if (!IS_OSX) {
2293
- // Before v22, windows will throw EPERM error
2294
- watcher.emit("error", createEPERMError(filename));
2295
- }
2296
- // Before v22, macos nothing to do
2297
- return;
2298
- }
2299
- handleChangeEvent(type, filename);
2300
- };
2301
- }
2302
-
2303
- class DirectWatcher {
2304
- constructor(filePath) {
2305
- this.filePath = filePath;
2306
- this.watchers = new Set();
2307
- this.watcher = undefined;
2308
- try {
2309
- const watcher = fs.watch(filePath);
2310
-
2311
- this.watcher = watcher;
2312
- const handleChangeEvent = createHandleChangeEvent(
2313
- watcher,
2314
- filePath,
2315
- (type, filename) => {
2316
- for (const w of this.watchers) {
2317
- w.emit("change", type, filename);
2318
- }
2319
- }
2320
- );
2321
- watcher.on("change", handleChangeEvent);
2322
- watcher.on("error", error => {
2323
- for (const w of this.watchers) {
2324
- w.emit("error", error);
2325
- }
2326
- });
2327
- } catch (err) {
2328
- process.nextTick(() => {
2329
- for (const w of this.watchers) {
2330
- w.emit("error", err);
2331
- }
2332
- });
2333
- }
2334
- watcherCount++;
2335
- }
2336
-
2337
- add(watcher) {
2338
- underlyingWatcher.set(watcher, this);
2339
- this.watchers.add(watcher);
2340
- }
2341
2930
 
2342
- remove(watcher) {
2343
- this.watchers.delete(watcher);
2344
- if (this.watchers.size === 0) {
2345
- directWatchers.delete(this.filePath);
2346
- watcherCount--;
2347
- if (this.watcher) this.watcher.close();
2348
- }
2349
- }
2931
+ /**
2932
+ * @template T
2933
+ * @typedef {object} TreeNode
2934
+ * @property {string} target target
2935
+ * @property {TreeNode<T>} parent parent
2936
+ * @property {TreeNode<T>[]} children children
2937
+ * @property {number} entries number of entries
2938
+ * @property {boolean} active true when active, otherwise false
2939
+ * @property {T[] | T | undefined} value value
2940
+ */
2350
2941
 
2351
- getWatchers() {
2352
- return this.watchers;
2942
+ /**
2943
+ * @template T
2944
+ * @param {Map<string, T[] | T>} plan plan
2945
+ * @param {number} limit limit
2946
+ * @returns {Map<string, Map<T, string>>} the new plan
2947
+ */
2948
+ module.exports = (plan, limit) => {
2949
+ const treeMap = new Map();
2950
+ // Convert to tree
2951
+ for (const [target, value] of plan) {
2952
+ treeMap.set(target, {
2953
+ target,
2954
+ parent: undefined,
2955
+ children: undefined,
2956
+ entries: 1,
2957
+ active: true,
2958
+ value,
2959
+ });
2353
2960
  }
2354
- }
2355
-
2356
- class RecursiveWatcher {
2357
- constructor(rootPath) {
2358
- this.rootPath = rootPath;
2359
- /** @type {Map<Watcher, string>} */
2360
- this.mapWatcherToPath = new Map();
2361
- /** @type {Map<string, Set<Watcher>>} */
2362
- this.mapPathToWatchers = new Map();
2363
- this.watcher = undefined;
2364
- try {
2365
- const watcher = fs.watch(rootPath, {
2366
- recursive: true
2367
- });
2368
- this.watcher = watcher;
2369
- watcher.on("change", (type, filename) => {
2370
- if (!filename) {
2371
- if (recursiveWatcherLogging) {
2372
- process.stderr.write(
2373
- `[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) to all watchers\n`
2374
- );
2375
- }
2376
- for (const w of this.mapWatcherToPath.keys()) {
2377
- w.emit("change", type);
2378
- }
2961
+ let currentCount = treeMap.size;
2962
+ // Create parents and calculate sum of entries
2963
+ for (const node of treeMap.values()) {
2964
+ const parentPath = path.dirname(node.target);
2965
+ if (parentPath !== node.target) {
2966
+ let parent = treeMap.get(parentPath);
2967
+ if (parent === undefined) {
2968
+ parent = {
2969
+ target: parentPath,
2970
+ parent: undefined,
2971
+ children: [node],
2972
+ entries: node.entries,
2973
+ active: false,
2974
+ value: undefined,
2975
+ };
2976
+ treeMap.set(parentPath, parent);
2977
+ node.parent = parent;
2978
+ } else {
2979
+ node.parent = parent;
2980
+ if (parent.children === undefined) {
2981
+ parent.children = [node];
2379
2982
  } else {
2380
- const dir = path.dirname(filename);
2381
- const watchers = this.mapPathToWatchers.get(dir);
2382
- if (recursiveWatcherLogging) {
2383
- process.stderr.write(
2384
- `[watchpack] dispatch ${type} event in recursive watcher (${
2385
- this.rootPath
2386
- }) for '${filename}' to ${
2387
- watchers ? watchers.size : 0
2388
- } watchers\n`
2389
- );
2390
- }
2391
- if (watchers === undefined) return;
2392
- for (const w of watchers) {
2393
- w.emit("change", type, path.basename(filename));
2394
- }
2395
- }
2396
- });
2397
- watcher.on("error", error => {
2398
- for (const w of this.mapWatcherToPath.keys()) {
2399
- w.emit("error", error);
2400
- }
2401
- });
2402
- } catch (err) {
2403
- process.nextTick(() => {
2404
- for (const w of this.mapWatcherToPath.keys()) {
2405
- w.emit("error", err);
2983
+ parent.children.push(node);
2406
2984
  }
2407
- });
2408
- }
2409
- watcherCount++;
2410
- if (recursiveWatcherLogging) {
2411
- process.stderr.write(
2412
- `[watchpack] created recursive watcher at ${rootPath}\n`
2413
- );
2414
- }
2415
- }
2416
-
2417
- add(filePath, watcher) {
2418
- underlyingWatcher.set(watcher, this);
2419
- const subpath = filePath.slice(this.rootPath.length + 1) || ".";
2420
- this.mapWatcherToPath.set(watcher, subpath);
2421
- const set = this.mapPathToWatchers.get(subpath);
2422
- if (set === undefined) {
2423
- const newSet = new Set();
2424
- newSet.add(watcher);
2425
- this.mapPathToWatchers.set(subpath, newSet);
2426
- } else {
2427
- set.add(watcher);
2985
+ do {
2986
+ parent.entries += node.entries;
2987
+ parent = parent.parent;
2988
+ } while (parent);
2989
+ }
2428
2990
  }
2429
2991
  }
2430
-
2431
- remove(watcher) {
2432
- const subpath = this.mapWatcherToPath.get(watcher);
2433
- if (!subpath) return;
2434
- this.mapWatcherToPath.delete(watcher);
2435
- const set = this.mapPathToWatchers.get(subpath);
2436
- set.delete(watcher);
2437
- if (set.size === 0) {
2438
- this.mapPathToWatchers.delete(subpath);
2439
- }
2440
- if (this.mapWatcherToPath.size === 0) {
2441
- recursiveWatchers.delete(this.rootPath);
2442
- watcherCount--;
2443
- if (this.watcher) this.watcher.close();
2444
- if (recursiveWatcherLogging) {
2445
- process.stderr.write(
2446
- `[watchpack] closed recursive watcher at ${this.rootPath}\n`
2447
- );
2992
+ // Reduce until limit reached. When no reduction is needed at all, skip
2993
+ // building the candidate set entirely to avoid paying for the setup on the
2994
+ // common fast path.
2995
+ if (currentCount > limit) {
2996
+ // Pre-filter candidate nodes so the inner selection loop skips structural
2997
+ // non-candidates entirely. `children` length and parent presence are
2998
+ // fixed after tree construction; only `entries` can change (it can only
2999
+ // decrease), so a node that fails the `entries` check in a later round
3000
+ // is simply skipped via `continue`. When we merge a subtree we drop the
3001
+ // descendants from the candidate set to keep it shrinking over
3002
+ // iterations.
3003
+ /** @type {Set<TreeNode<T>>} */
3004
+ const candidates = new Set();
3005
+ for (const node of treeMap.values()) {
3006
+ if (!node.parent || !node.children) continue;
3007
+ if (node.children.length === 0) continue;
3008
+ if (node.children.length === 1 && !node.value) continue;
3009
+ candidates.add(node);
3010
+ }
3011
+ const costBias = limit * 0.3;
3012
+ while (currentCount > limit) {
3013
+ // Select node that helps reaching the limit most effectively without overmerging
3014
+ const overLimit = currentCount - limit;
3015
+ let bestNode;
3016
+ let bestCost = Infinity;
3017
+ for (const node of candidates) {
3018
+ if (node.entries <= 1) continue;
3019
+ // Try to select the node with has just a bit more entries than we need to reduce
3020
+ // When just a bit more is over 30% over the limit,
3021
+ // also consider just a bit less entries then we need to reduce
3022
+ const diff = node.entries - 1 - overLimit;
3023
+ const cost = diff >= 0 ? diff : -diff + costBias;
3024
+ if (cost < bestCost) {
3025
+ bestNode = node;
3026
+ bestCost = cost;
3027
+ // A cost of 0 means the merge reduces exactly to the limit;
3028
+ // no further candidate can improve on that, so stop scanning.
3029
+ if (cost === 0) break;
3030
+ }
3031
+ }
3032
+ if (!bestNode) break;
3033
+ // Merge all children
3034
+ const reduction = bestNode.entries - 1;
3035
+ bestNode.active = true;
3036
+ bestNode.entries = 1;
3037
+ candidates.delete(bestNode);
3038
+ currentCount -= reduction;
3039
+ let { parent } = bestNode;
3040
+ while (parent) {
3041
+ parent.entries -= reduction;
3042
+ parent = parent.parent;
3043
+ }
3044
+ const queue = new Set(bestNode.children);
3045
+ for (const node of queue) {
3046
+ node.active = false;
3047
+ node.entries = 0;
3048
+ candidates.delete(node);
3049
+ if (node.children) {
3050
+ for (const child of node.children) queue.add(child);
3051
+ }
2448
3052
  }
2449
3053
  }
2450
3054
  }
2451
-
2452
- getWatchers() {
2453
- return this.mapWatcherToPath;
2454
- }
2455
- }
2456
-
2457
- class Watcher extends EventEmitter {
2458
- close() {
2459
- if (pendingWatchers.has(this)) {
2460
- pendingWatchers.delete(this);
2461
- return;
3055
+ // Write down new plan
3056
+ const newPlan = new Map();
3057
+ for (const rootNode of treeMap.values()) {
3058
+ if (!rootNode.active) continue;
3059
+ const map = new Map();
3060
+ const queue = new Set([rootNode]);
3061
+ for (const node of queue) {
3062
+ if (node.active && node !== rootNode) continue;
3063
+ if (node.value) {
3064
+ if (Array.isArray(node.value)) {
3065
+ for (const item of node.value) {
3066
+ map.set(item, node.target);
3067
+ }
3068
+ } else {
3069
+ map.set(node.value, node.target);
3070
+ }
3071
+ }
3072
+ if (node.children) {
3073
+ for (const child of node.children) {
3074
+ queue.add(child);
3075
+ }
3076
+ }
2462
3077
  }
2463
- const watcher = underlyingWatcher.get(this);
2464
- watcher.remove(this);
2465
- underlyingWatcher.delete(this);
3078
+ newPlan.set(rootNode.target, map);
2466
3079
  }
2467
- }
2468
-
2469
- const createDirectWatcher = filePath => {
2470
- const existing = directWatchers.get(filePath);
2471
- if (existing !== undefined) return existing;
2472
- const w = new DirectWatcher(filePath);
2473
- directWatchers.set(filePath, w);
2474
- return w;
3080
+ return newPlan;
2475
3081
  };
2476
3082
 
2477
- const createRecursiveWatcher = rootPath => {
2478
- const existing = recursiveWatchers.get(rootPath);
2479
- if (existing !== undefined) return existing;
2480
- const w = new RecursiveWatcher(rootPath);
2481
- recursiveWatchers.set(rootPath, w);
2482
- return w;
2483
- };
2484
3083
 
2485
- const execute = () => {
2486
- /** @type {Map<string, Watcher[] | Watcher>} */
2487
- const map = new Map();
2488
- const addWatcher = (watcher, filePath) => {
2489
- const entry = map.get(filePath);
2490
- if (entry === undefined) {
2491
- map.set(filePath, watcher);
2492
- } else if (Array.isArray(entry)) {
2493
- entry.push(watcher);
2494
- } else {
2495
- map.set(filePath, [entry, watcher]);
2496
- }
2497
- };
2498
- for (const [watcher, filePath] of pendingWatchers) {
2499
- addWatcher(watcher, filePath);
2500
- }
2501
- pendingWatchers.clear();
3084
+ /***/ }),
2502
3085
 
2503
- // Fast case when we are not reaching the limit
2504
- if (!SUPPORTS_RECURSIVE_WATCHING || watcherLimit - watcherCount >= map.size) {
2505
- // Create watchers for all entries in the map
2506
- for (const [filePath, entry] of map) {
2507
- const w = createDirectWatcher(filePath);
2508
- if (Array.isArray(entry)) {
2509
- for (const item of entry) w.add(item);
2510
- } else {
2511
- w.add(entry);
2512
- }
2513
- }
2514
- return;
2515
- }
3086
+ /***/ 737:
3087
+ /***/ ((module) => {
2516
3088
 
2517
- // Reconsider existing watchers to improving watch plan
2518
- for (const watcher of recursiveWatchers.values()) {
2519
- for (const [w, subpath] of watcher.getWatchers()) {
2520
- addWatcher(w, path.join(watcher.rootPath, subpath));
2521
- }
2522
- }
2523
- for (const watcher of directWatchers.values()) {
2524
- for (const w of watcher.getWatchers()) {
2525
- addWatcher(w, watcher.filePath);
2526
- }
2527
- }
3089
+ "use strict";
3090
+ /*
3091
+ MIT License http://www.opensource.org/licenses/mit-license.php
3092
+ Author Haijie Xie @hai-x
3093
+ */
2528
3094
 
2529
- // Merge map entries to keep watcher limit
2530
- // Create a 10% buffer to be able to enter fast case more often
2531
- const plan = reducePlan(map, watcherLimit * 0.9);
2532
3095
 
2533
- // Update watchers for all entries in the map
2534
- for (const [filePath, entry] of plan) {
2535
- if (entry.size === 1) {
2536
- for (const [watcher, filePath] of entry) {
2537
- const w = createDirectWatcher(filePath);
2538
- const old = underlyingWatcher.get(watcher);
2539
- if (old === w) continue;
2540
- w.add(watcher);
2541
- if (old !== undefined) old.remove(watcher);
2542
- }
2543
- } else {
2544
- const filePaths = new Set(entry.values());
2545
- if (filePaths.size > 1) {
2546
- const w = createRecursiveWatcher(filePath);
2547
- for (const [watcher, watcherPath] of entry) {
2548
- const old = underlyingWatcher.get(watcher);
2549
- if (old === w) continue;
2550
- w.add(watcherPath, watcher);
2551
- if (old !== undefined) old.remove(watcher);
3096
+
3097
+ // Based on https://github.com/fitzgen/glob-to-regexp (MIT)
3098
+ // Specialized for watchpack: `extended` and `globstar` always enabled.
3099
+ // Returns the regexp source without `^`/`$` anchors.
3100
+
3101
+ const CC_EXCLAMATION = 33; // "!"
3102
+ const CC_DOLLAR = 36; // "$"
3103
+ const CC_LEFT_PARENTHESIS = 40; // "("
3104
+ const CC_RIGHT_PARENTHESIS = 41; // ")"
3105
+ const CC_ASTERISK = 42; // "*"
3106
+ const CC_PLUS = 43; // "+"
3107
+ const CC_COMMA = 44; // ","
3108
+ const CC_DOT = 46; // "."
3109
+ const CC_SLASH = 47; // "/"
3110
+ const CC_EQUAL = 61; // "="
3111
+ const CC_QUESTION_MARK = 63; // "?"
3112
+ const CC_LEFT_BRACKET = 91; // "["
3113
+ const CC_RIGHT_BRACKET = 93; // "]"
3114
+ const CC_CARET = 94; // "^"
3115
+ const CC_LEFT_BRACE = 123; // "{"
3116
+ const CC_PIPE = 124; // "|"
3117
+ const CC_RIGHT_BRACE = 125; // "}"
3118
+
3119
+ /**
3120
+ * @param {string} glob glob pattern
3121
+ * @returns {string} regexp source without anchors
3122
+ */
3123
+ module.exports = (glob) => {
3124
+ if (typeof glob !== "string") {
3125
+ throw new TypeError("Expected a string");
3126
+ }
3127
+
3128
+ const len = glob.length;
3129
+ let reStr = "";
3130
+ let inGroup = false;
3131
+ // Start of the current run of literal characters, copied with one slice
3132
+ let literalStart = 0;
3133
+
3134
+ for (let i = 0; i < len; i++) {
3135
+ const cc = glob.charCodeAt(i);
3136
+ const tokenStart = i;
3137
+ let mapped;
3138
+
3139
+ switch (cc) {
3140
+ case CC_SLASH:
3141
+ mapped = "\\/";
3142
+ break;
3143
+ case CC_DOLLAR:
3144
+ mapped = "\\$";
3145
+ break;
3146
+ case CC_CARET:
3147
+ mapped = "\\^";
3148
+ break;
3149
+ case CC_PLUS:
3150
+ mapped = "\\+";
3151
+ break;
3152
+ case CC_DOT:
3153
+ mapped = "\\.";
3154
+ break;
3155
+ case CC_LEFT_PARENTHESIS:
3156
+ mapped = "\\(";
3157
+ break;
3158
+ case CC_RIGHT_PARENTHESIS:
3159
+ mapped = "\\)";
3160
+ break;
3161
+ case CC_EQUAL:
3162
+ mapped = "\\=";
3163
+ break;
3164
+ case CC_EXCLAMATION:
3165
+ mapped = "\\!";
3166
+ break;
3167
+ case CC_PIPE:
3168
+ mapped = "\\|";
3169
+ break;
3170
+ case CC_QUESTION_MARK:
3171
+ mapped = ".";
3172
+ break;
3173
+ case CC_LEFT_BRACKET:
3174
+ mapped = "[";
3175
+ break;
3176
+ case CC_RIGHT_BRACKET:
3177
+ mapped = "]";
3178
+ break;
3179
+ case CC_LEFT_BRACE:
3180
+ inGroup = true;
3181
+ mapped = "(";
3182
+ break;
3183
+ case CC_RIGHT_BRACE:
3184
+ inGroup = false;
3185
+ mapped = ")";
3186
+ break;
3187
+ case CC_COMMA:
3188
+ mapped = inGroup ? "|" : "\\,";
3189
+ break;
3190
+ case CC_ASTERISK: {
3191
+ const atStart = i === 0;
3192
+ const afterSlash = !atStart && glob.charCodeAt(i - 1) === CC_SLASH;
3193
+ let starCount = 1;
3194
+ while (i + 1 < len && glob.charCodeAt(i + 1) === CC_ASTERISK) {
3195
+ starCount++;
3196
+ i++;
2552
3197
  }
2553
- } else {
2554
- for (const filePath of filePaths) {
2555
- const w = createDirectWatcher(filePath);
2556
- for (const watcher of entry.keys()) {
2557
- const old = underlyingWatcher.get(watcher);
2558
- if (old === w) continue;
2559
- w.add(watcher);
2560
- if (old !== undefined) old.remove(watcher);
2561
- }
3198
+ const atEnd = i + 1 === len;
3199
+ const beforeSlash = !atEnd && glob.charCodeAt(i + 1) === CC_SLASH;
3200
+ if (
3201
+ starCount > 1 &&
3202
+ (atStart || afterSlash) &&
3203
+ (atEnd || beforeSlash)
3204
+ ) {
3205
+ // Globstar segment, matches zero or more path segments
3206
+ mapped = "((?:[^/]*(?:\\/|$))*)";
3207
+ i++; // Move over the "/"
3208
+ } else {
3209
+ // Not a globstar, matches one path segment
3210
+ mapped = "([^/]*)";
2562
3211
  }
3212
+ break;
2563
3213
  }
3214
+ default:
3215
+ // Literal character, extend the current run
3216
+ continue;
2564
3217
  }
2565
- }
2566
- };
2567
3218
 
2568
- exports.watch = filePath => {
2569
- const watcher = new Watcher();
2570
- // Find an existing watcher
2571
- const directWatcher = directWatchers.get(filePath);
2572
- if (directWatcher !== undefined) {
2573
- directWatcher.add(watcher);
2574
- return watcher;
2575
- }
2576
- let current = filePath;
2577
- for (;;) {
2578
- const recursiveWatcher = recursiveWatchers.get(current);
2579
- if (recursiveWatcher !== undefined) {
2580
- recursiveWatcher.add(filePath, watcher);
2581
- return watcher;
3219
+ if (literalStart < tokenStart) {
3220
+ reStr += glob.slice(literalStart, tokenStart);
2582
3221
  }
2583
- const parent = path.dirname(current);
2584
- if (parent === current) break;
2585
- current = parent;
3222
+ reStr += mapped;
3223
+ literalStart = i + 1;
2586
3224
  }
2587
- // Queue up watcher for creation
2588
- pendingWatchers.set(watcher, filePath);
2589
- if (!isBatch) execute();
2590
- return watcher;
2591
- };
2592
3225
 
2593
- exports.batch = fn => {
2594
- isBatch = true;
2595
- try {
2596
- fn();
2597
- } finally {
2598
- isBatch = false;
2599
- execute();
3226
+ if (literalStart < len) {
3227
+ reStr += literalStart === 0 ? glob : glob.slice(literalStart);
2600
3228
  }
2601
- };
2602
3229
 
2603
- exports.getNumberOfWatchers = () => {
2604
- return watcherCount;
3230
+ return reStr;
2605
3231
  };
2606
3232
 
2607
- exports.createHandleChangeEvent = createHandleChangeEvent;
2608
- exports.watcherLimit = watcherLimit;
2609
-
2610
3233
 
2611
3234
  /***/ }),
2612
3235
 
2613
- /***/ 851:
3236
+ /***/ 92:
2614
3237
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2615
3238
 
2616
3239
  "use strict";
@@ -2620,393 +3243,457 @@ exports.watcherLimit = watcherLimit;
2620
3243
  */
2621
3244
 
2622
3245
 
2623
- const getWatcherManager = __nccwpck_require__(510);
2624
- const LinkResolver = __nccwpck_require__(751);
2625
- const EventEmitter = (__nccwpck_require__(434).EventEmitter);
2626
- const globToRegExp = __nccwpck_require__(428);
2627
- const watchEventSource = __nccwpck_require__(729);
3246
+ const { EventEmitter } = __nccwpck_require__(434);
3247
+ const fs = __nccwpck_require__(896);
3248
+ const path = __nccwpck_require__(928);
3249
+ const reducePlan = __nccwpck_require__(817);
2628
3250
 
2629
- const EMPTY_ARRAY = [];
2630
- const EMPTY_OPTIONS = {};
3251
+ /** @typedef {import("fs").FSWatcher} FSWatcher */
3252
+ /** @typedef {import("./index").EventType} EventType */
2631
3253
 
2632
- function addWatchersToSet(watchers, set) {
2633
- for (const ww of watchers) {
2634
- const w = ww.watcher;
2635
- if (!set.has(w.directoryWatcher)) {
2636
- set.add(w.directoryWatcher);
2637
- }
2638
- }
2639
- }
3254
+ const IS_OSX = (__nccwpck_require__(857).platform)() === "darwin";
3255
+ const IS_WIN = (__nccwpck_require__(857).platform)() === "win32";
2640
3256
 
2641
- const stringToRegexp = ignored => {
2642
- if (ignored.length === 0) {
2643
- return;
2644
- }
2645
- const source = globToRegExp(ignored, { globstar: true, extended: true })
2646
- .source;
2647
- return source.slice(0, source.length - 1) + "(?:$|\\/)";
2648
- };
3257
+ const SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN;
2649
3258
 
2650
- const ignoredToFunction = ignored => {
2651
- if (Array.isArray(ignored)) {
2652
- const stringRegexps = ignored.map(i => stringToRegexp(i)).filter(Boolean);
2653
- if (stringRegexps.length === 0) {
2654
- return () => false;
2655
- }
2656
- const regexp = new RegExp(stringRegexps.join("|"));
2657
- return x => regexp.test(x.replace(/\\/g, "/"));
2658
- } else if (typeof ignored === "string") {
2659
- const stringRegexp = stringToRegexp(ignored);
2660
- if (!stringRegexp) {
2661
- return () => false;
2662
- }
2663
- const regexp = new RegExp(stringRegexp);
2664
- return x => regexp.test(x.replace(/\\/g, "/"));
2665
- } else if (ignored instanceof RegExp) {
2666
- return x => ignored.test(x.replace(/\\/g, "/"));
2667
- } else if (ignored instanceof Function) {
2668
- return ignored;
2669
- } else if (ignored) {
2670
- throw new Error(`Invalid option for 'ignored': ${ignored}`);
2671
- } else {
2672
- return () => false;
2673
- }
2674
- };
3259
+ // Use 20 for OSX to make `FSWatcher.close` faster
3260
+ // https://github.com/nodejs/node/issues/29949
3261
+ const watcherLimit =
3262
+ // @ts-expect-error avoid additional checks
3263
+ +process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 20 : 10000);
2675
3264
 
2676
- const normalizeOptions = options => {
2677
- return {
2678
- followSymlinks: !!options.followSymlinks,
2679
- ignored: ignoredToFunction(options.ignored),
2680
- poll: options.poll
2681
- };
2682
- };
3265
+ const recursiveWatcherLogging = Boolean(
3266
+ process.env.WATCHPACK_RECURSIVE_WATCHER_LOGGING,
3267
+ );
2683
3268
 
2684
- const normalizeCache = new WeakMap();
2685
- const cachedNormalizeOptions = options => {
2686
- const cacheEntry = normalizeCache.get(options);
2687
- if (cacheEntry !== undefined) return cacheEntry;
2688
- const normalized = normalizeOptions(options);
2689
- normalizeCache.set(options, normalized);
2690
- return normalized;
2691
- };
3269
+ let isBatch = false;
3270
+ let watcherCount = 0;
2692
3271
 
2693
- class WatchpackFileWatcher {
2694
- constructor(watchpack, watcher, files) {
2695
- this.files = Array.isArray(files) ? files : [files];
2696
- this.watcher = watcher;
2697
- watcher.on("initial-missing", type => {
2698
- for (const file of this.files) {
2699
- if (!watchpack._missing.has(file))
2700
- watchpack._onRemove(file, file, type);
2701
- }
2702
- });
2703
- watcher.on("change", (mtime, type) => {
2704
- for (const file of this.files) {
2705
- watchpack._onChange(file, mtime, file, type);
2706
- }
2707
- });
2708
- watcher.on("remove", type => {
2709
- for (const file of this.files) {
2710
- watchpack._onRemove(file, file, type);
2711
- }
2712
- });
2713
- }
3272
+ /** @type {Map<Watcher, string>} */
3273
+ const pendingWatchers = new Map();
3274
+
3275
+ /** @type {Map<string, RecursiveWatcher>} */
3276
+ const recursiveWatchers = new Map();
3277
+
3278
+ /** @type {Map<string, DirectWatcher>} */
3279
+ const directWatchers = new Map();
3280
+
3281
+ /** @type {Map<Watcher, RecursiveWatcher | DirectWatcher>} */
3282
+ const underlyingWatcher = new Map();
3283
+
3284
+ /**
3285
+ * @param {string} filePath file path
3286
+ * @returns {NodeJS.ErrnoException} new error with file path in the message
3287
+ */
3288
+ function createEPERMError(filePath) {
3289
+ const error =
3290
+ /** @type {NodeJS.ErrnoException} */
3291
+ (new Error(`Operation not permitted: ${filePath}`));
3292
+ error.code = "EPERM";
3293
+ return error;
3294
+ }
2714
3295
 
2715
- update(files) {
2716
- if (!Array.isArray(files)) {
2717
- if (this.files.length !== 1) {
2718
- this.files = [files];
2719
- } else if (this.files[0] !== files) {
2720
- this.files[0] = files;
3296
+ /**
3297
+ * @param {FSWatcher} watcher watcher
3298
+ * @param {string} filePath a file path
3299
+ * @param {(type: "rename" | "change", filename: string) => void} handleChangeEvent function to handle change
3300
+ * @returns {(type: "rename" | "change", filename: string) => void} handler of change event
3301
+ */
3302
+ function createHandleChangeEvent(watcher, filePath, handleChangeEvent) {
3303
+ // path.basename(filePath) is invariant for the lifetime of the watcher,
3304
+ // so compute it once rather than on every dispatched event.
3305
+ const ownBasename = path.basename(filePath);
3306
+ return (type, filename) => {
3307
+ // TODO: After Node.js v22, fs.watch(dir) and deleting a dir will trigger the rename change event.
3308
+ // Here we just ignore it and keep the same behavior as before v22
3309
+ // https://github.com/libuv/libuv/pull/4376
3310
+ if (
3311
+ type === "rename" &&
3312
+ path.isAbsolute(filename) &&
3313
+ path.basename(filename) === ownBasename
3314
+ ) {
3315
+ if (!IS_OSX) {
3316
+ // Before v22, windows will throw EPERM error
3317
+ watcher.emit("error", createEPERMError(filename));
2721
3318
  }
2722
- } else {
2723
- this.files = files;
3319
+ // Before v22, macos nothing to do
3320
+ return;
2724
3321
  }
2725
- }
3322
+ handleChangeEvent(type, filename);
3323
+ };
3324
+ }
2726
3325
 
2727
- close() {
2728
- this.watcher.close();
3326
+ class DirectWatcher {
3327
+ /**
3328
+ * @param {string} filePath file path
3329
+ */
3330
+ constructor(filePath) {
3331
+ this.filePath = filePath;
3332
+ this.watchers = new Set();
3333
+ /** @type {FSWatcher | undefined} */
3334
+ this.watcher = undefined;
3335
+ try {
3336
+ const watcher = fs.watch(filePath);
3337
+
3338
+ this.watcher = watcher;
3339
+ const handleChangeEvent = createHandleChangeEvent(
3340
+ watcher,
3341
+ filePath,
3342
+ (type, filename) => {
3343
+ for (const w of this.watchers) {
3344
+ w.emit("change", type, filename);
3345
+ }
3346
+ },
3347
+ );
3348
+ watcher.on("change", handleChangeEvent);
3349
+ watcher.on("error", (error) => {
3350
+ for (const w of this.watchers) {
3351
+ w.emit("error", error);
3352
+ }
3353
+ });
3354
+ } catch (err) {
3355
+ process.nextTick(() => {
3356
+ for (const w of this.watchers) {
3357
+ w.emit("error", err);
3358
+ }
3359
+ });
3360
+ }
3361
+ watcherCount++;
2729
3362
  }
2730
- }
2731
3363
 
2732
- class WatchpackDirectoryWatcher {
2733
- constructor(watchpack, watcher, directories) {
2734
- this.directories = Array.isArray(directories) ? directories : [directories];
2735
- this.watcher = watcher;
2736
- watcher.on("initial-missing", type => {
2737
- for (const item of this.directories) {
2738
- watchpack._onRemove(item, item, type);
2739
- }
2740
- });
2741
- watcher.on("change", (file, mtime, type) => {
2742
- for (const item of this.directories) {
2743
- watchpack._onChange(item, mtime, file, type);
2744
- }
2745
- });
2746
- watcher.on("remove", type => {
2747
- for (const item of this.directories) {
2748
- watchpack._onRemove(item, item, type);
2749
- }
2750
- });
3364
+ /**
3365
+ * @param {Watcher} watcher a watcher
3366
+ */
3367
+ add(watcher) {
3368
+ underlyingWatcher.set(watcher, this);
3369
+ this.watchers.add(watcher);
2751
3370
  }
2752
3371
 
2753
- update(directories) {
2754
- if (!Array.isArray(directories)) {
2755
- if (this.directories.length !== 1) {
2756
- this.directories = [directories];
2757
- } else if (this.directories[0] !== directories) {
2758
- this.directories[0] = directories;
2759
- }
2760
- } else {
2761
- this.directories = directories;
3372
+ /**
3373
+ * @param {Watcher} watcher a watcher
3374
+ */
3375
+ remove(watcher) {
3376
+ this.watchers.delete(watcher);
3377
+ if (this.watchers.size === 0) {
3378
+ directWatchers.delete(this.filePath);
3379
+ watcherCount--;
3380
+ if (this.watcher) this.watcher.close();
2762
3381
  }
2763
3382
  }
2764
3383
 
2765
- close() {
2766
- this.watcher.close();
3384
+ getWatchers() {
3385
+ return this.watchers;
2767
3386
  }
2768
3387
  }
2769
3388
 
2770
- class Watchpack extends EventEmitter {
2771
- constructor(options) {
2772
- super();
2773
- if (!options) options = EMPTY_OPTIONS;
2774
- this.options = options;
2775
- this.aggregateTimeout =
2776
- typeof options.aggregateTimeout === "number"
2777
- ? options.aggregateTimeout
2778
- : 200;
2779
- this.watcherOptions = cachedNormalizeOptions(options);
2780
- this.watcherManager = getWatcherManager(this.watcherOptions);
2781
- this.fileWatchers = new Map();
2782
- this.directoryWatchers = new Map();
2783
- this._missing = new Set();
2784
- this.startTime = undefined;
2785
- this.paused = false;
2786
- this.aggregatedChanges = new Set();
2787
- this.aggregatedRemovals = new Set();
2788
- this.aggregateTimer = undefined;
2789
- this._onTimeout = this._onTimeout.bind(this);
2790
- }
3389
+ /** @typedef {Set<Watcher>} WatcherSet */
2791
3390
 
2792
- watch(arg1, arg2, arg3) {
2793
- let files, directories, missing, startTime;
2794
- if (!arg2) {
2795
- ({
2796
- files = EMPTY_ARRAY,
2797
- directories = EMPTY_ARRAY,
2798
- missing = EMPTY_ARRAY,
2799
- startTime
2800
- } = arg1);
2801
- } else {
2802
- files = arg1;
2803
- directories = arg2;
2804
- missing = EMPTY_ARRAY;
2805
- startTime = arg3;
2806
- }
2807
- this.paused = false;
2808
- const fileWatchers = this.fileWatchers;
2809
- const directoryWatchers = this.directoryWatchers;
2810
- const ignored = this.watcherOptions.ignored;
2811
- const filter = path => !ignored(path);
2812
- const addToMap = (map, key, item) => {
2813
- const list = map.get(key);
2814
- if (list === undefined) {
2815
- map.set(key, item);
2816
- } else if (Array.isArray(list)) {
2817
- list.push(item);
2818
- } else {
2819
- map.set(key, [list, item]);
2820
- }
2821
- };
2822
- const fileWatchersNeeded = new Map();
2823
- const directoryWatchersNeeded = new Map();
2824
- const missingFiles = new Set();
2825
- if (this.watcherOptions.followSymlinks) {
2826
- const resolver = new LinkResolver();
2827
- for (const file of files) {
2828
- if (filter(file)) {
2829
- for (const innerFile of resolver.resolve(file)) {
2830
- if (file === innerFile || filter(innerFile)) {
2831
- addToMap(fileWatchersNeeded, innerFile, file);
2832
- }
3391
+ class RecursiveWatcher {
3392
+ /**
3393
+ * @param {string} rootPath a root path
3394
+ */
3395
+ constructor(rootPath) {
3396
+ this.rootPath = rootPath;
3397
+ /** @type {Map<Watcher, string>} */
3398
+ this.mapWatcherToPath = new Map();
3399
+ /** @type {Map<string, WatcherSet>} */
3400
+ this.mapPathToWatchers = new Map();
3401
+ this.watcher = undefined;
3402
+ try {
3403
+ const watcher = fs.watch(rootPath, {
3404
+ recursive: true,
3405
+ });
3406
+ this.watcher = watcher;
3407
+ watcher.on("change", (type, filename) => {
3408
+ if (!filename) {
3409
+ if (recursiveWatcherLogging) {
3410
+ process.stderr.write(
3411
+ `[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) to all watchers\n`,
3412
+ );
2833
3413
  }
2834
- }
2835
- }
2836
- for (const file of missing) {
2837
- if (filter(file)) {
2838
- for (const innerFile of resolver.resolve(file)) {
2839
- if (file === innerFile || filter(innerFile)) {
2840
- missingFiles.add(file);
2841
- addToMap(fileWatchersNeeded, innerFile, file);
2842
- }
3414
+ for (const w of this.mapWatcherToPath.keys()) {
3415
+ w.emit("change", /** @type {EventType} */ (type));
2843
3416
  }
2844
- }
2845
- }
2846
- for (const dir of directories) {
2847
- if (filter(dir)) {
2848
- let first = true;
2849
- for (const innerItem of resolver.resolve(dir)) {
2850
- if (filter(innerItem)) {
2851
- addToMap(
2852
- first ? directoryWatchersNeeded : fileWatchersNeeded,
2853
- innerItem,
2854
- dir
2855
- );
2856
- }
2857
- first = false;
3417
+ } else {
3418
+ const dir = path.dirname(/** @type {string} */ (filename));
3419
+ const watchers = this.mapPathToWatchers.get(dir);
3420
+ if (recursiveWatcherLogging) {
3421
+ process.stderr.write(
3422
+ `[watchpack] dispatch ${type} event in recursive watcher (${
3423
+ this.rootPath
3424
+ }) for '${filename}' to ${
3425
+ watchers ? watchers.size : 0
3426
+ } watchers\n`,
3427
+ );
3428
+ }
3429
+ if (watchers === undefined) return;
3430
+ for (const w of watchers) {
3431
+ w.emit(
3432
+ "change",
3433
+ /** @type {EventType} */ (type),
3434
+ path.basename(/** @type {string} */ (filename)),
3435
+ );
2858
3436
  }
2859
3437
  }
2860
- }
2861
- } else {
2862
- for (const file of files) {
2863
- if (filter(file)) {
2864
- addToMap(fileWatchersNeeded, file, file);
2865
- }
2866
- }
2867
- for (const file of missing) {
2868
- if (filter(file)) {
2869
- missingFiles.add(file);
2870
- addToMap(fileWatchersNeeded, file, file);
3438
+ });
3439
+ watcher.on("error", (error) => {
3440
+ for (const w of this.mapWatcherToPath.keys()) {
3441
+ w.emit("error", error);
2871
3442
  }
2872
- }
2873
- for (const dir of directories) {
2874
- if (filter(dir)) {
2875
- addToMap(directoryWatchersNeeded, dir, dir);
3443
+ });
3444
+ } catch (err) {
3445
+ process.nextTick(() => {
3446
+ for (const w of this.mapWatcherToPath.keys()) {
3447
+ w.emit("error", err);
2876
3448
  }
2877
- }
3449
+ });
3450
+ }
3451
+ watcherCount++;
3452
+ if (recursiveWatcherLogging) {
3453
+ process.stderr.write(
3454
+ `[watchpack] created recursive watcher at ${rootPath}\n`,
3455
+ );
3456
+ }
3457
+ }
3458
+
3459
+ /**
3460
+ * @param {string} filePath a file path
3461
+ * @param {Watcher} watcher a watcher
3462
+ */
3463
+ add(filePath, watcher) {
3464
+ underlyingWatcher.set(watcher, this);
3465
+ const subpath = filePath.slice(this.rootPath.length + 1) || ".";
3466
+ this.mapWatcherToPath.set(watcher, subpath);
3467
+ const set = this.mapPathToWatchers.get(subpath);
3468
+ if (set === undefined) {
3469
+ const newSet = new Set();
3470
+ newSet.add(watcher);
3471
+ this.mapPathToWatchers.set(subpath, newSet);
3472
+ } else {
3473
+ set.add(watcher);
2878
3474
  }
2879
- // Close unneeded old watchers
2880
- // and update existing watchers
2881
- for (const [key, w] of fileWatchers) {
2882
- const needed = fileWatchersNeeded.get(key);
2883
- if (needed === undefined) {
2884
- w.close();
2885
- fileWatchers.delete(key);
2886
- } else {
2887
- w.update(needed);
2888
- fileWatchersNeeded.delete(key);
2889
- }
3475
+ }
3476
+
3477
+ /**
3478
+ * @param {Watcher} watcher a watcher
3479
+ */
3480
+ remove(watcher) {
3481
+ const subpath = this.mapWatcherToPath.get(watcher);
3482
+ if (!subpath) return;
3483
+ this.mapWatcherToPath.delete(watcher);
3484
+ const set = /** @type {WatcherSet} */ (this.mapPathToWatchers.get(subpath));
3485
+ set.delete(watcher);
3486
+ if (set.size === 0) {
3487
+ this.mapPathToWatchers.delete(subpath);
2890
3488
  }
2891
- for (const [key, w] of directoryWatchers) {
2892
- const needed = directoryWatchersNeeded.get(key);
2893
- if (needed === undefined) {
2894
- w.close();
2895
- directoryWatchers.delete(key);
2896
- } else {
2897
- w.update(needed);
2898
- directoryWatchersNeeded.delete(key);
3489
+ if (this.mapWatcherToPath.size === 0) {
3490
+ recursiveWatchers.delete(this.rootPath);
3491
+ watcherCount--;
3492
+ if (this.watcher) this.watcher.close();
3493
+ if (recursiveWatcherLogging) {
3494
+ process.stderr.write(
3495
+ `[watchpack] closed recursive watcher at ${this.rootPath}\n`,
3496
+ );
2899
3497
  }
2900
3498
  }
2901
- // Create new watchers and install handlers on these watchers
2902
- watchEventSource.batch(() => {
2903
- for (const [key, files] of fileWatchersNeeded) {
2904
- const watcher = this.watcherManager.watchFile(key, startTime);
2905
- if (watcher) {
2906
- fileWatchers.set(key, new WatchpackFileWatcher(this, watcher, files));
2907
- }
2908
- }
2909
- for (const [key, directories] of directoryWatchersNeeded) {
2910
- const watcher = this.watcherManager.watchDirectory(key, startTime);
2911
- if (watcher) {
2912
- directoryWatchers.set(
2913
- key,
2914
- new WatchpackDirectoryWatcher(this, watcher, directories)
2915
- );
2916
- }
2917
- }
2918
- });
2919
- this._missing = missingFiles;
2920
- this.startTime = startTime;
2921
3499
  }
2922
3500
 
2923
- close() {
2924
- this.paused = true;
2925
- if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2926
- for (const w of this.fileWatchers.values()) w.close();
2927
- for (const w of this.directoryWatchers.values()) w.close();
2928
- this.fileWatchers.clear();
2929
- this.directoryWatchers.clear();
3501
+ getWatchers() {
3502
+ return this.mapWatcherToPath;
2930
3503
  }
3504
+ }
2931
3505
 
2932
- pause() {
2933
- this.paused = true;
2934
- if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
3506
+ /**
3507
+ * @typedef {object} WatcherEvents
3508
+ * @property {(eventType: EventType, filename?: string) => void} change change event
3509
+ * @property {(err: unknown) => void} error error event
3510
+ */
3511
+
3512
+ /**
3513
+ * @extends {EventEmitter<{ [K in keyof WatcherEvents]: Parameters<WatcherEvents[K]> }>}
3514
+ */
3515
+ class Watcher extends EventEmitter {
3516
+ constructor() {
3517
+ super();
2935
3518
  }
2936
3519
 
2937
- getTimes() {
2938
- const directoryWatchers = new Set();
2939
- addWatchersToSet(this.fileWatchers.values(), directoryWatchers);
2940
- addWatchersToSet(this.directoryWatchers.values(), directoryWatchers);
2941
- const obj = Object.create(null);
2942
- for (const w of directoryWatchers) {
2943
- const times = w.getTimes();
2944
- for (const file of Object.keys(times)) obj[file] = times[file];
3520
+ close() {
3521
+ if (pendingWatchers.has(this)) {
3522
+ pendingWatchers.delete(this);
3523
+ return;
2945
3524
  }
2946
- return obj;
3525
+ const watcher = underlyingWatcher.get(this);
3526
+ /** @type {RecursiveWatcher | DirectWatcher} */
3527
+ (watcher).remove(this);
3528
+ underlyingWatcher.delete(this);
2947
3529
  }
3530
+ }
2948
3531
 
2949
- getTimeInfoEntries() {
2950
- const map = new Map();
2951
- this.collectTimeInfoEntries(map, map);
2952
- return map;
2953
- }
3532
+ /**
3533
+ * @param {string} filePath a file path
3534
+ * @returns {DirectWatcher} a directory watcher
3535
+ */
3536
+ const createDirectWatcher = (filePath) => {
3537
+ const existing = directWatchers.get(filePath);
3538
+ if (existing !== undefined) return existing;
3539
+ const w = new DirectWatcher(filePath);
3540
+ directWatchers.set(filePath, w);
3541
+ return w;
3542
+ };
2954
3543
 
2955
- collectTimeInfoEntries(fileTimestamps, directoryTimestamps) {
2956
- const allWatchers = new Set();
2957
- addWatchersToSet(this.fileWatchers.values(), allWatchers);
2958
- addWatchersToSet(this.directoryWatchers.values(), allWatchers);
2959
- const safeTime = { value: 0 };
2960
- for (const w of allWatchers) {
2961
- w.collectTimeInfoEntries(fileTimestamps, directoryTimestamps, safeTime);
3544
+ /**
3545
+ * @param {string} rootPath a root path
3546
+ * @returns {RecursiveWatcher} a recursive watcher
3547
+ */
3548
+ const createRecursiveWatcher = (rootPath) => {
3549
+ const existing = recursiveWatchers.get(rootPath);
3550
+ if (existing !== undefined) return existing;
3551
+ const w = new RecursiveWatcher(rootPath);
3552
+ recursiveWatchers.set(rootPath, w);
3553
+ return w;
3554
+ };
3555
+
3556
+ const execute = () => {
3557
+ /** @type {Map<string, Watcher[] | Watcher>} */
3558
+ const map = new Map();
3559
+ /**
3560
+ * @param {Watcher} watcher a watcher
3561
+ * @param {string} filePath a file path
3562
+ */
3563
+ const addWatcher = (watcher, filePath) => {
3564
+ const entry = map.get(filePath);
3565
+ if (entry === undefined) {
3566
+ map.set(filePath, watcher);
3567
+ } else if (Array.isArray(entry)) {
3568
+ entry.push(watcher);
3569
+ } else {
3570
+ map.set(filePath, [entry, watcher]);
2962
3571
  }
3572
+ };
3573
+ for (const [watcher, filePath] of pendingWatchers) {
3574
+ addWatcher(watcher, filePath);
2963
3575
  }
3576
+ pendingWatchers.clear();
2964
3577
 
2965
- getAggregated() {
2966
- if (this.aggregateTimer) {
2967
- clearTimeout(this.aggregateTimer);
2968
- this.aggregateTimer = undefined;
3578
+ // Fast case when we are not reaching the limit
3579
+ if (!SUPPORTS_RECURSIVE_WATCHING || watcherLimit - watcherCount >= map.size) {
3580
+ // Create watchers for all entries in the map
3581
+ for (const [filePath, entry] of map) {
3582
+ const w = createDirectWatcher(filePath);
3583
+ if (Array.isArray(entry)) {
3584
+ for (const item of entry) w.add(item);
3585
+ } else {
3586
+ w.add(entry);
3587
+ }
2969
3588
  }
2970
- const changes = this.aggregatedChanges;
2971
- const removals = this.aggregatedRemovals;
2972
- this.aggregatedChanges = new Set();
2973
- this.aggregatedRemovals = new Set();
2974
- return { changes, removals };
3589
+ return;
2975
3590
  }
2976
3591
 
2977
- _onChange(item, mtime, file, type) {
2978
- file = file || item;
2979
- if (!this.paused) {
2980
- this.emit("change", file, mtime, type);
2981
- if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2982
- this.aggregateTimer = setTimeout(this._onTimeout, this.aggregateTimeout);
3592
+ // Reconsider existing watchers to improving watch plan
3593
+ for (const watcher of recursiveWatchers.values()) {
3594
+ for (const [w, subpath] of watcher.getWatchers()) {
3595
+ addWatcher(w, path.join(watcher.rootPath, subpath));
3596
+ }
3597
+ }
3598
+ for (const watcher of directWatchers.values()) {
3599
+ for (const w of watcher.getWatchers()) {
3600
+ addWatcher(w, watcher.filePath);
2983
3601
  }
2984
- this.aggregatedRemovals.delete(item);
2985
- this.aggregatedChanges.add(item);
2986
3602
  }
2987
3603
 
2988
- _onRemove(item, file, type) {
2989
- file = file || item;
2990
- if (!this.paused) {
2991
- this.emit("remove", file, type);
2992
- if (this.aggregateTimer) clearTimeout(this.aggregateTimer);
2993
- this.aggregateTimer = setTimeout(this._onTimeout, this.aggregateTimeout);
3604
+ // Merge map entries to keep watcher limit
3605
+ // Create a 10% buffer to be able to enter fast case more often
3606
+ const plan = reducePlan(map, watcherLimit * 0.9);
3607
+
3608
+ // Update watchers for all entries in the map
3609
+ for (const [filePath, entry] of plan) {
3610
+ if (entry.size === 1) {
3611
+ for (const [watcher, filePath] of entry) {
3612
+ const w = createDirectWatcher(filePath);
3613
+ const old = underlyingWatcher.get(watcher);
3614
+ if (old === w) continue;
3615
+ w.add(watcher);
3616
+ if (old !== undefined) old.remove(watcher);
3617
+ }
3618
+ } else {
3619
+ const filePaths = new Set(entry.values());
3620
+ if (filePaths.size > 1) {
3621
+ const w = createRecursiveWatcher(filePath);
3622
+ for (const [watcher, watcherPath] of entry) {
3623
+ const old = underlyingWatcher.get(watcher);
3624
+ if (old === w) continue;
3625
+ w.add(watcherPath, watcher);
3626
+ if (old !== undefined) old.remove(watcher);
3627
+ }
3628
+ } else {
3629
+ for (const filePath of filePaths) {
3630
+ const w = createDirectWatcher(filePath);
3631
+ for (const watcher of entry.keys()) {
3632
+ const old = underlyingWatcher.get(watcher);
3633
+ if (old === w) continue;
3634
+ w.add(watcher);
3635
+ if (old !== undefined) old.remove(watcher);
3636
+ }
3637
+ }
3638
+ }
2994
3639
  }
2995
- this.aggregatedChanges.delete(item);
2996
- this.aggregatedRemovals.add(item);
2997
3640
  }
3641
+ };
2998
3642
 
2999
- _onTimeout() {
3000
- this.aggregateTimer = undefined;
3001
- const changes = this.aggregatedChanges;
3002
- const removals = this.aggregatedRemovals;
3003
- this.aggregatedChanges = new Set();
3004
- this.aggregatedRemovals = new Set();
3005
- this.emit("aggregated", changes, removals);
3643
+ module.exports.Watcher = Watcher;
3644
+
3645
+ /**
3646
+ * @param {() => void} fn a function
3647
+ */
3648
+ module.exports.batch = (fn) => {
3649
+ isBatch = true;
3650
+ try {
3651
+ fn();
3652
+ } finally {
3653
+ isBatch = false;
3654
+ execute();
3006
3655
  }
3007
- }
3656
+ };
3657
+
3658
+ module.exports.createHandleChangeEvent = createHandleChangeEvent;
3659
+
3660
+ module.exports.getNumberOfWatchers = () => watcherCount;
3661
+
3662
+ /**
3663
+ * @param {string} filePath a file path
3664
+ * @returns {Watcher} watcher
3665
+ */
3666
+ module.exports.watch = (filePath) => {
3667
+ const watcher = new Watcher();
3668
+ // Find an existing watcher
3669
+ const directWatcher = directWatchers.get(filePath);
3670
+ if (directWatcher !== undefined) {
3671
+ directWatcher.add(watcher);
3672
+ return watcher;
3673
+ }
3674
+ // Only platforms with recursive fs.watch ever populate recursiveWatchers,
3675
+ // so skip the entire parent walk when the map is empty (always the case
3676
+ // on Linux and the common case before the watcher limit is reached).
3677
+ if (recursiveWatchers.size !== 0) {
3678
+ let current = filePath;
3679
+ for (;;) {
3680
+ const recursiveWatcher = recursiveWatchers.get(current);
3681
+ if (recursiveWatcher !== undefined) {
3682
+ recursiveWatcher.add(filePath, watcher);
3683
+ return watcher;
3684
+ }
3685
+ const parent = path.dirname(current);
3686
+ if (parent === current) break;
3687
+ current = parent;
3688
+ }
3689
+ }
3690
+ // Queue up watcher for creation
3691
+ pendingWatchers.set(watcher, filePath);
3692
+ if (!isBatch) execute();
3693
+ return watcher;
3694
+ };
3008
3695
 
3009
- module.exports = Watchpack;
3696
+ module.exports.watcherLimit = watcherLimit;
3010
3697
 
3011
3698
 
3012
3699
  /***/ }),
@@ -3117,7 +3804,7 @@ module.exports = require("util");
3117
3804
  /******/ // startup
3118
3805
  /******/ // Load entry module and return exports
3119
3806
  /******/ // This entry module is referenced by other modules so it can't be inlined
3120
- /******/ var __webpack_exports__ = __nccwpck_require__(851);
3807
+ /******/ var __webpack_exports__ = __nccwpck_require__(934);
3121
3808
  /******/ module.exports = __webpack_exports__;
3122
3809
  /******/
3123
3810
  /******/ })()