@supsign/unplugin-interfaces 0.2.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +9 -7
- package/dist/{astro.d.ts → astro.d.mts} +1 -1
- package/dist/{astro.js → astro.mjs} +3 -5
- package/dist/esbuild.d.mts +7 -0
- package/dist/{esbuild.js → esbuild.mjs} +2 -4
- package/dist/{farm.d.ts → farm.d.mts} +1 -1
- package/dist/{farm.js → farm.mjs} +2 -4
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +2 -0
- package/dist/{nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/{nuxt.js → nuxt.mjs} +4 -6
- package/dist/rollup.d.mts +7 -0
- package/dist/{rollup.js → rollup.mjs} +2 -4
- package/dist/{rspack.d.ts → rspack.d.mts} +1 -1
- package/dist/{rspack.js → rspack.mjs} +2 -4
- package/dist/{src-BKy9tiI6.js → src-BBWM3Bz4.mjs} +279 -239
- package/dist/{types-BVbGtSvv.d.ts → types.d.mts} +0 -1
- package/dist/types.mjs +1 -0
- package/dist/vite.d.mts +6 -0
- package/dist/{vite-gMMORSxX.js → vite.mjs} +2 -4
- package/dist/webpack.d.mts +7 -0
- package/dist/{webpack-BsOsB8pU.js → webpack.mjs} +2 -4
- package/package.json +60 -55
- package/dist/esbuild.d.ts +0 -7
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -3
- package/dist/rollup.d.ts +0 -7
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/dist/vite.d.ts +0 -7
- package/dist/vite.js +0 -4
- package/dist/webpack.d.ts +0 -7
- package/dist/webpack.js +0 -4
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { Readable } from "node:stream";
|
|
1
|
+
import process$1 from "node:process";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import fs, { stat, unwatchFile, watch, watchFile } from "node:fs";
|
|
4
|
+
import { lstat, open, readdir, realpath, stat as stat$1 } from "node:fs/promises";
|
|
5
|
+
import * as sp from "node:path";
|
|
7
6
|
import path, { join, relative, resolve, sep } from "node:path";
|
|
8
|
-
import {
|
|
7
|
+
import { Readable } from "node:stream";
|
|
8
|
+
import { type } from "node:os";
|
|
9
9
|
import { createUnplugin } from "unplugin";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//#region node_modules/readdirp/esm/index.js
|
|
10
|
+
//#region node_modules/readdirp/index.js
|
|
13
11
|
const EntryTypes = {
|
|
14
12
|
FILE_TYPE: "files",
|
|
15
13
|
DIR_TYPE: "directories",
|
|
@@ -69,6 +67,20 @@ const normalizeFilter = (filter) => {
|
|
|
69
67
|
};
|
|
70
68
|
/** Readable readdir stream, emitting new files as they're being listed. */
|
|
71
69
|
var ReaddirpStream = class extends Readable {
|
|
70
|
+
parents;
|
|
71
|
+
reading;
|
|
72
|
+
parent;
|
|
73
|
+
_stat;
|
|
74
|
+
_maxDepth;
|
|
75
|
+
_wantsDir;
|
|
76
|
+
_wantsFile;
|
|
77
|
+
_wantsEverything;
|
|
78
|
+
_root;
|
|
79
|
+
_isDirent;
|
|
80
|
+
_statsProp;
|
|
81
|
+
_rdOptions;
|
|
82
|
+
_fileFilter;
|
|
83
|
+
_directoryFilter;
|
|
72
84
|
constructor(options = {}) {
|
|
73
85
|
super({
|
|
74
86
|
objectMode: true,
|
|
@@ -79,16 +91,16 @@ var ReaddirpStream = class extends Readable {
|
|
|
79
91
|
...defaultOptions,
|
|
80
92
|
...options
|
|
81
93
|
};
|
|
82
|
-
const { root, type
|
|
94
|
+
const { root, type } = opts;
|
|
83
95
|
this._fileFilter = normalizeFilter(opts.fileFilter);
|
|
84
96
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
85
|
-
const statMethod = opts.lstat ? lstat
|
|
86
|
-
if (wantBigintFsStats) this._stat = (path
|
|
97
|
+
const statMethod = opts.lstat ? lstat : stat$1;
|
|
98
|
+
if (wantBigintFsStats) this._stat = (path) => statMethod(path, { bigint: true });
|
|
87
99
|
else this._stat = statMethod;
|
|
88
|
-
this._maxDepth = opts.depth
|
|
89
|
-
this._wantsDir = type
|
|
90
|
-
this._wantsFile = type
|
|
91
|
-
this._wantsEverything = type
|
|
100
|
+
this._maxDepth = opts.depth != null && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth;
|
|
101
|
+
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
|
102
|
+
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
|
103
|
+
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
|
92
104
|
this._root = resolve(root);
|
|
93
105
|
this._isDirent = !opts.alwaysStat;
|
|
94
106
|
this._statsProp = this._isDirent ? "dirent" : "stats";
|
|
@@ -108,8 +120,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
108
120
|
const par = this.parent;
|
|
109
121
|
const fil = par && par.files;
|
|
110
122
|
if (fil && fil.length > 0) {
|
|
111
|
-
const { path
|
|
112
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path
|
|
123
|
+
const { path, depth } = par;
|
|
124
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
|
113
125
|
const awaited = await Promise.all(slice);
|
|
114
126
|
for (const entry of awaited) {
|
|
115
127
|
if (!entry) continue;
|
|
@@ -144,24 +156,24 @@ var ReaddirpStream = class extends Readable {
|
|
|
144
156
|
this.reading = false;
|
|
145
157
|
}
|
|
146
158
|
}
|
|
147
|
-
async _exploreDir(path
|
|
159
|
+
async _exploreDir(path, depth) {
|
|
148
160
|
let files;
|
|
149
161
|
try {
|
|
150
|
-
files = await readdir
|
|
162
|
+
files = await readdir(path, this._rdOptions);
|
|
151
163
|
} catch (error) {
|
|
152
164
|
this._onError(error);
|
|
153
165
|
}
|
|
154
166
|
return {
|
|
155
167
|
files,
|
|
156
168
|
depth,
|
|
157
|
-
path
|
|
169
|
+
path
|
|
158
170
|
};
|
|
159
171
|
}
|
|
160
|
-
async _formatEntry(dirent, path
|
|
172
|
+
async _formatEntry(dirent, path) {
|
|
161
173
|
let entry;
|
|
162
174
|
const basename = this._isDirent ? dirent.name : dirent;
|
|
163
175
|
try {
|
|
164
|
-
const fullPath = resolve(join(path
|
|
176
|
+
const fullPath = resolve(join(path, basename));
|
|
165
177
|
entry = {
|
|
166
178
|
path: relative(this._root, fullPath),
|
|
167
179
|
fullPath,
|
|
@@ -186,8 +198,8 @@ var ReaddirpStream = class extends Readable {
|
|
|
186
198
|
if (stats && stats.isSymbolicLink()) {
|
|
187
199
|
const full = entry.fullPath;
|
|
188
200
|
try {
|
|
189
|
-
const entryRealPath = await realpath
|
|
190
|
-
const entryRealPathStats = await lstat
|
|
201
|
+
const entryRealPath = await realpath(full);
|
|
202
|
+
const entryRealPathStats = await lstat(entryRealPath);
|
|
191
203
|
if (entryRealPathStats.isFile()) return "file";
|
|
192
204
|
if (entryRealPathStats.isDirectory()) {
|
|
193
205
|
const len = entryRealPath.length;
|
|
@@ -216,20 +228,18 @@ var ReaddirpStream = class extends Readable {
|
|
|
216
228
|
* @param options Options to specify root (start directory), filters and recursion depth
|
|
217
229
|
*/
|
|
218
230
|
function readdirp(root, options = {}) {
|
|
219
|
-
let type
|
|
220
|
-
if (type
|
|
221
|
-
if (type
|
|
231
|
+
let type = options.entryType || options.type;
|
|
232
|
+
if (type === "both") type = EntryTypes.FILE_DIR_TYPE;
|
|
233
|
+
if (type) options.type = type;
|
|
222
234
|
if (!root) throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");
|
|
223
235
|
else if (typeof root !== "string") throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");
|
|
224
|
-
else if (type
|
|
236
|
+
else if (type && !ALL_TYPES.includes(type)) throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(", ")}`);
|
|
225
237
|
options.root = root;
|
|
226
238
|
return new ReaddirpStream(options);
|
|
227
239
|
}
|
|
228
|
-
|
|
229
240
|
//#endregion
|
|
230
|
-
//#region node_modules/chokidar/
|
|
241
|
+
//#region node_modules/chokidar/handler.js
|
|
231
242
|
const STR_DATA = "data";
|
|
232
|
-
const STR_END = "end";
|
|
233
243
|
const STR_CLOSE = "close";
|
|
234
244
|
const EMPTY_FN = () => {};
|
|
235
245
|
const pl = process.platform;
|
|
@@ -526,7 +536,7 @@ const binaryExtensions = new Set([
|
|
|
526
536
|
"zip",
|
|
527
537
|
"zipx"
|
|
528
538
|
]);
|
|
529
|
-
const isBinaryPath = (filePath) => binaryExtensions.has(
|
|
539
|
+
const isBinaryPath = (filePath) => binaryExtensions.has(sp.extname(filePath).slice(1).toLowerCase());
|
|
530
540
|
const foreach = (val, fn) => {
|
|
531
541
|
if (val instanceof Set) val.forEach(fn);
|
|
532
542
|
else fn(val);
|
|
@@ -557,14 +567,14 @@ const FsWatchInstances = /* @__PURE__ */ new Map();
|
|
|
557
567
|
* @param emitRaw emits raw event data
|
|
558
568
|
* @returns {NativeFsWatcher}
|
|
559
569
|
*/
|
|
560
|
-
function createFsWatchInstance(path
|
|
570
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
561
571
|
const handleEvent = (rawEvent, evPath) => {
|
|
562
|
-
listener(path
|
|
563
|
-
emitRaw(rawEvent, evPath, { watchedPath: path
|
|
564
|
-
if (evPath && path
|
|
572
|
+
listener(path);
|
|
573
|
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
574
|
+
if (evPath && path !== evPath) fsWatchBroadcast(sp.resolve(path, evPath), KEY_LISTENERS, sp.join(path, evPath));
|
|
565
575
|
};
|
|
566
576
|
try {
|
|
567
|
-
return watch(path
|
|
577
|
+
return watch(path, { persistent: options.persistent }, handleEvent);
|
|
568
578
|
} catch (error) {
|
|
569
579
|
errHandler(error);
|
|
570
580
|
return;
|
|
@@ -589,12 +599,12 @@ const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
589
599
|
* @param options to be passed to fs_watch
|
|
590
600
|
* @param handlers container for event listener functions
|
|
591
601
|
*/
|
|
592
|
-
const setFsWatchListener = (path
|
|
602
|
+
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
593
603
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
594
604
|
let cont = FsWatchInstances.get(fullPath);
|
|
595
605
|
let watcher;
|
|
596
606
|
if (!options.persistent) {
|
|
597
|
-
watcher = createFsWatchInstance(path
|
|
607
|
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
598
608
|
if (!watcher) return;
|
|
599
609
|
return watcher.close.bind(watcher);
|
|
600
610
|
}
|
|
@@ -603,13 +613,13 @@ const setFsWatchListener = (path$1, fullPath, options, handlers) => {
|
|
|
603
613
|
addAndConvert(cont, KEY_ERR, errHandler);
|
|
604
614
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
605
615
|
} else {
|
|
606
|
-
watcher = createFsWatchInstance(path
|
|
616
|
+
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
|
607
617
|
if (!watcher) return;
|
|
608
618
|
watcher.on(EV.ERROR, async (error) => {
|
|
609
619
|
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
610
620
|
if (cont) cont.watcherUnusable = true;
|
|
611
621
|
if (isWindows && error.code === "EPERM") try {
|
|
612
|
-
await (await open(path
|
|
622
|
+
await (await open(path, "r")).close();
|
|
613
623
|
broadcastErr(error);
|
|
614
624
|
} catch (err) {}
|
|
615
625
|
else broadcastErr(error);
|
|
@@ -645,7 +655,7 @@ const FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
|
645
655
|
* @param handlers container for event listener functions
|
|
646
656
|
* @returns closer
|
|
647
657
|
*/
|
|
648
|
-
const setFsWatchFileListener = (path
|
|
658
|
+
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
649
659
|
const { listener, rawEmitter } = handlers;
|
|
650
660
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
651
661
|
const copts = cont && cont.options;
|
|
@@ -662,14 +672,14 @@ const setFsWatchFileListener = (path$1, fullPath, options, handlers) => {
|
|
|
662
672
|
rawEmitters: rawEmitter,
|
|
663
673
|
options,
|
|
664
674
|
watcher: watchFile(fullPath, options, (curr, prev) => {
|
|
665
|
-
foreach(cont.rawEmitters, (rawEmitter
|
|
666
|
-
rawEmitter
|
|
675
|
+
foreach(cont.rawEmitters, (rawEmitter) => {
|
|
676
|
+
rawEmitter(EV.CHANGE, fullPath, {
|
|
667
677
|
curr,
|
|
668
678
|
prev
|
|
669
679
|
});
|
|
670
680
|
});
|
|
671
681
|
const currmtime = curr.mtimeMs;
|
|
672
|
-
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener
|
|
682
|
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) foreach(cont.listeners, (listener) => listener(path, curr));
|
|
673
683
|
})
|
|
674
684
|
};
|
|
675
685
|
FsWatchFileInstances.set(fullPath, cont);
|
|
@@ -689,6 +699,8 @@ const setFsWatchFileListener = (path$1, fullPath, options, handlers) => {
|
|
|
689
699
|
* @mixin
|
|
690
700
|
*/
|
|
691
701
|
var NodeFsHandler = class {
|
|
702
|
+
fsw;
|
|
703
|
+
_boundHandleError;
|
|
692
704
|
constructor(fsW) {
|
|
693
705
|
this.fsw = fsW;
|
|
694
706
|
this._boundHandleError = (error) => fsW._handleError(error);
|
|
@@ -699,22 +711,22 @@ var NodeFsHandler = class {
|
|
|
699
711
|
* @param listener on fs change
|
|
700
712
|
* @returns closer for the watcher instance
|
|
701
713
|
*/
|
|
702
|
-
_watchWithNodeFs(path
|
|
714
|
+
_watchWithNodeFs(path, listener) {
|
|
703
715
|
const opts = this.fsw.options;
|
|
704
|
-
const directory =
|
|
705
|
-
const basename =
|
|
716
|
+
const directory = sp.dirname(path);
|
|
717
|
+
const basename = sp.basename(path);
|
|
706
718
|
this.fsw._getWatchedDir(directory).add(basename);
|
|
707
|
-
const absolutePath =
|
|
719
|
+
const absolutePath = sp.resolve(path);
|
|
708
720
|
const options = { persistent: opts.persistent };
|
|
709
721
|
if (!listener) listener = EMPTY_FN;
|
|
710
722
|
let closer;
|
|
711
723
|
if (opts.usePolling) {
|
|
712
724
|
options.interval = opts.interval !== opts.binaryInterval && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
|
713
|
-
closer = setFsWatchFileListener(path
|
|
725
|
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
714
726
|
listener,
|
|
715
727
|
rawEmitter: this.fsw._emitRaw
|
|
716
728
|
});
|
|
717
|
-
} else closer = setFsWatchListener(path
|
|
729
|
+
} else closer = setFsWatchListener(path, absolutePath, options, {
|
|
718
730
|
listener,
|
|
719
731
|
errHandler: this._boundHandleError,
|
|
720
732
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -727,25 +739,25 @@ var NodeFsHandler = class {
|
|
|
727
739
|
*/
|
|
728
740
|
_handleFile(file, stats, initialAdd) {
|
|
729
741
|
if (this.fsw.closed) return;
|
|
730
|
-
const dirname =
|
|
731
|
-
const basename =
|
|
742
|
+
const dirname = sp.dirname(file);
|
|
743
|
+
const basename = sp.basename(file);
|
|
732
744
|
const parent = this.fsw._getWatchedDir(dirname);
|
|
733
745
|
let prevStats = stats;
|
|
734
746
|
if (parent.has(basename)) return;
|
|
735
|
-
const listener = async (path
|
|
747
|
+
const listener = async (path, newStats) => {
|
|
736
748
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
|
|
737
749
|
if (!newStats || newStats.mtimeMs === 0) try {
|
|
738
|
-
const newStats
|
|
750
|
+
const newStats = await stat$1(file);
|
|
739
751
|
if (this.fsw.closed) return;
|
|
740
|
-
const at = newStats
|
|
741
|
-
const mt = newStats
|
|
742
|
-
if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats
|
|
743
|
-
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats
|
|
744
|
-
this.fsw._closeFile(path
|
|
745
|
-
prevStats = newStats
|
|
746
|
-
const closer
|
|
747
|
-
if (closer
|
|
748
|
-
} else prevStats = newStats
|
|
752
|
+
const at = newStats.atimeMs;
|
|
753
|
+
const mt = newStats.mtimeMs;
|
|
754
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) this.fsw._emit(EV.CHANGE, file, newStats);
|
|
755
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
|
756
|
+
this.fsw._closeFile(path);
|
|
757
|
+
prevStats = newStats;
|
|
758
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
759
|
+
if (closer) this.fsw._addPathCloser(path, closer);
|
|
760
|
+
} else prevStats = newStats;
|
|
749
761
|
} catch (error) {
|
|
750
762
|
this.fsw._remove(dirname, basename);
|
|
751
763
|
}
|
|
@@ -771,7 +783,7 @@ var NodeFsHandler = class {
|
|
|
771
783
|
* @param item basename of this item
|
|
772
784
|
* @returns true if no more processing is needed for this entry.
|
|
773
785
|
*/
|
|
774
|
-
async _handleSymlink(entry, directory, path
|
|
786
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
775
787
|
if (this.fsw.closed) return;
|
|
776
788
|
const full = entry.fullPath;
|
|
777
789
|
const dir = this.fsw._getWatchedDir(directory);
|
|
@@ -779,7 +791,7 @@ var NodeFsHandler = class {
|
|
|
779
791
|
this.fsw._incrReadyCount();
|
|
780
792
|
let linkPath;
|
|
781
793
|
try {
|
|
782
|
-
linkPath = await realpath(path
|
|
794
|
+
linkPath = await realpath(path);
|
|
783
795
|
} catch (e) {
|
|
784
796
|
this.fsw._emitReady();
|
|
785
797
|
return true;
|
|
@@ -788,12 +800,12 @@ var NodeFsHandler = class {
|
|
|
788
800
|
if (dir.has(item)) {
|
|
789
801
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
790
802
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
791
|
-
this.fsw._emit(EV.CHANGE, path
|
|
803
|
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
792
804
|
}
|
|
793
805
|
} else {
|
|
794
806
|
dir.add(item);
|
|
795
807
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
796
|
-
this.fsw._emit(EV.ADD, path
|
|
808
|
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
797
809
|
}
|
|
798
810
|
this.fsw._emitReady();
|
|
799
811
|
return true;
|
|
@@ -802,8 +814,9 @@ var NodeFsHandler = class {
|
|
|
802
814
|
this.fsw._symlinkPaths.set(full, true);
|
|
803
815
|
}
|
|
804
816
|
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
805
|
-
directory =
|
|
806
|
-
|
|
817
|
+
directory = sp.join(directory, "");
|
|
818
|
+
const throttleKey = target ? `${directory}:${target}` : directory;
|
|
819
|
+
throttler = this.fsw._throttle("readdir", throttleKey, 1e3);
|
|
807
820
|
if (!throttler) return;
|
|
808
821
|
const previous = this.fsw._getWatchedDir(wh.path);
|
|
809
822
|
const current = /* @__PURE__ */ new Set();
|
|
@@ -818,28 +831,28 @@ var NodeFsHandler = class {
|
|
|
818
831
|
return;
|
|
819
832
|
}
|
|
820
833
|
const item = entry.path;
|
|
821
|
-
let path
|
|
834
|
+
let path = sp.join(directory, item);
|
|
822
835
|
current.add(item);
|
|
823
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path
|
|
836
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) return;
|
|
824
837
|
if (this.fsw.closed) {
|
|
825
838
|
stream = void 0;
|
|
826
839
|
return;
|
|
827
840
|
}
|
|
828
841
|
if (item === target || !target && !previous.has(item)) {
|
|
829
842
|
this.fsw._incrReadyCount();
|
|
830
|
-
path
|
|
831
|
-
this._addToNodeFs(path
|
|
843
|
+
path = sp.join(dir, sp.relative(dir, path));
|
|
844
|
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
832
845
|
}
|
|
833
846
|
}).on(EV.ERROR, this._boundHandleError);
|
|
834
|
-
return new Promise((resolve
|
|
847
|
+
return new Promise((resolve, reject) => {
|
|
835
848
|
if (!stream) return reject();
|
|
836
|
-
stream.once(
|
|
849
|
+
stream.once("end", () => {
|
|
837
850
|
if (this.fsw.closed) {
|
|
838
851
|
stream = void 0;
|
|
839
852
|
return;
|
|
840
853
|
}
|
|
841
854
|
const wasThrottled = throttler ? throttler.clear() : false;
|
|
842
|
-
resolve
|
|
855
|
+
resolve(void 0);
|
|
843
856
|
previous.getChildren().filter((item) => {
|
|
844
857
|
return item !== directory && !current.has(item);
|
|
845
858
|
}).forEach((item) => {
|
|
@@ -861,22 +874,22 @@ var NodeFsHandler = class {
|
|
|
861
874
|
* @param realpath
|
|
862
875
|
* @returns closer for the watcher instance.
|
|
863
876
|
*/
|
|
864
|
-
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath
|
|
865
|
-
const parentDir = this.fsw._getWatchedDir(
|
|
866
|
-
const tracked = parentDir.has(
|
|
877
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
|
878
|
+
const parentDir = this.fsw._getWatchedDir(sp.dirname(dir));
|
|
879
|
+
const tracked = parentDir.has(sp.basename(dir));
|
|
867
880
|
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
868
|
-
parentDir.add(
|
|
881
|
+
parentDir.add(sp.basename(dir));
|
|
869
882
|
this.fsw._getWatchedDir(dir);
|
|
870
883
|
let throttler;
|
|
871
884
|
let closer;
|
|
872
885
|
const oDepth = this.fsw.options.depth;
|
|
873
|
-
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath
|
|
886
|
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
|
874
887
|
if (!target) {
|
|
875
888
|
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
876
889
|
if (this.fsw.closed) return;
|
|
877
890
|
}
|
|
878
|
-
closer = this._watchWithNodeFs(dir, (dirPath, stats
|
|
879
|
-
if (stats
|
|
891
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
|
892
|
+
if (stats && stats.mtimeMs === 0) return;
|
|
880
893
|
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
881
894
|
});
|
|
882
895
|
}
|
|
@@ -891,13 +904,13 @@ var NodeFsHandler = class {
|
|
|
891
904
|
* @param depth Child path actually targeted for watch
|
|
892
905
|
* @param target Child path actually targeted for watch
|
|
893
906
|
*/
|
|
894
|
-
async _addToNodeFs(path
|
|
907
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
895
908
|
const ready = this.fsw._emitReady;
|
|
896
|
-
if (this.fsw._isIgnored(path
|
|
909
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
897
910
|
ready();
|
|
898
911
|
return false;
|
|
899
912
|
}
|
|
900
|
-
const wh = this.fsw._getWatchHelpers(path
|
|
913
|
+
const wh = this.fsw._getWatchHelpers(path);
|
|
901
914
|
if (priorWh) {
|
|
902
915
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
903
916
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -912,43 +925,43 @@ var NodeFsHandler = class {
|
|
|
912
925
|
const follow = this.fsw.options.followSymlinks;
|
|
913
926
|
let closer;
|
|
914
927
|
if (stats.isDirectory()) {
|
|
915
|
-
const absPath =
|
|
916
|
-
const targetPath = follow ? await realpath(path
|
|
928
|
+
const absPath = sp.resolve(path);
|
|
929
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
917
930
|
if (this.fsw.closed) return;
|
|
918
931
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
919
932
|
if (this.fsw.closed) return;
|
|
920
933
|
if (absPath !== targetPath && targetPath !== void 0) this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
921
934
|
} else if (stats.isSymbolicLink()) {
|
|
922
|
-
const targetPath = follow ? await realpath(path
|
|
935
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
923
936
|
if (this.fsw.closed) return;
|
|
924
|
-
const parent =
|
|
937
|
+
const parent = sp.dirname(wh.watchPath);
|
|
925
938
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
926
939
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
927
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth, path
|
|
940
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
928
941
|
if (this.fsw.closed) return;
|
|
929
|
-
if (targetPath !== void 0) this.fsw._symlinkPaths.set(
|
|
942
|
+
if (targetPath !== void 0) this.fsw._symlinkPaths.set(sp.resolve(path), targetPath);
|
|
930
943
|
} else closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
931
944
|
ready();
|
|
932
|
-
if (closer) this.fsw._addPathCloser(path
|
|
945
|
+
if (closer) this.fsw._addPathCloser(path, closer);
|
|
933
946
|
return false;
|
|
934
947
|
} catch (error) {
|
|
935
948
|
if (this.fsw._handleError(error)) {
|
|
936
949
|
ready();
|
|
937
|
-
return path
|
|
950
|
+
return path;
|
|
938
951
|
}
|
|
939
952
|
}
|
|
940
953
|
}
|
|
941
954
|
};
|
|
942
|
-
|
|
943
955
|
//#endregion
|
|
944
|
-
//#region node_modules/chokidar/
|
|
956
|
+
//#region node_modules/chokidar/index.js
|
|
957
|
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
|
945
958
|
const SLASH = "/";
|
|
946
959
|
const SLASH_SLASH = "//";
|
|
947
960
|
const ONE_DOT = ".";
|
|
948
961
|
const TWO_DOTS = "..";
|
|
949
962
|
const STRING_TYPE = "string";
|
|
950
963
|
const BACK_SLASH_RE = /\\/g;
|
|
951
|
-
const DOUBLE_SLASH_RE =
|
|
964
|
+
const DOUBLE_SLASH_RE = /\/\//g;
|
|
952
965
|
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
953
966
|
const REPLACER_RE = /^\.[/\\]/;
|
|
954
967
|
function arrify(item) {
|
|
@@ -962,38 +975,37 @@ function createPattern(matcher) {
|
|
|
962
975
|
if (typeof matcher === "object" && matcher !== null) return (string) => {
|
|
963
976
|
if (matcher.path === string) return true;
|
|
964
977
|
if (matcher.recursive) {
|
|
965
|
-
const relative
|
|
966
|
-
if (!relative
|
|
967
|
-
return !relative
|
|
978
|
+
const relative = sp.relative(matcher.path, string);
|
|
979
|
+
if (!relative) return false;
|
|
980
|
+
return !relative.startsWith("..") && !sp.isAbsolute(relative);
|
|
968
981
|
}
|
|
969
982
|
return false;
|
|
970
983
|
};
|
|
971
984
|
return () => false;
|
|
972
985
|
}
|
|
973
|
-
function normalizePath(path
|
|
974
|
-
if (typeof path
|
|
975
|
-
path
|
|
976
|
-
path
|
|
986
|
+
function normalizePath(path) {
|
|
987
|
+
if (typeof path !== "string") throw new Error("string expected");
|
|
988
|
+
path = sp.normalize(path);
|
|
989
|
+
path = path.replace(/\\/g, "/");
|
|
977
990
|
let prepend = false;
|
|
978
|
-
if (path
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
return path$1;
|
|
991
|
+
if (path.startsWith("//")) prepend = true;
|
|
992
|
+
path = path.replace(DOUBLE_SLASH_RE, "/");
|
|
993
|
+
if (prepend) path = "/" + path;
|
|
994
|
+
return path;
|
|
983
995
|
}
|
|
984
996
|
function matchPatterns(patterns, testString, stats) {
|
|
985
|
-
const path
|
|
997
|
+
const path = normalizePath(testString);
|
|
986
998
|
for (let index = 0; index < patterns.length; index++) {
|
|
987
999
|
const pattern = patterns[index];
|
|
988
|
-
if (pattern(path
|
|
1000
|
+
if (pattern(path, stats)) return true;
|
|
989
1001
|
}
|
|
990
1002
|
return false;
|
|
991
1003
|
}
|
|
992
1004
|
function anymatch(matchers, testString) {
|
|
993
1005
|
if (matchers == null) throw new TypeError("anymatch: specify first argument");
|
|
994
1006
|
const patterns = arrify(matchers).map((matcher) => createPattern(matcher));
|
|
995
|
-
if (testString == null) return (testString
|
|
996
|
-
return matchPatterns(patterns, testString
|
|
1007
|
+
if (testString == null) return (testString, stats) => {
|
|
1008
|
+
return matchPatterns(patterns, testString, stats);
|
|
997
1009
|
};
|
|
998
1010
|
return matchPatterns(patterns, testString);
|
|
999
1011
|
}
|
|
@@ -1006,24 +1018,27 @@ const toUnix = (string) => {
|
|
|
1006
1018
|
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
1007
1019
|
let prepend = false;
|
|
1008
1020
|
if (str.startsWith(SLASH_SLASH)) prepend = true;
|
|
1009
|
-
|
|
1021
|
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
1010
1022
|
if (prepend) str = SLASH + str;
|
|
1011
1023
|
return str;
|
|
1012
1024
|
};
|
|
1013
|
-
const normalizePathToUnix = (path
|
|
1014
|
-
const normalizeIgnored = (cwd = "") => (path
|
|
1015
|
-
if (typeof path
|
|
1016
|
-
else return path
|
|
1025
|
+
const normalizePathToUnix = (path) => toUnix(sp.normalize(toUnix(path)));
|
|
1026
|
+
const normalizeIgnored = (cwd = "") => (path) => {
|
|
1027
|
+
if (typeof path === "string") return normalizePathToUnix(sp.isAbsolute(path) ? path : sp.join(cwd, path));
|
|
1028
|
+
else return path;
|
|
1017
1029
|
};
|
|
1018
|
-
const getAbsolutePath = (path
|
|
1019
|
-
if (
|
|
1020
|
-
return
|
|
1030
|
+
const getAbsolutePath = (path, cwd) => {
|
|
1031
|
+
if (sp.isAbsolute(path)) return path;
|
|
1032
|
+
return sp.join(cwd, path);
|
|
1021
1033
|
};
|
|
1022
1034
|
const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
1023
1035
|
/**
|
|
1024
1036
|
* Directory entry.
|
|
1025
1037
|
*/
|
|
1026
1038
|
var DirEntry = class {
|
|
1039
|
+
path;
|
|
1040
|
+
_removeWatcher;
|
|
1041
|
+
items;
|
|
1027
1042
|
constructor(dir, removeWatcher) {
|
|
1028
1043
|
this.path = dir;
|
|
1029
1044
|
this._removeWatcher = removeWatcher;
|
|
@@ -1043,7 +1058,7 @@ var DirEntry = class {
|
|
|
1043
1058
|
try {
|
|
1044
1059
|
await readdir(dir);
|
|
1045
1060
|
} catch (err) {
|
|
1046
|
-
if (this._removeWatcher) this._removeWatcher(
|
|
1061
|
+
if (this._removeWatcher) this._removeWatcher(sp.dirname(dir), sp.basename(dir));
|
|
1047
1062
|
}
|
|
1048
1063
|
}
|
|
1049
1064
|
has(item) {
|
|
@@ -1067,12 +1082,19 @@ var DirEntry = class {
|
|
|
1067
1082
|
const STAT_METHOD_F = "stat";
|
|
1068
1083
|
const STAT_METHOD_L = "lstat";
|
|
1069
1084
|
var WatchHelper = class {
|
|
1070
|
-
|
|
1085
|
+
fsw;
|
|
1086
|
+
path;
|
|
1087
|
+
watchPath;
|
|
1088
|
+
fullWatchPath;
|
|
1089
|
+
dirParts;
|
|
1090
|
+
followSymlinks;
|
|
1091
|
+
statMethod;
|
|
1092
|
+
constructor(path, follow, fsw) {
|
|
1071
1093
|
this.fsw = fsw;
|
|
1072
|
-
const watchPath = path
|
|
1073
|
-
this.path = path
|
|
1094
|
+
const watchPath = path;
|
|
1095
|
+
this.path = path = path.replace(REPLACER_RE, "");
|
|
1074
1096
|
this.watchPath = watchPath;
|
|
1075
|
-
this.fullWatchPath =
|
|
1097
|
+
this.fullWatchPath = sp.resolve(watchPath);
|
|
1076
1098
|
this.dirParts = [];
|
|
1077
1099
|
this.dirParts.forEach((parts) => {
|
|
1078
1100
|
if (parts.length > 1) parts.pop();
|
|
@@ -1081,7 +1103,7 @@ var WatchHelper = class {
|
|
|
1081
1103
|
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
1082
1104
|
}
|
|
1083
1105
|
entryPath(entry) {
|
|
1084
|
-
return
|
|
1106
|
+
return sp.join(this.watchPath, sp.relative(this.watchPath, entry.fullPath));
|
|
1085
1107
|
}
|
|
1086
1108
|
filterPath(entry) {
|
|
1087
1109
|
const { stats } = entry;
|
|
@@ -1102,6 +1124,24 @@ var WatchHelper = class {
|
|
|
1102
1124
|
* .on('add', path => log('File', path, 'was added'))
|
|
1103
1125
|
*/
|
|
1104
1126
|
var FSWatcher = class extends EventEmitter {
|
|
1127
|
+
closed;
|
|
1128
|
+
options;
|
|
1129
|
+
_closers;
|
|
1130
|
+
_ignoredPaths;
|
|
1131
|
+
_throttled;
|
|
1132
|
+
_streams;
|
|
1133
|
+
_symlinkPaths;
|
|
1134
|
+
_watched;
|
|
1135
|
+
_pendingWrites;
|
|
1136
|
+
_pendingUnlinks;
|
|
1137
|
+
_readyCount;
|
|
1138
|
+
_emitReady;
|
|
1139
|
+
_closePromise;
|
|
1140
|
+
_userIgnored;
|
|
1141
|
+
_readyEmitted;
|
|
1142
|
+
_emitRaw;
|
|
1143
|
+
_boundRemove;
|
|
1144
|
+
_nodeFsHandler;
|
|
1105
1145
|
constructor(_opts = {}) {
|
|
1106
1146
|
super();
|
|
1107
1147
|
this.closed = false;
|
|
@@ -1183,23 +1223,23 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1183
1223
|
this.closed = false;
|
|
1184
1224
|
this._closePromise = void 0;
|
|
1185
1225
|
let paths = unifyPaths(paths_);
|
|
1186
|
-
if (cwd) paths = paths.map((path
|
|
1187
|
-
return getAbsolutePath(path
|
|
1226
|
+
if (cwd) paths = paths.map((path) => {
|
|
1227
|
+
return getAbsolutePath(path, cwd);
|
|
1188
1228
|
});
|
|
1189
|
-
paths.forEach((path
|
|
1190
|
-
this._removeIgnoredPath(path
|
|
1229
|
+
paths.forEach((path) => {
|
|
1230
|
+
this._removeIgnoredPath(path);
|
|
1191
1231
|
});
|
|
1192
1232
|
this._userIgnored = void 0;
|
|
1193
1233
|
if (!this._readyCount) this._readyCount = 0;
|
|
1194
1234
|
this._readyCount += paths.length;
|
|
1195
|
-
Promise.all(paths.map(async (path
|
|
1196
|
-
const res = await this._nodeFsHandler._addToNodeFs(path
|
|
1235
|
+
Promise.all(paths.map(async (path) => {
|
|
1236
|
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
1197
1237
|
if (res) this._emitReady();
|
|
1198
1238
|
return res;
|
|
1199
1239
|
})).then((results) => {
|
|
1200
1240
|
if (this.closed) return;
|
|
1201
1241
|
results.forEach((item) => {
|
|
1202
|
-
if (item) this.add(
|
|
1242
|
+
if (item) this.add(sp.dirname(item), sp.basename(_origAdd || item));
|
|
1203
1243
|
});
|
|
1204
1244
|
});
|
|
1205
1245
|
return this;
|
|
@@ -1211,15 +1251,15 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1211
1251
|
if (this.closed) return this;
|
|
1212
1252
|
const paths = unifyPaths(paths_);
|
|
1213
1253
|
const { cwd } = this.options;
|
|
1214
|
-
paths.forEach((path
|
|
1215
|
-
if (!
|
|
1216
|
-
if (cwd) path
|
|
1217
|
-
path
|
|
1254
|
+
paths.forEach((path) => {
|
|
1255
|
+
if (!sp.isAbsolute(path) && !this._closers.has(path)) {
|
|
1256
|
+
if (cwd) path = sp.join(cwd, path);
|
|
1257
|
+
path = sp.resolve(path);
|
|
1218
1258
|
}
|
|
1219
|
-
this._closePath(path
|
|
1220
|
-
this._addIgnoredPath(path
|
|
1221
|
-
if (this._watched.has(path
|
|
1222
|
-
path
|
|
1259
|
+
this._closePath(path);
|
|
1260
|
+
this._addIgnoredPath(path);
|
|
1261
|
+
if (this._watched.has(path)) this._addIgnoredPath({
|
|
1262
|
+
path,
|
|
1223
1263
|
recursive: true
|
|
1224
1264
|
});
|
|
1225
1265
|
this._userIgnored = void 0;
|
|
@@ -1258,7 +1298,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1258
1298
|
getWatched() {
|
|
1259
1299
|
const watchList = {};
|
|
1260
1300
|
this._watched.forEach((entry, dir) => {
|
|
1261
|
-
const index = (this.options.cwd ?
|
|
1301
|
+
const index = (this.options.cwd ? sp.relative(this.options.cwd, dir) : dir) || ONE_DOT;
|
|
1262
1302
|
watchList[index] = entry.getChildren().sort();
|
|
1263
1303
|
});
|
|
1264
1304
|
return watchList;
|
|
@@ -1275,62 +1315,62 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1275
1315
|
* @param stats arguments to be passed with event
|
|
1276
1316
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
1277
1317
|
*/
|
|
1278
|
-
async _emit(event, path
|
|
1318
|
+
async _emit(event, path, stats) {
|
|
1279
1319
|
if (this.closed) return;
|
|
1280
1320
|
const opts = this.options;
|
|
1281
|
-
if (isWindows) path
|
|
1282
|
-
if (opts.cwd) path
|
|
1283
|
-
const args = [path
|
|
1321
|
+
if (isWindows) path = sp.normalize(path);
|
|
1322
|
+
if (opts.cwd) path = sp.relative(opts.cwd, path);
|
|
1323
|
+
const args = [path];
|
|
1284
1324
|
if (stats != null) args.push(stats);
|
|
1285
1325
|
const awf = opts.awaitWriteFinish;
|
|
1286
1326
|
let pw;
|
|
1287
|
-
if (awf && (pw = this._pendingWrites.get(path
|
|
1327
|
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
1288
1328
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
1289
1329
|
return this;
|
|
1290
1330
|
}
|
|
1291
1331
|
if (opts.atomic) {
|
|
1292
1332
|
if (event === EVENTS.UNLINK) {
|
|
1293
|
-
this._pendingUnlinks.set(path
|
|
1333
|
+
this._pendingUnlinks.set(path, [event, ...args]);
|
|
1294
1334
|
setTimeout(() => {
|
|
1295
|
-
this._pendingUnlinks.forEach((entry, path
|
|
1335
|
+
this._pendingUnlinks.forEach((entry, path) => {
|
|
1296
1336
|
this.emit(...entry);
|
|
1297
1337
|
this.emit(EVENTS.ALL, ...entry);
|
|
1298
|
-
this._pendingUnlinks.delete(path
|
|
1338
|
+
this._pendingUnlinks.delete(path);
|
|
1299
1339
|
});
|
|
1300
1340
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
1301
1341
|
return this;
|
|
1302
1342
|
}
|
|
1303
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(path
|
|
1343
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
1304
1344
|
event = EVENTS.CHANGE;
|
|
1305
|
-
this._pendingUnlinks.delete(path
|
|
1345
|
+
this._pendingUnlinks.delete(path);
|
|
1306
1346
|
}
|
|
1307
1347
|
}
|
|
1308
1348
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
1309
|
-
const awfEmit = (err, stats
|
|
1349
|
+
const awfEmit = (err, stats) => {
|
|
1310
1350
|
if (err) {
|
|
1311
1351
|
event = EVENTS.ERROR;
|
|
1312
1352
|
args[0] = err;
|
|
1313
1353
|
this.emitWithAll(event, args);
|
|
1314
|
-
} else if (stats
|
|
1315
|
-
if (args.length > 1) args[1] = stats
|
|
1316
|
-
else args.push(stats
|
|
1354
|
+
} else if (stats) {
|
|
1355
|
+
if (args.length > 1) args[1] = stats;
|
|
1356
|
+
else args.push(stats);
|
|
1317
1357
|
this.emitWithAll(event, args);
|
|
1318
1358
|
}
|
|
1319
1359
|
};
|
|
1320
|
-
this._awaitWriteFinish(path
|
|
1360
|
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
1321
1361
|
return this;
|
|
1322
1362
|
}
|
|
1323
1363
|
if (event === EVENTS.CHANGE) {
|
|
1324
|
-
if (!this._throttle(EVENTS.CHANGE, path
|
|
1364
|
+
if (!this._throttle(EVENTS.CHANGE, path, 50)) return this;
|
|
1325
1365
|
}
|
|
1326
1366
|
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
1327
|
-
const fullPath = opts.cwd ?
|
|
1328
|
-
let stats
|
|
1367
|
+
const fullPath = opts.cwd ? sp.join(opts.cwd, path) : path;
|
|
1368
|
+
let stats;
|
|
1329
1369
|
try {
|
|
1330
|
-
stats
|
|
1370
|
+
stats = await stat$1(fullPath);
|
|
1331
1371
|
} catch (err) {}
|
|
1332
|
-
if (!stats
|
|
1333
|
-
args.push(stats
|
|
1372
|
+
if (!stats || this.closed) return;
|
|
1373
|
+
args.push(stats);
|
|
1334
1374
|
}
|
|
1335
1375
|
this.emitWithAll(event, args);
|
|
1336
1376
|
return this;
|
|
@@ -1351,20 +1391,20 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1351
1391
|
* @param timeout duration of time to suppress duplicate actions
|
|
1352
1392
|
* @returns tracking object or false if action should be suppressed
|
|
1353
1393
|
*/
|
|
1354
|
-
_throttle(actionType, path
|
|
1394
|
+
_throttle(actionType, path, timeout) {
|
|
1355
1395
|
if (!this._throttled.has(actionType)) this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
1356
1396
|
const action = this._throttled.get(actionType);
|
|
1357
1397
|
if (!action) throw new Error("invalid throttle");
|
|
1358
|
-
const actionPath = action.get(path
|
|
1398
|
+
const actionPath = action.get(path);
|
|
1359
1399
|
if (actionPath) {
|
|
1360
1400
|
actionPath.count++;
|
|
1361
1401
|
return false;
|
|
1362
1402
|
}
|
|
1363
1403
|
let timeoutObject;
|
|
1364
1404
|
const clear = () => {
|
|
1365
|
-
const item = action.get(path
|
|
1405
|
+
const item = action.get(path);
|
|
1366
1406
|
const count = item ? item.count : 0;
|
|
1367
|
-
action.delete(path
|
|
1407
|
+
action.delete(path);
|
|
1368
1408
|
clearTimeout(timeoutObject);
|
|
1369
1409
|
if (item) clearTimeout(item.timeoutObject);
|
|
1370
1410
|
return count;
|
|
@@ -1375,7 +1415,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1375
1415
|
clear,
|
|
1376
1416
|
count: 0
|
|
1377
1417
|
};
|
|
1378
|
-
action.set(path
|
|
1418
|
+
action.set(path, thr);
|
|
1379
1419
|
return thr;
|
|
1380
1420
|
}
|
|
1381
1421
|
_incrReadyCount() {
|
|
@@ -1389,34 +1429,34 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1389
1429
|
* @param event
|
|
1390
1430
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
1391
1431
|
*/
|
|
1392
|
-
_awaitWriteFinish(path
|
|
1432
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
1393
1433
|
const awf = this.options.awaitWriteFinish;
|
|
1394
1434
|
if (typeof awf !== "object") return;
|
|
1395
1435
|
const pollInterval = awf.pollInterval;
|
|
1396
1436
|
let timeoutHandler;
|
|
1397
|
-
let fullPath = path
|
|
1398
|
-
if (this.options.cwd && !
|
|
1437
|
+
let fullPath = path;
|
|
1438
|
+
if (this.options.cwd && !sp.isAbsolute(path)) fullPath = sp.join(this.options.cwd, path);
|
|
1399
1439
|
const now = /* @__PURE__ */ new Date();
|
|
1400
1440
|
const writes = this._pendingWrites;
|
|
1401
1441
|
function awaitWriteFinishFn(prevStat) {
|
|
1402
1442
|
stat(fullPath, (err, curStat) => {
|
|
1403
|
-
if (err || !writes.has(path
|
|
1443
|
+
if (err || !writes.has(path)) {
|
|
1404
1444
|
if (err && err.code !== "ENOENT") awfEmit(err);
|
|
1405
1445
|
return;
|
|
1406
1446
|
}
|
|
1407
|
-
const now
|
|
1408
|
-
if (prevStat && curStat.size !== prevStat.size) writes.get(path
|
|
1409
|
-
if (now
|
|
1410
|
-
writes.delete(path
|
|
1447
|
+
const now = Number(/* @__PURE__ */ new Date());
|
|
1448
|
+
if (prevStat && curStat.size !== prevStat.size) writes.get(path).lastChange = now;
|
|
1449
|
+
if (now - writes.get(path).lastChange >= threshold) {
|
|
1450
|
+
writes.delete(path);
|
|
1411
1451
|
awfEmit(void 0, curStat);
|
|
1412
1452
|
} else timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
1413
1453
|
});
|
|
1414
1454
|
}
|
|
1415
|
-
if (!writes.has(path
|
|
1416
|
-
writes.set(path
|
|
1455
|
+
if (!writes.has(path)) {
|
|
1456
|
+
writes.set(path, {
|
|
1417
1457
|
lastChange: now,
|
|
1418
1458
|
cancelWait: () => {
|
|
1419
|
-
writes.delete(path
|
|
1459
|
+
writes.delete(path);
|
|
1420
1460
|
clearTimeout(timeoutHandler);
|
|
1421
1461
|
return event;
|
|
1422
1462
|
}
|
|
@@ -1427,31 +1467,31 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1427
1467
|
/**
|
|
1428
1468
|
* Determines whether user has asked to ignore this path.
|
|
1429
1469
|
*/
|
|
1430
|
-
_isIgnored(path
|
|
1431
|
-
if (this.options.atomic && DOT_RE.test(path
|
|
1470
|
+
_isIgnored(path, stats) {
|
|
1471
|
+
if (this.options.atomic && DOT_RE.test(path)) return true;
|
|
1432
1472
|
if (!this._userIgnored) {
|
|
1433
1473
|
const { cwd } = this.options;
|
|
1434
1474
|
const ignored = (this.options.ignored || []).map(normalizeIgnored(cwd));
|
|
1435
1475
|
this._userIgnored = anymatch([...[...this._ignoredPaths].map(normalizeIgnored(cwd)), ...ignored], void 0);
|
|
1436
1476
|
}
|
|
1437
|
-
return this._userIgnored(path
|
|
1477
|
+
return this._userIgnored(path, stats);
|
|
1438
1478
|
}
|
|
1439
|
-
_isntIgnored(path
|
|
1440
|
-
return !this._isIgnored(path
|
|
1479
|
+
_isntIgnored(path, stat) {
|
|
1480
|
+
return !this._isIgnored(path, stat);
|
|
1441
1481
|
}
|
|
1442
1482
|
/**
|
|
1443
1483
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
1444
1484
|
* @param path file or directory pattern being watched
|
|
1445
1485
|
*/
|
|
1446
|
-
_getWatchHelpers(path
|
|
1447
|
-
return new WatchHelper(path
|
|
1486
|
+
_getWatchHelpers(path) {
|
|
1487
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
1448
1488
|
}
|
|
1449
1489
|
/**
|
|
1450
1490
|
* Provides directory tracking objects
|
|
1451
1491
|
* @param directory path of the directory
|
|
1452
1492
|
*/
|
|
1453
1493
|
_getWatchedDir(directory) {
|
|
1454
|
-
const dir =
|
|
1494
|
+
const dir = sp.resolve(directory);
|
|
1455
1495
|
if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
1456
1496
|
return this._watched.get(dir);
|
|
1457
1497
|
}
|
|
@@ -1470,50 +1510,50 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1470
1510
|
* @param item base path of item/directory
|
|
1471
1511
|
*/
|
|
1472
1512
|
_remove(directory, item, isDirectory) {
|
|
1473
|
-
const path
|
|
1474
|
-
const fullPath =
|
|
1475
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path
|
|
1476
|
-
if (!this._throttle("remove", path
|
|
1513
|
+
const path = sp.join(directory, item);
|
|
1514
|
+
const fullPath = sp.resolve(path);
|
|
1515
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
1516
|
+
if (!this._throttle("remove", path, 100)) return;
|
|
1477
1517
|
if (!isDirectory && this._watched.size === 1) this.add(directory, item, true);
|
|
1478
|
-
this._getWatchedDir(path
|
|
1518
|
+
this._getWatchedDir(path).getChildren().forEach((nested) => this._remove(path, nested));
|
|
1479
1519
|
const parent = this._getWatchedDir(directory);
|
|
1480
1520
|
const wasTracked = parent.has(item);
|
|
1481
1521
|
parent.remove(item);
|
|
1482
1522
|
if (this._symlinkPaths.has(fullPath)) this._symlinkPaths.delete(fullPath);
|
|
1483
|
-
let relPath = path
|
|
1484
|
-
if (this.options.cwd) relPath =
|
|
1523
|
+
let relPath = path;
|
|
1524
|
+
if (this.options.cwd) relPath = sp.relative(this.options.cwd, path);
|
|
1485
1525
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
1486
1526
|
if (this._pendingWrites.get(relPath).cancelWait() === EVENTS.ADD) return;
|
|
1487
1527
|
}
|
|
1488
|
-
this._watched.delete(path
|
|
1528
|
+
this._watched.delete(path);
|
|
1489
1529
|
this._watched.delete(fullPath);
|
|
1490
1530
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
1491
|
-
if (wasTracked && !this._isIgnored(path
|
|
1492
|
-
this._closePath(path
|
|
1531
|
+
if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
|
|
1532
|
+
this._closePath(path);
|
|
1493
1533
|
}
|
|
1494
1534
|
/**
|
|
1495
1535
|
* Closes all watchers for a path
|
|
1496
1536
|
*/
|
|
1497
|
-
_closePath(path
|
|
1498
|
-
this._closeFile(path
|
|
1499
|
-
const dir =
|
|
1500
|
-
this._getWatchedDir(dir).remove(
|
|
1537
|
+
_closePath(path) {
|
|
1538
|
+
this._closeFile(path);
|
|
1539
|
+
const dir = sp.dirname(path);
|
|
1540
|
+
this._getWatchedDir(dir).remove(sp.basename(path));
|
|
1501
1541
|
}
|
|
1502
1542
|
/**
|
|
1503
1543
|
* Closes only file-specific watchers
|
|
1504
1544
|
*/
|
|
1505
|
-
_closeFile(path
|
|
1506
|
-
const closers = this._closers.get(path
|
|
1545
|
+
_closeFile(path) {
|
|
1546
|
+
const closers = this._closers.get(path);
|
|
1507
1547
|
if (!closers) return;
|
|
1508
1548
|
closers.forEach((closer) => closer());
|
|
1509
|
-
this._closers.delete(path
|
|
1549
|
+
this._closers.delete(path);
|
|
1510
1550
|
}
|
|
1511
|
-
_addPathCloser(path
|
|
1551
|
+
_addPathCloser(path, closer) {
|
|
1512
1552
|
if (!closer) return;
|
|
1513
|
-
let list = this._closers.get(path
|
|
1553
|
+
let list = this._closers.get(path);
|
|
1514
1554
|
if (!list) {
|
|
1515
1555
|
list = [];
|
|
1516
|
-
this._closers.set(path
|
|
1556
|
+
this._closers.set(path, list);
|
|
1517
1557
|
}
|
|
1518
1558
|
list.push(closer);
|
|
1519
1559
|
}
|
|
@@ -1530,7 +1570,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
1530
1570
|
stream.once(STR_CLOSE, () => {
|
|
1531
1571
|
stream = void 0;
|
|
1532
1572
|
});
|
|
1533
|
-
stream.once(
|
|
1573
|
+
stream.once("end", () => {
|
|
1534
1574
|
if (stream) {
|
|
1535
1575
|
this._streams.delete(stream);
|
|
1536
1576
|
stream = void 0;
|
|
@@ -1553,63 +1593,65 @@ function watch$1(paths, options = {}) {
|
|
|
1553
1593
|
watcher.add(paths);
|
|
1554
1594
|
return watcher;
|
|
1555
1595
|
}
|
|
1556
|
-
var
|
|
1596
|
+
var chokidar_default = {
|
|
1557
1597
|
watch: watch$1,
|
|
1558
1598
|
FSWatcher
|
|
1559
1599
|
};
|
|
1560
|
-
|
|
1561
1600
|
//#endregion
|
|
1562
1601
|
//#region src/core/generator.ts
|
|
1602
|
+
const RE_INTERFACE = /^export\s+interface\s+([A-Za-z_$][\w$]*)/gm;
|
|
1603
|
+
const RE_NAMED_EXPORT = /export\s*\{([^}]+)\}/g;
|
|
1604
|
+
const RE_TYPE_EXPORT = /export\s+type\s*\{([^}]+)\}/g;
|
|
1605
|
+
const RE_AS_SPLIT = /\s+as\s+/;
|
|
1563
1606
|
function generateInterfaces(opts) {
|
|
1564
|
-
const { interfaceDir,
|
|
1607
|
+
const { interfaceDir, outputFile, excludeFiles } = opts;
|
|
1565
1608
|
const files = fs.readdirSync(interfaceDir).filter((file) => file.endsWith(".ts") && file !== "index.ts" && !excludeFiles.has(file));
|
|
1566
1609
|
const interfaces = [];
|
|
1567
1610
|
for (const file of files) {
|
|
1568
1611
|
const filePath = path.join(interfaceDir, file);
|
|
1569
|
-
const content = fs.readFileSync(filePath, "
|
|
1570
|
-
const interfaceNames = [...content.matchAll(
|
|
1571
|
-
const namedExportNames = [...content.matchAll(
|
|
1572
|
-
const
|
|
1612
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
1613
|
+
const interfaceNames = [...content.matchAll(RE_INTERFACE)].map((match) => match[1]);
|
|
1614
|
+
const namedExportNames = [...content.matchAll(RE_NAMED_EXPORT)].filter((match) => !content.substring(Math.max(0, match.index - 10), match.index).includes("type")).flatMap((match) => match[1].split(",").map((item) => item.trim().split(RE_AS_SPLIT)[0].trim()).filter((name) => name.length > 0));
|
|
1615
|
+
const typeExportNames = [...content.matchAll(RE_TYPE_EXPORT)].flatMap((match) => match[1].split(",").map((item) => item.trim().split(RE_AS_SPLIT)[0].trim()).filter((name) => name.length > 0));
|
|
1616
|
+
const allNames = [
|
|
1617
|
+
...interfaceNames,
|
|
1618
|
+
...namedExportNames,
|
|
1619
|
+
...typeExportNames
|
|
1620
|
+
];
|
|
1621
|
+
const names = [...new Set(allNames)].filter((name) => name && name !== "export");
|
|
1573
1622
|
if (names.length) interfaces.push({
|
|
1574
1623
|
file,
|
|
1575
1624
|
names
|
|
1576
1625
|
});
|
|
1577
1626
|
}
|
|
1578
|
-
const exportLines = interfaces.map((i) => `export * from './${path.basename(i.file, ".ts")}';`);
|
|
1579
|
-
fs.writeFileSync(indexFile, exportLines.join("\n"), "utf-8");
|
|
1580
1627
|
const globalLines = [
|
|
1581
|
-
`import type * as Interfaces from '../interfaces';`,
|
|
1582
|
-
"",
|
|
1583
1628
|
"declare global {",
|
|
1584
|
-
...interfaces.flatMap((
|
|
1629
|
+
...interfaces.flatMap((iface) => iface.names.map((name) => ` type ${name} = import('../interfaces/${path.basename(iface.file, ".ts")}').${name};`)),
|
|
1585
1630
|
"}",
|
|
1586
1631
|
"",
|
|
1587
|
-
"export {};"
|
|
1632
|
+
"export {};",
|
|
1633
|
+
""
|
|
1588
1634
|
];
|
|
1589
1635
|
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
1590
|
-
fs.writeFileSync(outputFile, globalLines.join("\n"), "
|
|
1636
|
+
fs.writeFileSync(outputFile, globalLines.join("\n"), "utf8");
|
|
1591
1637
|
return {
|
|
1592
1638
|
files: files.length,
|
|
1593
|
-
interfaces: interfaces.flatMap((
|
|
1639
|
+
interfaces: interfaces.flatMap((iface) => iface.names).length
|
|
1594
1640
|
};
|
|
1595
1641
|
}
|
|
1596
|
-
|
|
1597
1642
|
//#endregion
|
|
1598
1643
|
//#region src/core/paths.ts
|
|
1599
1644
|
function resolveOptions(root, options = {}) {
|
|
1600
|
-
const interfaceDir = path.resolve(root, options.dir ?? "resources/js/interfaces");
|
|
1601
1645
|
return {
|
|
1602
|
-
interfaceDir,
|
|
1603
|
-
indexFile: path.join(interfaceDir, "index.ts"),
|
|
1646
|
+
interfaceDir: path.resolve(root, options.dir ?? "resources/js/interfaces"),
|
|
1604
1647
|
outputFile: path.resolve(root, options.out ?? "resources/js/types/interfaces.d.ts"),
|
|
1605
|
-
excludeFiles: new Set(options.exclude
|
|
1648
|
+
excludeFiles: new Set(options.exclude)
|
|
1606
1649
|
};
|
|
1607
1650
|
}
|
|
1608
|
-
|
|
1609
1651
|
//#endregion
|
|
1610
1652
|
//#region src/index.ts
|
|
1611
1653
|
const unpluginFactory = (userOptions = {}, meta) => {
|
|
1612
|
-
const opts = resolveOptions(meta.framework === "vite" ? meta?.vite?.server?.config?.root ?? process.cwd() : process.cwd(), userOptions);
|
|
1654
|
+
const opts = resolveOptions(meta.framework === "vite" ? meta?.vite?.server?.config?.root ?? process$1.cwd() : process$1.cwd(), userOptions);
|
|
1613
1655
|
return {
|
|
1614
1656
|
name: "@supsign/unplugin-interfaces",
|
|
1615
1657
|
buildStart() {
|
|
@@ -1617,8 +1659,8 @@ const unpluginFactory = (userOptions = {}, meta) => {
|
|
|
1617
1659
|
this.info(`Generated ${result.interfaces} interfaces from ${result.files} files`);
|
|
1618
1660
|
},
|
|
1619
1661
|
vite: { configureServer(server) {
|
|
1620
|
-
const watcher =
|
|
1621
|
-
ignored: (filePath) => filePath.endsWith("index.ts") || filePath.endsWith(".d.ts") || [...opts.excludeFiles].some((
|
|
1662
|
+
const watcher = chokidar_default.watch(opts.interfaceDir, {
|
|
1663
|
+
ignored: (filePath) => filePath.endsWith("index.ts") || filePath.endsWith(".d.ts") || [...opts.excludeFiles].some((filename) => filePath.endsWith(filename)),
|
|
1622
1664
|
ignoreInitial: true
|
|
1623
1665
|
});
|
|
1624
1666
|
const log = (action) => {
|
|
@@ -1637,11 +1679,9 @@ const unpluginFactory = (userOptions = {}, meta) => {
|
|
|
1637
1679
|
};
|
|
1638
1680
|
};
|
|
1639
1681
|
const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
1640
|
-
var src_default = unplugin;
|
|
1641
1682
|
const vite = unplugin.vite;
|
|
1642
1683
|
const rollup = unplugin.rollup;
|
|
1643
1684
|
const webpack = unplugin.webpack;
|
|
1644
1685
|
const esbuild = unplugin.esbuild;
|
|
1645
|
-
|
|
1646
1686
|
//#endregion
|
|
1647
|
-
export {
|
|
1687
|
+
export { vite as a, unpluginFactory as i, rollup as n, webpack as o, unplugin as r, esbuild as t };
|