@ohos-ports/rspack-core 2.2.2-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 (326) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +15 -0
  3. package/compiled/@rspack/lite-tapable/dist/index.d.ts +176 -0
  4. package/compiled/@rspack/lite-tapable/license +22 -0
  5. package/compiled/@rspack/lite-tapable/package.json +1 -0
  6. package/compiled/@swc/types/index.d.ts +2284 -0
  7. package/compiled/@swc/types/index.js +19 -0
  8. package/compiled/@swc/types/license +201 -0
  9. package/compiled/@swc/types/package.json +1 -0
  10. package/compiled/connect-next/index.d.ts +57 -0
  11. package/compiled/connect-next/license +26 -0
  12. package/compiled/connect-next/package.json +1 -0
  13. package/compiled/http-proxy-middleware/index.d.ts +455 -0
  14. package/compiled/http-proxy-middleware/license +22 -0
  15. package/compiled/http-proxy-middleware/package.json +1 -0
  16. package/compiled/open/index.d.ts +161 -0
  17. package/compiled/open/package.json +1 -0
  18. package/compiled/tinypool/LICENSE +24 -0
  19. package/compiled/tinypool/README.md +214 -0
  20. package/compiled/tinypool/dist/common-Bo3KCGim.js +31 -0
  21. package/compiled/tinypool/dist/entry/process.d.ts +1 -0
  22. package/compiled/tinypool/dist/entry/process.js +72 -0
  23. package/compiled/tinypool/dist/entry/utils.d.ts +7 -0
  24. package/compiled/tinypool/dist/entry/utils.js +3 -0
  25. package/compiled/tinypool/dist/entry/worker.d.ts +1 -0
  26. package/compiled/tinypool/dist/entry/worker.js +76 -0
  27. package/compiled/tinypool/dist/index.d.ts +199 -0
  28. package/compiled/tinypool/dist/index.js +784 -0
  29. package/compiled/tinypool/dist/utils-B--2TaWv.js +38 -0
  30. package/compiled/tinypool/dist/utils-De75vAgL.js +10 -0
  31. package/compiled/tinypool/package.json +55 -0
  32. package/compiled/watchpack/index.d.ts +3 -0
  33. package/compiled/watchpack/index.js +3811 -0
  34. package/compiled/watchpack/license +20 -0
  35. package/compiled/watchpack/package.json +8 -0
  36. package/compiled/watchpack/types/DirectoryWatcher.d.ts +335 -0
  37. package/compiled/watchpack/types/LinkResolver.d.ts +10 -0
  38. package/compiled/watchpack/types/getWatcherManager.d.ts +62 -0
  39. package/compiled/watchpack/types/index.d.ts +269 -0
  40. package/compiled/watchpack/types/reducePlan.d.ts +34 -0
  41. package/compiled/watchpack/types/util/globToRegExp.d.ts +2 -0
  42. package/compiled/watchpack/types/watchEventSource.d.ts +53 -0
  43. package/compiled/watchpack/types/watchpack.d.ts +2 -0
  44. package/compiled/webpack-sources/index.js +5835 -0
  45. package/compiled/webpack-sources/license +21 -0
  46. package/compiled/webpack-sources/package.json +1 -0
  47. package/compiled/webpack-sources/types.d.ts +500 -0
  48. package/dist/612~0.js +32 -0
  49. package/dist/612~3.js +32 -0
  50. package/dist/BuildInfo.d.ts +17 -0
  51. package/dist/Chunk.d.ts +16 -0
  52. package/dist/ChunkGraph.d.ts +9 -0
  53. package/dist/Chunks.d.ts +12 -0
  54. package/dist/CodeGenerationResults.d.ts +1 -0
  55. package/dist/Compilation.d.ts +448 -0
  56. package/dist/Compiler.d.ts +229 -0
  57. package/dist/ConcatenatedModule.d.ts +1 -0
  58. package/dist/ContextModule.d.ts +1 -0
  59. package/dist/ContextModuleFactory.d.ts +13 -0
  60. package/dist/Diagnostics.d.ts +7 -0
  61. package/dist/Entrypoint.d.ts +2 -0
  62. package/dist/ErrorHelpers.d.ts +3 -0
  63. package/dist/ExecuteModulePlugin.d.ts +4 -0
  64. package/dist/ExportsInfo.d.ts +20 -0
  65. package/dist/ExternalModule.d.ts +15 -0
  66. package/dist/FileSystem.d.ts +54 -0
  67. package/dist/FileSystemInfo.d.ts +5 -0
  68. package/dist/Module.d.ts +41 -0
  69. package/dist/ModuleGraph.d.ts +22 -0
  70. package/dist/ModuleGraphConnection.d.ts +10 -0
  71. package/dist/ModuleTypeConstants.d.ts +8 -0
  72. package/dist/MultiCompiler.d.ts +82 -0
  73. package/dist/MultiStats.d.ts +23 -0
  74. package/dist/MultiWatching.d.ts +27 -0
  75. package/dist/NativeWatchFileSystem.d.ts +52 -0
  76. package/dist/NormalModule.d.ts +14 -0
  77. package/dist/NormalModuleFactory.d.ts +23 -0
  78. package/dist/Resolver.d.ts +30 -0
  79. package/dist/ResolverFactory.d.ts +17 -0
  80. package/dist/RspackError.d.ts +12 -0
  81. package/dist/RuleSetCompiler.d.ts +9 -0
  82. package/dist/RuntimeGlobals.d.ts +360 -0
  83. package/dist/RuntimeModule.d.ts +34 -0
  84. package/dist/RuntimeTemplate.d.ts +151 -0
  85. package/dist/Stats.d.ts +17 -0
  86. package/dist/Template.d.ts +77 -0
  87. package/dist/VirtualModulesPlugin.d.ts +12 -0
  88. package/dist/Watching.d.ts +56 -0
  89. package/dist/builtin-loader/lightningcss/index.d.ts +114 -0
  90. package/dist/builtin-loader/lightningcss/target.d.ts +4 -0
  91. package/dist/builtin-loader/swc/collectTypeScriptInfo.d.ts +21 -0
  92. package/dist/builtin-loader/swc/index.d.ts +3 -0
  93. package/dist/builtin-loader/swc/pluginImport.d.ts +33 -0
  94. package/dist/builtin-loader/swc/types.d.ts +60 -0
  95. package/dist/builtin-plugin/APIPlugin.d.ts +9 -0
  96. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +9 -0
  97. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +9 -0
  98. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +9 -0
  99. package/dist/builtin-plugin/BannerPlugin.d.ts +40 -0
  100. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +14 -0
  101. package/dist/builtin-plugin/CaseSensitivePlugin.d.ts +9 -0
  102. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +9 -0
  103. package/dist/builtin-plugin/CircularCheckRspackPlugin.d.ts +33 -0
  104. package/dist/builtin-plugin/CircularDependencyRspackPlugin.d.ts +60 -0
  105. package/dist/builtin-plugin/CircularModulesInfoPlugin.d.ts +7 -0
  106. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +9 -0
  107. package/dist/builtin-plugin/CompactHashedChunkIdsPlugin.d.ts +12 -0
  108. package/dist/builtin-plugin/CompactHashedModuleIdsPlugin.d.ts +12 -0
  109. package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +9 -0
  110. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +14 -0
  111. package/dist/builtin-plugin/CssChunkingPlugin.d.ts +21 -0
  112. package/dist/builtin-plugin/CssHttpExternalsRspackPlugin.d.ts +9 -0
  113. package/dist/builtin-plugin/CssModulesPlugin.d.ts +9 -0
  114. package/dist/builtin-plugin/DataUriPlugin.d.ts +9 -0
  115. package/dist/builtin-plugin/DefinePlugin.d.ts +16 -0
  116. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +7 -0
  117. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +18 -0
  118. package/dist/builtin-plugin/DllEntryPlugin.d.ts +12 -0
  119. package/dist/builtin-plugin/DllReferenceAgencyPlugin.d.ts +11 -0
  120. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +12 -0
  121. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +9 -0
  122. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +25 -0
  123. package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +11 -0
  124. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +9 -0
  125. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +9 -0
  126. package/dist/builtin-plugin/EntryPlugin.d.ts +32 -0
  127. package/dist/builtin-plugin/EsmLibraryPlugin.d.ts +16 -0
  128. package/dist/builtin-plugin/EsmNodeTargetPlugin.d.ts +9 -0
  129. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +11 -0
  130. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +10 -0
  131. package/dist/builtin-plugin/ExternalsPlugin.d.ts +13 -0
  132. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +9 -0
  133. package/dist/builtin-plugin/FileUriPlugin.d.ts +9 -0
  134. package/dist/builtin-plugin/FlagAllModulesAsUsedPlugin.d.ts +9 -0
  135. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +9 -0
  136. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +9 -0
  137. package/dist/builtin-plugin/HashedModuleIdsPlugin.d.ts +10 -0
  138. package/dist/builtin-plugin/HotModuleReplacementPlugin.d.ts +7 -0
  139. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +9 -0
  140. package/dist/builtin-plugin/HttpUriPlugin.d.ts +36 -0
  141. package/dist/builtin-plugin/IgnorePlugin.d.ts +19 -0
  142. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +9 -0
  143. package/dist/builtin-plugin/InlineExportsPlugin.d.ts +9 -0
  144. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +30 -0
  145. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +10 -0
  146. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +9 -0
  147. package/dist/builtin-plugin/LibManifestPlugin.d.ts +17 -0
  148. package/dist/builtin-plugin/LightningCssMinimizerRspackPlugin.d.ts +28 -0
  149. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +14 -0
  150. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +9 -0
  151. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +9 -0
  152. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +9 -0
  153. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +7 -0
  154. package/dist/builtin-plugin/ModuleInfoHeaderPlugin.d.ts +9 -0
  155. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +9 -0
  156. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +9 -0
  157. package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +7 -0
  158. package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +7 -0
  159. package/dist/builtin-plugin/NoEmitOnErrorsPlugin.d.ts +9 -0
  160. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +9 -0
  161. package/dist/builtin-plugin/NormalModuleReplacementPlugin.d.ts +10 -0
  162. package/dist/builtin-plugin/OccurrenceChunkIdsPlugin.d.ts +10 -0
  163. package/dist/builtin-plugin/ProgressPlugin.d.ts +12 -0
  164. package/dist/builtin-plugin/ProvidePlugin.d.ts +10 -0
  165. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +20 -0
  166. package/dist/builtin-plugin/RemoveDuplicateModulesPlugin.d.ts +9 -0
  167. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +9 -0
  168. package/dist/builtin-plugin/RsdoctorPlugin.d.ts +46 -0
  169. package/dist/builtin-plugin/RslibPlugin.d.ts +10 -0
  170. package/dist/builtin-plugin/RstestPlugin.d.ts +10 -0
  171. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +11 -0
  172. package/dist/builtin-plugin/RuntimePlugin.d.ts +25 -0
  173. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +9 -0
  174. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +19 -0
  175. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +11 -0
  176. package/dist/builtin-plugin/SplitChunksPlugin.d.ts +12 -0
  177. package/dist/builtin-plugin/SubresourceIntegrityPlugin.d.ts +39 -0
  178. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +216 -0
  179. package/dist/builtin-plugin/SyncModuleIdsPlugin.d.ts +16 -0
  180. package/dist/builtin-plugin/URLPlugin.d.ts +9 -0
  181. package/dist/builtin-plugin/WorkerPlugin.d.ts +14 -0
  182. package/dist/builtin-plugin/base.d.ts +45 -0
  183. package/dist/builtin-plugin/css-extract/index.d.ts +24 -0
  184. package/dist/builtin-plugin/css-extract/loader.d.ts +21 -0
  185. package/dist/builtin-plugin/css-extract/utils.d.ts +10 -0
  186. package/dist/builtin-plugin/html-plugin/hooks.d.ts +32 -0
  187. package/dist/builtin-plugin/html-plugin/index.d.ts +2 -0
  188. package/dist/builtin-plugin/html-plugin/options.d.ts +77 -0
  189. package/dist/builtin-plugin/html-plugin/plugin.d.ts +20 -0
  190. package/dist/builtin-plugin/html-plugin/taps.d.ts +2 -0
  191. package/dist/builtin-plugin/index.d.ts +92 -0
  192. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +10 -0
  193. package/dist/builtin-plugin/lazy-compilation/middleware.d.ts +12 -0
  194. package/dist/builtin-plugin/rsc/Coordinator.d.ts +8 -0
  195. package/dist/builtin-plugin/rsc/RscClientPlugin.d.ts +13 -0
  196. package/dist/builtin-plugin/rsc/RscServerPlugin.d.ts +47 -0
  197. package/dist/builtin-plugin/rsc/index.d.ts +24 -0
  198. package/dist/checkNodeVersion.d.ts +1 -0
  199. package/dist/config/adapter.d.ts +8 -0
  200. package/dist/config/adapterRuleUse.d.ts +424 -0
  201. package/dist/config/browserslistTargetHandler.d.ts +15 -0
  202. package/dist/config/defaults.d.ts +15 -0
  203. package/dist/config/devServer.d.ts +179 -0
  204. package/dist/config/index.d.ts +5 -0
  205. package/dist/config/normalization.d.ts +156 -0
  206. package/dist/config/target.d.ts +100 -0
  207. package/dist/config/types.d.ts +2728 -0
  208. package/dist/container/ContainerPlugin.d.ts +41 -0
  209. package/dist/container/ContainerReferencePlugin.d.ts +34 -0
  210. package/dist/container/ModuleFederationManifestPlugin.d.ts +44 -0
  211. package/dist/container/ModuleFederationPlugin.d.ts +34 -0
  212. package/dist/container/ModuleFederationPluginV1.d.ts +22 -0
  213. package/dist/container/ModuleFederationRuntimePlugin.d.ts +16 -0
  214. package/dist/container/options.d.ts +3 -0
  215. package/dist/cssExtractHmr.js +99 -0
  216. package/dist/cssExtractLoader.js +117 -0
  217. package/dist/error/ConcurrentCompilationError.d.ts +14 -0
  218. package/dist/exports.d.ts +192 -0
  219. package/dist/index.d.ts +11 -0
  220. package/dist/index.js +14552 -0
  221. package/dist/lib/AbstractMethodError.d.ts +23 -0
  222. package/dist/lib/Cache.d.ts +65 -0
  223. package/dist/lib/CacheFacade.d.ts +139 -0
  224. package/dist/lib/DllPlugin.d.ts +42 -0
  225. package/dist/lib/DllReferencePlugin.d.ts +119 -0
  226. package/dist/lib/EntryOptionPlugin.d.ts +33 -0
  227. package/dist/lib/EnvironmentPlugin.d.ts +22 -0
  228. package/dist/lib/HookWebpackError.d.ts +39 -0
  229. package/dist/lib/IgnoreWarningsPlugin.d.ts +25 -0
  230. package/dist/lib/LoaderOptionsPlugin.d.ts +28 -0
  231. package/dist/lib/LoaderTargetPlugin.d.ts +24 -0
  232. package/dist/lib/ModuleFilenameHelpers.d.ts +53 -0
  233. package/dist/lib/WebpackError.d.ts +21 -0
  234. package/dist/lib/cache/MemoryCachePlugin.d.ts +5 -0
  235. package/dist/lib/cache/getLazyHashedEtag.d.ts +35 -0
  236. package/dist/lib/cache/mergeEtags.d.ts +16 -0
  237. package/dist/loader-runner/LoaderLoadingError.d.ts +13 -0
  238. package/dist/loader-runner/ModuleError.d.ts +13 -0
  239. package/dist/loader-runner/cache.d.ts +18 -0
  240. package/dist/loader-runner/dependencies.d.ts +22 -0
  241. package/dist/loader-runner/index.d.ts +35 -0
  242. package/dist/loader-runner/loadLoader.d.ts +12 -0
  243. package/dist/loader-runner/service.d.ts +77 -0
  244. package/dist/loader-runner/utils.d.ts +7 -0
  245. package/dist/loader-runner/worker.d.ts +14 -0
  246. package/dist/logging/Logger.d.ts +61 -0
  247. package/dist/logging/createConsoleLogger.d.ts +35 -0
  248. package/dist/logging/truncateArgs.d.ts +16 -0
  249. package/dist/moduleFederationDefaultRuntime.js +1 -0
  250. package/dist/node/NodeEnvironmentPlugin.d.ts +10 -0
  251. package/dist/node/NodeTemplatePlugin.d.ts +18 -0
  252. package/dist/node/NodeWatchFileSystem.d.ts +30 -0
  253. package/dist/node/nodeConsole.d.ts +15 -0
  254. package/dist/rspack.d.ts +24 -0
  255. package/dist/rspackOptionsApply.d.ts +4 -0
  256. package/dist/runtime/cssExtractHmr.d.ts +4 -0
  257. package/dist/runtime/moduleFederationDefaultRuntime.d.ts +1 -0
  258. package/dist/sharing/CollectSharedEntryPlugin.d.ts +22 -0
  259. package/dist/sharing/ConsumeSharedPlugin.d.ts +54 -0
  260. package/dist/sharing/IndependentSharedPlugin.d.ts +37 -0
  261. package/dist/sharing/ProvideSharedPlugin.d.ts +54 -0
  262. package/dist/sharing/SharePlugin.d.ts +89 -0
  263. package/dist/sharing/ShareRuntimePlugin.d.ts +9 -0
  264. package/dist/sharing/SharedContainerPlugin.d.ts +23 -0
  265. package/dist/sharing/SharedUsedExportsOptimizerPlugin.d.ts +14 -0
  266. package/dist/sharing/TreeShakingSharedPlugin.d.ts +19 -0
  267. package/dist/sharing/utils.d.ts +2 -0
  268. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +20 -0
  269. package/dist/stats/DefaultStatsPresetPlugin.d.ts +4 -0
  270. package/dist/stats/DefaultStatsPrinterPlugin.d.ts +13 -0
  271. package/dist/stats/StatsFactory.d.ts +57 -0
  272. package/dist/stats/StatsPrinter.d.ts +57 -0
  273. package/dist/stats/statsFactoryUtils.d.ts +338 -0
  274. package/dist/swc.d.ts +7 -0
  275. package/dist/taps/compilation.d.ts +8 -0
  276. package/dist/taps/compiler.d.ts +2 -0
  277. package/dist/taps/contextModuleFactory.d.ts +2 -0
  278. package/dist/taps/externalModule.d.ts +2 -0
  279. package/dist/taps/index.d.ts +7 -0
  280. package/dist/taps/javascriptModules.d.ts +2 -0
  281. package/dist/taps/normalModuleFactory.d.ts +2 -0
  282. package/dist/taps/types.d.ts +11 -0
  283. package/dist/trace/index.d.ts +47 -0
  284. package/dist/trace/traceHookPlugin.d.ts +5 -0
  285. package/dist/util/ArrayQueue.d.ts +45 -0
  286. package/dist/util/AsyncTask.d.ts +7 -0
  287. package/dist/util/MergeCaller.d.ts +10 -0
  288. package/dist/util/SizeFormatHelpers.d.ts +10 -0
  289. package/dist/util/SplitChunkSize.d.ts +5 -0
  290. package/dist/util/assertNotNil.d.ts +1 -0
  291. package/dist/util/assetCondition.d.ts +2 -0
  292. package/dist/util/asyncLib.d.ts +54 -0
  293. package/dist/util/bindingVersionCheck.d.ts +5 -0
  294. package/dist/util/cleverMerge.d.ts +24 -0
  295. package/dist/util/comparators.d.ts +16 -0
  296. package/dist/util/createHash.d.ts +16 -0
  297. package/dist/util/createReadonlyMap.d.ts +1 -0
  298. package/dist/util/fake.d.ts +11 -0
  299. package/dist/util/fs.d.ts +376 -0
  300. package/dist/util/hash/index.d.ts +26 -0
  301. package/dist/util/hash/md4.d.ts +11 -0
  302. package/dist/util/hash/wasm-hash.d.ts +51 -0
  303. package/dist/util/hash/xxhash64.d.ts +11 -0
  304. package/dist/util/identifier.d.ts +57 -0
  305. package/dist/util/index.d.ts +9 -0
  306. package/dist/util/memoize.d.ts +2 -0
  307. package/dist/util/runtime.d.ts +2 -0
  308. package/dist/util/smartGrouping.d.ts +21 -0
  309. package/dist/util/source.d.ts +6 -0
  310. package/dist/util/supportsColor.d.ts +6 -0
  311. package/dist/util/targetsVersion.d.ts +2 -0
  312. package/dist/util/validateConfig.d.ts +5 -0
  313. package/dist/web/JsonpTemplatePlugin.d.ts +13 -0
  314. package/dist/webworker/WebWorkerTemplatePlugin.d.ts +13 -0
  315. package/dist/worker.js +971 -0
  316. package/hot/dev-server.js +76 -0
  317. package/hot/emitter.js +23 -0
  318. package/hot/lazy-compilation-node.js +109 -0
  319. package/hot/lazy-compilation-web.js +97 -0
  320. package/hot/log-apply-result.js +52 -0
  321. package/hot/log.js +87 -0
  322. package/hot/only-dev-server.js +104 -0
  323. package/hot/poll.js +41 -0
  324. package/hot/signal.js +68 -0
  325. package/module.d.ts +310 -0
  326. package/package.json +79 -0
