@stackone/cli 1.1.0 → 1.2.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.
@@ -1,1573 +1 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const fs = require_chunk.__toESM(require("fs"));
3
- const path = require_chunk.__toESM(require("path"));
4
- const fs_promises = require_chunk.__toESM(require("fs/promises"));
5
- const events = require_chunk.__toESM(require("events"));
6
- const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
7
- const node_stream = require_chunk.__toESM(require("node:stream"));
8
- const node_path = require_chunk.__toESM(require("node:path"));
9
- const os = require_chunk.__toESM(require("os"));
10
-
11
- //#region ../../node_modules/readdirp/esm/index.js
12
- const EntryTypes = {
13
- FILE_TYPE: "files",
14
- DIR_TYPE: "directories",
15
- FILE_DIR_TYPE: "files_directories",
16
- EVERYTHING_TYPE: "all"
17
- };
18
- const defaultOptions = {
19
- root: ".",
20
- fileFilter: (_entryInfo) => true,
21
- directoryFilter: (_entryInfo) => true,
22
- type: EntryTypes.FILE_TYPE,
23
- lstat: false,
24
- depth: 2147483648,
25
- alwaysStat: false,
26
- highWaterMark: 4096
27
- };
28
- Object.freeze(defaultOptions);
29
- const RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
30
- const NORMAL_FLOW_ERRORS = new Set([
31
- "ENOENT",
32
- "EPERM",
33
- "EACCES",
34
- "ELOOP",
35
- RECURSIVE_ERROR_CODE
36
- ]);
37
- const ALL_TYPES = [
38
- EntryTypes.DIR_TYPE,
39
- EntryTypes.EVERYTHING_TYPE,
40
- EntryTypes.FILE_DIR_TYPE,
41
- EntryTypes.FILE_TYPE
42
- ];
43
- const DIR_TYPES = new Set([
44
- EntryTypes.DIR_TYPE,
45
- EntryTypes.EVERYTHING_TYPE,
46
- EntryTypes.FILE_DIR_TYPE
47
- ]);
48
- const FILE_TYPES = new Set([
49
- EntryTypes.EVERYTHING_TYPE,
50
- EntryTypes.FILE_DIR_TYPE,
51
- EntryTypes.FILE_TYPE
52
- ]);
53
- const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
54
- const wantBigintFsStats = process.platform === "win32";
55
- const emptyFn = (_entryInfo) => true;
56
- const normalizeFilter = (filter) => {
57
- if (filter === void 0) return emptyFn;
58
- if (typeof filter === "function") return filter;
59
- if (typeof filter === "string") {
60
- const fl = filter.trim();
61
- return (entry) => entry.basename === fl;
62
- }
63
- if (Array.isArray(filter)) {
64
- const trItems = filter.map((item) => item.trim());
65
- return (entry) => trItems.some((f) => entry.basename === f);
66
- }
67
- return emptyFn;
68
- };
69
- /** Readable readdir stream, emitting new files as they're being listed. */
70
- var ReaddirpStream = class extends node_stream.Readable {
71
- constructor(options = {}) {
72
- super({
73
- objectMode: true,
74
- autoDestroy: true,
75
- highWaterMark: options.highWaterMark
76
- });
77
- const opts = {
78
- ...defaultOptions,
79
- ...options
80
- };
81
- const { root, type } = opts;
82
- this._fileFilter = normalizeFilter(opts.fileFilter);
83
- this._directoryFilter = normalizeFilter(opts.directoryFilter);
84
- const statMethod = opts.lstat ? node_fs_promises.lstat : node_fs_promises.stat;
85
- if (wantBigintFsStats) this._stat = (path$1) => statMethod(path$1, { bigint: true });
86
- else this._stat = statMethod;
87
- this._maxDepth = opts.depth ?? defaultOptions.depth;
88
- this._wantsDir = type ? DIR_TYPES.has(type) : false;
89
- this._wantsFile = type ? FILE_TYPES.has(type) : false;
90
- this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
91
- this._root = (0, node_path.resolve)(root);
92
- this._isDirent = !opts.alwaysStat;
93
- this._statsProp = this._isDirent ? "dirent" : "stats";
94
- this._rdOptions = {
95
- encoding: "utf8",
96
- withFileTypes: this._isDirent
97
- };
98
- this.parents = [this._exploreDir(root, 1)];
99
- this.reading = false;
100
- this.parent = void 0;
101
- }
102
- async _read(batch) {
103
- if (this.reading) return;
104
- this.reading = true;
105
- try {
106
- while (!this.destroyed && batch > 0) {
107
- const par = this.parent;
108
- const fil = par && par.files;
109
- if (fil && fil.length > 0) {
110
- const { path: path$1, depth } = par;
111
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path$1));
112
- const awaited = await Promise.all(slice);
113
- for (const entry of awaited) {
114
- if (!entry) continue;
115
- if (this.destroyed) return;
116
- const entryType = await this._getEntryType(entry);
117
- if (entryType === "directory" && this._directoryFilter(entry)) {
118
- if (depth <= this._maxDepth) this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
119
- if (this._wantsDir) {
120
- this.push(entry);
121
- batch--;
122
- }
123
- } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
124
- if (this._wantsFile) {
125
- this.push(entry);
126
- batch--;
127
- }
128
- }
129
- }
130
- } else {
131
- const parent = this.parents.pop();
132
- if (!parent) {
133
- this.push(null);
134
- break;
135
- }
136
- this.parent = await parent;
137
- if (this.destroyed) return;
138
- }
139
- }
140
- } catch (error) {
141
- this.destroy(error);
142
- } finally {
143
- this.reading = false;
144
- }
145
- }
146
- async _exploreDir(path$1, depth) {
147
- let files;
148
- try {
149
- files = await (0, node_fs_promises.readdir)(path$1, this._rdOptions);
150
- } catch (error) {
151
- this._onError(error);
152
- }
153
- return {
154
- files,
155
- depth,
156
- path: path$1
157
- };
158
- }
159
- async _formatEntry(dirent, path$1) {
160
- let entry;
161
- const basename = this._isDirent ? dirent.name : dirent;
162
- try {
163
- const fullPath = (0, node_path.resolve)((0, node_path.join)(path$1, basename));
164
- entry = {
165
- path: (0, node_path.relative)(this._root, fullPath),
166
- fullPath,
167
- basename
168
- };
169
- entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
170
- } catch (err) {
171
- this._onError(err);
172
- return;
173
- }
174
- return entry;
175
- }
176
- _onError(err) {
177
- if (isNormalFlowError(err) && !this.destroyed) this.emit("warn", err);
178
- else this.destroy(err);
179
- }
180
- async _getEntryType(entry) {
181
- if (!entry && this._statsProp in entry) return "";
182
- const stats = entry[this._statsProp];
183
- if (stats.isFile()) return "file";
184
- if (stats.isDirectory()) return "directory";
185
- if (stats && stats.isSymbolicLink()) {
186
- const full = entry.fullPath;
187
- try {
188
- const entryRealPath = await (0, node_fs_promises.realpath)(full);
189
- const entryRealPathStats = await (0, node_fs_promises.lstat)(entryRealPath);
190
- if (entryRealPathStats.isFile()) return "file";
191
- if (entryRealPathStats.isDirectory()) {
192
- const len = entryRealPath.length;
193
- if (full.startsWith(entryRealPath) && full.substr(len, 1) === node_path.sep) {
194
- const recursiveError = /* @__PURE__ */ new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
195
- recursiveError.code = RECURSIVE_ERROR_CODE;
196
- return this._onError(recursiveError);
197
- }
198
- return "directory";
199
- }
200
- } catch (error) {
201
- this._onError(error);
202
- return "";
203
- }
204
- }
205
- }
206
- _includeAsFile(entry) {
207
- const stats = entry && entry[this._statsProp];
208
- return stats && this._wantsEverything && !stats.isDirectory();
209
- }
210
- };
211
- /**
212
- * Streaming version: Reads all files and directories in given root recursively.
213
- * Consumes ~constant small amount of RAM.
214
- * @param root Root directory
215
- * @param options Options to specify root (start directory), filters and recursion depth
216
- */
217
- function readdirp(root, options = {}) {
218
- let type = options.entryType || options.type;
219
- if (type === "both") type = EntryTypes.FILE_DIR_TYPE;
220
- if (type) options.type = type;
221
- if (!root) throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
222
- else if (typeof root !== "string") throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
223
- else if (type && !ALL_TYPES.includes(type)) throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
224
- options.root = root;
225
- return new ReaddirpStream(options);
226
- }
227
-
228
- //#endregion
229
- //#region ../../node_modules/chokidar/esm/handler.js
230
- const STR_DATA = "data";
231
- const STR_END = "end";
232
- const STR_CLOSE = "close";
233
- const EMPTY_FN = () => {};
234
- const pl = process.platform;
235
- const isWindows = pl === "win32";
236
- const isMacos = pl === "darwin";
237
- const isLinux = pl === "linux";
238
- const isFreeBSD = pl === "freebsd";
239
- const isIBMi = (0, os.type)() === "OS400";
240
- const EVENTS = {
241
- ALL: "all",
242
- READY: "ready",
243
- ADD: "add",
244
- CHANGE: "change",
245
- ADD_DIR: "addDir",
246
- UNLINK: "unlink",
247
- UNLINK_DIR: "unlinkDir",
248
- RAW: "raw",
249
- ERROR: "error"
250
- };
251
- const EV = EVENTS;
252
- const THROTTLE_MODE_WATCH = "watch";
253
- const statMethods = {
254
- lstat: fs_promises.lstat,
255
- stat: fs_promises.stat
256
- };
257
- const KEY_LISTENERS = "listeners";
258
- const KEY_ERR = "errHandlers";
259
- const KEY_RAW = "rawEmitters";
260
- const HANDLER_KEYS = [
261
- KEY_LISTENERS,
262
- KEY_ERR,
263
- KEY_RAW
264
- ];
265
- const binaryExtensions = new Set([
266
- "3dm",
267
- "3ds",
268
- "3g2",
269
- "3gp",
270
- "7z",
271
- "a",
272
- "aac",
273
- "adp",
274
- "afdesign",
275
- "afphoto",
276
- "afpub",
277
- "ai",
278
- "aif",
279
- "aiff",
280
- "alz",
281
- "ape",
282
- "apk",
283
- "appimage",
284
- "ar",
285
- "arj",
286
- "asf",
287
- "au",
288
- "avi",
289
- "bak",
290
- "baml",
291
- "bh",
292
- "bin",
293
- "bk",
294
- "bmp",
295
- "btif",
296
- "bz2",
297
- "bzip2",
298
- "cab",
299
- "caf",
300
- "cgm",
301
- "class",
302
- "cmx",
303
- "cpio",
304
- "cr2",
305
- "cur",
306
- "dat",
307
- "dcm",
308
- "deb",
309
- "dex",
310
- "djvu",
311
- "dll",
312
- "dmg",
313
- "dng",
314
- "doc",
315
- "docm",
316
- "docx",
317
- "dot",
318
- "dotm",
319
- "dra",
320
- "DS_Store",
321
- "dsk",
322
- "dts",
323
- "dtshd",
324
- "dvb",
325
- "dwg",
326
- "dxf",
327
- "ecelp4800",
328
- "ecelp7470",
329
- "ecelp9600",
330
- "egg",
331
- "eol",
332
- "eot",
333
- "epub",
334
- "exe",
335
- "f4v",
336
- "fbs",
337
- "fh",
338
- "fla",
339
- "flac",
340
- "flatpak",
341
- "fli",
342
- "flv",
343
- "fpx",
344
- "fst",
345
- "fvt",
346
- "g3",
347
- "gh",
348
- "gif",
349
- "graffle",
350
- "gz",
351
- "gzip",
352
- "h261",
353
- "h263",
354
- "h264",
355
- "icns",
356
- "ico",
357
- "ief",
358
- "img",
359
- "ipa",
360
- "iso",
361
- "jar",
362
- "jpeg",
363
- "jpg",
364
- "jpgv",
365
- "jpm",
366
- "jxr",
367
- "key",
368
- "ktx",
369
- "lha",
370
- "lib",
371
- "lvp",
372
- "lz",
373
- "lzh",
374
- "lzma",
375
- "lzo",
376
- "m3u",
377
- "m4a",
378
- "m4v",
379
- "mar",
380
- "mdi",
381
- "mht",
382
- "mid",
383
- "midi",
384
- "mj2",
385
- "mka",
386
- "mkv",
387
- "mmr",
388
- "mng",
389
- "mobi",
390
- "mov",
391
- "movie",
392
- "mp3",
393
- "mp4",
394
- "mp4a",
395
- "mpeg",
396
- "mpg",
397
- "mpga",
398
- "mxu",
399
- "nef",
400
- "npx",
401
- "numbers",
402
- "nupkg",
403
- "o",
404
- "odp",
405
- "ods",
406
- "odt",
407
- "oga",
408
- "ogg",
409
- "ogv",
410
- "otf",
411
- "ott",
412
- "pages",
413
- "pbm",
414
- "pcx",
415
- "pdb",
416
- "pdf",
417
- "pea",
418
- "pgm",
419
- "pic",
420
- "png",
421
- "pnm",
422
- "pot",
423
- "potm",
424
- "potx",
425
- "ppa",
426
- "ppam",
427
- "ppm",
428
- "pps",
429
- "ppsm",
430
- "ppsx",
431
- "ppt",
432
- "pptm",
433
- "pptx",
434
- "psd",
435
- "pya",
436
- "pyc",
437
- "pyo",
438
- "pyv",
439
- "qt",
440
- "rar",
441
- "ras",
442
- "raw",
443
- "resources",
444
- "rgb",
445
- "rip",
446
- "rlc",
447
- "rmf",
448
- "rmvb",
449
- "rpm",
450
- "rtf",
451
- "rz",
452
- "s3m",
453
- "s7z",
454
- "scpt",
455
- "sgi",
456
- "shar",
457
- "snap",
458
- "sil",
459
- "sketch",
460
- "slk",
461
- "smv",
462
- "snk",
463
- "so",
464
- "stl",
465
- "suo",
466
- "sub",
467
- "swf",
468
- "tar",
469
- "tbz",
470
- "tbz2",
471
- "tga",
472
- "tgz",
473
- "thmx",
474
- "tif",
475
- "tiff",
476
- "tlz",
477
- "ttc",
478
- "ttf",
479
- "txz",
480
- "udf",
481
- "uvh",
482
- "uvi",
483
- "uvm",
484
- "uvp",
485
- "uvs",
486
- "uvu",
487
- "viv",
488
- "vob",
489
- "war",
490
- "wav",
491
- "wax",
492
- "wbmp",
493
- "wdp",
494
- "weba",
495
- "webm",
496
- "webp",
497
- "whl",
498
- "wim",
499
- "wm",
500
- "wma",
501
- "wmv",
502
- "wmx",
503
- "woff",
504
- "woff2",
505
- "wrm",
506
- "wvx",
507
- "xbm",
508
- "xif",
509
- "xla",
510
- "xlam",
511
- "xls",
512
- "xlsb",
513
- "xlsm",
514
- "xlsx",
515
- "xlt",
516
- "xltm",
517
- "xltx",
518
- "xm",
519
- "xmind",
520
- "xpi",
521
- "xpm",
522
- "xwd",
523
- "xz",
524
- "z",
525
- "zip",
526
- "zipx"
527
- ]);
528
- const isBinaryPath = (filePath) => binaryExtensions.has(path.extname(filePath).slice(1).toLowerCase());
529
- const foreach = (val, fn) => {
530
- if (val instanceof Set) val.forEach(fn);
531
- else fn(val);
532
- };
533
- const addAndConvert = (main, prop, item) => {
534
- let container = main[prop];
535
- if (!(container instanceof Set)) main[prop] = container = new Set([container]);
536
- container.add(item);
537
- };
538
- const clearItem = (cont) => (key) => {
539
- const set = cont[key];
540
- if (set instanceof Set) set.clear();
541
- else delete cont[key];
542
- };
543
- const delFromSet = (main, prop, item) => {
544
- const container = main[prop];
545
- if (container instanceof Set) container.delete(item);
546
- else if (container === item) delete main[prop];
547
- };
548
- const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
549
- const FsWatchInstances = /* @__PURE__ */ new Map();
550
- /**
551
- * Instantiates the fs_watch interface
552
- * @param path to be watched
553
- * @param options to be passed to fs_watch
554
- * @param listener main event handler
555
- * @param errHandler emits info about errors
556
- * @param emitRaw emits raw event data
557
- * @returns {NativeFsWatcher}
558
- */
559
- function createFsWatchInstance(path$1, options, listener, errHandler, emitRaw) {
560
- const handleEvent = (rawEvent, evPath) => {
561
- listener(path$1);
562
- emitRaw(rawEvent, evPath, { watchedPath: path$1 });
563
- if (evPath && path$1 !== evPath) fsWatchBroadcast(path.resolve(path$1, evPath), KEY_LISTENERS, path.join(path$1, evPath));
564
- };
565
- try {
566
- return (0, fs.watch)(path$1, { persistent: options.persistent }, handleEvent);
567
- } catch (error) {
568
- errHandler(error);
569
- return void 0;
570
- }
571
- }
572
- /**
573
- * Helper for passing fs_watch event data to a collection of listeners
574
- * @param fullPath absolute path bound to fs_watch instance
575
- */
576
- const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
577
- const cont = FsWatchInstances.get(fullPath);
578
- if (!cont) return;
579
- foreach(cont[listenerType], (listener) => {
580
- listener(val1, val2, val3);
581
- });
582
- };
583
- /**
584
- * Instantiates the fs_watch interface or binds listeners
585
- * to an existing one covering the same file system entry
586
- * @param path
587
- * @param fullPath absolute path
588
- * @param options to be passed to fs_watch
589
- * @param handlers container for event listener functions
590
- */
591
- const setFsWatchListener = (path$1, fullPath, options, handlers) => {
592
- const { listener, errHandler, rawEmitter } = handlers;
593
- let cont = FsWatchInstances.get(fullPath);
594
- let watcher;
595
- if (!options.persistent) {
596
- watcher = createFsWatchInstance(path$1, options, listener, errHandler, rawEmitter);
597
- if (!watcher) return;
598
- return watcher.close.bind(watcher);
599
- }
600
- if (cont) {
601
- addAndConvert(cont, KEY_LISTENERS, listener);
602
- addAndConvert(cont, KEY_ERR, errHandler);
603
- addAndConvert(cont, KEY_RAW, rawEmitter);
604
- } else {
605
- watcher = createFsWatchInstance(path$1, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
606
- if (!watcher) return;
607
- watcher.on(EV.ERROR, async (error) => {
608
- const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
609
- if (cont) cont.watcherUnusable = true;
610
- if (isWindows && error.code === "EPERM") try {
611
- const fd = await (0, fs_promises.open)(path$1, "r");
612
- await fd.close();
613
- broadcastErr(error);
614
- } catch (err) {}
615
- else broadcastErr(error);
616
- });
617
- cont = {
618
- listeners: listener,
619
- errHandlers: errHandler,
620
- rawEmitters: rawEmitter,
621
- watcher
622
- };
623
- FsWatchInstances.set(fullPath, cont);
624
- }
625
- return () => {
626
- delFromSet(cont, KEY_LISTENERS, listener);
627
- delFromSet(cont, KEY_ERR, errHandler);
628
- delFromSet(cont, KEY_RAW, rawEmitter);
629
- if (isEmptySet(cont.listeners)) {
630
- cont.watcher.close();
631
- FsWatchInstances.delete(fullPath);
632
- HANDLER_KEYS.forEach(clearItem(cont));
633
- cont.watcher = void 0;
634
- Object.freeze(cont);
635
- }
636
- };
637
- };
638
- const FsWatchFileInstances = /* @__PURE__ */ new Map();
639
- /**
640
- * Instantiates the fs_watchFile interface or binds listeners
641
- * to an existing one covering the same file system entry
642
- * @param path to be watched
643
- * @param fullPath absolute path
644
- * @param options options to be passed to fs_watchFile
645
- * @param handlers container for event listener functions
646
- * @returns closer
647
- */
648
- const setFsWatchFileListener = (path$1, fullPath, options, handlers) => {
649
- const { listener, rawEmitter } = handlers;
650
- let cont = FsWatchFileInstances.get(fullPath);
651
- const copts = cont && cont.options;
652
- if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
653
- (0, fs.unwatchFile)(fullPath);
654
- cont = void 0;
655
- }
656
- if (cont) {
657
- addAndConvert(cont, KEY_LISTENERS, listener);
658
- addAndConvert(cont, KEY_RAW, rawEmitter);
659
- } else {
660
- cont = {
661
- listeners: listener,
662
- rawEmitters: rawEmitter,
663
- options,
664
- watcher: (0, fs.watchFile)(fullPath, options, (curr, prev) => {
665
- foreach(cont.rawEmitters, (rawEmitter$1) => {
666
- rawEmitter$1(EV.CHANGE, fullPath, {
667
- curr,
668
- prev
669
- });
670
- });
671
- const currmtime = curr.mtimeMs;
672
- if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener$1) => listener$1(path$1, curr));
673
- })
674
- };
675
- FsWatchFileInstances.set(fullPath, cont);
676
- }
677
- return () => {
678
- delFromSet(cont, KEY_LISTENERS, listener);
679
- delFromSet(cont, KEY_RAW, rawEmitter);
680
- if (isEmptySet(cont.listeners)) {
681
- FsWatchFileInstances.delete(fullPath);
682
- (0, fs.unwatchFile)(fullPath);
683
- cont.options = cont.watcher = void 0;
684
- Object.freeze(cont);
685
- }
686
- };
687
- };
688
- /**
689
- * @mixin
690
- */
691
- var NodeFsHandler = class {
692
- constructor(fsW) {
693
- this.fsw = fsW;
694
- this._boundHandleError = (error) => fsW._handleError(error);
695
- }
696
- /**
697
- * Watch file for changes with fs_watchFile or fs_watch.
698
- * @param path to file or dir
699
- * @param listener on fs change
700
- * @returns closer for the watcher instance
701
- */
702
- _watchWithNodeFs(path$1, listener) {
703
- const opts = this.fsw.options;
704
- const directory = path.dirname(path$1);
705
- const basename = path.basename(path$1);
706
- const parent = this.fsw._getWatchedDir(directory);
707
- parent.add(basename);
708
- const absolutePath = path.resolve(path$1);
709
- const options = { persistent: opts.persistent };
710
- if (!listener) listener = EMPTY_FN;
711
- let closer;
712
- if (opts.usePolling) {
713
- const enableBin = opts.interval !== opts.binaryInterval;
714
- options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
715
- closer = setFsWatchFileListener(path$1, absolutePath, options, {
716
- listener,
717
- rawEmitter: this.fsw._emitRaw
718
- });
719
- } else closer = setFsWatchListener(path$1, absolutePath, options, {
720
- listener,
721
- errHandler: this._boundHandleError,
722
- rawEmitter: this.fsw._emitRaw
723
- });
724
- return closer;
725
- }
726
- /**
727
- * Watch a file and emit add event if warranted.
728
- * @returns closer for the watcher instance
729
- */
730
- _handleFile(file, stats, initialAdd) {
731
- if (this.fsw.closed) return;
732
- const dirname = path.dirname(file);
733
- const basename = path.basename(file);
734
- const parent = this.fsw._getWatchedDir(dirname);
735
- let prevStats = stats;
736
- if (parent.has(basename)) return;
737
- const listener = async (path$1, newStats) => {
738
- if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
739
- if (!newStats || newStats.mtimeMs === 0) try {
740
- const newStats$1 = await (0, fs_promises.stat)(file);
741
- if (this.fsw.closed) return;
742
- const at = newStats$1.atimeMs;
743
- const mt = newStats$1.mtimeMs;
744
- if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats$1);
745
- if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats$1.ino) {
746
- this.fsw._closeFile(path$1);
747
- prevStats = newStats$1;
748
- const closer$1 = this._watchWithNodeFs(file, listener);
749
- if (closer$1) this.fsw._addPathCloser(path$1, closer$1);
750
- } else prevStats = newStats$1;
751
- } catch (error) {
752
- this.fsw._remove(dirname, basename);
753
- }
754
- else if (parent.has(basename)) {
755
- const at = newStats.atimeMs;
756
- const mt = newStats.mtimeMs;
757
- if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
758
- prevStats = newStats;
759
- }
760
- };
761
- const closer = this._watchWithNodeFs(file, listener);
762
- if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
763
- if (!this.fsw._throttle(EV.ADD, file, 0)) return;
764
- this.fsw._emit(EV.ADD, file, stats);
765
- }
766
- return closer;
767
- }
768
- /**
769
- * Handle symlinks encountered while reading a dir.
770
- * @param entry returned by readdirp
771
- * @param directory path of dir being read
772
- * @param path of this item
773
- * @param item basename of this item
774
- * @returns true if no more processing is needed for this entry.
775
- */
776
- async _handleSymlink(entry, directory, path$1, item) {
777
- if (this.fsw.closed) return;
778
- const full = entry.fullPath;
779
- const dir = this.fsw._getWatchedDir(directory);
780
- if (!this.fsw.options.followSymlinks) {
781
- this.fsw._incrReadyCount();
782
- let linkPath;
783
- try {
784
- linkPath = await (0, fs_promises.realpath)(path$1);
785
- } catch (e) {
786
- this.fsw._emitReady();
787
- return true;
788
- }
789
- if (this.fsw.closed) return;
790
- if (dir.has(item)) {
791
- if (this.fsw._symlinkPaths.get(full) !== linkPath) {
792
- this.fsw._symlinkPaths.set(full, linkPath);
793
- this.fsw._emit(EV.CHANGE, path$1, entry.stats);
794
- }
795
- } else {
796
- dir.add(item);
797
- this.fsw._symlinkPaths.set(full, linkPath);
798
- this.fsw._emit(EV.ADD, path$1, entry.stats);
799
- }
800
- this.fsw._emitReady();
801
- return true;
802
- }
803
- if (this.fsw._symlinkPaths.has(full)) return true;
804
- this.fsw._symlinkPaths.set(full, true);
805
- }
806
- _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
807
- directory = path.join(directory, "");
808
- throttler = this.fsw._throttle("readdir", directory, 1e3);
809
- if (!throttler) return;
810
- const previous = this.fsw._getWatchedDir(wh.path);
811
- const current = /* @__PURE__ */ new Set();
812
- let stream = this.fsw._readdirp(directory, {
813
- fileFilter: (entry) => wh.filterPath(entry),
814
- directoryFilter: (entry) => wh.filterDir(entry)
815
- });
816
- if (!stream) return;
817
- stream.on(STR_DATA, async (entry) => {
818
- if (this.fsw.closed) {
819
- stream = void 0;
820
- return;
821
- }
822
- const item = entry.path;
823
- let path$1 = path.join(directory, item);
824
- current.add(item);
825
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path$1, item)) return;
826
- if (this.fsw.closed) {
827
- stream = void 0;
828
- return;
829
- }
830
- if (item === target || !target && !previous.has(item)) {
831
- this.fsw._incrReadyCount();
832
- path$1 = path.join(dir, path.relative(dir, path$1));
833
- this._addToNodeFs(path$1, initialAdd, wh, depth + 1);
834
- }
835
- }).on(EV.ERROR, this._boundHandleError);
836
- return new Promise((resolve, reject) => {
837
- if (!stream) return reject();
838
- stream.once(STR_END, () => {
839
- if (this.fsw.closed) {
840
- stream = void 0;
841
- return;
842
- }
843
- const wasThrottled = throttler ? throttler.clear() : false;
844
- resolve(void 0);
845
- previous.getChildren().filter((item) => {
846
- return item !== directory && !current.has(item);
847
- }).forEach((item) => {
848
- this.fsw._remove(directory, item);
849
- });
850
- stream = void 0;
851
- if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
852
- });
853
- });
854
- }
855
- /**
856
- * Read directory to add / remove files from `@watched` list and re-read it on change.
857
- * @param dir fs path
858
- * @param stats
859
- * @param initialAdd
860
- * @param depth relative to user-supplied path
861
- * @param target child path targeted for watch
862
- * @param wh Common watch helpers for this path
863
- * @param realpath
864
- * @returns closer for the watcher instance.
865
- */
866
- async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath$1) {
867
- const parentDir = this.fsw._getWatchedDir(path.dirname(dir));
868
- const tracked = parentDir.has(path.basename(dir));
869
- if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) this.fsw._emit(EV.ADD_DIR, dir, stats);
870
- parentDir.add(path.basename(dir));
871
- this.fsw._getWatchedDir(dir);
872
- let throttler;
873
- let closer;
874
- const oDepth = this.fsw.options.depth;
875
- if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath$1)) {
876
- if (!target) {
877
- await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
878
- if (this.fsw.closed) return;
879
- }
880
- closer = this._watchWithNodeFs(dir, (dirPath, stats$1) => {
881
- if (stats$1 && stats$1.mtimeMs === 0) return;
882
- this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
883
- });
884
- }
885
- return closer;
886
- }
887
- /**
888
- * Handle added file, directory, or glob pattern.
889
- * Delegates call to _handleFile / _handleDir after checks.
890
- * @param path to file or ir
891
- * @param initialAdd was the file added at watch instantiation?
892
- * @param priorWh depth relative to user-supplied path
893
- * @param depth Child path actually targeted for watch
894
- * @param target Child path actually targeted for watch
895
- */
896
- async _addToNodeFs(path$1, initialAdd, priorWh, depth, target) {
897
- const ready = this.fsw._emitReady;
898
- if (this.fsw._isIgnored(path$1) || this.fsw.closed) {
899
- ready();
900
- return false;
901
- }
902
- const wh = this.fsw._getWatchHelpers(path$1);
903
- if (priorWh) {
904
- wh.filterPath = (entry) => priorWh.filterPath(entry);
905
- wh.filterDir = (entry) => priorWh.filterDir(entry);
906
- }
907
- try {
908
- const stats = await statMethods[wh.statMethod](wh.watchPath);
909
- if (this.fsw.closed) return;
910
- if (this.fsw._isIgnored(wh.watchPath, stats)) {
911
- ready();
912
- return false;
913
- }
914
- const follow = this.fsw.options.followSymlinks;
915
- let closer;
916
- if (stats.isDirectory()) {
917
- const absPath = path.resolve(path$1);
918
- const targetPath = follow ? await (0, fs_promises.realpath)(path$1) : path$1;
919
- if (this.fsw.closed) return;
920
- closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
921
- if (this.fsw.closed) return;
922
- if (absPath !== targetPath && targetPath !== void 0) this.fsw._symlinkPaths.set(absPath, targetPath);
923
- } else if (stats.isSymbolicLink()) {
924
- const targetPath = follow ? await (0, fs_promises.realpath)(path$1) : path$1;
925
- if (this.fsw.closed) return;
926
- const parent = path.dirname(wh.watchPath);
927
- this.fsw._getWatchedDir(parent).add(wh.watchPath);
928
- this.fsw._emit(EV.ADD, wh.watchPath, stats);
929
- closer = await this._handleDir(parent, stats, initialAdd, depth, path$1, wh, targetPath);
930
- if (this.fsw.closed) return;
931
- if (targetPath !== void 0) this.fsw._symlinkPaths.set(path.resolve(path$1), targetPath);
932
- } else closer = this._handleFile(wh.watchPath, stats, initialAdd);
933
- ready();
934
- if (closer) this.fsw._addPathCloser(path$1, closer);
935
- return false;
936
- } catch (error) {
937
- if (this.fsw._handleError(error)) {
938
- ready();
939
- return path$1;
940
- }
941
- }
942
- }
943
- };
944
-
945
- //#endregion
946
- //#region ../../node_modules/chokidar/esm/index.js
947
- const SLASH = "/";
948
- const SLASH_SLASH = "//";
949
- const ONE_DOT = ".";
950
- const TWO_DOTS = "..";
951
- const STRING_TYPE = "string";
952
- const BACK_SLASH_RE = /\\/g;
953
- const DOUBLE_SLASH_RE = /\/\//;
954
- const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
955
- const REPLACER_RE = /^\.[/\\]/;
956
- function arrify(item) {
957
- return Array.isArray(item) ? item : [item];
958
- }
959
- const isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
960
- function createPattern(matcher) {
961
- if (typeof matcher === "function") return matcher;
962
- if (typeof matcher === "string") return (string) => matcher === string;
963
- if (matcher instanceof RegExp) return (string) => matcher.test(string);
964
- if (typeof matcher === "object" && matcher !== null) return (string) => {
965
- if (matcher.path === string) return true;
966
- if (matcher.recursive) {
967
- const relative = path.relative(matcher.path, string);
968
- if (!relative) return false;
969
- return !relative.startsWith("..") && !path.isAbsolute(relative);
970
- }
971
- return false;
972
- };
973
- return () => false;
974
- }
975
- function normalizePath(path$1) {
976
- if (typeof path$1 !== "string") throw new Error("string expected");
977
- path$1 = path.normalize(path$1);
978
- path$1 = path$1.replace(/\\/g, "/");
979
- let prepend = false;
980
- if (path$1.startsWith("//")) prepend = true;
981
- const DOUBLE_SLASH_RE$1 = /\/\//;
982
- while (path$1.match(DOUBLE_SLASH_RE$1)) path$1 = path$1.replace(DOUBLE_SLASH_RE$1, "/");
983
- if (prepend) path$1 = "/" + path$1;
984
- return path$1;
985
- }
986
- function matchPatterns(patterns, testString, stats) {
987
- const path$1 = normalizePath(testString);
988
- for (let index = 0; index < patterns.length; index++) {
989
- const pattern = patterns[index];
990
- if (pattern(path$1, stats)) return true;
991
- }
992
- return false;
993
- }
994
- function anymatch(matchers, testString) {
995
- if (matchers == null) throw new TypeError("anymatch: specify first argument");
996
- const matchersArray = arrify(matchers);
997
- const patterns = matchersArray.map((matcher) => createPattern(matcher));
998
- if (testString == null) return (testString$1, stats) => {
999
- return matchPatterns(patterns, testString$1, stats);
1000
- };
1001
- return matchPatterns(patterns, testString);
1002
- }
1003
- const unifyPaths = (paths_) => {
1004
- const paths = arrify(paths_).flat();
1005
- if (!paths.every((p) => typeof p === STRING_TYPE)) throw new TypeError(`Non-string provided as watch path: ${paths}`);
1006
- return paths.map(normalizePathToUnix);
1007
- };
1008
- const toUnix = (string) => {
1009
- let str = string.replace(BACK_SLASH_RE, SLASH);
1010
- let prepend = false;
1011
- if (str.startsWith(SLASH_SLASH)) prepend = true;
1012
- while (str.match(DOUBLE_SLASH_RE)) str = str.replace(DOUBLE_SLASH_RE, SLASH);
1013
- if (prepend) str = SLASH + str;
1014
- return str;
1015
- };
1016
- const normalizePathToUnix = (path$1) => toUnix(path.normalize(toUnix(path$1)));
1017
- const normalizeIgnored = (cwd = "") => (path$1) => {
1018
- if (typeof path$1 === "string") return normalizePathToUnix(path.isAbsolute(path$1) ? path$1 : path.join(cwd, path$1));
1019
- else return path$1;
1020
- };
1021
- const getAbsolutePath = (path$1, cwd) => {
1022
- if (path.isAbsolute(path$1)) return path$1;
1023
- return path.join(cwd, path$1);
1024
- };
1025
- const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
1026
- /**
1027
- * Directory entry.
1028
- */
1029
- var DirEntry = class {
1030
- constructor(dir, removeWatcher) {
1031
- this.path = dir;
1032
- this._removeWatcher = removeWatcher;
1033
- this.items = /* @__PURE__ */ new Set();
1034
- }
1035
- add(item) {
1036
- const { items } = this;
1037
- if (!items) return;
1038
- if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
1039
- }
1040
- async remove(item) {
1041
- const { items } = this;
1042
- if (!items) return;
1043
- items.delete(item);
1044
- if (items.size > 0) return;
1045
- const dir = this.path;
1046
- try {
1047
- await (0, fs_promises.readdir)(dir);
1048
- } catch (err) {
1049
- if (this._removeWatcher) this._removeWatcher(path.dirname(dir), path.basename(dir));
1050
- }
1051
- }
1052
- has(item) {
1053
- const { items } = this;
1054
- if (!items) return;
1055
- return items.has(item);
1056
- }
1057
- getChildren() {
1058
- const { items } = this;
1059
- if (!items) return [];
1060
- return [...items.values()];
1061
- }
1062
- dispose() {
1063
- this.items.clear();
1064
- this.path = "";
1065
- this._removeWatcher = EMPTY_FN;
1066
- this.items = EMPTY_SET;
1067
- Object.freeze(this);
1068
- }
1069
- };
1070
- const STAT_METHOD_F = "stat";
1071
- const STAT_METHOD_L = "lstat";
1072
- var WatchHelper = class {
1073
- constructor(path$1, follow, fsw) {
1074
- this.fsw = fsw;
1075
- const watchPath = path$1;
1076
- this.path = path$1 = path$1.replace(REPLACER_RE, "");
1077
- this.watchPath = watchPath;
1078
- this.fullWatchPath = path.resolve(watchPath);
1079
- this.dirParts = [];
1080
- this.dirParts.forEach((parts) => {
1081
- if (parts.length > 1) parts.pop();
1082
- });
1083
- this.followSymlinks = follow;
1084
- this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
1085
- }
1086
- entryPath(entry) {
1087
- return path.join(this.watchPath, path.relative(this.watchPath, entry.fullPath));
1088
- }
1089
- filterPath(entry) {
1090
- const { stats } = entry;
1091
- if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
1092
- const resolvedPath = this.entryPath(entry);
1093
- return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
1094
- }
1095
- filterDir(entry) {
1096
- return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
1097
- }
1098
- };
1099
- /**
1100
- * Watches files & directories for changes. Emitted events:
1101
- * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
1102
- *
1103
- * new FSWatcher()
1104
- * .add(directories)
1105
- * .on('add', path => log('File', path, 'was added'))
1106
- */
1107
- var FSWatcher = class extends events.EventEmitter {
1108
- constructor(_opts = {}) {
1109
- super();
1110
- this.closed = false;
1111
- this._closers = /* @__PURE__ */ new Map();
1112
- this._ignoredPaths = /* @__PURE__ */ new Set();
1113
- this._throttled = /* @__PURE__ */ new Map();
1114
- this._streams = /* @__PURE__ */ new Set();
1115
- this._symlinkPaths = /* @__PURE__ */ new Map();
1116
- this._watched = /* @__PURE__ */ new Map();
1117
- this._pendingWrites = /* @__PURE__ */ new Map();
1118
- this._pendingUnlinks = /* @__PURE__ */ new Map();
1119
- this._readyCount = 0;
1120
- this._readyEmitted = false;
1121
- const awf = _opts.awaitWriteFinish;
1122
- const DEF_AWF = {
1123
- stabilityThreshold: 2e3,
1124
- pollInterval: 100
1125
- };
1126
- const opts = {
1127
- persistent: true,
1128
- ignoreInitial: false,
1129
- ignorePermissionErrors: false,
1130
- interval: 100,
1131
- binaryInterval: 300,
1132
- followSymlinks: true,
1133
- usePolling: false,
1134
- atomic: true,
1135
- ..._opts,
1136
- ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
1137
- awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? {
1138
- ...DEF_AWF,
1139
- ...awf
1140
- } : false
1141
- };
1142
- if (isIBMi) opts.usePolling = true;
1143
- if (opts.atomic === void 0) opts.atomic = !opts.usePolling;
1144
- const envPoll = process.env.CHOKIDAR_USEPOLLING;
1145
- if (envPoll !== void 0) {
1146
- const envLower = envPoll.toLowerCase();
1147
- if (envLower === "false" || envLower === "0") opts.usePolling = false;
1148
- else if (envLower === "true" || envLower === "1") opts.usePolling = true;
1149
- else opts.usePolling = !!envLower;
1150
- }
1151
- const envInterval = process.env.CHOKIDAR_INTERVAL;
1152
- if (envInterval) opts.interval = Number.parseInt(envInterval, 10);
1153
- let readyCalls = 0;
1154
- this._emitReady = () => {
1155
- readyCalls++;
1156
- if (readyCalls >= this._readyCount) {
1157
- this._emitReady = EMPTY_FN;
1158
- this._readyEmitted = true;
1159
- process.nextTick(() => this.emit(EVENTS.READY));
1160
- }
1161
- };
1162
- this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
1163
- this._boundRemove = this._remove.bind(this);
1164
- this.options = opts;
1165
- this._nodeFsHandler = new NodeFsHandler(this);
1166
- Object.freeze(opts);
1167
- }
1168
- _addIgnoredPath(matcher) {
1169
- if (isMatcherObject(matcher)) {
1170
- for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
1171
- }
1172
- this._ignoredPaths.add(matcher);
1173
- }
1174
- _removeIgnoredPath(matcher) {
1175
- this._ignoredPaths.delete(matcher);
1176
- if (typeof matcher === "string") {
1177
- for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher) this._ignoredPaths.delete(ignored);
1178
- }
1179
- }
1180
- /**
1181
- * Adds paths to be watched on an existing FSWatcher instance.
1182
- * @param paths_ file or file list. Other arguments are unused
1183
- */
1184
- add(paths_, _origAdd, _internal) {
1185
- const { cwd } = this.options;
1186
- this.closed = false;
1187
- this._closePromise = void 0;
1188
- let paths = unifyPaths(paths_);
1189
- if (cwd) paths = paths.map((path$1) => {
1190
- const absPath = getAbsolutePath(path$1, cwd);
1191
- return absPath;
1192
- });
1193
- paths.forEach((path$1) => {
1194
- this._removeIgnoredPath(path$1);
1195
- });
1196
- this._userIgnored = void 0;
1197
- if (!this._readyCount) this._readyCount = 0;
1198
- this._readyCount += paths.length;
1199
- Promise.all(paths.map(async (path$1) => {
1200
- const res = await this._nodeFsHandler._addToNodeFs(path$1, !_internal, void 0, 0, _origAdd);
1201
- if (res) this._emitReady();
1202
- return res;
1203
- })).then((results) => {
1204
- if (this.closed) return;
1205
- results.forEach((item) => {
1206
- if (item) this.add(path.dirname(item), path.basename(_origAdd || item));
1207
- });
1208
- });
1209
- return this;
1210
- }
1211
- /**
1212
- * Close watchers or start ignoring events from specified paths.
1213
- */
1214
- unwatch(paths_) {
1215
- if (this.closed) return this;
1216
- const paths = unifyPaths(paths_);
1217
- const { cwd } = this.options;
1218
- paths.forEach((path$1) => {
1219
- if (!path.isAbsolute(path$1) && !this._closers.has(path$1)) {
1220
- if (cwd) path$1 = path.join(cwd, path$1);
1221
- path$1 = path.resolve(path$1);
1222
- }
1223
- this._closePath(path$1);
1224
- this._addIgnoredPath(path$1);
1225
- if (this._watched.has(path$1)) this._addIgnoredPath({
1226
- path: path$1,
1227
- recursive: true
1228
- });
1229
- this._userIgnored = void 0;
1230
- });
1231
- return this;
1232
- }
1233
- /**
1234
- * Close watchers and remove all listeners from watched paths.
1235
- */
1236
- close() {
1237
- if (this._closePromise) return this._closePromise;
1238
- this.closed = true;
1239
- this.removeAllListeners();
1240
- const closers = [];
1241
- this._closers.forEach((closerList) => closerList.forEach((closer) => {
1242
- const promise = closer();
1243
- if (promise instanceof Promise) closers.push(promise);
1244
- }));
1245
- this._streams.forEach((stream) => stream.destroy());
1246
- this._userIgnored = void 0;
1247
- this._readyCount = 0;
1248
- this._readyEmitted = false;
1249
- this._watched.forEach((dirent) => dirent.dispose());
1250
- this._closers.clear();
1251
- this._watched.clear();
1252
- this._streams.clear();
1253
- this._symlinkPaths.clear();
1254
- this._throttled.clear();
1255
- this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
1256
- return this._closePromise;
1257
- }
1258
- /**
1259
- * Expose list of watched paths
1260
- * @returns for chaining
1261
- */
1262
- getWatched() {
1263
- const watchList = {};
1264
- this._watched.forEach((entry, dir) => {
1265
- const key = this.options.cwd ? path.relative(this.options.cwd, dir) : dir;
1266
- const index = key || ONE_DOT;
1267
- watchList[index] = entry.getChildren().sort();
1268
- });
1269
- return watchList;
1270
- }
1271
- emitWithAll(event, args) {
1272
- this.emit(event, ...args);
1273
- if (event !== EVENTS.ERROR) this.emit(EVENTS.ALL, event, ...args);
1274
- }
1275
- /**
1276
- * Normalize and emit events.
1277
- * Calling _emit DOES NOT MEAN emit() would be called!
1278
- * @param event Type of event
1279
- * @param path File or directory path
1280
- * @param stats arguments to be passed with event
1281
- * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1282
- */
1283
- async _emit(event, path$1, stats) {
1284
- if (this.closed) return;
1285
- const opts = this.options;
1286
- if (isWindows) path$1 = path.normalize(path$1);
1287
- if (opts.cwd) path$1 = path.relative(opts.cwd, path$1);
1288
- const args = [path$1];
1289
- if (stats != null) args.push(stats);
1290
- const awf = opts.awaitWriteFinish;
1291
- let pw;
1292
- if (awf && (pw = this._pendingWrites.get(path$1))) {
1293
- pw.lastChange = /* @__PURE__ */ new Date();
1294
- return this;
1295
- }
1296
- if (opts.atomic) {
1297
- if (event === EVENTS.UNLINK) {
1298
- this._pendingUnlinks.set(path$1, [event, ...args]);
1299
- setTimeout(() => {
1300
- this._pendingUnlinks.forEach((entry, path$2) => {
1301
- this.emit(...entry);
1302
- this.emit(EVENTS.ALL, ...entry);
1303
- this._pendingUnlinks.delete(path$2);
1304
- });
1305
- }, typeof opts.atomic === "number" ? opts.atomic : 100);
1306
- return this;
1307
- }
1308
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path$1)) {
1309
- event = EVENTS.CHANGE;
1310
- this._pendingUnlinks.delete(path$1);
1311
- }
1312
- }
1313
- if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
1314
- const awfEmit = (err, stats$1) => {
1315
- if (err) {
1316
- event = EVENTS.ERROR;
1317
- args[0] = err;
1318
- this.emitWithAll(event, args);
1319
- } else if (stats$1) {
1320
- if (args.length > 1) args[1] = stats$1;
1321
- else args.push(stats$1);
1322
- this.emitWithAll(event, args);
1323
- }
1324
- };
1325
- this._awaitWriteFinish(path$1, awf.stabilityThreshold, event, awfEmit);
1326
- return this;
1327
- }
1328
- if (event === EVENTS.CHANGE) {
1329
- const isThrottled = !this._throttle(EVENTS.CHANGE, path$1, 50);
1330
- if (isThrottled) return this;
1331
- }
1332
- if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
1333
- const fullPath = opts.cwd ? path.join(opts.cwd, path$1) : path$1;
1334
- let stats$1;
1335
- try {
1336
- stats$1 = await (0, fs_promises.stat)(fullPath);
1337
- } catch (err) {}
1338
- if (!stats$1 || this.closed) return;
1339
- args.push(stats$1);
1340
- }
1341
- this.emitWithAll(event, args);
1342
- return this;
1343
- }
1344
- /**
1345
- * Common handler for errors
1346
- * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1347
- */
1348
- _handleError(error) {
1349
- const code = error && error.code;
1350
- if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) this.emit(EVENTS.ERROR, error);
1351
- return error || this.closed;
1352
- }
1353
- /**
1354
- * Helper utility for throttling
1355
- * @param actionType type being throttled
1356
- * @param path being acted upon
1357
- * @param timeout duration of time to suppress duplicate actions
1358
- * @returns tracking object or false if action should be suppressed
1359
- */
1360
- _throttle(actionType, path$1, timeout) {
1361
- if (!this._throttled.has(actionType)) this._throttled.set(actionType, /* @__PURE__ */ new Map());
1362
- const action = this._throttled.get(actionType);
1363
- if (!action) throw new Error("invalid throttle");
1364
- const actionPath = action.get(path$1);
1365
- if (actionPath) {
1366
- actionPath.count++;
1367
- return false;
1368
- }
1369
- let timeoutObject;
1370
- const clear = () => {
1371
- const item = action.get(path$1);
1372
- const count = item ? item.count : 0;
1373
- action.delete(path$1);
1374
- clearTimeout(timeoutObject);
1375
- if (item) clearTimeout(item.timeoutObject);
1376
- return count;
1377
- };
1378
- timeoutObject = setTimeout(clear, timeout);
1379
- const thr = {
1380
- timeoutObject,
1381
- clear,
1382
- count: 0
1383
- };
1384
- action.set(path$1, thr);
1385
- return thr;
1386
- }
1387
- _incrReadyCount() {
1388
- return this._readyCount++;
1389
- }
1390
- /**
1391
- * Awaits write operation to finish.
1392
- * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
1393
- * @param path being acted upon
1394
- * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
1395
- * @param event
1396
- * @param awfEmit Callback to be called when ready for event to be emitted.
1397
- */
1398
- _awaitWriteFinish(path$1, threshold, event, awfEmit) {
1399
- const awf = this.options.awaitWriteFinish;
1400
- if (typeof awf !== "object") return;
1401
- const pollInterval = awf.pollInterval;
1402
- let timeoutHandler;
1403
- let fullPath = path$1;
1404
- if (this.options.cwd && !path.isAbsolute(path$1)) fullPath = path.join(this.options.cwd, path$1);
1405
- const now = /* @__PURE__ */ new Date();
1406
- const writes = this._pendingWrites;
1407
- function awaitWriteFinishFn(prevStat) {
1408
- (0, fs.stat)(fullPath, (err, curStat) => {
1409
- if (err || !writes.has(path$1)) {
1410
- if (err && err.code !== "ENOENT") awfEmit(err);
1411
- return;
1412
- }
1413
- const now$1 = Number(/* @__PURE__ */ new Date());
1414
- if (prevStat && curStat.size !== prevStat.size) writes.get(path$1).lastChange = now$1;
1415
- const pw = writes.get(path$1);
1416
- const df = now$1 - pw.lastChange;
1417
- if (df >= threshold) {
1418
- writes.delete(path$1);
1419
- awfEmit(void 0, curStat);
1420
- } else timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
1421
- });
1422
- }
1423
- if (!writes.has(path$1)) {
1424
- writes.set(path$1, {
1425
- lastChange: now,
1426
- cancelWait: () => {
1427
- writes.delete(path$1);
1428
- clearTimeout(timeoutHandler);
1429
- return event;
1430
- }
1431
- });
1432
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
1433
- }
1434
- }
1435
- /**
1436
- * Determines whether user has asked to ignore this path.
1437
- */
1438
- _isIgnored(path$1, stats) {
1439
- if (this.options.atomic && DOT_RE.test(path$1)) return true;
1440
- if (!this._userIgnored) {
1441
- const { cwd } = this.options;
1442
- const ign = this.options.ignored;
1443
- const ignored = (ign || []).map(normalizeIgnored(cwd));
1444
- const ignoredPaths = [...this._ignoredPaths];
1445
- const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
1446
- this._userIgnored = anymatch(list, void 0);
1447
- }
1448
- return this._userIgnored(path$1, stats);
1449
- }
1450
- _isntIgnored(path$1, stat$3) {
1451
- return !this._isIgnored(path$1, stat$3);
1452
- }
1453
- /**
1454
- * Provides a set of common helpers and properties relating to symlink handling.
1455
- * @param path file or directory pattern being watched
1456
- */
1457
- _getWatchHelpers(path$1) {
1458
- return new WatchHelper(path$1, this.options.followSymlinks, this);
1459
- }
1460
- /**
1461
- * Provides directory tracking objects
1462
- * @param directory path of the directory
1463
- */
1464
- _getWatchedDir(directory) {
1465
- const dir = path.resolve(directory);
1466
- if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
1467
- return this._watched.get(dir);
1468
- }
1469
- /**
1470
- * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
1471
- */
1472
- _hasReadPermissions(stats) {
1473
- if (this.options.ignorePermissionErrors) return true;
1474
- return Boolean(Number(stats.mode) & 256);
1475
- }
1476
- /**
1477
- * Handles emitting unlink events for
1478
- * files and directories, and via recursion, for
1479
- * files and directories within directories that are unlinked
1480
- * @param directory within which the following item is located
1481
- * @param item base path of item/directory
1482
- */
1483
- _remove(directory, item, isDirectory) {
1484
- const path$1 = path.join(directory, item);
1485
- const fullPath = path.resolve(path$1);
1486
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path$1) || this._watched.has(fullPath);
1487
- if (!this._throttle("remove", path$1, 100)) return;
1488
- if (!isDirectory && this._watched.size === 1) this.add(directory, item, true);
1489
- const wp = this._getWatchedDir(path$1);
1490
- const nestedDirectoryChildren = wp.getChildren();
1491
- nestedDirectoryChildren.forEach((nested) => this._remove(path$1, nested));
1492
- const parent = this._getWatchedDir(directory);
1493
- const wasTracked = parent.has(item);
1494
- parent.remove(item);
1495
- if (this._symlinkPaths.has(fullPath)) this._symlinkPaths.delete(fullPath);
1496
- let relPath = path$1;
1497
- if (this.options.cwd) relPath = path.relative(this.options.cwd, path$1);
1498
- if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
1499
- const event = this._pendingWrites.get(relPath).cancelWait();
1500
- if (event === EVENTS.ADD) return;
1501
- }
1502
- this._watched.delete(path$1);
1503
- this._watched.delete(fullPath);
1504
- const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
1505
- if (wasTracked && !this._isIgnored(path$1)) this._emit(eventName, path$1);
1506
- this._closePath(path$1);
1507
- }
1508
- /**
1509
- * Closes all watchers for a path
1510
- */
1511
- _closePath(path$1) {
1512
- this._closeFile(path$1);
1513
- const dir = path.dirname(path$1);
1514
- this._getWatchedDir(dir).remove(path.basename(path$1));
1515
- }
1516
- /**
1517
- * Closes only file-specific watchers
1518
- */
1519
- _closeFile(path$1) {
1520
- const closers = this._closers.get(path$1);
1521
- if (!closers) return;
1522
- closers.forEach((closer) => closer());
1523
- this._closers.delete(path$1);
1524
- }
1525
- _addPathCloser(path$1, closer) {
1526
- if (!closer) return;
1527
- let list = this._closers.get(path$1);
1528
- if (!list) {
1529
- list = [];
1530
- this._closers.set(path$1, list);
1531
- }
1532
- list.push(closer);
1533
- }
1534
- _readdirp(root, opts) {
1535
- if (this.closed) return;
1536
- const options = {
1537
- type: EVENTS.ALL,
1538
- alwaysStat: true,
1539
- lstat: true,
1540
- ...opts,
1541
- depth: 0
1542
- };
1543
- let stream = readdirp(root, options);
1544
- this._streams.add(stream);
1545
- stream.once(STR_CLOSE, () => {
1546
- stream = void 0;
1547
- });
1548
- stream.once(STR_END, () => {
1549
- if (stream) {
1550
- this._streams.delete(stream);
1551
- stream = void 0;
1552
- }
1553
- });
1554
- return stream;
1555
- }
1556
- };
1557
- /**
1558
- * Instantiates watcher with paths to be tracked.
1559
- * @param paths file / directory paths
1560
- * @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
1561
- * @returns an instance of FSWatcher for chaining.
1562
- * @example
1563
- * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
1564
- * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
1565
- */
1566
- function watch(paths, options = {}) {
1567
- const watcher = new FSWatcher(options);
1568
- watcher.add(paths);
1569
- return watcher;
1570
- }
1571
-
1572
- //#endregion
1573
- exports.watch = watch;
1
+ const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`fs`)),n=e.__toESM(require(`path`)),r=e.__toESM(require(`fs/promises`)),i=e.__toESM(require(`events`)),a=e.__toESM(require(`node:fs/promises`)),o=e.__toESM(require(`node:stream`)),s=e.__toESM(require(`node:path`)),c=e.__toESM(require(`os`)),l={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},u={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:l.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(u);const d=`READDIRP_RECURSIVE_ERROR`,f=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,d]),p=[l.DIR_TYPE,l.EVERYTHING_TYPE,l.FILE_DIR_TYPE,l.FILE_TYPE],ee=new Set([l.DIR_TYPE,l.EVERYTHING_TYPE,l.FILE_DIR_TYPE]),m=new Set([l.EVERYTHING_TYPE,l.FILE_DIR_TYPE,l.FILE_TYPE]),te=e=>f.has(e.code),ne=process.platform===`win32`,h=e=>!0,g=e=>{if(e===void 0)return h;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return h};var _=class extends o.Readable{constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...u,...e},{root:n,type:r}=t;this._fileFilter=g(t.fileFilter),this._directoryFilter=g(t.directoryFilter);let i=t.lstat?a.lstat:a.stat;ne?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth??u.depth,this._wantsDir=r?ee.has(r):!1,this._wantsFile=r?m.has(r):!1,this._wantsEverything=r===l.EVERYTHING_TYPE,this._root=(0,s.resolve)(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await(0,a.readdir)(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=(0,s.resolve)((0,s.join)(t,r));n={path:(0,s.relative)(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){te(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await(0,a.realpath)(t),n=await(0,a.lstat)(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===s.sep){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=d,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function v(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=l.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!p.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${p.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new _(t)}const re=`data`,y=`end`,ie=`close`,b=()=>{},x=process.platform,S=x===`win32`,C=x===`darwin`,w=x===`linux`,T=x===`freebsd`,E=(0,c.type)()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,ae=`watch`,oe={lstat:r.lstat,stat:r.stat},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,se=[k,A,j],ce=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),le=e=>ce.has(n.extname(e).slice(1).toLowerCase()),M=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},N=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ue=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},P=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},F=e=>e instanceof Set?e.size===0:!e,I=new Map;function L(e,r,i,a,o){let s=(t,r)=>{i(e),o(t,r,{watchedPath:e}),r&&e!==r&&R(n.resolve(e,r),k,n.join(e,r))};try{return(0,t.watch)(e,{persistent:r.persistent},s)}catch(e){a(e);return}}const R=(e,t,n,r,i)=>{let a=I.get(e);a&&M(a[t],e=>{e(n,r,i)})},z=(e,t,n,i)=>{let{listener:a,errHandler:o,rawEmitter:s}=i,c=I.get(t),l;if(!n.persistent)return l=L(e,n,a,o,s),l?l.close.bind(l):void 0;if(c)N(c,k,a),N(c,A,o),N(c,j,s);else{if(l=L(e,n,R.bind(null,t,k),o,R.bind(null,t,j)),!l)return;l.on(O.ERROR,async n=>{let i=R.bind(null,t,A);if(c&&(c.watcherUnusable=!0),S&&n.code===`EPERM`)try{let t=await(0,r.open)(e,`r`);await t.close(),i(n)}catch{}else i(n)}),c={listeners:a,errHandlers:o,rawEmitters:s,watcher:l},I.set(t,c)}return()=>{P(c,k,a),P(c,A,o),P(c,j,s),F(c.listeners)&&(c.watcher.close(),I.delete(t),se.forEach(ue(c)),c.watcher=void 0,Object.freeze(c))}},B=new Map,V=(e,n,r,i)=>{let{listener:a,rawEmitter:o}=i,s=B.get(n),c=s&&s.options;return c&&(c.persistent<r.persistent||c.interval>r.interval)&&((0,t.unwatchFile)(n),s=void 0),s?(N(s,k,a),N(s,j,o)):(s={listeners:a,rawEmitters:o,options:r,watcher:(0,t.watchFile)(n,r,(t,r)=>{M(s.rawEmitters,e=>{e(O.CHANGE,n,{curr:t,prev:r})});let i=t.mtimeMs;(t.size!==r.size||i>r.mtimeMs||i===0)&&M(s.listeners,n=>n(e,t))})},B.set(n,s)),()=>{P(s,k,a),P(s,j,o),F(s.listeners)&&(B.delete(n),(0,t.unwatchFile)(n),s.options=s.watcher=void 0,Object.freeze(s))}};var H=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let r=this.fsw.options,i=n.dirname(e),a=n.basename(e),o=this.fsw._getWatchedDir(i);o.add(a);let s=n.resolve(e),c={persistent:r.persistent};t||=b;let l;if(r.usePolling){let n=r.interval!==r.binaryInterval;c.interval=n&&le(a)?r.binaryInterval:r.interval,l=V(e,s,c,{listener:t,rawEmitter:this.fsw._emitRaw})}else l=z(e,s,c,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(e,t,i){if(this.fsw.closed)return;let a=n.dirname(e),o=n.basename(e),s=this.fsw._getWatchedDir(a),c=t;if(s.has(o))return;let l=async(t,n)=>{if(this.fsw._throttle(ae,e,5)){if(!n||n.mtimeMs===0)try{let n=await(0,r.stat)(e);if(this.fsw.closed)return;let i=n.atimeMs,a=n.mtimeMs;if((!i||i<=a||a!==c.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(C||w||T)&&c.ino!==n.ino){this.fsw._closeFile(t),c=n;let r=this._watchWithNodeFs(e,l);r&&this.fsw._addPathCloser(t,r)}else c=n}catch{this.fsw._remove(a,o)}else if(s.has(o)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==c.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),c=n}}},u=this._watchWithNodeFs(e,l);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return u}async _handleSymlink(e,t,n,i){if(this.fsw.closed)return;let a=e.fullPath,o=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await(0,r.realpath)(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(o.has(i)?this.fsw._symlinkPaths.get(a)!==t&&(this.fsw._symlinkPaths.set(a,t),this.fsw._emit(O.CHANGE,n,e.stats)):(o.add(i),this.fsw._symlinkPaths.set(a,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(a))return!0;this.fsw._symlinkPaths.set(a,!0)}_handleRead(e,t,r,i,a,o,s){if(e=n.join(e,``),s=this.fsw._throttle(`readdir`,e,1e3),!s)return;let c=this.fsw._getWatchedDir(r.path),l=new Set,u=this.fsw._readdirp(e,{fileFilter:e=>r.filterPath(e),directoryFilter:e=>r.filterDir(e)});if(u)return u.on(re,async s=>{if(this.fsw.closed){u=void 0;return}let d=s.path,f=n.join(e,d);if(l.add(d),!(s.stats.isSymbolicLink()&&await this._handleSymlink(s,e,f,d))){if(this.fsw.closed){u=void 0;return}(d===i||!i&&!c.has(d))&&(this.fsw._incrReadyCount(),f=n.join(a,n.relative(a,f)),this._addToNodeFs(f,t,r,o+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,n)=>{if(!u)return n();u.once(y,()=>{if(this.fsw.closed){u=void 0;return}let n=s?s.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),u=void 0,n&&this._handleRead(e,!1,r,i,a,o,s)})})}async _handleDir(e,t,r,i,a,o,s){let c=this.fsw._getWatchedDir(n.dirname(e)),l=c.has(n.basename(e));!(r&&this.fsw.options.ignoreInitial)&&!a&&!l&&this.fsw._emit(O.ADD_DIR,e,t),c.add(n.basename(e)),this.fsw._getWatchedDir(e);let u,d,f=this.fsw.options.depth;if((f==null||i<=f)&&!this.fsw._symlinkPaths.has(s)){if(!a&&(await this._handleRead(e,r,o,a,e,i,u),this.fsw.closed))return;d=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,o,a,e,i,u)})}return d}async _addToNodeFs(e,t,i,a,o){let s=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return s(),!1;let c=this.fsw._getWatchHelpers(e);i&&(c.filterPath=e=>i.filterPath(e),c.filterDir=e=>i.filterDir(e));try{let i=await oe[c.statMethod](c.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(c.watchPath,i))return s(),!1;let l=this.fsw.options.followSymlinks,u;if(i.isDirectory()){let s=n.resolve(e),d=l?await(0,r.realpath)(e):e;if(this.fsw.closed||(u=await this._handleDir(c.watchPath,i,t,a,o,c,d),this.fsw.closed))return;s!==d&&d!==void 0&&this.fsw._symlinkPaths.set(s,d)}else if(i.isSymbolicLink()){let o=l?await(0,r.realpath)(e):e;if(this.fsw.closed)return;let s=n.dirname(c.watchPath);if(this.fsw._getWatchedDir(s).add(c.watchPath),this.fsw._emit(O.ADD,c.watchPath,i),u=await this._handleDir(s,i,t,a,e,c,o),this.fsw.closed)return;o!==void 0&&this.fsw._symlinkPaths.set(n.resolve(e),o)}else u=this._handleFile(c.watchPath,i,t);return s(),u&&this.fsw._addPathCloser(e,u),!1}catch(t){if(this.fsw._handleError(t))return s(),e}}};const U=`/`,de=`//`,W=`.`,fe=`..`,pe=`string`,me=/\\/g,G=/\/\//,he=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,ge=/^\.[/\\]/;function K(e){return Array.isArray(e)?e:[e]}const q=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function _e(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let r=n.relative(e.path,t);return r?!r.startsWith(`..`)&&!n.isAbsolute(r):!1}return!1}:()=>!1}function ve(e){if(typeof e!=`string`)throw Error(`string expected`);e=n.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let r=/\/\//;for(;e.match(r);)e=e.replace(r,`/`);return t&&(e=`/`+e),e}function J(e,t,n){let r=ve(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function ye(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=K(e),r=n.map(e=>_e(e));return t==null?(e,t)=>J(r,e,t):J(r,t)}const Y=e=>{let t=K(e).flat();if(!t.every(e=>typeof e===pe))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Z)},X=e=>{let t=e.replace(me,U),n=!1;for(t.startsWith(de)&&(n=!0);t.match(G);)t=t.replace(G,U);return n&&(t=U+t),t},Z=e=>X(n.normalize(X(e))),Q=(e=``)=>t=>typeof t==`string`?Z(n.isAbsolute(t)?t:n.join(e,t)):t,be=(e,t)=>n.isAbsolute(e)?e:n.join(t,e),xe=Object.freeze(new Set);var Se=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==W&&e!==fe&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let i=this.path;try{await(0,r.readdir)(i)}catch{this._removeWatcher&&this._removeWatcher(n.dirname(i),n.basename(i))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=b,this.items=xe,Object.freeze(this)}};const Ce=`stat`,$=`lstat`;var we=class{constructor(e,t,r){this.fsw=r;let i=e;this.path=e=e.replace(ge,``),this.watchPath=i,this.fullWatchPath=n.resolve(i),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Ce:$}entryPath(e){return n.join(this.watchPath,n.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Te=class extends i.EventEmitter{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?K(e.ignored):K([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};E&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=b,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new H(this),Object.freeze(r)}_addIgnoredPath(e){if(q(e)){for(let t of this._ignoredPaths)if(q(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)q(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,r){let{cwd:i}=this.options;this.closed=!1,this._closePromise=void 0;let a=Y(e);return i&&(a=a.map(e=>{let t=be(e,i);return t})),a.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=a.length,Promise.all(a.map(async e=>{let n=await this._nodeFsHandler._addToNodeFs(e,!r,void 0,0,t);return n&&this._emitReady(),n})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(n.dirname(e),n.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Y(e),{cwd:r}=this.options;return t.forEach(e=>{!n.isAbsolute(e)&&!this._closers.has(e)&&(r&&(e=n.join(r,e)),e=n.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,r)=>{let i=this.options.cwd?n.relative(this.options.cwd,r):r,a=i||W;e[a]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,i){if(this.closed)return;let a=this.options;S&&(t=n.normalize(t)),a.cwd&&(t=n.relative(a.cwd,t));let o=[t];i!=null&&o.push(i);let s=a.awaitWriteFinish,c;if(s&&(c=this._pendingWrites.get(t)))return c.lastChange=new Date,this;if(a.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...o]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof a.atomic==`number`?a.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(s&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,o[0]=t,this.emitWithAll(e,o)):n&&(o.length>1?o[1]=n:o.push(n),this.emitWithAll(e,o))};return this._awaitWriteFinish(t,s.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(a.alwaysStat&&i===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=a.cwd?n.join(a.cwd,t):t,i;try{i=await(0,r.stat)(e)}catch{}if(!i||this.closed)return;o.push(i)}return this.emitWithAll(e,o),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,r,i,a){let o=this.options.awaitWriteFinish;if(typeof o!=`object`)return;let s=o.pollInterval,c,l=e;this.options.cwd&&!n.isAbsolute(e)&&(l=n.join(this.options.cwd,e));let u=new Date,d=this._pendingWrites;function f(n){(0,t.stat)(l,(t,i)=>{if(t||!d.has(e)){t&&t.code!==`ENOENT`&&a(t);return}let o=Number(new Date);n&&i.size!==n.size&&(d.get(e).lastChange=o);let l=d.get(e),u=o-l.lastChange;u>=r?(d.delete(e),a(void 0,i)):c=setTimeout(f,s,i)})}d.has(e)||(d.set(e,{lastChange:u,cancelWait:()=>(d.delete(e),clearTimeout(c),i)}),c=setTimeout(f,s))}_isIgnored(e,t){if(this.options.atomic&&he.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map(Q(e)),r=[...this._ignoredPaths],i=[...r.map(Q(e)),...n];this._userIgnored=ye(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new we(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=n.resolve(e);return this._watched.has(t)||this._watched.set(t,new Se(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,r){let i=n.join(e,t),a=n.resolve(i);if(r??=this._watched.has(i)||this._watched.has(a),!this._throttle(`remove`,i,100))return;!r&&this._watched.size===1&&this.add(e,t,!0);let o=this._getWatchedDir(i),s=o.getChildren();s.forEach(e=>this._remove(i,e));let c=this._getWatchedDir(e),l=c.has(t);c.remove(t),this._symlinkPaths.has(a)&&this._symlinkPaths.delete(a);let u=i;if(this.options.cwd&&(u=n.relative(this.options.cwd,i)),this.options.awaitWriteFinish&&this._pendingWrites.has(u)){let e=this._pendingWrites.get(u).cancelWait();if(e===D.ADD)return}this._watched.delete(i),this._watched.delete(a);let d=r?D.UNLINK_DIR:D.UNLINK;l&&!this._isIgnored(i)&&this._emit(d,i),this._closePath(i)}_closePath(e){this._closeFile(e);let t=n.dirname(e);this._getWatchedDir(t).remove(n.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=v(e,n);return this._streams.add(r),r.once(ie,()=>{r=void 0}),r.once(y,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Ee(e,t={}){let n=new Te(t);return n.add(e),n}exports.watch=Ee;