@igstack/app-catalog-frontend-build-vite 0.0.1
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 -0
- package/dist/esm/frontendViteConfig.d.ts +36 -0
- package/dist/esm/frontendViteConfig.js +151 -0
- package/dist/esm/frontendViteConfig.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/handler.js +774 -0
- package/dist/esm/node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/handler.js.map +1 -0
- package/dist/esm/node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.js +746 -0
- package/dist/esm/node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.js.map +1 -0
- package/dist/esm/node_modules/.pnpm/readdirp@5.0.0/node_modules/readdirp/index.js +241 -0
- package/dist/esm/node_modules/.pnpm/readdirp@5.0.0/node_modules/readdirp/index.js.map +1 -0
- package/dist/esm/watchExternalSource.d.ts +69 -0
- package/dist/esm/watchExternalSource.js +85 -0
- package/dist/esm/watchExternalSource.js.map +1 -0
- package/package.json +64 -0
- package/src/frontendViteConfig.ts +178 -0
- package/src/index.ts +7 -0
- package/src/watchExternalSource.ts +177 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { unwatchFile, watchFile, watch } from "node:fs";
|
|
5
|
+
import { realpath, stat, lstat, open } from "node:fs/promises";
|
|
6
|
+
import { type } from "node:os";
|
|
7
|
+
import * as sp from "node:path";
|
|
8
|
+
const STR_DATA = "data";
|
|
9
|
+
const STR_END = "end";
|
|
10
|
+
const STR_CLOSE = "close";
|
|
11
|
+
const EMPTY_FN = () => {
|
|
12
|
+
};
|
|
13
|
+
const pl = process.platform;
|
|
14
|
+
const isWindows = pl === "win32";
|
|
15
|
+
const isMacos = pl === "darwin";
|
|
16
|
+
const isLinux = pl === "linux";
|
|
17
|
+
const isFreeBSD = pl === "freebsd";
|
|
18
|
+
const isIBMi = type() === "OS400";
|
|
19
|
+
const EVENTS = {
|
|
20
|
+
ALL: "all",
|
|
21
|
+
READY: "ready",
|
|
22
|
+
ADD: "add",
|
|
23
|
+
CHANGE: "change",
|
|
24
|
+
ADD_DIR: "addDir",
|
|
25
|
+
UNLINK: "unlink",
|
|
26
|
+
UNLINK_DIR: "unlinkDir",
|
|
27
|
+
RAW: "raw",
|
|
28
|
+
ERROR: "error"
|
|
29
|
+
};
|
|
30
|
+
const EV = EVENTS;
|
|
31
|
+
const THROTTLE_MODE_WATCH = "watch";
|
|
32
|
+
const statMethods = { lstat, stat };
|
|
33
|
+
const KEY_LISTENERS = "listeners";
|
|
34
|
+
const KEY_ERR = "errHandlers";
|
|
35
|
+
const KEY_RAW = "rawEmitters";
|
|
36
|
+
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
|
37
|
+
const binaryExtensions = /* @__PURE__ */ new Set([
|
|
38
|
+
"3dm",
|
|
39
|
+
"3ds",
|
|
40
|
+
"3g2",
|
|
41
|
+
"3gp",
|
|
42
|
+
"7z",
|
|
43
|
+
"a",
|
|
44
|
+
"aac",
|
|
45
|
+
"adp",
|
|
46
|
+
"afdesign",
|
|
47
|
+
"afphoto",
|
|
48
|
+
"afpub",
|
|
49
|
+
"ai",
|
|
50
|
+
"aif",
|
|
51
|
+
"aiff",
|
|
52
|
+
"alz",
|
|
53
|
+
"ape",
|
|
54
|
+
"apk",
|
|
55
|
+
"appimage",
|
|
56
|
+
"ar",
|
|
57
|
+
"arj",
|
|
58
|
+
"asf",
|
|
59
|
+
"au",
|
|
60
|
+
"avi",
|
|
61
|
+
"bak",
|
|
62
|
+
"baml",
|
|
63
|
+
"bh",
|
|
64
|
+
"bin",
|
|
65
|
+
"bk",
|
|
66
|
+
"bmp",
|
|
67
|
+
"btif",
|
|
68
|
+
"bz2",
|
|
69
|
+
"bzip2",
|
|
70
|
+
"cab",
|
|
71
|
+
"caf",
|
|
72
|
+
"cgm",
|
|
73
|
+
"class",
|
|
74
|
+
"cmx",
|
|
75
|
+
"cpio",
|
|
76
|
+
"cr2",
|
|
77
|
+
"cur",
|
|
78
|
+
"dat",
|
|
79
|
+
"dcm",
|
|
80
|
+
"deb",
|
|
81
|
+
"dex",
|
|
82
|
+
"djvu",
|
|
83
|
+
"dll",
|
|
84
|
+
"dmg",
|
|
85
|
+
"dng",
|
|
86
|
+
"doc",
|
|
87
|
+
"docm",
|
|
88
|
+
"docx",
|
|
89
|
+
"dot",
|
|
90
|
+
"dotm",
|
|
91
|
+
"dra",
|
|
92
|
+
"DS_Store",
|
|
93
|
+
"dsk",
|
|
94
|
+
"dts",
|
|
95
|
+
"dtshd",
|
|
96
|
+
"dvb",
|
|
97
|
+
"dwg",
|
|
98
|
+
"dxf",
|
|
99
|
+
"ecelp4800",
|
|
100
|
+
"ecelp7470",
|
|
101
|
+
"ecelp9600",
|
|
102
|
+
"egg",
|
|
103
|
+
"eol",
|
|
104
|
+
"eot",
|
|
105
|
+
"epub",
|
|
106
|
+
"exe",
|
|
107
|
+
"f4v",
|
|
108
|
+
"fbs",
|
|
109
|
+
"fh",
|
|
110
|
+
"fla",
|
|
111
|
+
"flac",
|
|
112
|
+
"flatpak",
|
|
113
|
+
"fli",
|
|
114
|
+
"flv",
|
|
115
|
+
"fpx",
|
|
116
|
+
"fst",
|
|
117
|
+
"fvt",
|
|
118
|
+
"g3",
|
|
119
|
+
"gh",
|
|
120
|
+
"gif",
|
|
121
|
+
"graffle",
|
|
122
|
+
"gz",
|
|
123
|
+
"gzip",
|
|
124
|
+
"h261",
|
|
125
|
+
"h263",
|
|
126
|
+
"h264",
|
|
127
|
+
"icns",
|
|
128
|
+
"ico",
|
|
129
|
+
"ief",
|
|
130
|
+
"img",
|
|
131
|
+
"ipa",
|
|
132
|
+
"iso",
|
|
133
|
+
"jar",
|
|
134
|
+
"jpeg",
|
|
135
|
+
"jpg",
|
|
136
|
+
"jpgv",
|
|
137
|
+
"jpm",
|
|
138
|
+
"jxr",
|
|
139
|
+
"key",
|
|
140
|
+
"ktx",
|
|
141
|
+
"lha",
|
|
142
|
+
"lib",
|
|
143
|
+
"lvp",
|
|
144
|
+
"lz",
|
|
145
|
+
"lzh",
|
|
146
|
+
"lzma",
|
|
147
|
+
"lzo",
|
|
148
|
+
"m3u",
|
|
149
|
+
"m4a",
|
|
150
|
+
"m4v",
|
|
151
|
+
"mar",
|
|
152
|
+
"mdi",
|
|
153
|
+
"mht",
|
|
154
|
+
"mid",
|
|
155
|
+
"midi",
|
|
156
|
+
"mj2",
|
|
157
|
+
"mka",
|
|
158
|
+
"mkv",
|
|
159
|
+
"mmr",
|
|
160
|
+
"mng",
|
|
161
|
+
"mobi",
|
|
162
|
+
"mov",
|
|
163
|
+
"movie",
|
|
164
|
+
"mp3",
|
|
165
|
+
"mp4",
|
|
166
|
+
"mp4a",
|
|
167
|
+
"mpeg",
|
|
168
|
+
"mpg",
|
|
169
|
+
"mpga",
|
|
170
|
+
"mxu",
|
|
171
|
+
"nef",
|
|
172
|
+
"npx",
|
|
173
|
+
"numbers",
|
|
174
|
+
"nupkg",
|
|
175
|
+
"o",
|
|
176
|
+
"odp",
|
|
177
|
+
"ods",
|
|
178
|
+
"odt",
|
|
179
|
+
"oga",
|
|
180
|
+
"ogg",
|
|
181
|
+
"ogv",
|
|
182
|
+
"otf",
|
|
183
|
+
"ott",
|
|
184
|
+
"pages",
|
|
185
|
+
"pbm",
|
|
186
|
+
"pcx",
|
|
187
|
+
"pdb",
|
|
188
|
+
"pdf",
|
|
189
|
+
"pea",
|
|
190
|
+
"pgm",
|
|
191
|
+
"pic",
|
|
192
|
+
"png",
|
|
193
|
+
"pnm",
|
|
194
|
+
"pot",
|
|
195
|
+
"potm",
|
|
196
|
+
"potx",
|
|
197
|
+
"ppa",
|
|
198
|
+
"ppam",
|
|
199
|
+
"ppm",
|
|
200
|
+
"pps",
|
|
201
|
+
"ppsm",
|
|
202
|
+
"ppsx",
|
|
203
|
+
"ppt",
|
|
204
|
+
"pptm",
|
|
205
|
+
"pptx",
|
|
206
|
+
"psd",
|
|
207
|
+
"pya",
|
|
208
|
+
"pyc",
|
|
209
|
+
"pyo",
|
|
210
|
+
"pyv",
|
|
211
|
+
"qt",
|
|
212
|
+
"rar",
|
|
213
|
+
"ras",
|
|
214
|
+
"raw",
|
|
215
|
+
"resources",
|
|
216
|
+
"rgb",
|
|
217
|
+
"rip",
|
|
218
|
+
"rlc",
|
|
219
|
+
"rmf",
|
|
220
|
+
"rmvb",
|
|
221
|
+
"rpm",
|
|
222
|
+
"rtf",
|
|
223
|
+
"rz",
|
|
224
|
+
"s3m",
|
|
225
|
+
"s7z",
|
|
226
|
+
"scpt",
|
|
227
|
+
"sgi",
|
|
228
|
+
"shar",
|
|
229
|
+
"snap",
|
|
230
|
+
"sil",
|
|
231
|
+
"sketch",
|
|
232
|
+
"slk",
|
|
233
|
+
"smv",
|
|
234
|
+
"snk",
|
|
235
|
+
"so",
|
|
236
|
+
"stl",
|
|
237
|
+
"suo",
|
|
238
|
+
"sub",
|
|
239
|
+
"swf",
|
|
240
|
+
"tar",
|
|
241
|
+
"tbz",
|
|
242
|
+
"tbz2",
|
|
243
|
+
"tga",
|
|
244
|
+
"tgz",
|
|
245
|
+
"thmx",
|
|
246
|
+
"tif",
|
|
247
|
+
"tiff",
|
|
248
|
+
"tlz",
|
|
249
|
+
"ttc",
|
|
250
|
+
"ttf",
|
|
251
|
+
"txz",
|
|
252
|
+
"udf",
|
|
253
|
+
"uvh",
|
|
254
|
+
"uvi",
|
|
255
|
+
"uvm",
|
|
256
|
+
"uvp",
|
|
257
|
+
"uvs",
|
|
258
|
+
"uvu",
|
|
259
|
+
"viv",
|
|
260
|
+
"vob",
|
|
261
|
+
"war",
|
|
262
|
+
"wav",
|
|
263
|
+
"wax",
|
|
264
|
+
"wbmp",
|
|
265
|
+
"wdp",
|
|
266
|
+
"weba",
|
|
267
|
+
"webm",
|
|
268
|
+
"webp",
|
|
269
|
+
"whl",
|
|
270
|
+
"wim",
|
|
271
|
+
"wm",
|
|
272
|
+
"wma",
|
|
273
|
+
"wmv",
|
|
274
|
+
"wmx",
|
|
275
|
+
"woff",
|
|
276
|
+
"woff2",
|
|
277
|
+
"wrm",
|
|
278
|
+
"wvx",
|
|
279
|
+
"xbm",
|
|
280
|
+
"xif",
|
|
281
|
+
"xla",
|
|
282
|
+
"xlam",
|
|
283
|
+
"xls",
|
|
284
|
+
"xlsb",
|
|
285
|
+
"xlsm",
|
|
286
|
+
"xlsx",
|
|
287
|
+
"xlt",
|
|
288
|
+
"xltm",
|
|
289
|
+
"xltx",
|
|
290
|
+
"xm",
|
|
291
|
+
"xmind",
|
|
292
|
+
"xpi",
|
|
293
|
+
"xpm",
|
|
294
|
+
"xwd",
|
|
295
|
+
"xz",
|
|
296
|
+
"z",
|
|
297
|
+
"zip",
|
|
298
|
+
"zipx"
|
|
299
|
+
]);
|
|
300
|
+
const isBinaryPath = (filePath) => binaryExtensions.has(sp.extname(filePath).slice(1).toLowerCase());
|
|
301
|
+
const foreach = (val, fn) => {
|
|
302
|
+
if (val instanceof Set) {
|
|
303
|
+
val.forEach(fn);
|
|
304
|
+
} else {
|
|
305
|
+
fn(val);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const addAndConvert = (main, prop, item) => {
|
|
309
|
+
let container = main[prop];
|
|
310
|
+
if (!(container instanceof Set)) {
|
|
311
|
+
main[prop] = container = /* @__PURE__ */ new Set([container]);
|
|
312
|
+
}
|
|
313
|
+
container.add(item);
|
|
314
|
+
};
|
|
315
|
+
const clearItem = (cont) => (key) => {
|
|
316
|
+
const set = cont[key];
|
|
317
|
+
if (set instanceof Set) {
|
|
318
|
+
set.clear();
|
|
319
|
+
} else {
|
|
320
|
+
delete cont[key];
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
const delFromSet = (main, prop, item) => {
|
|
324
|
+
const container = main[prop];
|
|
325
|
+
if (container instanceof Set) {
|
|
326
|
+
container.delete(item);
|
|
327
|
+
} else if (container === item) {
|
|
328
|
+
delete main[prop];
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
332
|
+
const FsWatchInstances = /* @__PURE__ */ new Map();
|
|
333
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
334
|
+
const handleEvent = (rawEvent, evPath) => {
|
|
335
|
+
listener(path);
|
|
336
|
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
|
337
|
+
if (evPath && path !== evPath) {
|
|
338
|
+
fsWatchBroadcast(sp.resolve(path, evPath), KEY_LISTENERS, sp.join(path, evPath));
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
try {
|
|
342
|
+
return watch(path, {
|
|
343
|
+
persistent: options.persistent
|
|
344
|
+
}, handleEvent);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
errHandler(error);
|
|
347
|
+
return void 0;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
351
|
+
const cont = FsWatchInstances.get(fullPath);
|
|
352
|
+
if (!cont)
|
|
353
|
+
return;
|
|
354
|
+
foreach(cont[listenerType], (listener) => {
|
|
355
|
+
listener(val1, val2, val3);
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
|
359
|
+
const { listener, errHandler, rawEmitter } = handlers;
|
|
360
|
+
let cont = FsWatchInstances.get(fullPath);
|
|
361
|
+
let watcher;
|
|
362
|
+
if (!options.persistent) {
|
|
363
|
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
|
364
|
+
if (!watcher)
|
|
365
|
+
return;
|
|
366
|
+
return watcher.close.bind(watcher);
|
|
367
|
+
}
|
|
368
|
+
if (cont) {
|
|
369
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
370
|
+
addAndConvert(cont, KEY_ERR, errHandler);
|
|
371
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
372
|
+
} else {
|
|
373
|
+
watcher = createFsWatchInstance(
|
|
374
|
+
path,
|
|
375
|
+
options,
|
|
376
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
377
|
+
errHandler,
|
|
378
|
+
// no need to use broadcast here
|
|
379
|
+
fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
|
|
380
|
+
);
|
|
381
|
+
if (!watcher)
|
|
382
|
+
return;
|
|
383
|
+
watcher.on(EV.ERROR, async (error) => {
|
|
384
|
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
385
|
+
if (cont)
|
|
386
|
+
cont.watcherUnusable = true;
|
|
387
|
+
if (isWindows && error.code === "EPERM") {
|
|
388
|
+
try {
|
|
389
|
+
const fd = await open(path, "r");
|
|
390
|
+
await fd.close();
|
|
391
|
+
broadcastErr(error);
|
|
392
|
+
} catch (err) {
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
broadcastErr(error);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
cont = {
|
|
399
|
+
listeners: listener,
|
|
400
|
+
errHandlers: errHandler,
|
|
401
|
+
rawEmitters: rawEmitter,
|
|
402
|
+
watcher
|
|
403
|
+
};
|
|
404
|
+
FsWatchInstances.set(fullPath, cont);
|
|
405
|
+
}
|
|
406
|
+
return () => {
|
|
407
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
408
|
+
delFromSet(cont, KEY_ERR, errHandler);
|
|
409
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
410
|
+
if (isEmptySet(cont.listeners)) {
|
|
411
|
+
cont.watcher.close();
|
|
412
|
+
FsWatchInstances.delete(fullPath);
|
|
413
|
+
HANDLER_KEYS.forEach(clearItem(cont));
|
|
414
|
+
cont.watcher = void 0;
|
|
415
|
+
Object.freeze(cont);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
const FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
420
|
+
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
|
421
|
+
const { listener, rawEmitter } = handlers;
|
|
422
|
+
let cont = FsWatchFileInstances.get(fullPath);
|
|
423
|
+
const copts = cont && cont.options;
|
|
424
|
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
425
|
+
unwatchFile(fullPath);
|
|
426
|
+
cont = void 0;
|
|
427
|
+
}
|
|
428
|
+
if (cont) {
|
|
429
|
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
|
430
|
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
431
|
+
} else {
|
|
432
|
+
cont = {
|
|
433
|
+
listeners: listener,
|
|
434
|
+
rawEmitters: rawEmitter,
|
|
435
|
+
options,
|
|
436
|
+
watcher: watchFile(fullPath, options, (curr, prev) => {
|
|
437
|
+
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
438
|
+
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
439
|
+
});
|
|
440
|
+
const currmtime = curr.mtimeMs;
|
|
441
|
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
442
|
+
foreach(cont.listeners, (listener2) => listener2(path, curr));
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
};
|
|
446
|
+
FsWatchFileInstances.set(fullPath, cont);
|
|
447
|
+
}
|
|
448
|
+
return () => {
|
|
449
|
+
delFromSet(cont, KEY_LISTENERS, listener);
|
|
450
|
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
451
|
+
if (isEmptySet(cont.listeners)) {
|
|
452
|
+
FsWatchFileInstances.delete(fullPath);
|
|
453
|
+
unwatchFile(fullPath);
|
|
454
|
+
cont.options = cont.watcher = void 0;
|
|
455
|
+
Object.freeze(cont);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
class NodeFsHandler {
|
|
460
|
+
constructor(fsW) {
|
|
461
|
+
__publicField(this, "fsw");
|
|
462
|
+
__publicField(this, "_boundHandleError");
|
|
463
|
+
this.fsw = fsW;
|
|
464
|
+
this._boundHandleError = (error) => fsW._handleError(error);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Watch file for changes with fs_watchFile or fs_watch.
|
|
468
|
+
* @param path to file or dir
|
|
469
|
+
* @param listener on fs change
|
|
470
|
+
* @returns closer for the watcher instance
|
|
471
|
+
*/
|
|
472
|
+
_watchWithNodeFs(path, listener) {
|
|
473
|
+
const opts = this.fsw.options;
|
|
474
|
+
const directory = sp.dirname(path);
|
|
475
|
+
const basename = sp.basename(path);
|
|
476
|
+
const parent = this.fsw._getWatchedDir(directory);
|
|
477
|
+
parent.add(basename);
|
|
478
|
+
const absolutePath = sp.resolve(path);
|
|
479
|
+
const options = {
|
|
480
|
+
persistent: opts.persistent
|
|
481
|
+
};
|
|
482
|
+
if (!listener)
|
|
483
|
+
listener = EMPTY_FN;
|
|
484
|
+
let closer;
|
|
485
|
+
if (opts.usePolling) {
|
|
486
|
+
const enableBin = opts.interval !== opts.binaryInterval;
|
|
487
|
+
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
|
488
|
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
489
|
+
listener,
|
|
490
|
+
rawEmitter: this.fsw._emitRaw
|
|
491
|
+
});
|
|
492
|
+
} else {
|
|
493
|
+
closer = setFsWatchListener(path, absolutePath, options, {
|
|
494
|
+
listener,
|
|
495
|
+
errHandler: this._boundHandleError,
|
|
496
|
+
rawEmitter: this.fsw._emitRaw
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
return closer;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Watch a file and emit add event if warranted.
|
|
503
|
+
* @returns closer for the watcher instance
|
|
504
|
+
*/
|
|
505
|
+
_handleFile(file, stats, initialAdd) {
|
|
506
|
+
if (this.fsw.closed) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const dirname = sp.dirname(file);
|
|
510
|
+
const basename = sp.basename(file);
|
|
511
|
+
const parent = this.fsw._getWatchedDir(dirname);
|
|
512
|
+
let prevStats = stats;
|
|
513
|
+
if (parent.has(basename))
|
|
514
|
+
return;
|
|
515
|
+
const listener = async (path, newStats) => {
|
|
516
|
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
517
|
+
return;
|
|
518
|
+
if (!newStats || newStats.mtimeMs === 0) {
|
|
519
|
+
try {
|
|
520
|
+
const newStats2 = await stat(file);
|
|
521
|
+
if (this.fsw.closed)
|
|
522
|
+
return;
|
|
523
|
+
const at = newStats2.atimeMs;
|
|
524
|
+
const mt = newStats2.mtimeMs;
|
|
525
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
526
|
+
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
527
|
+
}
|
|
528
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
529
|
+
this.fsw._closeFile(path);
|
|
530
|
+
prevStats = newStats2;
|
|
531
|
+
const closer2 = this._watchWithNodeFs(file, listener);
|
|
532
|
+
if (closer2)
|
|
533
|
+
this.fsw._addPathCloser(path, closer2);
|
|
534
|
+
} else {
|
|
535
|
+
prevStats = newStats2;
|
|
536
|
+
}
|
|
537
|
+
} catch (error) {
|
|
538
|
+
this.fsw._remove(dirname, basename);
|
|
539
|
+
}
|
|
540
|
+
} else if (parent.has(basename)) {
|
|
541
|
+
const at = newStats.atimeMs;
|
|
542
|
+
const mt = newStats.mtimeMs;
|
|
543
|
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
544
|
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
|
545
|
+
}
|
|
546
|
+
prevStats = newStats;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const closer = this._watchWithNodeFs(file, listener);
|
|
550
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
551
|
+
if (!this.fsw._throttle(EV.ADD, file, 0))
|
|
552
|
+
return;
|
|
553
|
+
this.fsw._emit(EV.ADD, file, stats);
|
|
554
|
+
}
|
|
555
|
+
return closer;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Handle symlinks encountered while reading a dir.
|
|
559
|
+
* @param entry returned by readdirp
|
|
560
|
+
* @param directory path of dir being read
|
|
561
|
+
* @param path of this item
|
|
562
|
+
* @param item basename of this item
|
|
563
|
+
* @returns true if no more processing is needed for this entry.
|
|
564
|
+
*/
|
|
565
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
566
|
+
if (this.fsw.closed) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const full = entry.fullPath;
|
|
570
|
+
const dir = this.fsw._getWatchedDir(directory);
|
|
571
|
+
if (!this.fsw.options.followSymlinks) {
|
|
572
|
+
this.fsw._incrReadyCount();
|
|
573
|
+
let linkPath;
|
|
574
|
+
try {
|
|
575
|
+
linkPath = await realpath(path);
|
|
576
|
+
} catch (e) {
|
|
577
|
+
this.fsw._emitReady();
|
|
578
|
+
return true;
|
|
579
|
+
}
|
|
580
|
+
if (this.fsw.closed)
|
|
581
|
+
return;
|
|
582
|
+
if (dir.has(item)) {
|
|
583
|
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
584
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
585
|
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
dir.add(item);
|
|
589
|
+
this.fsw._symlinkPaths.set(full, linkPath);
|
|
590
|
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
|
591
|
+
}
|
|
592
|
+
this.fsw._emitReady();
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
if (this.fsw._symlinkPaths.has(full)) {
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
this.fsw._symlinkPaths.set(full, true);
|
|
599
|
+
}
|
|
600
|
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
601
|
+
directory = sp.join(directory, "");
|
|
602
|
+
const throttleKey = target ? `${directory}:${target}` : directory;
|
|
603
|
+
throttler = this.fsw._throttle("readdir", throttleKey, 1e3);
|
|
604
|
+
if (!throttler)
|
|
605
|
+
return;
|
|
606
|
+
const previous = this.fsw._getWatchedDir(wh.path);
|
|
607
|
+
const current = /* @__PURE__ */ new Set();
|
|
608
|
+
let stream = this.fsw._readdirp(directory, {
|
|
609
|
+
fileFilter: (entry) => wh.filterPath(entry),
|
|
610
|
+
directoryFilter: (entry) => wh.filterDir(entry)
|
|
611
|
+
});
|
|
612
|
+
if (!stream)
|
|
613
|
+
return;
|
|
614
|
+
stream.on(STR_DATA, async (entry) => {
|
|
615
|
+
if (this.fsw.closed) {
|
|
616
|
+
stream = void 0;
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const item = entry.path;
|
|
620
|
+
let path = sp.join(directory, item);
|
|
621
|
+
current.add(item);
|
|
622
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (this.fsw.closed) {
|
|
626
|
+
stream = void 0;
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (item === target || !target && !previous.has(item)) {
|
|
630
|
+
this.fsw._incrReadyCount();
|
|
631
|
+
path = sp.join(dir, sp.relative(dir, path));
|
|
632
|
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
|
633
|
+
}
|
|
634
|
+
}).on(EV.ERROR, this._boundHandleError);
|
|
635
|
+
return new Promise((resolve, reject) => {
|
|
636
|
+
if (!stream)
|
|
637
|
+
return reject();
|
|
638
|
+
stream.once(STR_END, () => {
|
|
639
|
+
if (this.fsw.closed) {
|
|
640
|
+
stream = void 0;
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const wasThrottled = throttler ? throttler.clear() : false;
|
|
644
|
+
resolve(void 0);
|
|
645
|
+
previous.getChildren().filter((item) => {
|
|
646
|
+
return item !== directory && !current.has(item);
|
|
647
|
+
}).forEach((item) => {
|
|
648
|
+
this.fsw._remove(directory, item);
|
|
649
|
+
});
|
|
650
|
+
stream = void 0;
|
|
651
|
+
if (wasThrottled)
|
|
652
|
+
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
|
658
|
+
* @param dir fs path
|
|
659
|
+
* @param stats
|
|
660
|
+
* @param initialAdd
|
|
661
|
+
* @param depth relative to user-supplied path
|
|
662
|
+
* @param target child path targeted for watch
|
|
663
|
+
* @param wh Common watch helpers for this path
|
|
664
|
+
* @param realpath
|
|
665
|
+
* @returns closer for the watcher instance.
|
|
666
|
+
*/
|
|
667
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath2) {
|
|
668
|
+
const parentDir = this.fsw._getWatchedDir(sp.dirname(dir));
|
|
669
|
+
const tracked = parentDir.has(sp.basename(dir));
|
|
670
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
|
671
|
+
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
|
672
|
+
}
|
|
673
|
+
parentDir.add(sp.basename(dir));
|
|
674
|
+
this.fsw._getWatchedDir(dir);
|
|
675
|
+
let throttler;
|
|
676
|
+
let closer;
|
|
677
|
+
const oDepth = this.fsw.options.depth;
|
|
678
|
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath2)) {
|
|
679
|
+
if (!target) {
|
|
680
|
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
|
681
|
+
if (this.fsw.closed)
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats2) => {
|
|
685
|
+
if (stats2 && stats2.mtimeMs === 0)
|
|
686
|
+
return;
|
|
687
|
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
return closer;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Handle added file, directory, or glob pattern.
|
|
694
|
+
* Delegates call to _handleFile / _handleDir after checks.
|
|
695
|
+
* @param path to file or ir
|
|
696
|
+
* @param initialAdd was the file added at watch instantiation?
|
|
697
|
+
* @param priorWh depth relative to user-supplied path
|
|
698
|
+
* @param depth Child path actually targeted for watch
|
|
699
|
+
* @param target Child path actually targeted for watch
|
|
700
|
+
*/
|
|
701
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
702
|
+
const ready = this.fsw._emitReady;
|
|
703
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
|
704
|
+
ready();
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
const wh = this.fsw._getWatchHelpers(path);
|
|
708
|
+
if (priorWh) {
|
|
709
|
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
710
|
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
711
|
+
}
|
|
712
|
+
try {
|
|
713
|
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
714
|
+
if (this.fsw.closed)
|
|
715
|
+
return;
|
|
716
|
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
|
717
|
+
ready();
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
const follow = this.fsw.options.followSymlinks;
|
|
721
|
+
let closer;
|
|
722
|
+
if (stats.isDirectory()) {
|
|
723
|
+
const absPath = sp.resolve(path);
|
|
724
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
725
|
+
if (this.fsw.closed)
|
|
726
|
+
return;
|
|
727
|
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
728
|
+
if (this.fsw.closed)
|
|
729
|
+
return;
|
|
730
|
+
if (absPath !== targetPath && targetPath !== void 0) {
|
|
731
|
+
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
732
|
+
}
|
|
733
|
+
} else if (stats.isSymbolicLink()) {
|
|
734
|
+
const targetPath = follow ? await realpath(path) : path;
|
|
735
|
+
if (this.fsw.closed)
|
|
736
|
+
return;
|
|
737
|
+
const parent = sp.dirname(wh.watchPath);
|
|
738
|
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
739
|
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
740
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
|
741
|
+
if (this.fsw.closed)
|
|
742
|
+
return;
|
|
743
|
+
if (targetPath !== void 0) {
|
|
744
|
+
this.fsw._symlinkPaths.set(sp.resolve(path), targetPath);
|
|
745
|
+
}
|
|
746
|
+
} else {
|
|
747
|
+
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
748
|
+
}
|
|
749
|
+
ready();
|
|
750
|
+
if (closer)
|
|
751
|
+
this.fsw._addPathCloser(path, closer);
|
|
752
|
+
return false;
|
|
753
|
+
} catch (error) {
|
|
754
|
+
if (this.fsw._handleError(error)) {
|
|
755
|
+
ready();
|
|
756
|
+
return path;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
export {
|
|
762
|
+
EMPTY_FN,
|
|
763
|
+
EVENTS,
|
|
764
|
+
NodeFsHandler,
|
|
765
|
+
STR_CLOSE,
|
|
766
|
+
STR_DATA,
|
|
767
|
+
STR_END,
|
|
768
|
+
isFreeBSD,
|
|
769
|
+
isIBMi,
|
|
770
|
+
isLinux,
|
|
771
|
+
isMacos,
|
|
772
|
+
isWindows
|
|
773
|
+
};
|
|
774
|
+
//# sourceMappingURL=handler.js.map
|