@@ -0,0 +1,3811 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ var __webpack_modules__ = ({
3
+
4
+ /***/ 648:
5
+ /***/ ((module) => {
6
+
7
+ "use strict";
8
+
9
+
10
+ module.exports = clone
11
+
12
+ var getPrototypeOf = Object.getPrototypeOf || function (obj) {
13
+ return obj.__proto__
14
+ }
15
+
16
+ function clone (obj) {
17
+ if (obj === null || typeof obj !== 'object')
18
+ return obj
19
+
20
+ if (obj instanceof Object)
21
+ var copy = { __proto__: getPrototypeOf(obj) }
22
+ else
23
+ var copy = Object.create(null)
24
+
25
+ Object.getOwnPropertyNames(obj).forEach(function (key) {
26
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
27
+ })
28
+
29
+ return copy
30
+ }
31
+
32
+
33
+ /***/ }),
34
+
35
+ /***/ 692:
36
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
37
+
38
+ var fs = __nccwpck_require__(896)
39
+ var polyfills = __nccwpck_require__(161)
40
+ var legacy = __nccwpck_require__(50)
41
+ var clone = __nccwpck_require__(648)
42
+
43
+ var util = __nccwpck_require__(23)
44
+
45
+ /* istanbul ignore next - node 0.x polyfill */
46
+ var gracefulQueue
47
+ var previousSymbol
48
+
49
+ /* istanbul ignore else - node 0.x polyfill */
50
+ if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
51
+ gracefulQueue = Symbol.for('graceful-fs.queue')
52
+ // This is used in testing by future versions
53
+ previousSymbol = Symbol.for('graceful-fs.previous')
54
+ } else {
55
+ gracefulQueue = '___graceful-fs.queue'
56
+ previousSymbol = '___graceful-fs.previous'
57
+ }
58
+
59
+ function noop () {}
60
+
61
+ function publishQueue(context, queue) {
62
+ Object.defineProperty(context, gracefulQueue, {
63
+ get: function() {
64
+ return queue
65
+ }
66
+ })
67
+ }
68
+
69
+ var debug = noop
70
+ if (util.debuglog)
71
+ debug = util.debuglog('gfs4')
72
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
73
+ debug = function() {
74
+ var m = util.format.apply(util, arguments)
75
+ m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ')
76
+ console.error(m)
77
+ }
78
+
79
+ // Once time initialization
80
+ if (!fs[gracefulQueue]) {
81
+ // This queue can be shared by multiple loaded instances
82
+ var queue = global[gracefulQueue] || []
83
+ publishQueue(fs, queue)
84
+
85
+ // Patch fs.close/closeSync to shared queue version, because we need
86
+ // to retry() whenever a close happens *anywhere* in the program.
87
+ // This is essential when multiple graceful-fs instances are
88
+ // in play at the same time.
89
+ fs.close = (function (fs$close) {
90
+ function close (fd, cb) {
91
+ return fs$close.call(fs, fd, function (err) {
92
+ // This function uses the graceful-fs shared queue
93
+ if (!err) {
94
+ resetQueue()
95
+ }
96
+
97
+ if (typeof cb === 'function')
98
+ cb.apply(this, arguments)
99
+ })
100
+ }
101
+
102
+ Object.defineProperty(close, previousSymbol, {
103
+ value: fs$close
104
+ })
105
+ return close
106
+ })(fs.close)
107
+
108
+ fs.closeSync = (function (fs$closeSync) {
109
+ function closeSync (fd) {
110
+ // This function uses the graceful-fs shared queue
111
+ fs$closeSync.apply(fs, arguments)
112
+ resetQueue()
113
+ }
114
+
115
+ Object.defineProperty(closeSync, previousSymbol, {
116
+ value: fs$closeSync
117
+ })
118
+ return closeSync
119
+ })(fs.closeSync)
120
+
121
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
122
+ process.on('exit', function() {
123
+ debug(fs[gracefulQueue])
124
+ __nccwpck_require__(613).equal(fs[gracefulQueue].length, 0)
125
+ })
126
+ }
127
+ }
128
+
129
+ if (!global[gracefulQueue]) {
130
+ publishQueue(global, fs[gracefulQueue]);
131
+ }
132
+
133
+ module.exports = patch(clone(fs))
134
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) {
135
+ module.exports = patch(fs)
136
+ fs.__patched = true;
137
+ }
138
+
139
+ function patch (fs) {
140
+ // Everything that references the open() function needs to be in here
141
+ polyfills(fs)
142
+ fs.gracefulify = patch
143
+
144
+ fs.createReadStream = createReadStream
145
+ fs.createWriteStream = createWriteStream
146
+ var fs$readFile = fs.readFile
147
+ fs.readFile = readFile
148
+ function readFile (path, options, cb) {
149
+ if (typeof options === 'function')
150
+ cb = options, options = null
151
+
152
+ return go$readFile(path, options, cb)
153
+
154
+ function go$readFile (path, options, cb, startTime) {
155
+ return fs$readFile(path, options, function (err) {
156
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
157
+ enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()])
158
+ else {
159
+ if (typeof cb === 'function')
160
+ cb.apply(this, arguments)
161
+ }
162
+ })
163
+ }
164
+ }
165
+
166
+ var fs$writeFile = fs.writeFile
167
+ fs.writeFile = writeFile
168
+ function writeFile (path, data, options, cb) {
169
+ if (typeof options === 'function')
170
+ cb = options, options = null
171
+
172
+ return go$writeFile(path, data, options, cb)
173
+
174
+ function go$writeFile (path, data, options, cb, startTime) {
175
+ return fs$writeFile(path, data, options, function (err) {
176
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
177
+ enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()])
178
+ else {
179
+ if (typeof cb === 'function')
180
+ cb.apply(this, arguments)
181
+ }
182
+ })
183
+ }
184
+ }
185
+
186
+ var fs$appendFile = fs.appendFile
187
+ if (fs$appendFile)
188
+ fs.appendFile = appendFile
189
+ function appendFile (path, data, options, cb) {
190
+ if (typeof options === 'function')
191
+ cb = options, options = null
192
+
193
+ return go$appendFile(path, data, options, cb)
194
+
195
+ function go$appendFile (path, data, options, cb, startTime) {
196
+ return fs$appendFile(path, data, options, function (err) {
197
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
198
+ enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()])
199
+ else {
200
+ if (typeof cb === 'function')
201
+ cb.apply(this, arguments)
202
+ }
203
+ })
204
+ }
205
+ }
206
+
207
+ var fs$copyFile = fs.copyFile
208
+ if (fs$copyFile)
209
+ fs.copyFile = copyFile
210
+ function copyFile (src, dest, flags, cb) {
211
+ if (typeof flags === 'function') {
212
+ cb = flags
213
+ flags = 0
214
+ }
215
+ return go$copyFile(src, dest, flags, cb)
216
+
217
+ function go$copyFile (src, dest, flags, cb, startTime) {
218
+ return fs$copyFile(src, dest, flags, function (err) {
219
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
220
+ enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()])
221
+ else {
222
+ if (typeof cb === 'function')
223
+ cb.apply(this, arguments)
224
+ }
225
+ })
226
+ }
227
+ }
228
+
229
+ var fs$readdir = fs.readdir
230
+ fs.readdir = readdir
231
+ var noReaddirOptionVersions = /^v[0-5]\./
232
+ function readdir (path, options, cb) {
233
+ if (typeof options === 'function')
234
+ cb = options, options = null
235
+
236
+ var go$readdir = noReaddirOptionVersions.test(process.version)
237
+ ? function go$readdir (path, options, cb, startTime) {
238
+ return fs$readdir(path, fs$readdirCallback(
239
+ path, options, cb, startTime
240
+ ))
241
+ }
242
+ : function go$readdir (path, options, cb, startTime) {
243
+ return fs$readdir(path, options, fs$readdirCallback(
244
+ path, options, cb, startTime
245
+ ))
246
+ }
247
+
248
+ return go$readdir(path, options, cb)
249
+
250
+ function fs$readdirCallback (path, options, cb, startTime) {
251
+ return function (err, files) {
252
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
253
+ enqueue([
254
+ go$readdir,
255
+ [path, options, cb],
256
+ err,
257
+ startTime || Date.now(),
258
+ Date.now()
259
+ ])
260
+ else {
261
+ if (files && files.sort)
262
+ files.sort()
263
+
264
+ if (typeof cb === 'function')
265
+ cb.call(this, err, files)
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ if (process.version.substr(0, 4) === 'v0.8') {
272
+ var legStreams = legacy(fs)
273
+ ReadStream = legStreams.ReadStream
274
+ WriteStream = legStreams.WriteStream
275
+ }
276
+
277
+ var fs$ReadStream = fs.ReadStream
278
+ if (fs$ReadStream) {
279
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype)
280
+ ReadStream.prototype.open = ReadStream$open
281
+ }
282
+
283
+ var fs$WriteStream = fs.WriteStream
284
+ if (fs$WriteStream) {
285
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype)
286
+ WriteStream.prototype.open = WriteStream$open
287
+ }
288
+
289
+ Object.defineProperty(fs, 'ReadStream', {
290
+ get: function () {
291
+ return ReadStream
292
+ },
293
+ set: function (val) {
294
+ ReadStream = val
295
+ },
296
+ enumerable: true,
297
+ configurable: true
298
+ })
299
+ Object.defineProperty(fs, 'WriteStream', {
300
+ get: function () {
301
+ return WriteStream
302
+ },
303
+ set: function (val) {
304
+ WriteStream = val
305
+ },
306
+ enumerable: true,
307
+ configurable: true
308
+ })
309
+
310
+ // legacy names
311
+ var FileReadStream = ReadStream
312
+ Object.defineProperty(fs, 'FileReadStream', {
313
+ get: function () {
314
+ return FileReadStream
315
+ },
316
+ set: function (val) {
317
+ FileReadStream = val
318
+ },
319
+ enumerable: true,
320
+ configurable: true
321
+ })
322
+ var FileWriteStream = WriteStream
323
+ Object.defineProperty(fs, 'FileWriteStream', {
324
+ get: function () {
325
+ return FileWriteStream
326
+ },
327
+ set: function (val) {
328
+ FileWriteStream = val
329
+ },
330
+ enumerable: true,
331
+ configurable: true
332
+ })
333
+
334
+ function ReadStream (path, options) {
335
+ if (this instanceof ReadStream)
336
+ return fs$ReadStream.apply(this, arguments), this
337
+ else
338
+ return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
339
+ }
340
+
341
+ function ReadStream$open () {
342
+ var that = this
343
+ open(that.path, that.flags, that.mode, function (err, fd) {
344
+ if (err) {
345
+ if (that.autoClose)
346
+ that.destroy()
347
+
348
+ that.emit('error', err)
349
+ } else {
350
+ that.fd = fd
351
+ that.emit('open', fd)
352
+ that.read()
353
+ }
354
+ })
355
+ }
356
+
357
+ function WriteStream (path, options) {
358
+ if (this instanceof WriteStream)
359
+ return fs$WriteStream.apply(this, arguments), this
360
+ else
361
+ return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
362
+ }
363
+
364
+ function WriteStream$open () {
365
+ var that = this
366
+ open(that.path, that.flags, that.mode, function (err, fd) {
367
+ if (err) {
368
+ that.destroy()
369
+ that.emit('error', err)
370
+ } else {
371
+ that.fd = fd
372
+ that.emit('open', fd)
373
+ }
374
+ })
375
+ }
376
+
377
+ function createReadStream (path, options) {
378
+ return new fs.ReadStream(path, options)
379
+ }
380
+
381
+ function createWriteStream (path, options) {
382
+ return new fs.WriteStream(path, options)
383
+ }
384
+
385
+ var fs$open = fs.open
386
+ fs.open = open
387
+ function open (path, flags, mode, cb) {
388
+ if (typeof mode === 'function')
389
+ cb = mode, mode = null
390
+
391
+ return go$open(path, flags, mode, cb)
392
+
393
+ function go$open (path, flags, mode, cb, startTime) {
394
+ return fs$open(path, flags, mode, function (err, fd) {
395
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
396
+ enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()])
397
+ else {
398
+ if (typeof cb === 'function')
399
+ cb.apply(this, arguments)
400
+ }
401
+ })
402
+ }
403
+ }
404
+
405
+ return fs
406
+ }
407
+
408
+ function enqueue (elem) {
409
+ debug('ENQUEUE', elem[0].name, elem[1])
410
+ fs[gracefulQueue].push(elem)
411
+ retry()
412
+ }
413
+
414
+ // keep track of the timeout between retry() calls
415
+ var retryTimer
416
+
417
+ // reset the startTime and lastTime to now
418
+ // this resets the start of the 60 second overall timeout as well as the
419
+ // delay between attempts so that we'll retry these jobs sooner
420
+ function resetQueue () {
421
+ var now = Date.now()
422
+ for (var i = 0; i < fs[gracefulQueue].length; ++i) {
423
+ // entries that are only a length of 2 are from an older version, don't
424
+ // bother modifying those since they'll be retried anyway.
425
+ if (fs[gracefulQueue][i].length > 2) {
426
+ fs[gracefulQueue][i][3] = now // startTime
427
+ fs[gracefulQueue][i][4] = now // lastTime
428
+ }
429
+ }
430
+ // call retry to make sure we're actively processing the queue
431
+ retry()
432
+ }
433
+
434
+ function retry () {
435
+ // clear the timer and remove it to help prevent unintended concurrency
436
+ clearTimeout(retryTimer)
437
+ retryTimer = undefined
438
+
439
+ if (fs[gracefulQueue].length === 0)
440
+ return
441
+
442
+ var elem = fs[gracefulQueue].shift()
443
+ var fn = elem[0]
444
+ var args = elem[1]
445
+ // these items may be unset if they were added by an older graceful-fs
446
+ var err = elem[2]
447
+ var startTime = elem[3]
448
+ var lastTime = elem[4]
449
+
450
+ // if we don't have a startTime we have no way of knowing if we've waited
451
+ // long enough, so go ahead and retry this item now
452
+ if (startTime === undefined) {
453
+ debug('RETRY', fn.name, args)
454
+ fn.apply(null, args)
455
+ } else if (Date.now() - startTime >= 60000) {
456
+ // it's been more than 60 seconds total, bail now
457
+ debug('TIMEOUT', fn.name, args)
458
+ var cb = args.pop()
459
+ if (typeof cb === 'function')
460
+ cb.call(null, err)
461
+ } else {
462
+ // the amount of time between the last attempt and right now
463
+ var sinceAttempt = Date.now() - lastTime
464
+ // the amount of time between when we first tried, and when we last tried
465
+ // rounded up to at least 1
466
+ var sinceStart = Math.max(lastTime - startTime, 1)
467
+ // backoff. wait longer than the total time we've been retrying, but only
468
+ // up to a maximum of 100ms
469
+ var desiredDelay = Math.min(sinceStart * 1.2, 100)
470
+ // it's been long enough since the last retry, do it again
471
+ if (sinceAttempt >= desiredDelay) {
472
+ debug('RETRY', fn.name, args)
473
+ fn.apply(null, args.concat([startTime]))
474
+ } else {
475
+ // if we can't do this job yet, push it to the end of the queue
476
+ // and let the next iteration check again
477
+ fs[gracefulQueue].push(elem)
478
+ }
479
+ }
480
+
481
+ // schedule our next run if one isn't already scheduled
482
+ if (retryTimer === undefined) {
483
+ retryTimer = setTimeout(retry, 0)
484
+ }
485
+ }
486
+
487
+
488
+ /***/ }),
489
+
490
+ /***/ 50:
491
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
492
+
493
+ var Stream = (__nccwpck_require__(203).Stream)
494
+
495
+ module.exports = legacy
496
+
497
+ function legacy (fs) {
498
+ return {
499
+ ReadStream: ReadStream,
500
+ WriteStream: WriteStream
501
+ }
502
+
503
+ function ReadStream (path, options) {
504
+ if (!(this instanceof ReadStream)) return new ReadStream(path, options);
505
+
506
+ Stream.call(this);
507
+
508
+ var self = this;
509
+
510
+ this.path = path;
511
+ this.fd = null;
512
+ this.readable = true;
513
+ this.paused = false;
514
+
515
+ this.flags = 'r';
516
+ this.mode = 438; /*=0666*/
517
+ this.bufferSize = 64 * 1024;
518
+
519
+ options = options || {};
520
+
521
+ // Mixin options into this
522
+ var keys = Object.keys(options);
523
+ for (var index = 0, length = keys.length; index < length; index++) {
524
+ var key = keys[index];
525
+ this[key] = options[key];
526
+ }
527
+
528
+ if (this.encoding) this.setEncoding(this.encoding);
529
+
530
+ if (this.start !== undefined) {
531
+ if ('number' !== typeof this.start) {
532
+ throw TypeError('start must be a Number');
533
+ }
534
+ if (this.end === undefined) {
535
+ this.end = Infinity;
536
+ } else if ('number' !== typeof this.end) {
537
+ throw TypeError('end must be a Number');
538
+ }
539
+
540
+ if (this.start > this.end) {
541
+ throw new Error('start must be <= end');
542
+ }
543
+
544
+ this.pos = this.start;
545
+ }
546
+
547
+ if (this.fd !== null) {
548
+ process.nextTick(function() {
549
+ self._read();
550
+ });
551
+ return;
552
+ }
553
+
554
+ fs.open(this.path, this.flags, this.mode, function (err, fd) {
555
+ if (err) {
556
+ self.emit('error', err);
557
+ self.readable = false;
558
+ return;
559
+ }
560
+
561
+ self.fd = fd;
562
+ self.emit('open', fd);
563
+ self._read();
564
+ })
565
+ }
566
+
567
+ function WriteStream (path, options) {
568
+ if (!(this instanceof WriteStream)) return new WriteStream(path, options);
569
+
570
+ Stream.call(this);
571
+
572
+ this.path = path;
573
+ this.fd = null;
574
+ this.writable = true;
575
+
576
+ this.flags = 'w';
577
+ this.encoding = 'binary';
578
+ this.mode = 438; /*=0666*/
579
+ this.bytesWritten = 0;
580
+
581
+ options = options || {};
582
+
583
+ // Mixin options into this
584
+ var keys = Object.keys(options);
585
+ for (var index = 0, length = keys.length; index < length; index++) {
586
+ var key = keys[index];
587
+ this[key] = options[key];
588
+ }
589
+
590
+ if (this.start !== undefined) {
591
+ if ('number' !== typeof this.start) {
592
+ throw TypeError('start must be a Number');
593
+ }
594
+ if (this.start < 0) {
595
+ throw new Error('start must be >= zero');
596
+ }
597
+
598
+ this.pos = this.start;
599
+ }
600
+
601
+ this.busy = false;
602
+ this._queue = [];
603
+
604
+ if (this.fd === null) {
605
+ this._open = fs.open;
606
+ this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
607
+ this.flush();
608
+ }
609
+ }
610
+ }
611
+
612
+
613
+ /***/ }),
614
+
615
+ /***/ 161:
616
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
617
+
618
+ var constants = __nccwpck_require__(140)
619
+
620
+ var origCwd = process.cwd
621
+ var cwd = null
622
+
623
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform
624
+
625
+ process.cwd = function() {
626
+ if (!cwd)
627
+ cwd = origCwd.call(process)
628
+ return cwd
629
+ }
630
+ try {
631
+ process.cwd()
632
+ } catch (er) {}
633
+
634
+ // This check is needed until node.js 12 is required
635
+ if (typeof process.chdir === 'function') {
636
+ var chdir = process.chdir
637
+ process.chdir = function (d) {
638
+ cwd = null
639
+ chdir.call(process, d)
640
+ }
641
+ if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir)
642
+ }
643
+
644
+ module.exports = patch
645
+
646
+ function patch (fs) {
647
+ // (re-)implement some things that are known busted or missing.
648
+
649
+ // lchmod, broken prior to 0.6.2
650
+ // back-port the fix here.
651
+ if (constants.hasOwnProperty('O_SYMLINK') &&
652
+ process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
653
+ patchLchmod(fs)
654
+ }
655
+
656
+ // lutimes implementation, or no-op
657
+ if (!fs.lutimes) {
658
+ patchLutimes(fs)
659
+ }
660
+
661
+ // https://github.com/isaacs/node-graceful-fs/issues/4
662
+ // Chown should not fail on einval or eperm if non-root.
663
+ // It should not fail on enosys ever, as this just indicates
664
+ // that a fs doesn't support the intended operation.
665
+
666
+ fs.chown = chownFix(fs.chown)
667
+ fs.fchown = chownFix(fs.fchown)
668
+ fs.lchown = chownFix(fs.lchown)
669
+
670
+ fs.chmod = chmodFix(fs.chmod)
671
+ fs.fchmod = chmodFix(fs.fchmod)
672
+ fs.lchmod = chmodFix(fs.lchmod)
673
+
674
+ fs.chownSync = chownFixSync(fs.chownSync)
675
+ fs.fchownSync = chownFixSync(fs.fchownSync)
676
+ fs.lchownSync = chownFixSync(fs.lchownSync)
677
+
678
+ fs.chmodSync = chmodFixSync(fs.chmodSync)
679
+ fs.fchmodSync = chmodFixSync(fs.fchmodSync)
680
+ fs.lchmodSync = chmodFixSync(fs.lchmodSync)
681
+
682
+ fs.stat = statFix(fs.stat)
683
+ fs.fstat = statFix(fs.fstat)
684
+ fs.lstat = statFix(fs.lstat)
685
+
686
+ fs.statSync = statFixSync(fs.statSync)
687
+ fs.fstatSync = statFixSync(fs.fstatSync)
688
+ fs.lstatSync = statFixSync(fs.lstatSync)
689
+
690
+ // if lchmod/lchown do not exist, then make them no-ops
691
+ if (fs.chmod && !fs.lchmod) {
692
+ fs.lchmod = function (path, mode, cb) {
693
+ if (cb) process.nextTick(cb)
694
+ }
695
+ fs.lchmodSync = function () {}
696
+ }
697
+ if (fs.chown && !fs.lchown) {
698
+ fs.lchown = function (path, uid, gid, cb) {
699
+ if (cb) process.nextTick(cb)
700
+ }
701
+ fs.lchownSync = function () {}
702
+ }
703
+
704
+ // on Windows, A/V software can lock the directory, causing this
705
+ // to fail with an EACCES or EPERM if the directory contains newly
706
+ // created files. Try again on failure, for up to 60 seconds.
707
+
708
+ // Set the timeout this long because some Windows Anti-Virus, such as Parity
709
+ // bit9, may lock files for up to a minute, causing npm package install
710
+ // failures. Also, take care to yield the scheduler. Windows scheduling gives
711
+ // CPU to a busy looping process, which can cause the program causing the lock
712
+ // contention to be starved of CPU by node, so the contention doesn't resolve.
713
+ if (platform === "win32") {
714
+ fs.rename = typeof fs.rename !== 'function' ? fs.rename
715
+ : (function (fs$rename) {
716
+ function rename (from, to, cb) {
717
+ var start = Date.now()
718
+ var backoff = 0;
719
+ fs$rename(from, to, function CB (er) {
720
+ if (er
721
+ && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY")
722
+ && Date.now() - start < 60000) {
723
+ setTimeout(function() {
724
+ fs.stat(to, function (stater, st) {
725
+ if (stater && stater.code === "ENOENT")
726
+ fs$rename(from, to, CB);
727
+ else
728
+ cb(er)
729
+ })
730
+ }, backoff)
731
+ if (backoff < 100)
732
+ backoff += 10;
733
+ return;
734
+ }
735
+ if (cb) cb(er)
736
+ })
737
+ }
738
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename)
739
+ return rename
740
+ })(fs.rename)
741
+ }
742
+
743
+ // if read() returns EAGAIN, then just try it again.
744
+ fs.read = typeof fs.read !== 'function' ? fs.read
745
+ : (function (fs$read) {
746
+ function read (fd, buffer, offset, length, position, callback_) {
747
+ var callback
748
+ if (callback_ && typeof callback_ === 'function') {
749
+ var eagCounter = 0
750
+ callback = function (er, _, __) {
751
+ if (er && er.code === 'EAGAIN' && eagCounter < 10) {
752
+ eagCounter ++
753
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback)
754
+ }
755
+ callback_.apply(this, arguments)
756
+ }
757
+ }
758
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback)
759
+ }
760
+
761
+ // This ensures `util.promisify` works as it does for native `fs.read`.
762
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read)
763
+ return read
764
+ })(fs.read)
765
+
766
+ fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync
767
+ : (function (fs$readSync) { return function (fd, buffer, offset, length, position) {
768
+ var eagCounter = 0
769
+ while (true) {
770
+ try {
771
+ return fs$readSync.call(fs, fd, buffer, offset, length, position)
772
+ } catch (er) {
773
+ if (er.code === 'EAGAIN' && eagCounter < 10) {
774
+ eagCounter ++
775
+ continue
776
+ }
777
+ throw er
778
+ }
779
+ }
780
+ }})(fs.readSync)
781
+
782
+ function patchLchmod (fs) {
783
+ fs.lchmod = function (path, mode, callback) {
784
+ fs.open( path
785
+ , constants.O_WRONLY | constants.O_SYMLINK
786
+ , mode
787
+ , function (err, fd) {
788
+ if (err) {
789
+ if (callback) callback(err)
790
+ return
791
+ }
792
+ // prefer to return the chmod error, if one occurs,
793
+ // but still try to close, and report closing errors if they occur.
794
+ fs.fchmod(fd, mode, function (err) {
795
+ fs.close(fd, function(err2) {
796
+ if (callback) callback(err || err2)
797
+ })
798
+ })
799
+ })
800
+ }
801
+
802
+ fs.lchmodSync = function (path, mode) {
803
+ var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode)
804
+
805
+ // prefer to return the chmod error, if one occurs,
806
+ // but still try to close, and report closing errors if they occur.
807
+ var threw = true
808
+ var ret
809
+ try {
810
+ ret = fs.fchmodSync(fd, mode)
811
+ threw = false
812
+ } finally {
813
+ if (threw) {
814
+ try {
815
+ fs.closeSync(fd)
816
+ } catch (er) {}
817
+ } else {
818
+ fs.closeSync(fd)
819
+ }
820
+ }
821
+ return ret
822
+ }
823
+ }
824
+
825
+ function patchLutimes (fs) {
826
+ if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
827
+ fs.lutimes = function (path, at, mt, cb) {
828
+ fs.open(path, constants.O_SYMLINK, function (er, fd) {
829
+ if (er) {
830
+ if (cb) cb(er)
831
+ return
832
+ }
833
+ fs.futimes(fd, at, mt, function (er) {
834
+ fs.close(fd, function (er2) {
835
+ if (cb) cb(er || er2)
836
+ })
837
+ })
838
+ })
839
+ }
840
+
841
+ fs.lutimesSync = function (path, at, mt) {
842
+ var fd = fs.openSync(path, constants.O_SYMLINK)
843
+ var ret
844
+ var threw = true
845
+ try {
846
+ ret = fs.futimesSync(fd, at, mt)
847
+ threw = false
848
+ } finally {
849
+ if (threw) {
850
+ try {
851
+ fs.closeSync(fd)
852
+ } catch (er) {}
853
+ } else {
854
+ fs.closeSync(fd)
855
+ }
856
+ }
857
+ return ret
858
+ }
859
+
860
+ } else if (fs.futimes) {
861
+ fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb) }
862
+ fs.lutimesSync = function () {}
863
+ }
864
+ }
865
+
866
+ function chmodFix (orig) {
867
+ if (!orig) return orig
868
+ return function (target, mode, cb) {
869
+ return orig.call(fs, target, mode, function (er) {
870
+ if (chownErOk(er)) er = null
871
+ if (cb) cb.apply(this, arguments)
872
+ })
873
+ }
874
+ }
875
+
876
+ function chmodFixSync (orig) {
877
+ if (!orig) return orig
878
+ return function (target, mode) {
879
+ try {
880
+ return orig.call(fs, target, mode)
881
+ } catch (er) {
882
+ if (!chownErOk(er)) throw er
883
+ }
884
+ }
885
+ }
886
+
887
+
888
+ function chownFix (orig) {
889
+ if (!orig) return orig
890
+ return function (target, uid, gid, cb) {
891
+ return orig.call(fs, target, uid, gid, function (er) {
892
+ if (chownErOk(er)) er = null
893
+ if (cb) cb.apply(this, arguments)
894
+ })
895
+ }
896
+ }
897
+
898
+ function chownFixSync (orig) {
899
+ if (!orig) return orig
900
+ return function (target, uid, gid) {
901
+ try {
902
+ return orig.call(fs, target, uid, gid)
903
+ } catch (er) {
904
+ if (!chownErOk(er)) throw er
905
+ }
906
+ }
907
+ }
908
+
909
+ function statFix (orig) {
910
+ if (!orig) return orig
911
+ // Older versions of Node erroneously returned signed integers for
912
+ // uid + gid.
913
+ return function (target, options, cb) {
914
+ if (typeof options === 'function') {
915
+ cb = options
916
+ options = null
917
+ }
918
+ function callback (er, stats) {
919
+ if (stats) {
920
+ if (stats.uid < 0) stats.uid += 0x100000000
921
+ if (stats.gid < 0) stats.gid += 0x100000000
922
+ }
923
+ if (cb) cb.apply(this, arguments)
924
+ }
925
+ return options ? orig.call(fs, target, options, callback)
926
+ : orig.call(fs, target, callback)
927
+ }
928
+ }
929
+
930
+ function statFixSync (orig) {
931
+ if (!orig) return orig
932
+ // Older versions of Node erroneously returned signed integers for
933
+ // uid + gid.
934
+ return function (target, options) {
935
+ var stats = options ? orig.call(fs, target, options)
936
+ : orig.call(fs, target)
937
+ if (stats) {
938
+ if (stats.uid < 0) stats.uid += 0x100000000
939
+ if (stats.gid < 0) stats.gid += 0x100000000
940
+ }
941
+ return stats;
942
+ }
943
+ }
944
+
945
+ // ENOSYS means that the fs doesn't support the op. Just ignore
946
+ // that, because it doesn't matter.
947
+ //
948
+ // if there's no getuid, or if getuid() is something other
949
+ // than 0, and the error is EINVAL or EPERM, then just ignore
950
+ // it.
951
+ //
952
+ // This specific case is a silent failure in cp, install, tar,
953
+ // and most other unix tools that manage permissions.
954
+ //
955
+ // When running as root, or if other types of errors are
956
+ // encountered, then it's strict.
957
+ function chownErOk (er) {
958
+ if (!er)
959
+ return true
960
+
961
+ if (er.code === "ENOSYS")
962
+ return true
963
+
964
+ var nonroot = !process.getuid || process.getuid() !== 0
965
+ if (nonroot) {
966
+ if (er.code === "EINVAL" || er.code === "EPERM")
967
+ return true
968
+ }
969
+
970
+ return false
971
+ }
972
+ }
973
+
974
+
975
+ /***/ }),
976
+
977
+ /***/ 409:
978
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
979
+
980
+ "use strict";
981
+ /*
982
+ MIT License http://www.opensource.org/licenses/mit-license.php
983
+ Author Tobias Koppers @sokra
984
+ */
985
+
986
+
987
+ const { EventEmitter } = __nccwpck_require__(434);
988
+ const path = __nccwpck_require__(928);
989
+ const fs = __nccwpck_require__(692);
990
+
991
+ const watchEventSource = __nccwpck_require__(92);
992
+
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 */
1002
+
1003
+ /** @type {ExistenceOnlyTimeEntry} */
1004
+ const EXISTANCE_ONLY_TIME_ENTRY = Object.freeze({});
1005
+
1006
+ let FS_ACCURACY = 2000;
1007
+
1008
+ const IS_OSX = (__nccwpck_require__(857).platform)() === "darwin";
1009
+ const IS_WIN = (__nccwpck_require__(857).platform)() === "win32";
1010
+
1011
+ const { WATCHPACK_POLLING, WATCHPACK_RETRIES } = process.env;
1012
+ const FORCE_POLLING =
1013
+ // @ts-expect-error avoid additional checks
1014
+ `${+WATCHPACK_POLLING}` === WATCHPACK_POLLING
1015
+ ? +WATCHPACK_POLLING
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;
1032
+
1033
+ /**
1034
+ * @param {string} str string
1035
+ * @returns {string} lower cased string
1036
+ */
1037
+ function withoutCase(str) {
1038
+ return str.toLowerCase();
1039
+ }
1040
+
1041
+ /**
1042
+ * @param {number} times times
1043
+ * @param {() => void} callback callback
1044
+ * @returns {() => void} result
1045
+ */
1046
+ function needCalls(times, callback) {
1047
+ return function needCallsCallback() {
1048
+ if (--times === 0) {
1049
+ return callback();
1050
+ }
1051
+ };
1052
+ }
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
+ */
1127
+ class Watcher extends EventEmitter {
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) {
1134
+ super();
1135
+ this.directoryWatcher = directoryWatcher;
1136
+ this.path = target;
1137
+ this.startTime = startTime && +startTime;
1138
+ }
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
+ */
1145
+ checkStartTime(mtime, initial) {
1146
+ const { startTime } = this;
1147
+ if (typeof startTime !== "number") return !initial;
1148
+ return startTime <= mtime;
1149
+ }
1150
+
1151
+ close() {
1152
+ // @ts-expect-error bad typing in EventEmitter
1153
+ this.emit("closed");
1154
+ }
1155
+ }
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
+ */
1175
+ class DirectoryWatcher extends EventEmitter {
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 = {}) {
1182
+ super();
1183
+ if (FORCE_POLLING) {
1184
+ options.poll = FORCE_POLLING;
1185
+ }
1186
+ this.watcherManager = watcherManager;
1187
+ this.options = options;
1188
+ this.path = directoryPath;
1189
+ // safeTime is the point in time after which reading is safe to be unchanged
1190
+ // timestamp is a value that should be compared with another timestamp (mtime)
1191
+ /** @type {Map<string, Entry>} */
1192
+ this.files = new Map();
1193
+ /** @type {Map<string, number>} */
1194
+ this.filesWithoutCase = new Map();
1195
+ /** @type {Map<string, Watcher<DirectoryWatcherEvents> | boolean>} */
1196
+ this.directories = new Map();
1197
+ /** @type {Map<string, Watcher<FileWatcherEvents>>} */
1198
+ this._symlinkTargetWatchers = new Map();
1199
+ this.lastWatchEvent = 0;
1200
+ this.initialScan = true;
1201
+ this.ignored = options.ignored || (() => false);
1202
+ this.nestedWatching = false;
1203
+ /** @type {number | false} */
1204
+ this.polledWatching =
1205
+ typeof options.poll === "number"
1206
+ ? options.poll
1207
+ : options.poll
1208
+ ? 5007
1209
+ : false;
1210
+ /** @type {undefined | NodeJS.Timeout} */
1211
+ this.timeout = undefined;
1212
+ /** @type {null | InitialScanRemoved} */
1213
+ this.initialScanRemoved = new Set();
1214
+ /** @type {undefined | number} */
1215
+ this.initialScanFinished = undefined;
1216
+ /** @type {Map<string, Set<Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>>>} */
1217
+ this.watchers = new Map();
1218
+ /** @type {Watcher<FileWatcherEvents> | null} */
1219
+ this.parentWatcher = null;
1220
+ this.refs = 0;
1221
+ /** @type {Map<string, boolean>} */
1222
+ this._activeEvents = new Map();
1223
+ this.closed = false;
1224
+ this.scanning = false;
1225
+ this.scanAgain = false;
1226
+ this.scanAgainInitial = false;
1227
+
1228
+ this.createWatcher();
1229
+ this.doScan(true);
1230
+ }
1231
+
1232
+ createWatcher() {
1233
+ try {
1234
+ if (this.polledWatching) {
1235
+ /** @type {EventSourceWatcher} */
1236
+ (this.watcher) = /** @type {EventSourceWatcher} */ ({
1237
+ close: () => {
1238
+ if (this.timeout) {
1239
+ clearTimeout(this.timeout);
1240
+ this.timeout = undefined;
1241
+ }
1242
+ },
1243
+ });
1244
+ } else {
1245
+ if (IS_OSX) {
1246
+ this.watchInParentDirectory();
1247
+ }
1248
+ this.watcher =
1249
+ /** @type {EventSourceWatcher} */
1250
+ (watchEventSource.watch(this.path));
1251
+ this.watcher.on("change", this.onWatchEvent.bind(this));
1252
+ this.watcher.on("error", this.onWatcherError.bind(this));
1253
+ }
1254
+ } catch (err) {
1255
+ this.onWatcherError(err);
1256
+ }
1257
+ }
1258
+
1259
+ /**
1260
+ * @template {(watcher: Watcher<EventMap>) => void} T
1261
+ * @param {string} path path
1262
+ * @param {T} fn function
1263
+ */
1264
+ forEachWatcher(path, fn) {
1265
+ const watchers = this.watchers.get(withoutCase(path));
1266
+ if (watchers !== undefined) {
1267
+ for (const w of watchers) {
1268
+ fn(w);
1269
+ }
1270
+ }
1271
+ }
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
+ */
1278
+ setMissing(itemPath, initial, type) {
1279
+ if (this.initialScan) {
1280
+ /** @type {InitialScanRemoved} */
1281
+ (this.initialScanRemoved).add(itemPath);
1282
+ }
1283
+
1284
+ const oldDirectory = this.directories.get(itemPath);
1285
+ if (oldDirectory) {
1286
+ if (this.nestedWatching) {
1287
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1288
+ (oldDirectory).close();
1289
+ }
1290
+ this.directories.delete(itemPath);
1291
+ this.forEachWatcher(itemPath, (w) => w.emit("remove", type));
1292
+ if (!initial) {
1293
+ this.forEachWatcher(this.path, (w) =>
1294
+ w.emit("change", itemPath, null, type, initial),
1295
+ );
1296
+ }
1297
+ }
1298
+
1299
+ const oldFile = this.files.get(itemPath);
1300
+ if (oldFile) {
1301
+ this.files.delete(itemPath);
1302
+ const key = withoutCase(itemPath);
1303
+ const count = /** @type {number} */ (this.filesWithoutCase.get(key)) - 1;
1304
+ if (count <= 0) {
1305
+ this.filesWithoutCase.delete(key);
1306
+ this.forEachWatcher(itemPath, (w) => w.emit("remove", type));
1307
+ } else {
1308
+ this.filesWithoutCase.set(key, count);
1309
+ }
1310
+
1311
+ if (!initial) {
1312
+ this.forEachWatcher(this.path, (w) =>
1313
+ w.emit("change", itemPath, null, type, initial),
1314
+ );
1315
+ }
1316
+ }
1317
+ }
1318
+
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) {
1327
+ const now = Date.now();
1328
+
1329
+ if (this.ignored(target)) return;
1330
+
1331
+ const old = this.files.get(target);
1332
+
1333
+ let safeTime;
1334
+ let accuracy;
1335
+ if (initial) {
1336
+ safeTime = Math.min(now, mtime) + FS_ACCURACY;
1337
+ accuracy = FS_ACCURACY;
1338
+ } else {
1339
+ safeTime = now;
1340
+ accuracy = 0;
1341
+
1342
+ if (old && old.timestamp === mtime && mtime + FS_ACCURACY < now) {
1343
+ // We are sure that mtime is untouched
1344
+ // This can be caused by some file attribute change
1345
+ // e. g. when access time has been changed
1346
+ // but the file content is untouched
1347
+ return;
1348
+ }
1349
+ }
1350
+
1351
+ if (ignoreWhenEqual && old && old.timestamp === mtime) return;
1352
+
1353
+ this.files.set(target, {
1354
+ safeTime,
1355
+ accuracy,
1356
+ timestamp: mtime,
1357
+ });
1358
+
1359
+ if (!old) {
1360
+ const key = withoutCase(target);
1361
+ const count = this.filesWithoutCase.get(key);
1362
+ this.filesWithoutCase.set(key, (count || 0) + 1);
1363
+ if (count !== undefined) {
1364
+ // There is already a file with case-insensitive-equal name
1365
+ // On a case-insensitive filesystem we may miss the renaming
1366
+ // when only casing is changed.
1367
+ // To be sure that our information is correct
1368
+ // we trigger a rescan here
1369
+ this.doScan(false);
1370
+ }
1371
+
1372
+ this.forEachWatcher(target, (w) => {
1373
+ if (!initial || w.checkStartTime(safeTime, initial)) {
1374
+ w.emit("change", mtime, type);
1375
+ }
1376
+ });
1377
+ } else if (!initial) {
1378
+ this.forEachWatcher(target, (w) => w.emit("change", mtime, type));
1379
+ }
1380
+ this.forEachWatcher(this.path, (w) => {
1381
+ if (!initial || w.checkStartTime(safeTime, initial)) {
1382
+ w.emit("change", target, safeTime, type, initial);
1383
+ }
1384
+ });
1385
+ }
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
+ */
1393
+ setDirectory(directoryPath, birthtime, initial, type) {
1394
+ if (this.ignored(directoryPath)) return;
1395
+ if (directoryPath === this.path) {
1396
+ if (!initial) {
1397
+ this.forEachWatcher(this.path, (w) =>
1398
+ w.emit("change", directoryPath, birthtime, type, initial),
1399
+ );
1400
+ }
1401
+ } else {
1402
+ const old = this.directories.get(directoryPath);
1403
+ if (!old) {
1404
+ const now = Date.now();
1405
+
1406
+ if (this.nestedWatching) {
1407
+ this.createNestedWatcher(directoryPath);
1408
+ } else {
1409
+ this.directories.set(directoryPath, true);
1410
+ }
1411
+
1412
+ const safeTime = initial ? Math.min(now, birthtime) + FS_ACCURACY : now;
1413
+
1414
+ this.forEachWatcher(directoryPath, (w) => {
1415
+ if (!initial || w.checkStartTime(safeTime, false)) {
1416
+ w.emit("change", birthtime, type);
1417
+ }
1418
+ });
1419
+ this.forEachWatcher(this.path, (w) => {
1420
+ if (!initial || w.checkStartTime(safeTime, initial)) {
1421
+ w.emit("change", directoryPath, safeTime, type, initial);
1422
+ }
1423
+ });
1424
+ }
1425
+ }
1426
+ }
1427
+
1428
+ /**
1429
+ * @param {string} directoryPath directory path
1430
+ */
1431
+ createNestedWatcher(directoryPath) {
1432
+ const watcher = this.watcherManager.watchDirectory(directoryPath, 1);
1433
+ watcher.on("change", (target, mtime, type, initial) => {
1434
+ this.forEachWatcher(this.path, (w) => {
1435
+ if (!initial || w.checkStartTime(mtime, initial)) {
1436
+ w.emit("change", target, mtime, type, initial);
1437
+ }
1438
+ });
1439
+ });
1440
+ this.directories.set(directoryPath, watcher);
1441
+ }
1442
+
1443
+ /**
1444
+ * @param {boolean} flag true when nested, otherwise false
1445
+ */
1446
+ setNestedWatching(flag) {
1447
+ if (this.nestedWatching !== Boolean(flag)) {
1448
+ this.nestedWatching = Boolean(flag);
1449
+ if (this.nestedWatching) {
1450
+ for (const directory of this.directories.keys()) {
1451
+ this.createNestedWatcher(directory);
1452
+ }
1453
+ } else {
1454
+ for (const [directory, watcher] of this.directories) {
1455
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1456
+ (watcher).close();
1457
+ this.directories.set(directory, true);
1458
+ }
1459
+ for (const w of this._symlinkTargetWatchers.values()) {
1460
+ w.close();
1461
+ }
1462
+ this._symlinkTargetWatchers.clear();
1463
+ }
1464
+ }
1465
+ }
1466
+
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);
1474
+ let watchers = this.watchers.get(key);
1475
+ if (watchers === undefined) {
1476
+ watchers = new Set();
1477
+ this.watchers.set(key, watchers);
1478
+ }
1479
+ this.refs++;
1480
+ const watcher =
1481
+ /** @type {Watcher<DirectoryWatcherEvents> | Watcher<FileWatcherEvents>} */
1482
+ (new Watcher(this, target, startTime));
1483
+ watcher.on("closed", () => {
1484
+ if (--this.refs <= 0) {
1485
+ this.close();
1486
+ return;
1487
+ }
1488
+ watchers.delete(watcher);
1489
+ if (watchers.size === 0) {
1490
+ this.watchers.delete(key);
1491
+ if (this.path === target) this.setNestedWatching(false);
1492
+ }
1493
+ });
1494
+ watchers.add(watcher);
1495
+ let safeTime;
1496
+ if (target === this.path) {
1497
+ this.setNestedWatching(true);
1498
+ safeTime = this.lastWatchEvent;
1499
+ for (const entry of this.files.values()) {
1500
+ fixupEntryAccuracy(entry);
1501
+ safeTime = Math.max(safeTime, entry.safeTime);
1502
+ }
1503
+ } else {
1504
+ const entry = this.files.get(target);
1505
+ if (entry) {
1506
+ fixupEntryAccuracy(entry);
1507
+ safeTime = entry.safeTime;
1508
+ } else {
1509
+ safeTime = 0;
1510
+ }
1511
+ }
1512
+ if (safeTime) {
1513
+ if (startTime && safeTime >= startTime) {
1514
+ process.nextTick(() => {
1515
+ if (this.closed) return;
1516
+ if (target === this.path) {
1517
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1518
+ (watcher).emit(
1519
+ "change",
1520
+ target,
1521
+ safeTime,
1522
+ "watch (outdated on attach)",
1523
+ true,
1524
+ );
1525
+ } else {
1526
+ /** @type {Watcher<FileWatcherEvents>} */
1527
+ (watcher).emit(
1528
+ "change",
1529
+ safeTime,
1530
+ "watch (outdated on attach)",
1531
+ true,
1532
+ );
1533
+ }
1534
+ });
1535
+ }
1536
+ } else if (this.initialScan) {
1537
+ if (
1538
+ /** @type {InitialScanRemoved} */
1539
+ (this.initialScanRemoved).has(target)
1540
+ ) {
1541
+ process.nextTick(() => {
1542
+ if (this.closed) return;
1543
+ watcher.emit("remove");
1544
+ });
1545
+ }
1546
+ } else if (
1547
+ target !== this.path &&
1548
+ !this.directories.has(target) &&
1549
+ watcher.checkStartTime(
1550
+ /** @type {number} */
1551
+ (this.initialScanFinished),
1552
+ false,
1553
+ )
1554
+ ) {
1555
+ process.nextTick(() => {
1556
+ if (this.closed) return;
1557
+ watcher.emit("initial-missing", "watch (missing on attach)");
1558
+ });
1559
+ }
1560
+ return watcher;
1561
+ }
1562
+
1563
+ /**
1564
+ * @param {EventType} eventType event type
1565
+ * @param {string=} filename filename
1566
+ */
1567
+ onWatchEvent(eventType, filename) {
1568
+ if (this.closed) return;
1569
+ if (!filename) {
1570
+ // In some cases no filename is provided
1571
+ // This seem to happen on windows
1572
+ // So some event happened but we don't know which file is affected
1573
+ // We have to do a full scan of the directory
1574
+ this.doScan(false);
1575
+ return;
1576
+ }
1577
+
1578
+ const target = path.join(this.path, filename);
1579
+ if (this.ignored(target)) return;
1580
+
1581
+ if (this._activeEvents.get(filename) === undefined) {
1582
+ this._activeEvents.set(filename, false);
1583
+ const checkStats = () => {
1584
+ if (this.closed) return;
1585
+ this._activeEvents.set(filename, false);
1586
+ lstatWithRetry(target, this, (err, stats) => {
1587
+ if (this.closed) return;
1588
+ if (this._activeEvents.get(filename) === true) {
1589
+ process.nextTick(checkStats);
1590
+ return;
1591
+ }
1592
+ this._activeEvents.delete(filename);
1593
+ // ENOENT happens when the file/directory doesn't exist
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.
1598
+ if (err) {
1599
+ if (
1600
+ err.code !== "ENOENT" &&
1601
+ err.code !== "EPERM" &&
1602
+ err.code !== "EBUSY"
1603
+ ) {
1604
+ this.onStatsError(err);
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");
1610
+ }
1611
+ }
1612
+ this.lastWatchEvent = Date.now();
1613
+ if (!stats) {
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);
1622
+ } else if (stats.isDirectory()) {
1623
+ this.setDirectory(target, +stats.birthtime || 1, false, eventType);
1624
+ } else if (stats.isFile() || stats.isSymbolicLink()) {
1625
+ if (stats.mtime) {
1626
+ ensureFsAccuracy(+stats.mtime);
1627
+ }
1628
+ this.setFileTime(
1629
+ target,
1630
+ +stats.mtime || +stats.ctime || 1,
1631
+ false,
1632
+ false,
1633
+ eventType,
1634
+ );
1635
+ }
1636
+ });
1637
+ };
1638
+ process.nextTick(checkStats);
1639
+ } else {
1640
+ this._activeEvents.set(filename, true);
1641
+ }
1642
+ }
1643
+
1644
+ /**
1645
+ * @param {unknown=} err error
1646
+ */
1647
+ onWatcherError(err) {
1648
+ if (this.closed) return;
1649
+ if (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}`);
1658
+ }
1659
+ this.onDirectoryRemoved("watch error");
1660
+ }
1661
+ }
1662
+
1663
+ /**
1664
+ * @param {Error | NodeJS.ErrnoException=} err error
1665
+ */
1666
+ onStatsError(err) {
1667
+ if (err) {
1668
+ // eslint-disable-next-line no-console
1669
+ console.error(`Watchpack Error (stats): ${err}`);
1670
+ }
1671
+ }
1672
+
1673
+ /**
1674
+ * @param {Error | NodeJS.ErrnoException=} err error
1675
+ */
1676
+ onScanError(err) {
1677
+ if (err) {
1678
+ // eslint-disable-next-line no-console
1679
+ console.error(`Watchpack Error (initial scan): ${err}`);
1680
+ }
1681
+ this.onScanFinished();
1682
+ }
1683
+
1684
+ onScanFinished() {
1685
+ if (this.polledWatching) {
1686
+ this.timeout = setTimeout(() => {
1687
+ if (this.closed) return;
1688
+ this.doScan(false);
1689
+ }, this.polledWatching);
1690
+ }
1691
+ }
1692
+
1693
+ /**
1694
+ * @param {string} reason a reason
1695
+ */
1696
+ onDirectoryRemoved(reason) {
1697
+ if (this.watcher) {
1698
+ this.watcher.close();
1699
+ this.watcher = null;
1700
+ }
1701
+ this.watchInParentDirectory();
1702
+ const type = /** @type {EventType} */ (`directory-removed (${reason})`);
1703
+ for (const directory of this.directories.keys()) {
1704
+ this.setMissing(directory, false, type);
1705
+ }
1706
+ for (const file of this.files.keys()) {
1707
+ this.setMissing(file, false, type);
1708
+ }
1709
+ }
1710
+
1711
+ watchInParentDirectory() {
1712
+ if (!this.parentWatcher) {
1713
+ const parentDir = path.dirname(this.path);
1714
+ // avoid watching in the root directory
1715
+ // removing directories in the root directory is not supported
1716
+ if (path.dirname(parentDir) === parentDir) return;
1717
+
1718
+ this.parentWatcher = this.watcherManager.watchFile(this.path, 1);
1719
+ /** @type {Watcher<FileWatcherEvents>} */
1720
+ (this.parentWatcher).on("change", (mtime, type) => {
1721
+ if (this.closed) return;
1722
+
1723
+ // On non-osx platforms we don't need this watcher to detect
1724
+ // directory removal, as an EPERM error indicates that
1725
+ if ((!IS_OSX || this.polledWatching) && this.parentWatcher) {
1726
+ this.parentWatcher.close();
1727
+ this.parentWatcher = null;
1728
+ }
1729
+ // Try to create the watcher when parent directory is found
1730
+ if (!this.watcher) {
1731
+ this.createWatcher();
1732
+ this.doScan(false);
1733
+
1734
+ // directory was created so we emit an event
1735
+ this.forEachWatcher(this.path, (w) =>
1736
+ w.emit("change", this.path, mtime, type, false),
1737
+ );
1738
+ }
1739
+ });
1740
+ /** @type {Watcher<FileWatcherEvents>} */
1741
+ (this.parentWatcher).on("remove", () => {
1742
+ this.onDirectoryRemoved("parent directory removed");
1743
+ });
1744
+ }
1745
+ }
1746
+
1747
+ /**
1748
+ * @param {boolean} initial true when initial, otherwise false
1749
+ */
1750
+ doScan(initial) {
1751
+ if (this.scanning) {
1752
+ if (this.scanAgain) {
1753
+ if (!initial) this.scanAgainInitial = false;
1754
+ } else {
1755
+ this.scanAgain = true;
1756
+ this.scanAgainInitial = initial;
1757
+ }
1758
+ return;
1759
+ }
1760
+ this.scanning = true;
1761
+ if (this.timeout) {
1762
+ clearTimeout(this.timeout);
1763
+ this.timeout = undefined;
1764
+ }
1765
+ process.nextTick(() => {
1766
+ if (this.closed) return;
1767
+ fs.readdir(this.path, (err, items) => {
1768
+ if (this.closed) return;
1769
+ if (err) {
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
+ ) {
1784
+ this.onDirectoryRemoved("scan readdir failed");
1785
+ } else {
1786
+ this.onScanError(err);
1787
+ }
1788
+ this.initialScan = false;
1789
+ this.initialScanFinished = Date.now();
1790
+ if (initial) {
1791
+ for (const watchers of this.watchers.values()) {
1792
+ for (const watcher of watchers) {
1793
+ if (watcher.checkStartTime(this.initialScanFinished, false)) {
1794
+ watcher.emit(
1795
+ "initial-missing",
1796
+ "scan (parent directory missing in initial scan)",
1797
+ );
1798
+ }
1799
+ }
1800
+ }
1801
+ }
1802
+ if (this.scanAgain) {
1803
+ this.scanAgain = false;
1804
+ this.doScan(this.scanAgainInitial);
1805
+ } else {
1806
+ this.scanning = false;
1807
+ }
1808
+ return;
1809
+ }
1810
+ const itemPaths = new Set(
1811
+ items.map((item) => path.join(this.path, item.normalize("NFC"))),
1812
+ );
1813
+ for (const file of this.files.keys()) {
1814
+ if (!itemPaths.has(file)) {
1815
+ this.setMissing(file, initial, "scan (missing)");
1816
+ }
1817
+ }
1818
+ for (const directory of this.directories.keys()) {
1819
+ if (!itemPaths.has(directory)) {
1820
+ this.setMissing(directory, initial, "scan (missing)");
1821
+ }
1822
+ }
1823
+ if (this.scanAgain) {
1824
+ // Early repeat of scan
1825
+ this.scanAgain = false;
1826
+ this.doScan(initial);
1827
+ return;
1828
+ }
1829
+ const itemFinished = needCalls(itemPaths.size + 1, () => {
1830
+ if (this.closed) return;
1831
+ this.initialScan = false;
1832
+ this.initialScanRemoved = null;
1833
+ this.initialScanFinished = Date.now();
1834
+ if (initial) {
1835
+ const missingWatchers = new Map(this.watchers);
1836
+ missingWatchers.delete(withoutCase(this.path));
1837
+ for (const item of itemPaths) {
1838
+ missingWatchers.delete(withoutCase(item));
1839
+ }
1840
+ for (const watchers of missingWatchers.values()) {
1841
+ for (const watcher of watchers) {
1842
+ if (watcher.checkStartTime(this.initialScanFinished, false)) {
1843
+ watcher.emit(
1844
+ "initial-missing",
1845
+ "scan (missing in initial scan)",
1846
+ );
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+ if (this.scanAgain) {
1852
+ this.scanAgain = false;
1853
+ this.doScan(this.scanAgainInitial);
1854
+ } else {
1855
+ this.scanning = false;
1856
+ this.onScanFinished();
1857
+ }
1858
+ });
1859
+ for (const itemPath of itemPaths) {
1860
+ lstatWithRetry(itemPath, this, (err2, stats) => {
1861
+ if (this.closed) return;
1862
+ if (err2) {
1863
+ if (
1864
+ err2.code === "ENOENT" ||
1865
+ err2.code === "EPERM" ||
1866
+ err2.code === "EACCES" ||
1867
+ err2.code === "EBUSY" ||
1868
+ err2.code === "ENODEV" ||
1869
+ // TODO https://github.com/libuv/libuv/pull/4566
1870
+ (err2.code === "EINVAL" && IS_WIN)
1871
+ ) {
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
+ }
1884
+ } else {
1885
+ this.onScanError(err2);
1886
+ }
1887
+ itemFinished();
1888
+ return;
1889
+ }
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
+ ) {
1917
+ this.setDirectory(
1918
+ itemPath,
1919
+ +stats.birthtime || 1,
1920
+ initial,
1921
+ "scan (dir)",
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;
1975
+ }
1976
+ apply(null);
1977
+ });
1978
+ }
1979
+ itemFinished();
1980
+ });
1981
+ });
1982
+ }
1983
+
1984
+ /**
1985
+ * @returns {Record<string, number>} times
1986
+ */
1987
+ getTimes() {
1988
+ const obj = Object.create(null);
1989
+ let safeTime = this.lastWatchEvent;
1990
+ for (const [file, entry] of this.files) {
1991
+ fixupEntryAccuracy(entry);
1992
+ safeTime = Math.max(safeTime, entry.safeTime);
1993
+ obj[file] = Math.max(entry.safeTime, entry.timestamp);
1994
+ }
1995
+ if (this.nestedWatching) {
1996
+ for (const w of this.directories.values()) {
1997
+ const times =
1998
+ /** @type {Watcher<DirectoryWatcherEvents>} */
1999
+ (w).directoryWatcher.getTimes();
2000
+ for (const file of Object.keys(times)) {
2001
+ const time = times[file];
2002
+ safeTime = Math.max(safeTime, time);
2003
+ obj[file] = time;
2004
+ }
2005
+ }
2006
+ obj[this.path] = safeTime;
2007
+ }
2008
+ if (!this.initialScan) {
2009
+ for (const watchers of this.watchers.values()) {
2010
+ for (const watcher of watchers) {
2011
+ const { path } = watcher;
2012
+ if (!Object.prototype.hasOwnProperty.call(obj, path)) {
2013
+ obj[path] = null;
2014
+ }
2015
+ }
2016
+ }
2017
+ }
2018
+ return obj;
2019
+ }
2020
+
2021
+ /**
2022
+ * @param {TimeInfoEntries} fileTimestamps file timestamps
2023
+ * @param {TimeInfoEntries} directoryTimestamps directory timestamps
2024
+ * @returns {number} safe time
2025
+ */
2026
+ collectTimeInfoEntries(fileTimestamps, directoryTimestamps) {
2027
+ let safeTime = this.lastWatchEvent;
2028
+ for (const [file, entry] of this.files) {
2029
+ fixupEntryAccuracy(entry);
2030
+ safeTime = Math.max(safeTime, entry.safeTime);
2031
+ fileTimestamps.set(file, entry);
2032
+ }
2033
+ if (this.nestedWatching) {
2034
+ for (const w of this.directories.values()) {
2035
+ safeTime = Math.max(
2036
+ safeTime,
2037
+ /** @type {Watcher<DirectoryWatcherEvents>} */
2038
+ (w).directoryWatcher.collectTimeInfoEntries(
2039
+ fileTimestamps,
2040
+ directoryTimestamps,
2041
+ ),
2042
+ );
2043
+ }
2044
+ fileTimestamps.set(this.path, EXISTANCE_ONLY_TIME_ENTRY);
2045
+ directoryTimestamps.set(this.path, {
2046
+ safeTime,
2047
+ });
2048
+ } else {
2049
+ for (const dir of this.directories.keys()) {
2050
+ // No additional info about this directory
2051
+ // but maybe another DirectoryWatcher has info
2052
+ fileTimestamps.set(dir, EXISTANCE_ONLY_TIME_ENTRY);
2053
+ if (!directoryTimestamps.has(dir)) {
2054
+ directoryTimestamps.set(dir, EXISTANCE_ONLY_TIME_ENTRY);
2055
+ }
2056
+ }
2057
+ fileTimestamps.set(this.path, EXISTANCE_ONLY_TIME_ENTRY);
2058
+ directoryTimestamps.set(this.path, EXISTANCE_ONLY_TIME_ENTRY);
2059
+ }
2060
+ if (!this.initialScan) {
2061
+ for (const watchers of this.watchers.values()) {
2062
+ for (const watcher of watchers) {
2063
+ const { path } = watcher;
2064
+ if (!fileTimestamps.has(path)) {
2065
+ fileTimestamps.set(path, null);
2066
+ }
2067
+ }
2068
+ }
2069
+ }
2070
+ return safeTime;
2071
+ }
2072
+
2073
+ close() {
2074
+ if (this.closed) return;
2075
+ this.closed = true;
2076
+ this.initialScan = false;
2077
+ if (this.watcher) {
2078
+ this.watcher.close();
2079
+ this.watcher = null;
2080
+ }
2081
+ if (this.nestedWatching) {
2082
+ for (const w of this.directories.values()) {
2083
+ /** @type {Watcher<DirectoryWatcherEvents>} */
2084
+ (w).close();
2085
+ }
2086
+ this.directories.clear();
2087
+ }
2088
+ for (const w of this._symlinkTargetWatchers.values()) {
2089
+ w.close();
2090
+ }
2091
+ this._symlinkTargetWatchers.clear();
2092
+ if (this.parentWatcher) {
2093
+ this.parentWatcher.close();
2094
+ this.parentWatcher = null;
2095
+ }
2096
+ this.emit("closed");
2097
+ }
2098
+ }
2099
+
2100
+ module.exports = DirectoryWatcher;
2101
+ module.exports.EXISTANCE_ONLY_TIME_ENTRY = EXISTANCE_ONLY_TIME_ENTRY;
2102
+ module.exports.Watcher = Watcher;
2103
+
2104
+
2105
+ /***/ }),
2106
+
2107
+ /***/ 366:
2108
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2109
+
2110
+ "use strict";
2111
+ /*
2112
+ MIT License http://www.opensource.org/licenses/mit-license.php
2113
+ Author Tobias Koppers @sokra
2114
+ */
2115
+
2116
+
2117
+ const fs = __nccwpck_require__(896);
2118
+ const path = __nccwpck_require__(928);
2119
+
2120
+ // macOS, Linux, and Windows all rely on these errors
2121
+ const EXPECTED_ERRORS = new Set(["EINVAL", "ENOENT"]);
2122
+
2123
+ // On Windows there is also this error in some cases
2124
+ if (process.platform === "win32") EXPECTED_ERRORS.add("UNKNOWN");
2125
+
2126
+ class LinkResolver {
2127
+ constructor() {
2128
+ /** @type {Map<string, readonly string[]>} */
2129
+ this.cache = new Map();
2130
+ }
2131
+
2132
+ /**
2133
+ * @param {string} file path to file or directory
2134
+ * @returns {readonly string[]} array of file and all symlinks contributed in the resolving process (first item is the resolved file)
2135
+ */
2136
+ resolve(file) {
2137
+ const cacheEntry = this.cache.get(file);
2138
+ if (cacheEntry !== undefined) {
2139
+ return cacheEntry;
2140
+ }
2141
+ const parent = path.dirname(file);
2142
+ if (parent === file) {
2143
+ // At root of filesystem there can't be a link
2144
+ const result = Object.freeze([file]);
2145
+ this.cache.set(file, result);
2146
+ return result;
2147
+ }
2148
+ // resolve the parent directory to find links there and get the real path
2149
+ const parentResolved = this.resolve(parent);
2150
+ let realFile = file;
2151
+
2152
+ // is the parent directory really somewhere else?
2153
+ if (parentResolved[0] !== parent) {
2154
+ // get the real location of file
2155
+ const basename = path.basename(file);
2156
+ realFile = path.resolve(parentResolved[0], basename);
2157
+ }
2158
+ // try to read the link content
2159
+ try {
2160
+ const linkContent = fs.readlinkSync(realFile);
2161
+
2162
+ // resolve the link content relative to the parent directory
2163
+ const resolvedLink = path.resolve(parentResolved[0], linkContent);
2164
+
2165
+ // recursive resolve the link content for more links in the structure
2166
+ const linkResolved = this.resolve(resolvedLink);
2167
+
2168
+ // merge parent and link resolve results
2169
+ let result;
2170
+ if (linkResolved.length > 1 && parentResolved.length > 1) {
2171
+ // when both contain links we need to duplicate them with a Set
2172
+ const resultSet = new Set(linkResolved);
2173
+ // add the link
2174
+ resultSet.add(realFile);
2175
+ // add all symlinks of the parent
2176
+ for (let i = 1; i < parentResolved.length; i++) {
2177
+ resultSet.add(parentResolved[i]);
2178
+ }
2179
+ result = Object.freeze([...resultSet]);
2180
+ } else if (parentResolved.length > 1) {
2181
+ // we have links in the parent but not for the link content location
2182
+ result = [...parentResolved];
2183
+ // eslint-disable-next-line prefer-destructuring
2184
+ result[0] = linkResolved[0];
2185
+ // add the link
2186
+ result.push(realFile);
2187
+ Object.freeze(result);
2188
+ } else if (linkResolved.length > 1) {
2189
+ // we can return the link content location result
2190
+ result = [...linkResolved];
2191
+ // add the link
2192
+ result.push(realFile);
2193
+ Object.freeze(result);
2194
+ } else {
2195
+ // neither link content location nor parent have links
2196
+ // this link is the only link here
2197
+ result = Object.freeze([
2198
+ // the resolve real location
2199
+ linkResolved[0],
2200
+ // add the link
2201
+ realFile,
2202
+ ]);
2203
+ }
2204
+ this.cache.set(file, result);
2205
+ return result;
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;
2213
+ }
2214
+ // no link
2215
+ const result = [...parentResolved];
2216
+ result[0] = realFile;
2217
+ Object.freeze(result);
2218
+ this.cache.set(file, result);
2219
+ return result;
2220
+ }
2221
+ }
2222
+ }
2223
+
2224
+ module.exports = LinkResolver;
2225
+
2226
+
2227
+ /***/ }),
2228
+
2229
+ /***/ 213:
2230
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2231
+
2232
+ "use strict";
2233
+ /*
2234
+ MIT License http://www.opensource.org/licenses/mit-license.php
2235
+ Author Tobias Koppers @sokra
2236
+ */
2237
+
2238
+
2239
+ const path = __nccwpck_require__(928);
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
+ */
2250
+
2251
+ class WatcherManager {
2252
+ /**
2253
+ * @param {DirectoryWatcherOptions=} options options
2254
+ */
2255
+ constructor(options = {}) {
2256
+ this.options = options;
2257
+ /** @type {Map<string, DirectoryWatcher>} */
2258
+ this.directoryWatchers = new Map();
2259
+ }
2260
+
2261
+ /**
2262
+ * @param {string} directory a directory
2263
+ * @returns {DirectoryWatcher} a directory watcher
2264
+ */
2265
+ getDirectoryWatcher(directory) {
2266
+ const watcher = this.directoryWatchers.get(directory);
2267
+ if (watcher === undefined) {
2268
+ const newWatcher = new DirectoryWatcher(this, directory, this.options);
2269
+ this.directoryWatchers.set(directory, newWatcher);
2270
+ newWatcher.on("closed", () => {
2271
+ this.directoryWatchers.delete(directory);
2272
+ });
2273
+ return newWatcher;
2274
+ }
2275
+ return watcher;
2276
+ }
2277
+
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);
2287
+ }
2288
+
2289
+ /**
2290
+ * @param {string} directory directory
2291
+ * @param {number=} startTime start time
2292
+ * @returns {Watcher<DirectoryWatcherEvents>} watcher
2293
+ */
2294
+ watchDirectory(directory, startTime) {
2295
+ return this.getDirectoryWatcher(directory).watch(directory, startTime);
2296
+ }
2297
+ }
2298
+
2299
+ const watcherManagers = new WeakMap();
2300
+
2301
+ /**
2302
+ * @param {DirectoryWatcherOptions} options options
2303
+ * @returns {WatcherManager} the watcher manager
2304
+ */
2305
+ module.exports = (options) => {
2306
+ const watcherManager = watcherManagers.get(options);
2307
+ if (watcherManager !== undefined) return watcherManager;
2308
+ const newWatcherManager = new WatcherManager(options);
2309
+ watcherManagers.set(options, newWatcherManager);
2310
+ return newWatcherManager;
2311
+ };
2312
+ module.exports.WatcherManager = WatcherManager;
2313
+
2314
+
2315
+ /***/ }),
2316
+
2317
+ /***/ 934:
2318
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2319
+
2320
+ "use strict";
2321
+ /*
2322
+ MIT License http://www.opensource.org/licenses/mit-license.php
2323
+ Author Tobias Koppers @sokra
2324
+ */
2325
+
2326
+
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 */
2340
+
2341
+ /**
2342
+ * @template {EventMap} T
2343
+ * @typedef {import("./DirectoryWatcher").Watcher<T>} Watcher
2344
+ */
2345
+
2346
+ /** @typedef {(item: string) => boolean} IgnoredFunction */
2347
+ /** @typedef {string[] | RegExp | string | IgnoredFunction} Ignored */
2348
+
2349
+ /**
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
2354
+ */
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);
2386
+ }
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;
2396
+ }
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
+ }
2686
+ }
2687
+ }
2688
+ }
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
+ }
2697
+ }
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);
2830
+ }
2831
+ }
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));
2902
+ };
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
+
2916
+
2917
+ /***/ }),
2918
+
2919
+ /***/ 817:
2920
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2921
+
2922
+ "use strict";
2923
+ /*
2924
+ MIT License http://www.opensource.org/licenses/mit-license.php
2925
+ Author Tobias Koppers @sokra
2926
+ */
2927
+
2928
+
2929
+ const path = __nccwpck_require__(928);
2930
+
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
+ */
2941
+
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
+ });
2960
+ }
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];
2982
+ } else {
2983
+ parent.children.push(node);
2984
+ }
2985
+ do {
2986
+ parent.entries += node.entries;
2987
+ parent = parent.parent;
2988
+ } while (parent);
2989
+ }
2990
+ }
2991
+ }
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
+ }
3052
+ }
3053
+ }
3054
+ }
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
+ }
3077
+ }
3078
+ newPlan.set(rootNode.target, map);
3079
+ }
3080
+ return newPlan;
3081
+ };
3082
+
3083
+
3084
+ /***/ }),
3085
+
3086
+ /***/ 737:
3087
+ /***/ ((module) => {
3088
+
3089
+ "use strict";
3090
+ /*
3091
+ MIT License http://www.opensource.org/licenses/mit-license.php
3092
+ Author Haijie Xie @hai-x
3093
+ */
3094
+
3095
+
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++;
3197
+ }
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 = "([^/]*)";
3211
+ }
3212
+ break;
3213
+ }
3214
+ default:
3215
+ // Literal character, extend the current run
3216
+ continue;
3217
+ }
3218
+
3219
+ if (literalStart < tokenStart) {
3220
+ reStr += glob.slice(literalStart, tokenStart);
3221
+ }
3222
+ reStr += mapped;
3223
+ literalStart = i + 1;
3224
+ }
3225
+
3226
+ if (literalStart < len) {
3227
+ reStr += literalStart === 0 ? glob : glob.slice(literalStart);
3228
+ }
3229
+
3230
+ return reStr;
3231
+ };
3232
+
3233
+
3234
+ /***/ }),
3235
+
3236
+ /***/ 92:
3237
+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3238
+
3239
+ "use strict";
3240
+ /*
3241
+ MIT License http://www.opensource.org/licenses/mit-license.php
3242
+ Author Tobias Koppers @sokra
3243
+ */
3244
+
3245
+
3246
+ const { EventEmitter } = __nccwpck_require__(434);
3247
+ const fs = __nccwpck_require__(896);
3248
+ const path = __nccwpck_require__(928);
3249
+ const reducePlan = __nccwpck_require__(817);
3250
+
3251
+ /** @typedef {import("fs").FSWatcher} FSWatcher */
3252
+ /** @typedef {import("./index").EventType} EventType */
3253
+
3254
+ const IS_OSX = (__nccwpck_require__(857).platform)() === "darwin";
3255
+ const IS_WIN = (__nccwpck_require__(857).platform)() === "win32";
3256
+
3257
+ const SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN;
3258
+
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);
3264
+
3265
+ const recursiveWatcherLogging = Boolean(
3266
+ process.env.WATCHPACK_RECURSIVE_WATCHER_LOGGING,
3267
+ );
3268
+
3269
+ let isBatch = false;
3270
+ let watcherCount = 0;
3271
+
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
+ }
3295
+
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));
3318
+ }
3319
+ // Before v22, macos nothing to do
3320
+ return;
3321
+ }
3322
+ handleChangeEvent(type, filename);
3323
+ };
3324
+ }
3325
+
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++;
3362
+ }
3363
+
3364
+ /**
3365
+ * @param {Watcher} watcher a watcher
3366
+ */
3367
+ add(watcher) {
3368
+ underlyingWatcher.set(watcher, this);
3369
+ this.watchers.add(watcher);
3370
+ }
3371
+
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();
3381
+ }
3382
+ }
3383
+
3384
+ getWatchers() {
3385
+ return this.watchers;
3386
+ }
3387
+ }
3388
+
3389
+ /** @typedef {Set<Watcher>} WatcherSet */
3390
+
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
+ );
3413
+ }
3414
+ for (const w of this.mapWatcherToPath.keys()) {
3415
+ w.emit("change", /** @type {EventType} */ (type));
3416
+ }
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
+ );
3436
+ }
3437
+ }
3438
+ });
3439
+ watcher.on("error", (error) => {
3440
+ for (const w of this.mapWatcherToPath.keys()) {
3441
+ w.emit("error", error);
3442
+ }
3443
+ });
3444
+ } catch (err) {
3445
+ process.nextTick(() => {
3446
+ for (const w of this.mapWatcherToPath.keys()) {
3447
+ w.emit("error", err);
3448
+ }
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);
3474
+ }
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);
3488
+ }
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
+ );
3497
+ }
3498
+ }
3499
+ }
3500
+
3501
+ getWatchers() {
3502
+ return this.mapWatcherToPath;
3503
+ }
3504
+ }
3505
+
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();
3518
+ }
3519
+
3520
+ close() {
3521
+ if (pendingWatchers.has(this)) {
3522
+ pendingWatchers.delete(this);
3523
+ return;
3524
+ }
3525
+ const watcher = underlyingWatcher.get(this);
3526
+ /** @type {RecursiveWatcher | DirectWatcher} */
3527
+ (watcher).remove(this);
3528
+ underlyingWatcher.delete(this);
3529
+ }
3530
+ }
3531
+
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
+ };
3543
+
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]);
3571
+ }
3572
+ };
3573
+ for (const [watcher, filePath] of pendingWatchers) {
3574
+ addWatcher(watcher, filePath);
3575
+ }
3576
+ pendingWatchers.clear();
3577
+
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
+ }
3588
+ }
3589
+ return;
3590
+ }
3591
+
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);
3601
+ }
3602
+ }
3603
+
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
+ }
3639
+ }
3640
+ }
3641
+ };
3642
+
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();
3655
+ }
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
+ };
3695
+
3696
+ module.exports.watcherLimit = watcherLimit;
3697
+
3698
+
3699
+ /***/ }),
3700
+
3701
+ /***/ 613:
3702
+ /***/ ((module) => {
3703
+
3704
+ "use strict";
3705
+ module.exports = require("assert");
3706
+
3707
+ /***/ }),
3708
+
3709
+ /***/ 140:
3710
+ /***/ ((module) => {
3711
+
3712
+ "use strict";
3713
+ module.exports = require("constants");
3714
+
3715
+ /***/ }),
3716
+
3717
+ /***/ 434:
3718
+ /***/ ((module) => {
3719
+
3720
+ "use strict";
3721
+ module.exports = require("events");
3722
+
3723
+ /***/ }),
3724
+
3725
+ /***/ 896:
3726
+ /***/ ((module) => {
3727
+
3728
+ "use strict";
3729
+ module.exports = require("fs");
3730
+
3731
+ /***/ }),
3732
+
3733
+ /***/ 857:
3734
+ /***/ ((module) => {
3735
+
3736
+ "use strict";
3737
+ module.exports = require("os");
3738
+
3739
+ /***/ }),
3740
+
3741
+ /***/ 928:
3742
+ /***/ ((module) => {
3743
+
3744
+ "use strict";
3745
+ module.exports = require("path");
3746
+
3747
+ /***/ }),
3748
+
3749
+ /***/ 203:
3750
+ /***/ ((module) => {
3751
+
3752
+ "use strict";
3753
+ module.exports = require("stream");
3754
+
3755
+ /***/ }),
3756
+
3757
+ /***/ 23:
3758
+ /***/ ((module) => {
3759
+
3760
+ "use strict";
3761
+ module.exports = require("util");
3762
+
3763
+ /***/ })
3764
+
3765
+ /******/ });
3766
+ /************************************************************************/
3767
+ /******/ // The module cache
3768
+ /******/ var __webpack_module_cache__ = {};
3769
+ /******/
3770
+ /******/ // The require function
3771
+ /******/ function __nccwpck_require__(moduleId) {
3772
+ /******/ // Check if module is in cache
3773
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
3774
+ /******/ if (cachedModule !== undefined) {
3775
+ /******/ return cachedModule.exports;
3776
+ /******/ }
3777
+ /******/ // Create a new module (and put it into the cache)
3778
+ /******/ var module = __webpack_module_cache__[moduleId] = {
3779
+ /******/ // no module.id needed
3780
+ /******/ // no module.loaded needed
3781
+ /******/ exports: {}
3782
+ /******/ };
3783
+ /******/
3784
+ /******/ // Execute the module function
3785
+ /******/ var threw = true;
3786
+ /******/ try {
3787
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
3788
+ /******/ threw = false;
3789
+ /******/ } finally {
3790
+ /******/ if(threw) delete __webpack_module_cache__[moduleId];
3791
+ /******/ }
3792
+ /******/
3793
+ /******/ // Return the exports of the module
3794
+ /******/ return module.exports;
3795
+ /******/ }
3796
+ /******/
3797
+ /************************************************************************/
3798
+ /******/ /* webpack/runtime/compat */
3799
+ /******/
3800
+ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
3801
+ /******/
3802
+ /************************************************************************/
3803
+ /******/
3804
+ /******/ // startup
3805
+ /******/ // Load entry module and return exports
3806
+ /******/ // This entry module is referenced by other modules so it can't be inlined
3807
+ /******/ var __webpack_exports__ = __nccwpck_require__(934);
3808
+ /******/ module.exports = __webpack_exports__;
3809
+ /******/
3810
+ /******/ })()
3811
+ ;