maxsimcli 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1561 +0,0 @@
1
- #!/usr/bin/env node
2
- const require_backend_server = require('./backend-server.cjs');
3
- let node_path = require("node:path");
4
- let path = require("path");
5
- path = require_backend_server.__toESM(path);
6
- let fs = require("fs");
7
- let events = require("events");
8
- let node_fs_promises = require("node:fs/promises");
9
- let os = require("os");
10
- let fs_promises = require("fs/promises");
11
- let node_stream = require("node:stream");
12
-
13
- //#region ../../node_modules/readdirp/esm/index.js
14
- const EntryTypes = {
15
- FILE_TYPE: "files",
16
- DIR_TYPE: "directories",
17
- FILE_DIR_TYPE: "files_directories",
18
- EVERYTHING_TYPE: "all"
19
- };
20
- const defaultOptions = {
21
- root: ".",
22
- fileFilter: (_entryInfo) => true,
23
- directoryFilter: (_entryInfo) => true,
24
- type: EntryTypes.FILE_TYPE,
25
- lstat: false,
26
- depth: 2147483648,
27
- alwaysStat: false,
28
- highWaterMark: 4096
29
- };
30
- Object.freeze(defaultOptions);
31
- const RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR";
32
- const NORMAL_FLOW_ERRORS = new Set([
33
- "ENOENT",
34
- "EPERM",
35
- "EACCES",
36
- "ELOOP",
37
- RECURSIVE_ERROR_CODE
38
- ]);
39
- const ALL_TYPES = [
40
- EntryTypes.DIR_TYPE,
41
- EntryTypes.EVERYTHING_TYPE,
42
- EntryTypes.FILE_DIR_TYPE,
43
- EntryTypes.FILE_TYPE
44
- ];
45
- const DIR_TYPES = new Set([
46
- EntryTypes.DIR_TYPE,
47
- EntryTypes.EVERYTHING_TYPE,
48
- EntryTypes.FILE_DIR_TYPE
49
- ]);
50
- const FILE_TYPES = new Set([
51
- EntryTypes.EVERYTHING_TYPE,
52
- EntryTypes.FILE_DIR_TYPE,
53
- EntryTypes.FILE_TYPE
54
- ]);
55
- const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
56
- const wantBigintFsStats = process.platform === "win32";
57
- const emptyFn = (_entryInfo) => true;
58
- const normalizeFilter = (filter) => {
59
- if (filter === void 0) return emptyFn;
60
- if (typeof filter === "function") return filter;
61
- if (typeof filter === "string") {
62
- const fl = filter.trim();
63
- return (entry) => entry.basename === fl;
64
- }
65
- if (Array.isArray(filter)) {
66
- const trItems = filter.map((item) => item.trim());
67
- return (entry) => trItems.some((f) => entry.basename === f);
68
- }
69
- return emptyFn;
70
- };
71
- /** Readable readdir stream, emitting new files as they're being listed. */
72
- var ReaddirpStream = class extends node_stream.Readable {
73
- constructor(options = {}) {
74
- super({
75
- objectMode: true,
76
- autoDestroy: true,
77
- highWaterMark: options.highWaterMark
78
- });
79
- const opts = {
80
- ...defaultOptions,
81
- ...options
82
- };
83
- const { root, type } = opts;
84
- this._fileFilter = normalizeFilter(opts.fileFilter);
85
- this._directoryFilter = normalizeFilter(opts.directoryFilter);
86
- const statMethod = opts.lstat ? node_fs_promises.lstat : node_fs_promises.stat;
87
- if (wantBigintFsStats) this._stat = (path) => statMethod(path, { bigint: true });
88
- else this._stat = statMethod;
89
- this._maxDepth = opts.depth ?? defaultOptions.depth;
90
- this._wantsDir = type ? DIR_TYPES.has(type) : false;
91
- this._wantsFile = type ? FILE_TYPES.has(type) : false;
92
- this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
93
- this._root = (0, node_path.resolve)(root);
94
- this._isDirent = !opts.alwaysStat;
95
- this._statsProp = this._isDirent ? "dirent" : "stats";
96
- this._rdOptions = {
97
- encoding: "utf8",
98
- withFileTypes: this._isDirent
99
- };
100
- this.parents = [this._exploreDir(root, 1)];
101
- this.reading = false;
102
- this.parent = void 0;
103
- }
104
- async _read(batch) {
105
- if (this.reading) return;
106
- this.reading = true;
107
- try {
108
- while (!this.destroyed && batch > 0) {
109
- const par = this.parent;
110
- const fil = par && par.files;
111
- if (fil && fil.length > 0) {
112
- const { path, depth } = par;
113
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
114
- const awaited = await Promise.all(slice);
115
- for (const entry of awaited) {
116
- if (!entry) continue;
117
- if (this.destroyed) return;
118
- const entryType = await this._getEntryType(entry);
119
- if (entryType === "directory" && this._directoryFilter(entry)) {
120
- if (depth <= this._maxDepth) this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
121
- if (this._wantsDir) {
122
- this.push(entry);
123
- batch--;
124
- }
125
- } else if ((entryType === "file" || this._includeAsFile(entry)) && this._fileFilter(entry)) {
126
- if (this._wantsFile) {
127
- this.push(entry);
128
- batch--;
129
- }
130
- }
131
- }
132
- } else {
133
- const parent = this.parents.pop();
134
- if (!parent) {
135
- this.push(null);
136
- break;
137
- }
138
- this.parent = await parent;
139
- if (this.destroyed) return;
140
- }
141
- }
142
- } catch (error) {
143
- this.destroy(error);
144
- } finally {
145
- this.reading = false;
146
- }
147
- }
148
- async _exploreDir(path, depth) {
149
- let files;
150
- try {
151
- files = await (0, node_fs_promises.readdir)(path, this._rdOptions);
152
- } catch (error) {
153
- this._onError(error);
154
- }
155
- return {
156
- files,
157
- depth,
158
- path
159
- };
160
- }
161
- async _formatEntry(dirent, path) {
162
- let entry;
163
- const basename = this._isDirent ? dirent.name : dirent;
164
- try {
165
- const fullPath = (0, node_path.resolve)((0, node_path.join)(path, basename));
166
- entry = {
167
- path: (0, node_path.relative)(this._root, fullPath),
168
- fullPath,
169
- basename
170
- };
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) this.emit("warn", err);
180
- else this.destroy(err);
181
- }
182
- async _getEntryType(entry) {
183
- if (!entry && this._statsProp in entry) return "";
184
- const stats = entry[this._statsProp];
185
- if (stats.isFile()) return "file";
186
- if (stats.isDirectory()) return "directory";
187
- if (stats && stats.isSymbolicLink()) {
188
- const full = entry.fullPath;
189
- try {
190
- const entryRealPath = await (0, node_fs_promises.realpath)(full);
191
- const entryRealPathStats = await (0, node_fs_promises.lstat)(entryRealPath);
192
- if (entryRealPathStats.isFile()) return "file";
193
- if (entryRealPathStats.isDirectory()) {
194
- const len = entryRealPath.length;
195
- if (full.startsWith(entryRealPath) && full.substr(len, 1) === node_path.sep) {
196
- const recursiveError = /* @__PURE__ */ new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
197
- recursiveError.code = RECURSIVE_ERROR_CODE;
198
- return this._onError(recursiveError);
199
- }
200
- return "directory";
201
- }
202
- } catch (error) {
203
- this._onError(error);
204
- return "";
205
- }
206
- }
207
- }
208
- _includeAsFile(entry) {
209
- const stats = entry && entry[this._statsProp];
210
- return stats && this._wantsEverything && !stats.isDirectory();
211
- }
212
- };
213
- /**
214
- * Streaming version: Reads all files and directories in given root recursively.
215
- * Consumes ~constant small amount of RAM.
216
- * @param root Root directory
217
- * @param options Options to specify root (start directory), filters and recursion depth
218
- */
219
- function readdirp(root, options = {}) {
220
- let type = options.entryType || options.type;
221
- if (type === "both") type = EntryTypes.FILE_DIR_TYPE;
222
- if (type) options.type = type;
223
- if (!root) throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
224
- else if (typeof root !== "string") throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
225
- else if (type && !ALL_TYPES.includes(type)) throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
226
- options.root = root;
227
- return new ReaddirpStream(options);
228
- }
229
-
230
- //#endregion
231
- //#region ../../node_modules/chokidar/esm/handler.js
232
- const STR_DATA = "data";
233
- const STR_END = "end";
234
- const STR_CLOSE = "close";
235
- const EMPTY_FN = () => {};
236
- const pl = process.platform;
237
- const isWindows = pl === "win32";
238
- const isMacos = pl === "darwin";
239
- const isLinux = pl === "linux";
240
- const isFreeBSD = pl === "freebsd";
241
- const isIBMi = (0, os.type)() === "OS400";
242
- const EVENTS = {
243
- ALL: "all",
244
- READY: "ready",
245
- ADD: "add",
246
- CHANGE: "change",
247
- ADD_DIR: "addDir",
248
- UNLINK: "unlink",
249
- UNLINK_DIR: "unlinkDir",
250
- RAW: "raw",
251
- ERROR: "error"
252
- };
253
- const EV = EVENTS;
254
- const THROTTLE_MODE_WATCH = "watch";
255
- const statMethods = {
256
- lstat: fs_promises.lstat,
257
- stat: fs_promises.stat
258
- };
259
- const KEY_LISTENERS = "listeners";
260
- const KEY_ERR = "errHandlers";
261
- const KEY_RAW = "rawEmitters";
262
- const HANDLER_KEYS = [
263
- KEY_LISTENERS,
264
- KEY_ERR,
265
- KEY_RAW
266
- ];
267
- const binaryExtensions = 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
- const isBinaryPath = (filePath) => binaryExtensions.has(path.extname(filePath).slice(1).toLowerCase());
531
- const foreach = (val, fn) => {
532
- if (val instanceof Set) val.forEach(fn);
533
- else fn(val);
534
- };
535
- const addAndConvert = (main, prop, item) => {
536
- let container = main[prop];
537
- if (!(container instanceof Set)) main[prop] = container = new Set([container]);
538
- container.add(item);
539
- };
540
- const clearItem = (cont) => (key) => {
541
- const set = cont[key];
542
- if (set instanceof Set) set.clear();
543
- else delete cont[key];
544
- };
545
- const delFromSet = (main, prop, item) => {
546
- const container = main[prop];
547
- if (container instanceof Set) container.delete(item);
548
- else if (container === item) delete main[prop];
549
- };
550
- const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
551
- const FsWatchInstances = /* @__PURE__ */ new Map();
552
- /**
553
- * Instantiates the fs_watch interface
554
- * @param path to be watched
555
- * @param options to be passed to fs_watch
556
- * @param listener main event handler
557
- * @param errHandler emits info about errors
558
- * @param emitRaw emits raw event data
559
- * @returns {NativeFsWatcher}
560
- */
561
- function createFsWatchInstance(path$22, options, listener, errHandler, emitRaw) {
562
- const handleEvent = (rawEvent, evPath) => {
563
- listener(path$22);
564
- emitRaw(rawEvent, evPath, { watchedPath: path$22 });
565
- if (evPath && path$22 !== evPath) fsWatchBroadcast(path.resolve(path$22, evPath), KEY_LISTENERS, path.join(path$22, evPath));
566
- };
567
- try {
568
- return (0, fs.watch)(path$22, { persistent: options.persistent }, handleEvent);
569
- } catch (error) {
570
- errHandler(error);
571
- return;
572
- }
573
- }
574
- /**
575
- * Helper for passing fs_watch event data to a collection of listeners
576
- * @param fullPath absolute path bound to fs_watch instance
577
- */
578
- const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
579
- const cont = FsWatchInstances.get(fullPath);
580
- if (!cont) return;
581
- foreach(cont[listenerType], (listener) => {
582
- listener(val1, val2, val3);
583
- });
584
- };
585
- /**
586
- * Instantiates the fs_watch interface or binds listeners
587
- * to an existing one covering the same file system entry
588
- * @param path
589
- * @param fullPath absolute path
590
- * @param options to be passed to fs_watch
591
- * @param handlers container for event listener functions
592
- */
593
- const setFsWatchListener = (path$26, fullPath, options, handlers) => {
594
- const { listener, errHandler, rawEmitter } = handlers;
595
- let cont = FsWatchInstances.get(fullPath);
596
- let watcher;
597
- if (!options.persistent) {
598
- watcher = createFsWatchInstance(path$26, options, listener, errHandler, rawEmitter);
599
- if (!watcher) return;
600
- return watcher.close.bind(watcher);
601
- }
602
- if (cont) {
603
- addAndConvert(cont, KEY_LISTENERS, listener);
604
- addAndConvert(cont, KEY_ERR, errHandler);
605
- addAndConvert(cont, KEY_RAW, rawEmitter);
606
- } else {
607
- watcher = createFsWatchInstance(path$26, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
608
- if (!watcher) return;
609
- watcher.on(EV.ERROR, async (error) => {
610
- const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
611
- if (cont) cont.watcherUnusable = true;
612
- if (isWindows && error.code === "EPERM") try {
613
- await (await (0, fs_promises.open)(path$26, "r")).close();
614
- broadcastErr(error);
615
- } catch (err) {}
616
- else broadcastErr(error);
617
- });
618
- cont = {
619
- listeners: listener,
620
- errHandlers: errHandler,
621
- rawEmitters: rawEmitter,
622
- watcher
623
- };
624
- FsWatchInstances.set(fullPath, cont);
625
- }
626
- return () => {
627
- delFromSet(cont, KEY_LISTENERS, listener);
628
- delFromSet(cont, KEY_ERR, errHandler);
629
- delFromSet(cont, KEY_RAW, rawEmitter);
630
- if (isEmptySet(cont.listeners)) {
631
- cont.watcher.close();
632
- FsWatchInstances.delete(fullPath);
633
- HANDLER_KEYS.forEach(clearItem(cont));
634
- cont.watcher = void 0;
635
- Object.freeze(cont);
636
- }
637
- };
638
- };
639
- const FsWatchFileInstances = /* @__PURE__ */ new Map();
640
- /**
641
- * Instantiates the fs_watchFile interface or binds listeners
642
- * to an existing one covering the same file system entry
643
- * @param path to be watched
644
- * @param fullPath absolute path
645
- * @param options options to be passed to fs_watchFile
646
- * @param handlers container for event listener functions
647
- * @returns closer
648
- */
649
- const setFsWatchFileListener = (path$27, fullPath, options, handlers) => {
650
- const { listener, rawEmitter } = handlers;
651
- let cont = FsWatchFileInstances.get(fullPath);
652
- const copts = cont && cont.options;
653
- if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
654
- (0, fs.unwatchFile)(fullPath);
655
- cont = void 0;
656
- }
657
- if (cont) {
658
- addAndConvert(cont, KEY_LISTENERS, listener);
659
- addAndConvert(cont, KEY_RAW, rawEmitter);
660
- } else {
661
- cont = {
662
- listeners: listener,
663
- rawEmitters: rawEmitter,
664
- options,
665
- watcher: (0, fs.watchFile)(fullPath, options, (curr, prev) => {
666
- foreach(cont.rawEmitters, (rawEmitter) => {
667
- rawEmitter(EV.CHANGE, fullPath, {
668
- curr,
669
- prev
670
- });
671
- });
672
- const currmtime = curr.mtimeMs;
673
- if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener) => listener(path$27, curr));
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
- (0, fs.unwatchFile)(fullPath);
684
- cont.options = cont.watcher = void 0;
685
- Object.freeze(cont);
686
- }
687
- };
688
- };
689
- /**
690
- * @mixin
691
- */
692
- var NodeFsHandler = class {
693
- constructor(fsW) {
694
- this.fsw = fsW;
695
- this._boundHandleError = (error) => fsW._handleError(error);
696
- }
697
- /**
698
- * Watch file for changes with fs_watchFile or fs_watch.
699
- * @param path to file or dir
700
- * @param listener on fs change
701
- * @returns closer for the watcher instance
702
- */
703
- _watchWithNodeFs(path$23, listener) {
704
- const opts = this.fsw.options;
705
- const directory = path.dirname(path$23);
706
- const basename = path.basename(path$23);
707
- this.fsw._getWatchedDir(directory).add(basename);
708
- const absolutePath = path.resolve(path$23);
709
- const options = { persistent: opts.persistent };
710
- if (!listener) listener = EMPTY_FN;
711
- let closer;
712
- if (opts.usePolling) {
713
- options.interval = opts.interval !== opts.binaryInterval && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
714
- closer = setFsWatchFileListener(path$23, absolutePath, options, {
715
- listener,
716
- rawEmitter: this.fsw._emitRaw
717
- });
718
- } else closer = setFsWatchListener(path$23, absolutePath, options, {
719
- listener,
720
- errHandler: this._boundHandleError,
721
- rawEmitter: this.fsw._emitRaw
722
- });
723
- return closer;
724
- }
725
- /**
726
- * Watch a file and emit add event if warranted.
727
- * @returns closer for the watcher instance
728
- */
729
- _handleFile(file, stats, initialAdd) {
730
- if (this.fsw.closed) return;
731
- const dirname = path.dirname(file);
732
- const basename = path.basename(file);
733
- const parent = this.fsw._getWatchedDir(dirname);
734
- let prevStats = stats;
735
- if (parent.has(basename)) return;
736
- const listener = async (path$28, newStats) => {
737
- if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
738
- if (!newStats || newStats.mtimeMs === 0) try {
739
- const newStats = await (0, fs_promises.stat)(file);
740
- if (this.fsw.closed) return;
741
- const at = newStats.atimeMs;
742
- const mt = newStats.mtimeMs;
743
- if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
744
- if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
745
- this.fsw._closeFile(path$28);
746
- prevStats = newStats;
747
- const closer = this._watchWithNodeFs(file, listener);
748
- if (closer) this.fsw._addPathCloser(path$28, closer);
749
- } else prevStats = newStats;
750
- } catch (error) {
751
- this.fsw._remove(dirname, basename);
752
- }
753
- else if (parent.has(basename)) {
754
- const at = newStats.atimeMs;
755
- const mt = newStats.mtimeMs;
756
- if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
757
- prevStats = newStats;
758
- }
759
- };
760
- const closer = this._watchWithNodeFs(file, listener);
761
- if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
762
- if (!this.fsw._throttle(EV.ADD, file, 0)) return;
763
- this.fsw._emit(EV.ADD, file, stats);
764
- }
765
- return closer;
766
- }
767
- /**
768
- * Handle symlinks encountered while reading a dir.
769
- * @param entry returned by readdirp
770
- * @param directory path of dir being read
771
- * @param path of this item
772
- * @param item basename of this item
773
- * @returns true if no more processing is needed for this entry.
774
- */
775
- async _handleSymlink(entry, directory, path$29, item) {
776
- if (this.fsw.closed) return;
777
- const full = entry.fullPath;
778
- const dir = this.fsw._getWatchedDir(directory);
779
- if (!this.fsw.options.followSymlinks) {
780
- this.fsw._incrReadyCount();
781
- let linkPath;
782
- try {
783
- linkPath = await (0, fs_promises.realpath)(path$29);
784
- } catch (e) {
785
- this.fsw._emitReady();
786
- return true;
787
- }
788
- if (this.fsw.closed) return;
789
- if (dir.has(item)) {
790
- if (this.fsw._symlinkPaths.get(full) !== linkPath) {
791
- this.fsw._symlinkPaths.set(full, linkPath);
792
- this.fsw._emit(EV.CHANGE, path$29, entry.stats);
793
- }
794
- } else {
795
- dir.add(item);
796
- this.fsw._symlinkPaths.set(full, linkPath);
797
- this.fsw._emit(EV.ADD, path$29, entry.stats);
798
- }
799
- this.fsw._emitReady();
800
- return true;
801
- }
802
- if (this.fsw._symlinkPaths.has(full)) return true;
803
- this.fsw._symlinkPaths.set(full, true);
804
- }
805
- _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
806
- directory = path.join(directory, "");
807
- throttler = this.fsw._throttle("readdir", directory, 1e3);
808
- if (!throttler) return;
809
- const previous = this.fsw._getWatchedDir(wh.path);
810
- const current = /* @__PURE__ */ new Set();
811
- let stream = this.fsw._readdirp(directory, {
812
- fileFilter: (entry) => wh.filterPath(entry),
813
- directoryFilter: (entry) => wh.filterDir(entry)
814
- });
815
- if (!stream) return;
816
- stream.on(STR_DATA, async (entry) => {
817
- if (this.fsw.closed) {
818
- stream = void 0;
819
- return;
820
- }
821
- const item = entry.path;
822
- let path$24 = path.join(directory, item);
823
- current.add(item);
824
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path$24, item)) return;
825
- if (this.fsw.closed) {
826
- stream = void 0;
827
- return;
828
- }
829
- if (item === target || !target && !previous.has(item)) {
830
- this.fsw._incrReadyCount();
831
- path$24 = path.join(dir, path.relative(dir, path$24));
832
- this._addToNodeFs(path$24, initialAdd, wh, depth + 1);
833
- }
834
- }).on(EV.ERROR, this._boundHandleError);
835
- return new Promise((resolve, reject) => {
836
- if (!stream) return reject();
837
- stream.once(STR_END, () => {
838
- if (this.fsw.closed) {
839
- stream = void 0;
840
- return;
841
- }
842
- const wasThrottled = throttler ? throttler.clear() : false;
843
- resolve(void 0);
844
- previous.getChildren().filter((item) => {
845
- return item !== directory && !current.has(item);
846
- }).forEach((item) => {
847
- this.fsw._remove(directory, item);
848
- });
849
- stream = void 0;
850
- if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
851
- });
852
- });
853
- }
854
- /**
855
- * Read directory to add / remove files from `@watched` list and re-read it on change.
856
- * @param dir fs path
857
- * @param stats
858
- * @param initialAdd
859
- * @param depth relative to user-supplied path
860
- * @param target child path targeted for watch
861
- * @param wh Common watch helpers for this path
862
- * @param realpath
863
- * @returns closer for the watcher instance.
864
- */
865
- async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
866
- const parentDir = this.fsw._getWatchedDir(path.dirname(dir));
867
- const tracked = parentDir.has(path.basename(dir));
868
- if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) this.fsw._emit(EV.ADD_DIR, dir, stats);
869
- parentDir.add(path.basename(dir));
870
- this.fsw._getWatchedDir(dir);
871
- let throttler;
872
- let closer;
873
- const oDepth = this.fsw.options.depth;
874
- if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
875
- if (!target) {
876
- await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
877
- if (this.fsw.closed) return;
878
- }
879
- closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
880
- if (stats && stats.mtimeMs === 0) return;
881
- this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
882
- });
883
- }
884
- return closer;
885
- }
886
- /**
887
- * Handle added file, directory, or glob pattern.
888
- * Delegates call to _handleFile / _handleDir after checks.
889
- * @param path to file or ir
890
- * @param initialAdd was the file added at watch instantiation?
891
- * @param priorWh depth relative to user-supplied path
892
- * @param depth Child path actually targeted for watch
893
- * @param target Child path actually targeted for watch
894
- */
895
- async _addToNodeFs(path$25, initialAdd, priorWh, depth, target) {
896
- const ready = this.fsw._emitReady;
897
- if (this.fsw._isIgnored(path$25) || this.fsw.closed) {
898
- ready();
899
- return false;
900
- }
901
- const wh = this.fsw._getWatchHelpers(path$25);
902
- if (priorWh) {
903
- wh.filterPath = (entry) => priorWh.filterPath(entry);
904
- wh.filterDir = (entry) => priorWh.filterDir(entry);
905
- }
906
- try {
907
- const stats = await statMethods[wh.statMethod](wh.watchPath);
908
- if (this.fsw.closed) return;
909
- if (this.fsw._isIgnored(wh.watchPath, stats)) {
910
- ready();
911
- return false;
912
- }
913
- const follow = this.fsw.options.followSymlinks;
914
- let closer;
915
- if (stats.isDirectory()) {
916
- const absPath = path.resolve(path$25);
917
- const targetPath = follow ? await (0, fs_promises.realpath)(path$25) : path$25;
918
- if (this.fsw.closed) return;
919
- closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
920
- if (this.fsw.closed) return;
921
- if (absPath !== targetPath && targetPath !== void 0) this.fsw._symlinkPaths.set(absPath, targetPath);
922
- } else if (stats.isSymbolicLink()) {
923
- const targetPath = follow ? await (0, fs_promises.realpath)(path$25) : path$25;
924
- if (this.fsw.closed) return;
925
- const parent = path.dirname(wh.watchPath);
926
- this.fsw._getWatchedDir(parent).add(wh.watchPath);
927
- this.fsw._emit(EV.ADD, wh.watchPath, stats);
928
- closer = await this._handleDir(parent, stats, initialAdd, depth, path$25, wh, targetPath);
929
- if (this.fsw.closed) return;
930
- if (targetPath !== void 0) this.fsw._symlinkPaths.set(path.resolve(path$25), targetPath);
931
- } else closer = this._handleFile(wh.watchPath, stats, initialAdd);
932
- ready();
933
- if (closer) this.fsw._addPathCloser(path$25, closer);
934
- return false;
935
- } catch (error) {
936
- if (this.fsw._handleError(error)) {
937
- ready();
938
- return path$25;
939
- }
940
- }
941
- }
942
- };
943
-
944
- //#endregion
945
- //#region ../../node_modules/chokidar/esm/index.js
946
- /*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
947
- const SLASH = "/";
948
- const SLASH_SLASH = "//";
949
- const ONE_DOT = ".";
950
- const TWO_DOTS = "..";
951
- const STRING_TYPE = "string";
952
- const BACK_SLASH_RE = /\\/g;
953
- const DOUBLE_SLASH_RE = /\/\//;
954
- const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
955
- const REPLACER_RE = /^\.[/\\]/;
956
- function arrify(item) {
957
- return Array.isArray(item) ? item : [item];
958
- }
959
- const isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
960
- function createPattern(matcher) {
961
- if (typeof matcher === "function") return matcher;
962
- if (typeof matcher === "string") return (string) => matcher === string;
963
- if (matcher instanceof RegExp) return (string) => matcher.test(string);
964
- if (typeof matcher === "object" && matcher !== null) return (string) => {
965
- if (matcher.path === string) return true;
966
- if (matcher.recursive) {
967
- const relative = path.relative(matcher.path, string);
968
- if (!relative) return false;
969
- return !relative.startsWith("..") && !path.isAbsolute(relative);
970
- }
971
- return false;
972
- };
973
- return () => false;
974
- }
975
- function normalizePath(path$1) {
976
- if (typeof path$1 !== "string") throw new Error("string expected");
977
- path$1 = path.normalize(path$1);
978
- path$1 = path$1.replace(/\\/g, "/");
979
- let prepend = false;
980
- if (path$1.startsWith("//")) prepend = true;
981
- const DOUBLE_SLASH_RE = /\/\//;
982
- while (path$1.match(DOUBLE_SLASH_RE)) path$1 = path$1.replace(DOUBLE_SLASH_RE, "/");
983
- if (prepend) path$1 = "/" + path$1;
984
- return path$1;
985
- }
986
- function matchPatterns(patterns, testString, stats) {
987
- const path$11 = normalizePath(testString);
988
- for (let index = 0; index < patterns.length; index++) {
989
- const pattern = patterns[index];
990
- if (pattern(path$11, stats)) return true;
991
- }
992
- return false;
993
- }
994
- function anymatch(matchers, testString) {
995
- if (matchers == null) throw new TypeError("anymatch: specify first argument");
996
- const patterns = arrify(matchers).map((matcher) => createPattern(matcher));
997
- if (testString == null) return (testString, stats) => {
998
- return matchPatterns(patterns, testString, stats);
999
- };
1000
- return matchPatterns(patterns, testString);
1001
- }
1002
- const unifyPaths = (paths_) => {
1003
- const paths = arrify(paths_).flat();
1004
- if (!paths.every((p) => typeof p === STRING_TYPE)) throw new TypeError(`Non-string provided as watch path: ${paths}`);
1005
- return paths.map(normalizePathToUnix);
1006
- };
1007
- const toUnix = (string) => {
1008
- let str = string.replace(BACK_SLASH_RE, SLASH);
1009
- let prepend = false;
1010
- if (str.startsWith(SLASH_SLASH)) prepend = true;
1011
- while (str.match(DOUBLE_SLASH_RE)) str = str.replace(DOUBLE_SLASH_RE, SLASH);
1012
- if (prepend) str = SLASH + str;
1013
- return str;
1014
- };
1015
- const normalizePathToUnix = (path$2) => toUnix(path.normalize(toUnix(path$2)));
1016
- const normalizeIgnored = (cwd = "") => (path$3) => {
1017
- if (typeof path$3 === "string") return normalizePathToUnix(path.isAbsolute(path$3) ? path$3 : path.join(cwd, path$3));
1018
- else return path$3;
1019
- };
1020
- const getAbsolutePath = (path$4, cwd) => {
1021
- if (path.isAbsolute(path$4)) return path$4;
1022
- return path.join(cwd, path$4);
1023
- };
1024
- const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
1025
- /**
1026
- * Directory entry.
1027
- */
1028
- var DirEntry = class {
1029
- constructor(dir, removeWatcher) {
1030
- this.path = dir;
1031
- this._removeWatcher = removeWatcher;
1032
- this.items = /* @__PURE__ */ new Set();
1033
- }
1034
- add(item) {
1035
- const { items } = this;
1036
- if (!items) return;
1037
- if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
1038
- }
1039
- async remove(item) {
1040
- const { items } = this;
1041
- if (!items) return;
1042
- items.delete(item);
1043
- if (items.size > 0) return;
1044
- const dir = this.path;
1045
- try {
1046
- await (0, fs_promises.readdir)(dir);
1047
- } catch (err) {
1048
- if (this._removeWatcher) this._removeWatcher(path.dirname(dir), path.basename(dir));
1049
- }
1050
- }
1051
- has(item) {
1052
- const { items } = this;
1053
- if (!items) return;
1054
- return items.has(item);
1055
- }
1056
- getChildren() {
1057
- const { items } = this;
1058
- if (!items) return [];
1059
- return [...items.values()];
1060
- }
1061
- dispose() {
1062
- this.items.clear();
1063
- this.path = "";
1064
- this._removeWatcher = EMPTY_FN;
1065
- this.items = EMPTY_SET;
1066
- Object.freeze(this);
1067
- }
1068
- };
1069
- const STAT_METHOD_F = "stat";
1070
- const STAT_METHOD_L = "lstat";
1071
- var WatchHelper = class {
1072
- constructor(path$5, follow, fsw) {
1073
- this.fsw = fsw;
1074
- const watchPath = path$5;
1075
- this.path = path$5 = path$5.replace(REPLACER_RE, "");
1076
- this.watchPath = watchPath;
1077
- this.fullWatchPath = path.resolve(watchPath);
1078
- this.dirParts = [];
1079
- this.dirParts.forEach((parts) => {
1080
- if (parts.length > 1) parts.pop();
1081
- });
1082
- this.followSymlinks = follow;
1083
- this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
1084
- }
1085
- entryPath(entry) {
1086
- return path.join(this.watchPath, path.relative(this.watchPath, entry.fullPath));
1087
- }
1088
- filterPath(entry) {
1089
- const { stats } = entry;
1090
- if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
1091
- const resolvedPath = this.entryPath(entry);
1092
- return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
1093
- }
1094
- filterDir(entry) {
1095
- return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
1096
- }
1097
- };
1098
- /**
1099
- * Watches files & directories for changes. Emitted events:
1100
- * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
1101
- *
1102
- * new FSWatcher()
1103
- * .add(directories)
1104
- * .on('add', path => log('File', path, 'was added'))
1105
- */
1106
- var FSWatcher = class extends events.EventEmitter {
1107
- constructor(_opts = {}) {
1108
- super();
1109
- this.closed = false;
1110
- this._closers = /* @__PURE__ */ new Map();
1111
- this._ignoredPaths = /* @__PURE__ */ new Set();
1112
- this._throttled = /* @__PURE__ */ new Map();
1113
- this._streams = /* @__PURE__ */ new Set();
1114
- this._symlinkPaths = /* @__PURE__ */ new Map();
1115
- this._watched = /* @__PURE__ */ new Map();
1116
- this._pendingWrites = /* @__PURE__ */ new Map();
1117
- this._pendingUnlinks = /* @__PURE__ */ new Map();
1118
- this._readyCount = 0;
1119
- this._readyEmitted = false;
1120
- const awf = _opts.awaitWriteFinish;
1121
- const DEF_AWF = {
1122
- stabilityThreshold: 2e3,
1123
- pollInterval: 100
1124
- };
1125
- const opts = {
1126
- persistent: true,
1127
- ignoreInitial: false,
1128
- ignorePermissionErrors: false,
1129
- interval: 100,
1130
- binaryInterval: 300,
1131
- followSymlinks: true,
1132
- usePolling: false,
1133
- atomic: true,
1134
- ..._opts,
1135
- ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
1136
- awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? {
1137
- ...DEF_AWF,
1138
- ...awf
1139
- } : false
1140
- };
1141
- if (isIBMi) opts.usePolling = true;
1142
- if (opts.atomic === void 0) opts.atomic = !opts.usePolling;
1143
- const envPoll = process.env.CHOKIDAR_USEPOLLING;
1144
- if (envPoll !== void 0) {
1145
- const envLower = envPoll.toLowerCase();
1146
- if (envLower === "false" || envLower === "0") opts.usePolling = false;
1147
- else if (envLower === "true" || envLower === "1") opts.usePolling = true;
1148
- else opts.usePolling = !!envLower;
1149
- }
1150
- const envInterval = process.env.CHOKIDAR_INTERVAL;
1151
- if (envInterval) opts.interval = Number.parseInt(envInterval, 10);
1152
- let readyCalls = 0;
1153
- this._emitReady = () => {
1154
- readyCalls++;
1155
- if (readyCalls >= this._readyCount) {
1156
- this._emitReady = EMPTY_FN;
1157
- this._readyEmitted = true;
1158
- process.nextTick(() => this.emit(EVENTS.READY));
1159
- }
1160
- };
1161
- this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
1162
- this._boundRemove = this._remove.bind(this);
1163
- this.options = opts;
1164
- this._nodeFsHandler = new NodeFsHandler(this);
1165
- Object.freeze(opts);
1166
- }
1167
- _addIgnoredPath(matcher) {
1168
- if (isMatcherObject(matcher)) {
1169
- for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
1170
- }
1171
- this._ignoredPaths.add(matcher);
1172
- }
1173
- _removeIgnoredPath(matcher) {
1174
- this._ignoredPaths.delete(matcher);
1175
- if (typeof matcher === "string") {
1176
- for (const ignored of this._ignoredPaths) if (isMatcherObject(ignored) && ignored.path === matcher) this._ignoredPaths.delete(ignored);
1177
- }
1178
- }
1179
- /**
1180
- * Adds paths to be watched on an existing FSWatcher instance.
1181
- * @param paths_ file or file list. Other arguments are unused
1182
- */
1183
- add(paths_, _origAdd, _internal) {
1184
- const { cwd } = this.options;
1185
- this.closed = false;
1186
- this._closePromise = void 0;
1187
- let paths = unifyPaths(paths_);
1188
- if (cwd) paths = paths.map((path$12) => {
1189
- return getAbsolutePath(path$12, cwd);
1190
- });
1191
- paths.forEach((path$13) => {
1192
- this._removeIgnoredPath(path$13);
1193
- });
1194
- this._userIgnored = void 0;
1195
- if (!this._readyCount) this._readyCount = 0;
1196
- this._readyCount += paths.length;
1197
- Promise.all(paths.map(async (path$14) => {
1198
- const res = await this._nodeFsHandler._addToNodeFs(path$14, !_internal, void 0, 0, _origAdd);
1199
- if (res) this._emitReady();
1200
- return res;
1201
- })).then((results) => {
1202
- if (this.closed) return;
1203
- results.forEach((item) => {
1204
- if (item) this.add(path.dirname(item), path.basename(_origAdd || item));
1205
- });
1206
- });
1207
- return this;
1208
- }
1209
- /**
1210
- * Close watchers or start ignoring events from specified paths.
1211
- */
1212
- unwatch(paths_) {
1213
- if (this.closed) return this;
1214
- const paths = unifyPaths(paths_);
1215
- const { cwd } = this.options;
1216
- paths.forEach((path$6) => {
1217
- if (!path.isAbsolute(path$6) && !this._closers.has(path$6)) {
1218
- if (cwd) path$6 = path.join(cwd, path$6);
1219
- path$6 = path.resolve(path$6);
1220
- }
1221
- this._closePath(path$6);
1222
- this._addIgnoredPath(path$6);
1223
- if (this._watched.has(path$6)) this._addIgnoredPath({
1224
- path: path$6,
1225
- recursive: true
1226
- });
1227
- this._userIgnored = void 0;
1228
- });
1229
- return this;
1230
- }
1231
- /**
1232
- * Close watchers and remove all listeners from watched paths.
1233
- */
1234
- close() {
1235
- if (this._closePromise) return this._closePromise;
1236
- this.closed = true;
1237
- this.removeAllListeners();
1238
- const closers = [];
1239
- this._closers.forEach((closerList) => closerList.forEach((closer) => {
1240
- const promise = closer();
1241
- if (promise instanceof Promise) closers.push(promise);
1242
- }));
1243
- this._streams.forEach((stream) => stream.destroy());
1244
- this._userIgnored = void 0;
1245
- this._readyCount = 0;
1246
- this._readyEmitted = false;
1247
- this._watched.forEach((dirent) => dirent.dispose());
1248
- this._closers.clear();
1249
- this._watched.clear();
1250
- this._streams.clear();
1251
- this._symlinkPaths.clear();
1252
- this._throttled.clear();
1253
- this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
1254
- return this._closePromise;
1255
- }
1256
- /**
1257
- * Expose list of watched paths
1258
- * @returns for chaining
1259
- */
1260
- getWatched() {
1261
- const watchList = {};
1262
- this._watched.forEach((entry, dir) => {
1263
- const index = (this.options.cwd ? path.relative(this.options.cwd, dir) : dir) || ONE_DOT;
1264
- watchList[index] = entry.getChildren().sort();
1265
- });
1266
- return watchList;
1267
- }
1268
- emitWithAll(event, args) {
1269
- this.emit(event, ...args);
1270
- if (event !== EVENTS.ERROR) this.emit(EVENTS.ALL, event, ...args);
1271
- }
1272
- /**
1273
- * Normalize and emit events.
1274
- * Calling _emit DOES NOT MEAN emit() would be called!
1275
- * @param event Type of event
1276
- * @param path File or directory path
1277
- * @param stats arguments to be passed with event
1278
- * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1279
- */
1280
- async _emit(event, path$7, stats) {
1281
- if (this.closed) return;
1282
- const opts = this.options;
1283
- if (isWindows) path$7 = path.normalize(path$7);
1284
- if (opts.cwd) path$7 = path.relative(opts.cwd, path$7);
1285
- const args = [path$7];
1286
- if (stats != null) args.push(stats);
1287
- const awf = opts.awaitWriteFinish;
1288
- let pw;
1289
- if (awf && (pw = this._pendingWrites.get(path$7))) {
1290
- pw.lastChange = /* @__PURE__ */ new Date();
1291
- return this;
1292
- }
1293
- if (opts.atomic) {
1294
- if (event === EVENTS.UNLINK) {
1295
- this._pendingUnlinks.set(path$7, [event, ...args]);
1296
- setTimeout(() => {
1297
- this._pendingUnlinks.forEach((entry, path$15) => {
1298
- this.emit(...entry);
1299
- this.emit(EVENTS.ALL, ...entry);
1300
- this._pendingUnlinks.delete(path$15);
1301
- });
1302
- }, typeof opts.atomic === "number" ? opts.atomic : 100);
1303
- return this;
1304
- }
1305
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path$7)) {
1306
- event = EVENTS.CHANGE;
1307
- this._pendingUnlinks.delete(path$7);
1308
- }
1309
- }
1310
- if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
1311
- const awfEmit = (err, stats) => {
1312
- if (err) {
1313
- event = EVENTS.ERROR;
1314
- args[0] = err;
1315
- this.emitWithAll(event, args);
1316
- } else if (stats) {
1317
- if (args.length > 1) args[1] = stats;
1318
- else args.push(stats);
1319
- this.emitWithAll(event, args);
1320
- }
1321
- };
1322
- this._awaitWriteFinish(path$7, awf.stabilityThreshold, event, awfEmit);
1323
- return this;
1324
- }
1325
- if (event === EVENTS.CHANGE) {
1326
- if (!this._throttle(EVENTS.CHANGE, path$7, 50)) return this;
1327
- }
1328
- if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
1329
- const fullPath = opts.cwd ? path.join(opts.cwd, path$7) : path$7;
1330
- let stats;
1331
- try {
1332
- stats = await (0, fs_promises.stat)(fullPath);
1333
- } catch (err) {}
1334
- if (!stats || this.closed) return;
1335
- args.push(stats);
1336
- }
1337
- this.emitWithAll(event, args);
1338
- return this;
1339
- }
1340
- /**
1341
- * Common handler for errors
1342
- * @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
1343
- */
1344
- _handleError(error) {
1345
- const code = error && error.code;
1346
- if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) this.emit(EVENTS.ERROR, error);
1347
- return error || this.closed;
1348
- }
1349
- /**
1350
- * Helper utility for throttling
1351
- * @param actionType type being throttled
1352
- * @param path being acted upon
1353
- * @param timeout duration of time to suppress duplicate actions
1354
- * @returns tracking object or false if action should be suppressed
1355
- */
1356
- _throttle(actionType, path$16, timeout) {
1357
- if (!this._throttled.has(actionType)) this._throttled.set(actionType, /* @__PURE__ */ new Map());
1358
- const action = this._throttled.get(actionType);
1359
- if (!action) throw new Error("invalid throttle");
1360
- const actionPath = action.get(path$16);
1361
- if (actionPath) {
1362
- actionPath.count++;
1363
- return false;
1364
- }
1365
- let timeoutObject;
1366
- const clear = () => {
1367
- const item = action.get(path$16);
1368
- const count = item ? item.count : 0;
1369
- action.delete(path$16);
1370
- clearTimeout(timeoutObject);
1371
- if (item) clearTimeout(item.timeoutObject);
1372
- return count;
1373
- };
1374
- timeoutObject = setTimeout(clear, timeout);
1375
- const thr = {
1376
- timeoutObject,
1377
- clear,
1378
- count: 0
1379
- };
1380
- action.set(path$16, thr);
1381
- return thr;
1382
- }
1383
- _incrReadyCount() {
1384
- return this._readyCount++;
1385
- }
1386
- /**
1387
- * Awaits write operation to finish.
1388
- * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
1389
- * @param path being acted upon
1390
- * @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
1391
- * @param event
1392
- * @param awfEmit Callback to be called when ready for event to be emitted.
1393
- */
1394
- _awaitWriteFinish(path$8, threshold, event, awfEmit) {
1395
- const awf = this.options.awaitWriteFinish;
1396
- if (typeof awf !== "object") return;
1397
- const pollInterval = awf.pollInterval;
1398
- let timeoutHandler;
1399
- let fullPath = path$8;
1400
- if (this.options.cwd && !path.isAbsolute(path$8)) fullPath = path.join(this.options.cwd, path$8);
1401
- const now = /* @__PURE__ */ new Date();
1402
- const writes = this._pendingWrites;
1403
- function awaitWriteFinishFn(prevStat) {
1404
- (0, fs.stat)(fullPath, (err, curStat) => {
1405
- if (err || !writes.has(path$8)) {
1406
- if (err && err.code !== "ENOENT") awfEmit(err);
1407
- return;
1408
- }
1409
- const now = Number(/* @__PURE__ */ new Date());
1410
- if (prevStat && curStat.size !== prevStat.size) writes.get(path$8).lastChange = now;
1411
- if (now - writes.get(path$8).lastChange >= threshold) {
1412
- writes.delete(path$8);
1413
- awfEmit(void 0, curStat);
1414
- } else timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
1415
- });
1416
- }
1417
- if (!writes.has(path$8)) {
1418
- writes.set(path$8, {
1419
- lastChange: now,
1420
- cancelWait: () => {
1421
- writes.delete(path$8);
1422
- clearTimeout(timeoutHandler);
1423
- return event;
1424
- }
1425
- });
1426
- timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
1427
- }
1428
- }
1429
- /**
1430
- * Determines whether user has asked to ignore this path.
1431
- */
1432
- _isIgnored(path$17, stats) {
1433
- if (this.options.atomic && DOT_RE.test(path$17)) return true;
1434
- if (!this._userIgnored) {
1435
- const { cwd } = this.options;
1436
- const ignored = (this.options.ignored || []).map(normalizeIgnored(cwd));
1437
- this._userIgnored = anymatch([...[...this._ignoredPaths].map(normalizeIgnored(cwd)), ...ignored], void 0);
1438
- }
1439
- return this._userIgnored(path$17, stats);
1440
- }
1441
- _isntIgnored(path$18, stat) {
1442
- return !this._isIgnored(path$18, stat);
1443
- }
1444
- /**
1445
- * Provides a set of common helpers and properties relating to symlink handling.
1446
- * @param path file or directory pattern being watched
1447
- */
1448
- _getWatchHelpers(path$19) {
1449
- return new WatchHelper(path$19, this.options.followSymlinks, this);
1450
- }
1451
- /**
1452
- * Provides directory tracking objects
1453
- * @param directory path of the directory
1454
- */
1455
- _getWatchedDir(directory) {
1456
- const dir = path.resolve(directory);
1457
- if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
1458
- return this._watched.get(dir);
1459
- }
1460
- /**
1461
- * Check for read permissions: https://stackoverflow.com/a/11781404/1358405
1462
- */
1463
- _hasReadPermissions(stats) {
1464
- if (this.options.ignorePermissionErrors) return true;
1465
- return Boolean(Number(stats.mode) & 256);
1466
- }
1467
- /**
1468
- * Handles emitting unlink events for
1469
- * files and directories, and via recursion, for
1470
- * files and directories within directories that are unlinked
1471
- * @param directory within which the following item is located
1472
- * @param item base path of item/directory
1473
- */
1474
- _remove(directory, item, isDirectory) {
1475
- const path$9 = path.join(directory, item);
1476
- const fullPath = path.resolve(path$9);
1477
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path$9) || this._watched.has(fullPath);
1478
- if (!this._throttle("remove", path$9, 100)) return;
1479
- if (!isDirectory && this._watched.size === 1) this.add(directory, item, true);
1480
- this._getWatchedDir(path$9).getChildren().forEach((nested) => this._remove(path$9, nested));
1481
- const parent = this._getWatchedDir(directory);
1482
- const wasTracked = parent.has(item);
1483
- parent.remove(item);
1484
- if (this._symlinkPaths.has(fullPath)) this._symlinkPaths.delete(fullPath);
1485
- let relPath = path$9;
1486
- if (this.options.cwd) relPath = path.relative(this.options.cwd, path$9);
1487
- if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
1488
- if (this._pendingWrites.get(relPath).cancelWait() === EVENTS.ADD) return;
1489
- }
1490
- this._watched.delete(path$9);
1491
- this._watched.delete(fullPath);
1492
- const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
1493
- if (wasTracked && !this._isIgnored(path$9)) this._emit(eventName, path$9);
1494
- this._closePath(path$9);
1495
- }
1496
- /**
1497
- * Closes all watchers for a path
1498
- */
1499
- _closePath(path$10) {
1500
- this._closeFile(path$10);
1501
- const dir = path.dirname(path$10);
1502
- this._getWatchedDir(dir).remove(path.basename(path$10));
1503
- }
1504
- /**
1505
- * Closes only file-specific watchers
1506
- */
1507
- _closeFile(path$20) {
1508
- const closers = this._closers.get(path$20);
1509
- if (!closers) return;
1510
- closers.forEach((closer) => closer());
1511
- this._closers.delete(path$20);
1512
- }
1513
- _addPathCloser(path$21, closer) {
1514
- if (!closer) return;
1515
- let list = this._closers.get(path$21);
1516
- if (!list) {
1517
- list = [];
1518
- this._closers.set(path$21, list);
1519
- }
1520
- list.push(closer);
1521
- }
1522
- _readdirp(root, opts) {
1523
- if (this.closed) return;
1524
- let stream = readdirp(root, {
1525
- type: EVENTS.ALL,
1526
- alwaysStat: true,
1527
- lstat: true,
1528
- ...opts,
1529
- depth: 0
1530
- });
1531
- this._streams.add(stream);
1532
- stream.once(STR_CLOSE, () => {
1533
- stream = void 0;
1534
- });
1535
- stream.once(STR_END, () => {
1536
- if (stream) {
1537
- this._streams.delete(stream);
1538
- stream = void 0;
1539
- }
1540
- });
1541
- return stream;
1542
- }
1543
- };
1544
- /**
1545
- * Instantiates watcher with paths to be tracked.
1546
- * @param paths file / directory paths
1547
- * @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
1548
- * @returns an instance of FSWatcher for chaining.
1549
- * @example
1550
- * const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
1551
- * watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
1552
- */
1553
- function watch(paths, options = {}) {
1554
- const watcher = new FSWatcher(options);
1555
- watcher.add(paths);
1556
- return watcher;
1557
- }
1558
-
1559
- //#endregion
1560
- exports.watch = watch;
1561
- //# sourceMappingURL=esm-iIOBzmdz.cjs.map