@nice2dev/design-tokens 1.0.28

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