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