@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,746 @@
|
|
|
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 { EventEmitter } from "node:events";
|
|
5
|
+
import { stat as stat$1 } from "node:fs";
|
|
6
|
+
import { stat, readdir } from "node:fs/promises";
|
|
7
|
+
import * as sp from "node:path";
|
|
8
|
+
import { readdirp } from "../../../readdirp@5.0.0/node_modules/readdirp/index.js";
|
|
9
|
+
import { EMPTY_FN, EVENTS, NodeFsHandler, isWindows, STR_CLOSE, STR_END, isIBMi } from "./handler.js";
|
|
10
|
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
|
11
|
+
const SLASH = "/";
|
|
12
|
+
const SLASH_SLASH = "//";
|
|
13
|
+
const ONE_DOT = ".";
|
|
14
|
+
const TWO_DOTS = "..";
|
|
15
|
+
const STRING_TYPE = "string";
|
|
16
|
+
const BACK_SLASH_RE = /\\/g;
|
|
17
|
+
const DOUBLE_SLASH_RE = /\/\//g;
|
|
18
|
+
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
19
|
+
const REPLACER_RE = /^\.[/\\]/;
|
|
20
|
+
function arrify(item) {
|
|
21
|
+
return Array.isArray(item) ? item : [item];
|
|
22
|
+
}
|
|
23
|
+
const isMatcherObject = (matcher) => typeof matcher === "object" && matcher !== null && !(matcher instanceof RegExp);
|
|
24
|
+
function createPattern(matcher) {
|
|
25
|
+
if (typeof matcher === "function")
|
|
26
|
+
return matcher;
|
|
27
|
+
if (typeof matcher === "string")
|
|
28
|
+
return (string) => matcher === string;
|
|
29
|
+
if (matcher instanceof RegExp)
|
|
30
|
+
return (string) => matcher.test(string);
|
|
31
|
+
if (typeof matcher === "object" && matcher !== null) {
|
|
32
|
+
return (string) => {
|
|
33
|
+
if (matcher.path === string)
|
|
34
|
+
return true;
|
|
35
|
+
if (matcher.recursive) {
|
|
36
|
+
const relative = sp.relative(matcher.path, string);
|
|
37
|
+
if (!relative) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return !relative.startsWith("..") && !sp.isAbsolute(relative);
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return () => false;
|
|
46
|
+
}
|
|
47
|
+
function normalizePath(path) {
|
|
48
|
+
if (typeof path !== "string")
|
|
49
|
+
throw new Error("string expected");
|
|
50
|
+
path = sp.normalize(path);
|
|
51
|
+
path = path.replace(/\\/g, "/");
|
|
52
|
+
let prepend = false;
|
|
53
|
+
if (path.startsWith("//"))
|
|
54
|
+
prepend = true;
|
|
55
|
+
path = path.replace(DOUBLE_SLASH_RE, "/");
|
|
56
|
+
if (prepend)
|
|
57
|
+
path = "/" + path;
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
60
|
+
function matchPatterns(patterns, testString, stats) {
|
|
61
|
+
const path = normalizePath(testString);
|
|
62
|
+
for (let index = 0; index < patterns.length; index++) {
|
|
63
|
+
const pattern = patterns[index];
|
|
64
|
+
if (pattern(path, stats)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function anymatch(matchers, testString) {
|
|
71
|
+
if (matchers == null) {
|
|
72
|
+
throw new TypeError("anymatch: specify first argument");
|
|
73
|
+
}
|
|
74
|
+
const matchersArray = arrify(matchers);
|
|
75
|
+
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
|
76
|
+
{
|
|
77
|
+
return (testString2, stats) => {
|
|
78
|
+
return matchPatterns(patterns, testString2, stats);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const unifyPaths = (paths_) => {
|
|
83
|
+
const paths = arrify(paths_).flat();
|
|
84
|
+
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
|
85
|
+
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
|
86
|
+
}
|
|
87
|
+
return paths.map(normalizePathToUnix);
|
|
88
|
+
};
|
|
89
|
+
const toUnix = (string) => {
|
|
90
|
+
let str = string.replace(BACK_SLASH_RE, SLASH);
|
|
91
|
+
let prepend = false;
|
|
92
|
+
if (str.startsWith(SLASH_SLASH)) {
|
|
93
|
+
prepend = true;
|
|
94
|
+
}
|
|
95
|
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
|
96
|
+
if (prepend) {
|
|
97
|
+
str = SLASH + str;
|
|
98
|
+
}
|
|
99
|
+
return str;
|
|
100
|
+
};
|
|
101
|
+
const normalizePathToUnix = (path) => toUnix(sp.normalize(toUnix(path)));
|
|
102
|
+
const normalizeIgnored = (cwd = "") => (path) => {
|
|
103
|
+
if (typeof path === "string") {
|
|
104
|
+
return normalizePathToUnix(sp.isAbsolute(path) ? path : sp.join(cwd, path));
|
|
105
|
+
} else {
|
|
106
|
+
return path;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const getAbsolutePath = (path, cwd) => {
|
|
110
|
+
if (sp.isAbsolute(path)) {
|
|
111
|
+
return path;
|
|
112
|
+
}
|
|
113
|
+
return sp.join(cwd, path);
|
|
114
|
+
};
|
|
115
|
+
const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
116
|
+
class DirEntry {
|
|
117
|
+
constructor(dir, removeWatcher) {
|
|
118
|
+
__publicField(this, "path");
|
|
119
|
+
__publicField(this, "_removeWatcher");
|
|
120
|
+
__publicField(this, "items");
|
|
121
|
+
this.path = dir;
|
|
122
|
+
this._removeWatcher = removeWatcher;
|
|
123
|
+
this.items = /* @__PURE__ */ new Set();
|
|
124
|
+
}
|
|
125
|
+
add(item) {
|
|
126
|
+
const { items } = this;
|
|
127
|
+
if (!items)
|
|
128
|
+
return;
|
|
129
|
+
if (item !== ONE_DOT && item !== TWO_DOTS)
|
|
130
|
+
items.add(item);
|
|
131
|
+
}
|
|
132
|
+
async remove(item) {
|
|
133
|
+
const { items } = this;
|
|
134
|
+
if (!items)
|
|
135
|
+
return;
|
|
136
|
+
items.delete(item);
|
|
137
|
+
if (items.size > 0)
|
|
138
|
+
return;
|
|
139
|
+
const dir = this.path;
|
|
140
|
+
try {
|
|
141
|
+
await readdir(dir);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
if (this._removeWatcher) {
|
|
144
|
+
this._removeWatcher(sp.dirname(dir), sp.basename(dir));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
has(item) {
|
|
149
|
+
const { items } = this;
|
|
150
|
+
if (!items)
|
|
151
|
+
return;
|
|
152
|
+
return items.has(item);
|
|
153
|
+
}
|
|
154
|
+
getChildren() {
|
|
155
|
+
const { items } = this;
|
|
156
|
+
if (!items)
|
|
157
|
+
return [];
|
|
158
|
+
return [...items.values()];
|
|
159
|
+
}
|
|
160
|
+
dispose() {
|
|
161
|
+
this.items.clear();
|
|
162
|
+
this.path = "";
|
|
163
|
+
this._removeWatcher = EMPTY_FN;
|
|
164
|
+
this.items = EMPTY_SET;
|
|
165
|
+
Object.freeze(this);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const STAT_METHOD_F = "stat";
|
|
169
|
+
const STAT_METHOD_L = "lstat";
|
|
170
|
+
class WatchHelper {
|
|
171
|
+
constructor(path, follow, fsw) {
|
|
172
|
+
__publicField(this, "fsw");
|
|
173
|
+
__publicField(this, "path");
|
|
174
|
+
__publicField(this, "watchPath");
|
|
175
|
+
__publicField(this, "fullWatchPath");
|
|
176
|
+
__publicField(this, "dirParts");
|
|
177
|
+
__publicField(this, "followSymlinks");
|
|
178
|
+
__publicField(this, "statMethod");
|
|
179
|
+
this.fsw = fsw;
|
|
180
|
+
const watchPath = path;
|
|
181
|
+
this.path = path = path.replace(REPLACER_RE, "");
|
|
182
|
+
this.watchPath = watchPath;
|
|
183
|
+
this.fullWatchPath = sp.resolve(watchPath);
|
|
184
|
+
this.dirParts = [];
|
|
185
|
+
this.dirParts.forEach((parts) => {
|
|
186
|
+
if (parts.length > 1)
|
|
187
|
+
parts.pop();
|
|
188
|
+
});
|
|
189
|
+
this.followSymlinks = follow;
|
|
190
|
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
|
191
|
+
}
|
|
192
|
+
entryPath(entry) {
|
|
193
|
+
return sp.join(this.watchPath, sp.relative(this.watchPath, entry.fullPath));
|
|
194
|
+
}
|
|
195
|
+
filterPath(entry) {
|
|
196
|
+
const { stats } = entry;
|
|
197
|
+
if (stats && stats.isSymbolicLink())
|
|
198
|
+
return this.filterDir(entry);
|
|
199
|
+
const resolvedPath = this.entryPath(entry);
|
|
200
|
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
201
|
+
}
|
|
202
|
+
filterDir(entry) {
|
|
203
|
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
class FSWatcher extends EventEmitter {
|
|
207
|
+
// Not indenting methods for history sake; for now.
|
|
208
|
+
constructor(_opts = {}) {
|
|
209
|
+
super();
|
|
210
|
+
__publicField(this, "closed");
|
|
211
|
+
__publicField(this, "options");
|
|
212
|
+
__publicField(this, "_closers");
|
|
213
|
+
__publicField(this, "_ignoredPaths");
|
|
214
|
+
__publicField(this, "_throttled");
|
|
215
|
+
__publicField(this, "_streams");
|
|
216
|
+
__publicField(this, "_symlinkPaths");
|
|
217
|
+
__publicField(this, "_watched");
|
|
218
|
+
__publicField(this, "_pendingWrites");
|
|
219
|
+
__publicField(this, "_pendingUnlinks");
|
|
220
|
+
__publicField(this, "_readyCount");
|
|
221
|
+
__publicField(this, "_emitReady");
|
|
222
|
+
__publicField(this, "_closePromise");
|
|
223
|
+
__publicField(this, "_userIgnored");
|
|
224
|
+
__publicField(this, "_readyEmitted");
|
|
225
|
+
__publicField(this, "_emitRaw");
|
|
226
|
+
__publicField(this, "_boundRemove");
|
|
227
|
+
__publicField(this, "_nodeFsHandler");
|
|
228
|
+
this.closed = false;
|
|
229
|
+
this._closers = /* @__PURE__ */ new Map();
|
|
230
|
+
this._ignoredPaths = /* @__PURE__ */ new Set();
|
|
231
|
+
this._throttled = /* @__PURE__ */ new Map();
|
|
232
|
+
this._streams = /* @__PURE__ */ new Set();
|
|
233
|
+
this._symlinkPaths = /* @__PURE__ */ new Map();
|
|
234
|
+
this._watched = /* @__PURE__ */ new Map();
|
|
235
|
+
this._pendingWrites = /* @__PURE__ */ new Map();
|
|
236
|
+
this._pendingUnlinks = /* @__PURE__ */ new Map();
|
|
237
|
+
this._readyCount = 0;
|
|
238
|
+
this._readyEmitted = false;
|
|
239
|
+
const awf = _opts.awaitWriteFinish;
|
|
240
|
+
const DEF_AWF = { stabilityThreshold: 2e3, pollInterval: 100 };
|
|
241
|
+
const opts = {
|
|
242
|
+
// Defaults
|
|
243
|
+
persistent: true,
|
|
244
|
+
ignoreInitial: false,
|
|
245
|
+
ignorePermissionErrors: false,
|
|
246
|
+
interval: 100,
|
|
247
|
+
binaryInterval: 300,
|
|
248
|
+
followSymlinks: true,
|
|
249
|
+
usePolling: false,
|
|
250
|
+
// useAsync: false,
|
|
251
|
+
atomic: true,
|
|
252
|
+
// NOTE: overwritten later (depends on usePolling)
|
|
253
|
+
..._opts,
|
|
254
|
+
// Change format
|
|
255
|
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
256
|
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === "object" ? { ...DEF_AWF, ...awf } : false
|
|
257
|
+
};
|
|
258
|
+
if (isIBMi)
|
|
259
|
+
opts.usePolling = true;
|
|
260
|
+
if (opts.atomic === void 0)
|
|
261
|
+
opts.atomic = !opts.usePolling;
|
|
262
|
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
263
|
+
if (envPoll !== void 0) {
|
|
264
|
+
const envLower = envPoll.toLowerCase();
|
|
265
|
+
if (envLower === "false" || envLower === "0")
|
|
266
|
+
opts.usePolling = false;
|
|
267
|
+
else if (envLower === "true" || envLower === "1")
|
|
268
|
+
opts.usePolling = true;
|
|
269
|
+
else
|
|
270
|
+
opts.usePolling = !!envLower;
|
|
271
|
+
}
|
|
272
|
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
273
|
+
if (envInterval)
|
|
274
|
+
opts.interval = Number.parseInt(envInterval, 10);
|
|
275
|
+
let readyCalls = 0;
|
|
276
|
+
this._emitReady = () => {
|
|
277
|
+
readyCalls++;
|
|
278
|
+
if (readyCalls >= this._readyCount) {
|
|
279
|
+
this._emitReady = EMPTY_FN;
|
|
280
|
+
this._readyEmitted = true;
|
|
281
|
+
process.nextTick(() => this.emit(EVENTS.READY));
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
this._emitRaw = (...args) => this.emit(EVENTS.RAW, ...args);
|
|
285
|
+
this._boundRemove = this._remove.bind(this);
|
|
286
|
+
this.options = opts;
|
|
287
|
+
this._nodeFsHandler = new NodeFsHandler(this);
|
|
288
|
+
Object.freeze(opts);
|
|
289
|
+
}
|
|
290
|
+
_addIgnoredPath(matcher) {
|
|
291
|
+
if (isMatcherObject(matcher)) {
|
|
292
|
+
for (const ignored of this._ignoredPaths) {
|
|
293
|
+
if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
this._ignoredPaths.add(matcher);
|
|
299
|
+
}
|
|
300
|
+
_removeIgnoredPath(matcher) {
|
|
301
|
+
this._ignoredPaths.delete(matcher);
|
|
302
|
+
if (typeof matcher === "string") {
|
|
303
|
+
for (const ignored of this._ignoredPaths) {
|
|
304
|
+
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
|
305
|
+
this._ignoredPaths.delete(ignored);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Public methods
|
|
311
|
+
/**
|
|
312
|
+
* Adds paths to be watched on an existing FSWatcher instance.
|
|
313
|
+
* @param paths_ file or file list. Other arguments are unused
|
|
314
|
+
*/
|
|
315
|
+
add(paths_, _origAdd, _internal) {
|
|
316
|
+
const { cwd } = this.options;
|
|
317
|
+
this.closed = false;
|
|
318
|
+
this._closePromise = void 0;
|
|
319
|
+
let paths = unifyPaths(paths_);
|
|
320
|
+
if (cwd) {
|
|
321
|
+
paths = paths.map((path) => {
|
|
322
|
+
const absPath = getAbsolutePath(path, cwd);
|
|
323
|
+
return absPath;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
paths.forEach((path) => {
|
|
327
|
+
this._removeIgnoredPath(path);
|
|
328
|
+
});
|
|
329
|
+
this._userIgnored = void 0;
|
|
330
|
+
if (!this._readyCount)
|
|
331
|
+
this._readyCount = 0;
|
|
332
|
+
this._readyCount += paths.length;
|
|
333
|
+
Promise.all(paths.map(async (path) => {
|
|
334
|
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
335
|
+
if (res)
|
|
336
|
+
this._emitReady();
|
|
337
|
+
return res;
|
|
338
|
+
})).then((results) => {
|
|
339
|
+
if (this.closed)
|
|
340
|
+
return;
|
|
341
|
+
results.forEach((item) => {
|
|
342
|
+
if (item)
|
|
343
|
+
this.add(sp.dirname(item), sp.basename(_origAdd || item));
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
return this;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Close watchers or start ignoring events from specified paths.
|
|
350
|
+
*/
|
|
351
|
+
unwatch(paths_) {
|
|
352
|
+
if (this.closed)
|
|
353
|
+
return this;
|
|
354
|
+
const paths = unifyPaths(paths_);
|
|
355
|
+
const { cwd } = this.options;
|
|
356
|
+
paths.forEach((path) => {
|
|
357
|
+
if (!sp.isAbsolute(path) && !this._closers.has(path)) {
|
|
358
|
+
if (cwd)
|
|
359
|
+
path = sp.join(cwd, path);
|
|
360
|
+
path = sp.resolve(path);
|
|
361
|
+
}
|
|
362
|
+
this._closePath(path);
|
|
363
|
+
this._addIgnoredPath(path);
|
|
364
|
+
if (this._watched.has(path)) {
|
|
365
|
+
this._addIgnoredPath({
|
|
366
|
+
path,
|
|
367
|
+
recursive: true
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
this._userIgnored = void 0;
|
|
371
|
+
});
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Close watchers and remove all listeners from watched paths.
|
|
376
|
+
*/
|
|
377
|
+
close() {
|
|
378
|
+
if (this._closePromise) {
|
|
379
|
+
return this._closePromise;
|
|
380
|
+
}
|
|
381
|
+
this.closed = true;
|
|
382
|
+
this.removeAllListeners();
|
|
383
|
+
const closers = [];
|
|
384
|
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
|
385
|
+
const promise = closer();
|
|
386
|
+
if (promise instanceof Promise)
|
|
387
|
+
closers.push(promise);
|
|
388
|
+
}));
|
|
389
|
+
this._streams.forEach((stream) => stream.destroy());
|
|
390
|
+
this._userIgnored = void 0;
|
|
391
|
+
this._readyCount = 0;
|
|
392
|
+
this._readyEmitted = false;
|
|
393
|
+
this._watched.forEach((dirent) => dirent.dispose());
|
|
394
|
+
this._closers.clear();
|
|
395
|
+
this._watched.clear();
|
|
396
|
+
this._streams.clear();
|
|
397
|
+
this._symlinkPaths.clear();
|
|
398
|
+
this._throttled.clear();
|
|
399
|
+
this._closePromise = closers.length ? Promise.all(closers).then(() => void 0) : Promise.resolve();
|
|
400
|
+
return this._closePromise;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Expose list of watched paths
|
|
404
|
+
* @returns for chaining
|
|
405
|
+
*/
|
|
406
|
+
getWatched() {
|
|
407
|
+
const watchList = {};
|
|
408
|
+
this._watched.forEach((entry, dir) => {
|
|
409
|
+
const key = this.options.cwd ? sp.relative(this.options.cwd, dir) : dir;
|
|
410
|
+
const index = key || ONE_DOT;
|
|
411
|
+
watchList[index] = entry.getChildren().sort();
|
|
412
|
+
});
|
|
413
|
+
return watchList;
|
|
414
|
+
}
|
|
415
|
+
emitWithAll(event, args) {
|
|
416
|
+
this.emit(event, ...args);
|
|
417
|
+
if (event !== EVENTS.ERROR)
|
|
418
|
+
this.emit(EVENTS.ALL, event, ...args);
|
|
419
|
+
}
|
|
420
|
+
// Common helpers
|
|
421
|
+
// --------------
|
|
422
|
+
/**
|
|
423
|
+
* Normalize and emit events.
|
|
424
|
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
|
425
|
+
* @param event Type of event
|
|
426
|
+
* @param path File or directory path
|
|
427
|
+
* @param stats arguments to be passed with event
|
|
428
|
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
429
|
+
*/
|
|
430
|
+
async _emit(event, path, stats) {
|
|
431
|
+
if (this.closed)
|
|
432
|
+
return;
|
|
433
|
+
const opts = this.options;
|
|
434
|
+
if (isWindows)
|
|
435
|
+
path = sp.normalize(path);
|
|
436
|
+
if (opts.cwd)
|
|
437
|
+
path = sp.relative(opts.cwd, path);
|
|
438
|
+
const args = [path];
|
|
439
|
+
if (stats != null)
|
|
440
|
+
args.push(stats);
|
|
441
|
+
const awf = opts.awaitWriteFinish;
|
|
442
|
+
let pw;
|
|
443
|
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
|
444
|
+
pw.lastChange = /* @__PURE__ */ new Date();
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
if (opts.atomic) {
|
|
448
|
+
if (event === EVENTS.UNLINK) {
|
|
449
|
+
this._pendingUnlinks.set(path, [event, ...args]);
|
|
450
|
+
setTimeout(() => {
|
|
451
|
+
this._pendingUnlinks.forEach((entry, path2) => {
|
|
452
|
+
this.emit(...entry);
|
|
453
|
+
this.emit(EVENTS.ALL, ...entry);
|
|
454
|
+
this._pendingUnlinks.delete(path2);
|
|
455
|
+
});
|
|
456
|
+
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
459
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
|
460
|
+
event = EVENTS.CHANGE;
|
|
461
|
+
this._pendingUnlinks.delete(path);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
465
|
+
const awfEmit = (err, stats2) => {
|
|
466
|
+
if (err) {
|
|
467
|
+
event = EVENTS.ERROR;
|
|
468
|
+
args[0] = err;
|
|
469
|
+
this.emitWithAll(event, args);
|
|
470
|
+
} else if (stats2) {
|
|
471
|
+
if (args.length > 1) {
|
|
472
|
+
args[1] = stats2;
|
|
473
|
+
} else {
|
|
474
|
+
args.push(stats2);
|
|
475
|
+
}
|
|
476
|
+
this.emitWithAll(event, args);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
|
480
|
+
return this;
|
|
481
|
+
}
|
|
482
|
+
if (event === EVENTS.CHANGE) {
|
|
483
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path, 50);
|
|
484
|
+
if (isThrottled)
|
|
485
|
+
return this;
|
|
486
|
+
}
|
|
487
|
+
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
488
|
+
const fullPath = opts.cwd ? sp.join(opts.cwd, path) : path;
|
|
489
|
+
let stats2;
|
|
490
|
+
try {
|
|
491
|
+
stats2 = await stat(fullPath);
|
|
492
|
+
} catch (err) {
|
|
493
|
+
}
|
|
494
|
+
if (!stats2 || this.closed)
|
|
495
|
+
return;
|
|
496
|
+
args.push(stats2);
|
|
497
|
+
}
|
|
498
|
+
this.emitWithAll(event, args);
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Common handler for errors
|
|
503
|
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
504
|
+
*/
|
|
505
|
+
_handleError(error) {
|
|
506
|
+
const code = error && error.code;
|
|
507
|
+
if (error && code !== "ENOENT" && code !== "ENOTDIR" && (!this.options.ignorePermissionErrors || code !== "EPERM" && code !== "EACCES")) {
|
|
508
|
+
this.emit(EVENTS.ERROR, error);
|
|
509
|
+
}
|
|
510
|
+
return error || this.closed;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Helper utility for throttling
|
|
514
|
+
* @param actionType type being throttled
|
|
515
|
+
* @param path being acted upon
|
|
516
|
+
* @param timeout duration of time to suppress duplicate actions
|
|
517
|
+
* @returns tracking object or false if action should be suppressed
|
|
518
|
+
*/
|
|
519
|
+
_throttle(actionType, path, timeout) {
|
|
520
|
+
if (!this._throttled.has(actionType)) {
|
|
521
|
+
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
522
|
+
}
|
|
523
|
+
const action = this._throttled.get(actionType);
|
|
524
|
+
if (!action)
|
|
525
|
+
throw new Error("invalid throttle");
|
|
526
|
+
const actionPath = action.get(path);
|
|
527
|
+
if (actionPath) {
|
|
528
|
+
actionPath.count++;
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
let timeoutObject;
|
|
532
|
+
const clear = () => {
|
|
533
|
+
const item = action.get(path);
|
|
534
|
+
const count = item ? item.count : 0;
|
|
535
|
+
action.delete(path);
|
|
536
|
+
clearTimeout(timeoutObject);
|
|
537
|
+
if (item)
|
|
538
|
+
clearTimeout(item.timeoutObject);
|
|
539
|
+
return count;
|
|
540
|
+
};
|
|
541
|
+
timeoutObject = setTimeout(clear, timeout);
|
|
542
|
+
const thr = { timeoutObject, clear, count: 0 };
|
|
543
|
+
action.set(path, thr);
|
|
544
|
+
return thr;
|
|
545
|
+
}
|
|
546
|
+
_incrReadyCount() {
|
|
547
|
+
return this._readyCount++;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Awaits write operation to finish.
|
|
551
|
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
|
552
|
+
* @param path being acted upon
|
|
553
|
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
|
554
|
+
* @param event
|
|
555
|
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
556
|
+
*/
|
|
557
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
558
|
+
const awf = this.options.awaitWriteFinish;
|
|
559
|
+
if (typeof awf !== "object")
|
|
560
|
+
return;
|
|
561
|
+
const pollInterval = awf.pollInterval;
|
|
562
|
+
let timeoutHandler;
|
|
563
|
+
let fullPath = path;
|
|
564
|
+
if (this.options.cwd && !sp.isAbsolute(path)) {
|
|
565
|
+
fullPath = sp.join(this.options.cwd, path);
|
|
566
|
+
}
|
|
567
|
+
const now = /* @__PURE__ */ new Date();
|
|
568
|
+
const writes = this._pendingWrites;
|
|
569
|
+
function awaitWriteFinishFn(prevStat) {
|
|
570
|
+
stat$1(fullPath, (err, curStat) => {
|
|
571
|
+
if (err || !writes.has(path)) {
|
|
572
|
+
if (err && err.code !== "ENOENT")
|
|
573
|
+
awfEmit(err);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const now2 = Number(/* @__PURE__ */ new Date());
|
|
577
|
+
if (prevStat && curStat.size !== prevStat.size) {
|
|
578
|
+
writes.get(path).lastChange = now2;
|
|
579
|
+
}
|
|
580
|
+
const pw = writes.get(path);
|
|
581
|
+
const df = now2 - pw.lastChange;
|
|
582
|
+
if (df >= threshold) {
|
|
583
|
+
writes.delete(path);
|
|
584
|
+
awfEmit(void 0, curStat);
|
|
585
|
+
} else {
|
|
586
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
if (!writes.has(path)) {
|
|
591
|
+
writes.set(path, {
|
|
592
|
+
lastChange: now,
|
|
593
|
+
cancelWait: () => {
|
|
594
|
+
writes.delete(path);
|
|
595
|
+
clearTimeout(timeoutHandler);
|
|
596
|
+
return event;
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Determines whether user has asked to ignore this path.
|
|
604
|
+
*/
|
|
605
|
+
_isIgnored(path, stats) {
|
|
606
|
+
if (this.options.atomic && DOT_RE.test(path))
|
|
607
|
+
return true;
|
|
608
|
+
if (!this._userIgnored) {
|
|
609
|
+
const { cwd } = this.options;
|
|
610
|
+
const ign = this.options.ignored;
|
|
611
|
+
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
|
612
|
+
const ignoredPaths = [...this._ignoredPaths];
|
|
613
|
+
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
614
|
+
this._userIgnored = anymatch(list);
|
|
615
|
+
}
|
|
616
|
+
return this._userIgnored(path, stats);
|
|
617
|
+
}
|
|
618
|
+
_isntIgnored(path, stat2) {
|
|
619
|
+
return !this._isIgnored(path, stat2);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Provides a set of common helpers and properties relating to symlink handling.
|
|
623
|
+
* @param path file or directory pattern being watched
|
|
624
|
+
*/
|
|
625
|
+
_getWatchHelpers(path) {
|
|
626
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
627
|
+
}
|
|
628
|
+
// Directory helpers
|
|
629
|
+
// -----------------
|
|
630
|
+
/**
|
|
631
|
+
* Provides directory tracking objects
|
|
632
|
+
* @param directory path of the directory
|
|
633
|
+
*/
|
|
634
|
+
_getWatchedDir(directory) {
|
|
635
|
+
const dir = sp.resolve(directory);
|
|
636
|
+
if (!this._watched.has(dir))
|
|
637
|
+
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
|
638
|
+
return this._watched.get(dir);
|
|
639
|
+
}
|
|
640
|
+
// File helpers
|
|
641
|
+
// ------------
|
|
642
|
+
/**
|
|
643
|
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
|
644
|
+
*/
|
|
645
|
+
_hasReadPermissions(stats) {
|
|
646
|
+
if (this.options.ignorePermissionErrors)
|
|
647
|
+
return true;
|
|
648
|
+
return Boolean(Number(stats.mode) & 256);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Handles emitting unlink events for
|
|
652
|
+
* files and directories, and via recursion, for
|
|
653
|
+
* files and directories within directories that are unlinked
|
|
654
|
+
* @param directory within which the following item is located
|
|
655
|
+
* @param item base path of item/directory
|
|
656
|
+
*/
|
|
657
|
+
_remove(directory, item, isDirectory) {
|
|
658
|
+
const path = sp.join(directory, item);
|
|
659
|
+
const fullPath = sp.resolve(path);
|
|
660
|
+
isDirectory = isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
|
661
|
+
if (!this._throttle("remove", path, 100))
|
|
662
|
+
return;
|
|
663
|
+
if (!isDirectory && this._watched.size === 1) {
|
|
664
|
+
this.add(directory, item, true);
|
|
665
|
+
}
|
|
666
|
+
const wp = this._getWatchedDir(path);
|
|
667
|
+
const nestedDirectoryChildren = wp.getChildren();
|
|
668
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
|
669
|
+
const parent = this._getWatchedDir(directory);
|
|
670
|
+
const wasTracked = parent.has(item);
|
|
671
|
+
parent.remove(item);
|
|
672
|
+
if (this._symlinkPaths.has(fullPath)) {
|
|
673
|
+
this._symlinkPaths.delete(fullPath);
|
|
674
|
+
}
|
|
675
|
+
let relPath = path;
|
|
676
|
+
if (this.options.cwd)
|
|
677
|
+
relPath = sp.relative(this.options.cwd, path);
|
|
678
|
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
679
|
+
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
680
|
+
if (event === EVENTS.ADD)
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
this._watched.delete(path);
|
|
684
|
+
this._watched.delete(fullPath);
|
|
685
|
+
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
686
|
+
if (wasTracked && !this._isIgnored(path))
|
|
687
|
+
this._emit(eventName, path);
|
|
688
|
+
this._closePath(path);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Closes all watchers for a path
|
|
692
|
+
*/
|
|
693
|
+
_closePath(path) {
|
|
694
|
+
this._closeFile(path);
|
|
695
|
+
const dir = sp.dirname(path);
|
|
696
|
+
this._getWatchedDir(dir).remove(sp.basename(path));
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Closes only file-specific watchers
|
|
700
|
+
*/
|
|
701
|
+
_closeFile(path) {
|
|
702
|
+
const closers = this._closers.get(path);
|
|
703
|
+
if (!closers)
|
|
704
|
+
return;
|
|
705
|
+
closers.forEach((closer) => closer());
|
|
706
|
+
this._closers.delete(path);
|
|
707
|
+
}
|
|
708
|
+
_addPathCloser(path, closer) {
|
|
709
|
+
if (!closer)
|
|
710
|
+
return;
|
|
711
|
+
let list = this._closers.get(path);
|
|
712
|
+
if (!list) {
|
|
713
|
+
list = [];
|
|
714
|
+
this._closers.set(path, list);
|
|
715
|
+
}
|
|
716
|
+
list.push(closer);
|
|
717
|
+
}
|
|
718
|
+
_readdirp(root, opts) {
|
|
719
|
+
if (this.closed)
|
|
720
|
+
return;
|
|
721
|
+
const options = { type: EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
|
722
|
+
let stream = readdirp(root, options);
|
|
723
|
+
this._streams.add(stream);
|
|
724
|
+
stream.once(STR_CLOSE, () => {
|
|
725
|
+
stream = void 0;
|
|
726
|
+
});
|
|
727
|
+
stream.once(STR_END, () => {
|
|
728
|
+
if (stream) {
|
|
729
|
+
this._streams.delete(stream);
|
|
730
|
+
stream = void 0;
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
return stream;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function watch(paths, options = {}) {
|
|
737
|
+
const watcher = new FSWatcher(options);
|
|
738
|
+
watcher.add(paths);
|
|
739
|
+
return watcher;
|
|
740
|
+
}
|
|
741
|
+
export {
|
|
742
|
+
FSWatcher,
|
|
743
|
+
WatchHelper,
|
|
744
|
+
watch
|
|
745
|
+
};
|
|
746
|
+
//# sourceMappingURL=index.js.map
|