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