@rsbuild/core 2.0.0-alpha.1 → 2.0.0-alpha.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/compiled/chokidar/handler.d.ts +90 -0
- package/compiled/chokidar/index.d.ts +34 -201
- package/compiled/chokidar/package.json +1 -1
- package/compiled/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.js +18 -15
- package/compiled/html-rspack-plugin/package.json +1 -1
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rslog/package.json +1 -1
- package/compiled/rspack-chain/package.json +1 -1
- package/dist/131.js +69 -49
- package/dist/397.js +11 -0
- package/dist/7.js +1 -0
- package/dist/chokidar.js +1044 -0
- package/dist/chokidar.js.LICENSE.txt +1 -0
- package/dist/client/hmr.js +33 -0
- package/dist/cors.js +2 -2
- package/dist/manifest-plugin.js +5 -5
- package/dist/memfs.js +3334 -857
- package/dist/open.js +1 -1
- package/dist/tinyglobby.js +9 -1
- package/dist-types/configChain.d.ts +21 -21
- package/dist-types/helpers/vendors.d.ts +0 -1
- package/dist-types/loadConfig.d.ts +1 -1
- package/dist-types/server/socketServer.d.ts +8 -1
- package/dist-types/types/config.d.ts +5 -0
- package/package.json +8 -8
- package/types.d.ts +8 -4
- package/compiled/chokidar/index.js +0 -1793
package/dist/chokidar.js
ADDED
|
@@ -0,0 +1,1044 @@
|
|
|
1
|
+
/*! For license information please see chokidar.js.LICENSE.txt */
|
|
2
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
3
|
+
import { external_node_os_type } from "./131.js";
|
|
4
|
+
import "./397.js";
|
|
5
|
+
import { readdir, lstat, stat as promises_stat, realpath as promises_realpath, promises_open } from "./7.js";
|
|
6
|
+
let external_node_path_ = __webpack_require__("node:path"), external_node_stream_ = __webpack_require__("node:stream"), EntryTypes_FILE_TYPE = 'files', EntryTypes_DIR_TYPE = 'directories', EntryTypes_FILE_DIR_TYPE = 'files_directories', defaultOptions = {
|
|
7
|
+
root: '.',
|
|
8
|
+
fileFilter: (_entryInfo)=>!0,
|
|
9
|
+
directoryFilter: (_entryInfo)=>!0,
|
|
10
|
+
type: EntryTypes_FILE_TYPE,
|
|
11
|
+
lstat: !1,
|
|
12
|
+
depth: 2147483648,
|
|
13
|
+
alwaysStat: !1,
|
|
14
|
+
highWaterMark: 4096
|
|
15
|
+
};
|
|
16
|
+
Object.freeze(defaultOptions);
|
|
17
|
+
let RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR', NORMAL_FLOW_ERRORS = new Set([
|
|
18
|
+
'ENOENT',
|
|
19
|
+
'EPERM',
|
|
20
|
+
'EACCES',
|
|
21
|
+
'ELOOP',
|
|
22
|
+
RECURSIVE_ERROR_CODE
|
|
23
|
+
]), ALL_TYPES = [
|
|
24
|
+
EntryTypes_DIR_TYPE,
|
|
25
|
+
'all',
|
|
26
|
+
EntryTypes_FILE_DIR_TYPE,
|
|
27
|
+
EntryTypes_FILE_TYPE
|
|
28
|
+
], DIR_TYPES = new Set([
|
|
29
|
+
EntryTypes_DIR_TYPE,
|
|
30
|
+
'all',
|
|
31
|
+
EntryTypes_FILE_DIR_TYPE
|
|
32
|
+
]), FILE_TYPES = new Set([
|
|
33
|
+
'all',
|
|
34
|
+
EntryTypes_FILE_DIR_TYPE,
|
|
35
|
+
EntryTypes_FILE_TYPE
|
|
36
|
+
]), wantBigintFsStats = 'win32' === process.platform, emptyFn = (_entryInfo)=>!0, normalizeFilter = (filter)=>{
|
|
37
|
+
if (void 0 === filter) return emptyFn;
|
|
38
|
+
if ('function' == typeof filter) return filter;
|
|
39
|
+
if ('string' == typeof filter) {
|
|
40
|
+
let fl = filter.trim();
|
|
41
|
+
return (entry)=>entry.basename === fl;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(filter)) {
|
|
44
|
+
let trItems = filter.map((item)=>item.trim());
|
|
45
|
+
return (entry)=>trItems.some((f)=>entry.basename === f);
|
|
46
|
+
}
|
|
47
|
+
return emptyFn;
|
|
48
|
+
};
|
|
49
|
+
class ReaddirpStream extends external_node_stream_.Readable {
|
|
50
|
+
parents;
|
|
51
|
+
reading;
|
|
52
|
+
parent;
|
|
53
|
+
_stat;
|
|
54
|
+
_maxDepth;
|
|
55
|
+
_wantsDir;
|
|
56
|
+
_wantsFile;
|
|
57
|
+
_wantsEverything;
|
|
58
|
+
_root;
|
|
59
|
+
_isDirent;
|
|
60
|
+
_statsProp;
|
|
61
|
+
_rdOptions;
|
|
62
|
+
_fileFilter;
|
|
63
|
+
_directoryFilter;
|
|
64
|
+
constructor(options = {}){
|
|
65
|
+
super({
|
|
66
|
+
objectMode: !0,
|
|
67
|
+
autoDestroy: !0,
|
|
68
|
+
highWaterMark: options.highWaterMark
|
|
69
|
+
});
|
|
70
|
+
let opts = {
|
|
71
|
+
...defaultOptions,
|
|
72
|
+
...options
|
|
73
|
+
}, { root, type } = opts;
|
|
74
|
+
this._fileFilter = normalizeFilter(opts.fileFilter), this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
75
|
+
let statMethod = opts.lstat ? lstat : promises_stat;
|
|
76
|
+
wantBigintFsStats ? this._stat = (path)=>statMethod(path, {
|
|
77
|
+
bigint: !0
|
|
78
|
+
}) : this._stat = statMethod, this._maxDepth = null != opts.depth && Number.isSafeInteger(opts.depth) ? opts.depth : defaultOptions.depth, this._wantsDir = !!type && DIR_TYPES.has(type), this._wantsFile = !!type && FILE_TYPES.has(type), this._wantsEverything = 'all' === type, this._root = (0, external_node_path_.resolve)(root), this._isDirent = !opts.alwaysStat, this._statsProp = this._isDirent ? 'dirent' : 'stats', this._rdOptions = {
|
|
79
|
+
encoding: 'utf8',
|
|
80
|
+
withFileTypes: this._isDirent
|
|
81
|
+
}, this.parents = [
|
|
82
|
+
this._exploreDir(root, 1)
|
|
83
|
+
], this.reading = !1, this.parent = void 0;
|
|
84
|
+
}
|
|
85
|
+
async _read(batch) {
|
|
86
|
+
if (!this.reading) {
|
|
87
|
+
this.reading = !0;
|
|
88
|
+
try {
|
|
89
|
+
for(; !this.destroyed && batch > 0;){
|
|
90
|
+
let par = this.parent, fil = par && par.files;
|
|
91
|
+
if (fil && fil.length > 0) {
|
|
92
|
+
let { path, depth } = par, slice = fil.splice(0, batch).map((dirent)=>this._formatEntry(dirent, path));
|
|
93
|
+
for (let entry of (await Promise.all(slice))){
|
|
94
|
+
if (!entry) continue;
|
|
95
|
+
if (this.destroyed) return;
|
|
96
|
+
let entryType = await this._getEntryType(entry);
|
|
97
|
+
'directory' === entryType && this._directoryFilter(entry) ? (depth <= this._maxDepth && this.parents.push(this._exploreDir(entry.fullPath, depth + 1)), this._wantsDir && (this.push(entry), batch--)) : ('file' === entryType || this._includeAsFile(entry)) && this._fileFilter(entry) && this._wantsFile && (this.push(entry), batch--);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
let parent = this.parents.pop();
|
|
101
|
+
if (!parent) {
|
|
102
|
+
this.push(null);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (this.parent = await parent, this.destroyed) return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
this.destroy(error);
|
|
110
|
+
} finally{
|
|
111
|
+
this.reading = !1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async _exploreDir(path, depth) {
|
|
116
|
+
let files;
|
|
117
|
+
try {
|
|
118
|
+
files = await readdir(path, this._rdOptions);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
this._onError(error);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
files,
|
|
124
|
+
depth,
|
|
125
|
+
path
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async _formatEntry(dirent, path) {
|
|
129
|
+
let entry, basename = this._isDirent ? dirent.name : dirent;
|
|
130
|
+
try {
|
|
131
|
+
let fullPath = (0, external_node_path_.resolve)((0, external_node_path_.join)(path, basename));
|
|
132
|
+
(entry = {
|
|
133
|
+
path: (0, external_node_path_.relative)(this._root, fullPath),
|
|
134
|
+
fullPath,
|
|
135
|
+
basename
|
|
136
|
+
})[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
this._onError(err);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
return entry;
|
|
142
|
+
}
|
|
143
|
+
_onError(err) {
|
|
144
|
+
NORMAL_FLOW_ERRORS.has(err.code) && !this.destroyed ? this.emit('warn', err) : this.destroy(err);
|
|
145
|
+
}
|
|
146
|
+
async _getEntryType(entry) {
|
|
147
|
+
if (!entry && this._statsProp in entry) return '';
|
|
148
|
+
let stats = entry[this._statsProp];
|
|
149
|
+
if (stats.isFile()) return 'file';
|
|
150
|
+
if (stats.isDirectory()) return 'directory';
|
|
151
|
+
if (stats && stats.isSymbolicLink()) {
|
|
152
|
+
let full = entry.fullPath;
|
|
153
|
+
try {
|
|
154
|
+
let entryRealPath = await promises_realpath(full), entryRealPathStats = await lstat(entryRealPath);
|
|
155
|
+
if (entryRealPathStats.isFile()) return 'file';
|
|
156
|
+
if (entryRealPathStats.isDirectory()) {
|
|
157
|
+
let len = entryRealPath.length;
|
|
158
|
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === external_node_path_.sep) {
|
|
159
|
+
let recursiveError = Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
160
|
+
return recursiveError.code = RECURSIVE_ERROR_CODE, this._onError(recursiveError);
|
|
161
|
+
}
|
|
162
|
+
return 'directory';
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return this._onError(error), '';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_includeAsFile(entry) {
|
|
170
|
+
let stats = entry && entry[this._statsProp];
|
|
171
|
+
return stats && this._wantsEverything && !stats.isDirectory();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function readdirp(root, options = {}) {
|
|
175
|
+
let type = options.entryType || options.type;
|
|
176
|
+
if ('both' === type && (type = EntryTypes_FILE_DIR_TYPE), type && (options.type = type), root) {
|
|
177
|
+
if ('string' != typeof root) throw TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
|
|
178
|
+
else if (type && !ALL_TYPES.includes(type)) throw Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
|
|
179
|
+
} else throw Error('readdirp: root argument is required. Usage: readdirp(root, options)');
|
|
180
|
+
return options.root = root, new ReaddirpStream(options);
|
|
181
|
+
}
|
|
182
|
+
let external_node_fs_ = __webpack_require__("node:fs"), EMPTY_FN = ()=>{}, pl = process.platform, isWindows = 'win32' === pl, isMacos = 'darwin' === pl, isLinux = 'linux' === pl, isFreeBSD = 'freebsd' === pl, isIBMi = 'OS400' === external_node_os_type(), EVENTS_ALL = 'all', EVENTS_READY = 'ready', EVENTS_ADD = 'add', EVENTS_CHANGE = 'change', EVENTS_ADD_DIR = 'addDir', EVENTS_UNLINK = 'unlink', EVENTS_UNLINK_DIR = 'unlinkDir', EVENTS_RAW = 'raw', EVENTS_ERROR = 'error', statMethods = {
|
|
183
|
+
lstat: lstat,
|
|
184
|
+
stat: promises_stat
|
|
185
|
+
}, KEY_LISTENERS = 'listeners', KEY_ERR = 'errHandlers', KEY_RAW = 'rawEmitters', HANDLER_KEYS = [
|
|
186
|
+
KEY_LISTENERS,
|
|
187
|
+
KEY_ERR,
|
|
188
|
+
KEY_RAW
|
|
189
|
+
], binaryExtensions = new Set([
|
|
190
|
+
'3dm',
|
|
191
|
+
'3ds',
|
|
192
|
+
'3g2',
|
|
193
|
+
'3gp',
|
|
194
|
+
'7z',
|
|
195
|
+
'a',
|
|
196
|
+
'aac',
|
|
197
|
+
'adp',
|
|
198
|
+
'afdesign',
|
|
199
|
+
'afphoto',
|
|
200
|
+
'afpub',
|
|
201
|
+
'ai',
|
|
202
|
+
'aif',
|
|
203
|
+
'aiff',
|
|
204
|
+
'alz',
|
|
205
|
+
'ape',
|
|
206
|
+
'apk',
|
|
207
|
+
'appimage',
|
|
208
|
+
'ar',
|
|
209
|
+
'arj',
|
|
210
|
+
'asf',
|
|
211
|
+
'au',
|
|
212
|
+
'avi',
|
|
213
|
+
'bak',
|
|
214
|
+
'baml',
|
|
215
|
+
'bh',
|
|
216
|
+
'bin',
|
|
217
|
+
'bk',
|
|
218
|
+
'bmp',
|
|
219
|
+
'btif',
|
|
220
|
+
'bz2',
|
|
221
|
+
'bzip2',
|
|
222
|
+
'cab',
|
|
223
|
+
'caf',
|
|
224
|
+
'cgm',
|
|
225
|
+
'class',
|
|
226
|
+
'cmx',
|
|
227
|
+
'cpio',
|
|
228
|
+
'cr2',
|
|
229
|
+
'cur',
|
|
230
|
+
'dat',
|
|
231
|
+
'dcm',
|
|
232
|
+
'deb',
|
|
233
|
+
'dex',
|
|
234
|
+
'djvu',
|
|
235
|
+
'dll',
|
|
236
|
+
'dmg',
|
|
237
|
+
'dng',
|
|
238
|
+
'doc',
|
|
239
|
+
'docm',
|
|
240
|
+
'docx',
|
|
241
|
+
'dot',
|
|
242
|
+
'dotm',
|
|
243
|
+
'dra',
|
|
244
|
+
'DS_Store',
|
|
245
|
+
'dsk',
|
|
246
|
+
'dts',
|
|
247
|
+
'dtshd',
|
|
248
|
+
'dvb',
|
|
249
|
+
'dwg',
|
|
250
|
+
'dxf',
|
|
251
|
+
'ecelp4800',
|
|
252
|
+
'ecelp7470',
|
|
253
|
+
'ecelp9600',
|
|
254
|
+
'egg',
|
|
255
|
+
'eol',
|
|
256
|
+
'eot',
|
|
257
|
+
'epub',
|
|
258
|
+
'exe',
|
|
259
|
+
'f4v',
|
|
260
|
+
'fbs',
|
|
261
|
+
'fh',
|
|
262
|
+
'fla',
|
|
263
|
+
'flac',
|
|
264
|
+
'flatpak',
|
|
265
|
+
'fli',
|
|
266
|
+
'flv',
|
|
267
|
+
'fpx',
|
|
268
|
+
'fst',
|
|
269
|
+
'fvt',
|
|
270
|
+
'g3',
|
|
271
|
+
'gh',
|
|
272
|
+
'gif',
|
|
273
|
+
'graffle',
|
|
274
|
+
'gz',
|
|
275
|
+
'gzip',
|
|
276
|
+
'h261',
|
|
277
|
+
'h263',
|
|
278
|
+
'h264',
|
|
279
|
+
'icns',
|
|
280
|
+
'ico',
|
|
281
|
+
'ief',
|
|
282
|
+
'img',
|
|
283
|
+
'ipa',
|
|
284
|
+
'iso',
|
|
285
|
+
'jar',
|
|
286
|
+
'jpeg',
|
|
287
|
+
'jpg',
|
|
288
|
+
'jpgv',
|
|
289
|
+
'jpm',
|
|
290
|
+
'jxr',
|
|
291
|
+
'key',
|
|
292
|
+
'ktx',
|
|
293
|
+
'lha',
|
|
294
|
+
'lib',
|
|
295
|
+
'lvp',
|
|
296
|
+
'lz',
|
|
297
|
+
'lzh',
|
|
298
|
+
'lzma',
|
|
299
|
+
'lzo',
|
|
300
|
+
'm3u',
|
|
301
|
+
'm4a',
|
|
302
|
+
'm4v',
|
|
303
|
+
'mar',
|
|
304
|
+
'mdi',
|
|
305
|
+
'mht',
|
|
306
|
+
'mid',
|
|
307
|
+
'midi',
|
|
308
|
+
'mj2',
|
|
309
|
+
'mka',
|
|
310
|
+
'mkv',
|
|
311
|
+
'mmr',
|
|
312
|
+
'mng',
|
|
313
|
+
'mobi',
|
|
314
|
+
'mov',
|
|
315
|
+
'movie',
|
|
316
|
+
'mp3',
|
|
317
|
+
'mp4',
|
|
318
|
+
'mp4a',
|
|
319
|
+
'mpeg',
|
|
320
|
+
'mpg',
|
|
321
|
+
'mpga',
|
|
322
|
+
'mxu',
|
|
323
|
+
'nef',
|
|
324
|
+
'npx',
|
|
325
|
+
'numbers',
|
|
326
|
+
'nupkg',
|
|
327
|
+
'o',
|
|
328
|
+
'odp',
|
|
329
|
+
'ods',
|
|
330
|
+
'odt',
|
|
331
|
+
'oga',
|
|
332
|
+
'ogg',
|
|
333
|
+
'ogv',
|
|
334
|
+
'otf',
|
|
335
|
+
'ott',
|
|
336
|
+
'pages',
|
|
337
|
+
'pbm',
|
|
338
|
+
'pcx',
|
|
339
|
+
'pdb',
|
|
340
|
+
'pdf',
|
|
341
|
+
'pea',
|
|
342
|
+
'pgm',
|
|
343
|
+
'pic',
|
|
344
|
+
'png',
|
|
345
|
+
'pnm',
|
|
346
|
+
'pot',
|
|
347
|
+
'potm',
|
|
348
|
+
'potx',
|
|
349
|
+
'ppa',
|
|
350
|
+
'ppam',
|
|
351
|
+
'ppm',
|
|
352
|
+
'pps',
|
|
353
|
+
'ppsm',
|
|
354
|
+
'ppsx',
|
|
355
|
+
'ppt',
|
|
356
|
+
'pptm',
|
|
357
|
+
'pptx',
|
|
358
|
+
'psd',
|
|
359
|
+
'pya',
|
|
360
|
+
'pyc',
|
|
361
|
+
'pyo',
|
|
362
|
+
'pyv',
|
|
363
|
+
'qt',
|
|
364
|
+
'rar',
|
|
365
|
+
'ras',
|
|
366
|
+
'raw',
|
|
367
|
+
'resources',
|
|
368
|
+
'rgb',
|
|
369
|
+
'rip',
|
|
370
|
+
'rlc',
|
|
371
|
+
'rmf',
|
|
372
|
+
'rmvb',
|
|
373
|
+
'rpm',
|
|
374
|
+
'rtf',
|
|
375
|
+
'rz',
|
|
376
|
+
's3m',
|
|
377
|
+
's7z',
|
|
378
|
+
'scpt',
|
|
379
|
+
'sgi',
|
|
380
|
+
'shar',
|
|
381
|
+
'snap',
|
|
382
|
+
'sil',
|
|
383
|
+
'sketch',
|
|
384
|
+
'slk',
|
|
385
|
+
'smv',
|
|
386
|
+
'snk',
|
|
387
|
+
'so',
|
|
388
|
+
'stl',
|
|
389
|
+
'suo',
|
|
390
|
+
'sub',
|
|
391
|
+
'swf',
|
|
392
|
+
'tar',
|
|
393
|
+
'tbz',
|
|
394
|
+
'tbz2',
|
|
395
|
+
'tga',
|
|
396
|
+
'tgz',
|
|
397
|
+
'thmx',
|
|
398
|
+
'tif',
|
|
399
|
+
'tiff',
|
|
400
|
+
'tlz',
|
|
401
|
+
'ttc',
|
|
402
|
+
'ttf',
|
|
403
|
+
'txz',
|
|
404
|
+
'udf',
|
|
405
|
+
'uvh',
|
|
406
|
+
'uvi',
|
|
407
|
+
'uvm',
|
|
408
|
+
'uvp',
|
|
409
|
+
'uvs',
|
|
410
|
+
'uvu',
|
|
411
|
+
'viv',
|
|
412
|
+
'vob',
|
|
413
|
+
'war',
|
|
414
|
+
'wav',
|
|
415
|
+
'wax',
|
|
416
|
+
'wbmp',
|
|
417
|
+
'wdp',
|
|
418
|
+
'weba',
|
|
419
|
+
'webm',
|
|
420
|
+
'webp',
|
|
421
|
+
'whl',
|
|
422
|
+
'wim',
|
|
423
|
+
'wm',
|
|
424
|
+
'wma',
|
|
425
|
+
'wmv',
|
|
426
|
+
'wmx',
|
|
427
|
+
'woff',
|
|
428
|
+
'woff2',
|
|
429
|
+
'wrm',
|
|
430
|
+
'wvx',
|
|
431
|
+
'xbm',
|
|
432
|
+
'xif',
|
|
433
|
+
'xla',
|
|
434
|
+
'xlam',
|
|
435
|
+
'xls',
|
|
436
|
+
'xlsb',
|
|
437
|
+
'xlsm',
|
|
438
|
+
'xlsx',
|
|
439
|
+
'xlt',
|
|
440
|
+
'xltm',
|
|
441
|
+
'xltx',
|
|
442
|
+
'xm',
|
|
443
|
+
'xmind',
|
|
444
|
+
'xpi',
|
|
445
|
+
'xpm',
|
|
446
|
+
'xwd',
|
|
447
|
+
'xz',
|
|
448
|
+
'z',
|
|
449
|
+
'zip',
|
|
450
|
+
'zipx'
|
|
451
|
+
]), foreach = (val, fn)=>{
|
|
452
|
+
val instanceof Set ? val.forEach(fn) : fn(val);
|
|
453
|
+
}, addAndConvert = (main, prop, item)=>{
|
|
454
|
+
let container = main[prop];
|
|
455
|
+
container instanceof Set || (main[prop] = container = new Set([
|
|
456
|
+
container
|
|
457
|
+
])), container.add(item);
|
|
458
|
+
}, delFromSet = (main, prop, item)=>{
|
|
459
|
+
let container = main[prop];
|
|
460
|
+
container instanceof Set ? container.delete(item) : container === item && delete main[prop];
|
|
461
|
+
}, isEmptySet = (val)=>val instanceof Set ? 0 === val.size : !val, FsWatchInstances = new Map();
|
|
462
|
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
|
463
|
+
try {
|
|
464
|
+
return (0, external_node_fs_.watch)(path, {
|
|
465
|
+
persistent: options.persistent
|
|
466
|
+
}, (rawEvent, evPath)=>{
|
|
467
|
+
listener(path), emitRaw(rawEvent, evPath, {
|
|
468
|
+
watchedPath: path
|
|
469
|
+
}), evPath && path !== evPath && fsWatchBroadcast(external_node_path_.resolve(path, evPath), KEY_LISTENERS, external_node_path_.join(path, evPath));
|
|
470
|
+
});
|
|
471
|
+
} catch (error) {
|
|
472
|
+
errHandler(error);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
let fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3)=>{
|
|
477
|
+
let cont = FsWatchInstances.get(fullPath);
|
|
478
|
+
cont && foreach(cont[listenerType], (listener)=>{
|
|
479
|
+
listener(val1, val2, val3);
|
|
480
|
+
});
|
|
481
|
+
}, FsWatchFileInstances = new Map();
|
|
482
|
+
class NodeFsHandler {
|
|
483
|
+
fsw;
|
|
484
|
+
_boundHandleError;
|
|
485
|
+
constructor(fsW){
|
|
486
|
+
this.fsw = fsW, this._boundHandleError = (error)=>fsW._handleError(error);
|
|
487
|
+
}
|
|
488
|
+
_watchWithNodeFs(path, listener) {
|
|
489
|
+
let closer, opts = this.fsw.options, directory = external_node_path_.dirname(path), basename = external_node_path_.basename(path);
|
|
490
|
+
this.fsw._getWatchedDir(directory).add(basename);
|
|
491
|
+
let absolutePath = external_node_path_.resolve(path), options = {
|
|
492
|
+
persistent: opts.persistent
|
|
493
|
+
};
|
|
494
|
+
if (listener || (listener = EMPTY_FN), opts.usePolling) options.interval = opts.interval !== opts.binaryInterval && binaryExtensions.has(external_node_path_.extname(basename).slice(1).toLowerCase()) ? opts.binaryInterval : opts.interval, closer = ((path, fullPath, options, handlers)=>{
|
|
495
|
+
let { listener, rawEmitter } = handlers, cont = FsWatchFileInstances.get(fullPath), copts = cont && cont.options;
|
|
496
|
+
return copts && (copts.persistent < options.persistent || copts.interval > options.interval) && ((0, external_node_fs_.unwatchFile)(fullPath), cont = void 0), cont ? (addAndConvert(cont, KEY_LISTENERS, listener), addAndConvert(cont, KEY_RAW, rawEmitter)) : (cont = {
|
|
497
|
+
listeners: listener,
|
|
498
|
+
rawEmitters: rawEmitter,
|
|
499
|
+
options,
|
|
500
|
+
watcher: (0, external_node_fs_.watchFile)(fullPath, options, (curr, prev)=>{
|
|
501
|
+
foreach(cont.rawEmitters, (rawEmitter)=>{
|
|
502
|
+
rawEmitter(EVENTS_CHANGE, fullPath, {
|
|
503
|
+
curr,
|
|
504
|
+
prev
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
let currmtime = curr.mtimeMs;
|
|
508
|
+
(curr.size !== prev.size || currmtime > prev.mtimeMs || 0 === currmtime) && foreach(cont.listeners, (listener)=>listener(path, curr));
|
|
509
|
+
})
|
|
510
|
+
}, FsWatchFileInstances.set(fullPath, cont)), ()=>{
|
|
511
|
+
delFromSet(cont, KEY_LISTENERS, listener), delFromSet(cont, KEY_RAW, rawEmitter), isEmptySet(cont.listeners) && (FsWatchFileInstances.delete(fullPath), (0, external_node_fs_.unwatchFile)(fullPath), cont.options = cont.watcher = void 0, Object.freeze(cont));
|
|
512
|
+
};
|
|
513
|
+
})(path, absolutePath, options, {
|
|
514
|
+
listener,
|
|
515
|
+
rawEmitter: this.fsw._emitRaw
|
|
516
|
+
});
|
|
517
|
+
else closer = ((path, fullPath, options, handlers)=>{
|
|
518
|
+
let watcher, { listener, errHandler, rawEmitter } = handlers, cont = FsWatchInstances.get(fullPath);
|
|
519
|
+
if (!options.persistent) {
|
|
520
|
+
if (!(watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter))) return;
|
|
521
|
+
return watcher.close.bind(watcher);
|
|
522
|
+
}
|
|
523
|
+
if (cont) addAndConvert(cont, KEY_LISTENERS, listener), addAndConvert(cont, KEY_ERR, errHandler), addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
524
|
+
else {
|
|
525
|
+
if (!(watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW)))) return;
|
|
526
|
+
watcher.on(EVENTS_ERROR, async (error)=>{
|
|
527
|
+
let broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
|
528
|
+
if (cont && (cont.watcherUnusable = !0), isWindows && 'EPERM' === error.code) try {
|
|
529
|
+
let fd = await promises_open(path, 'r');
|
|
530
|
+
await fd.close(), broadcastErr(error);
|
|
531
|
+
} catch (err) {}
|
|
532
|
+
else broadcastErr(error);
|
|
533
|
+
}), cont = {
|
|
534
|
+
listeners: listener,
|
|
535
|
+
errHandlers: errHandler,
|
|
536
|
+
rawEmitters: rawEmitter,
|
|
537
|
+
watcher
|
|
538
|
+
}, FsWatchInstances.set(fullPath, cont);
|
|
539
|
+
}
|
|
540
|
+
return ()=>{
|
|
541
|
+
if (delFromSet(cont, KEY_LISTENERS, listener), delFromSet(cont, KEY_ERR, errHandler), delFromSet(cont, KEY_RAW, rawEmitter), isEmptySet(cont.listeners)) {
|
|
542
|
+
let cont1;
|
|
543
|
+
cont.watcher.close(), FsWatchInstances.delete(fullPath), HANDLER_KEYS.forEach((cont1 = cont, (key)=>{
|
|
544
|
+
let set = cont1[key];
|
|
545
|
+
set instanceof Set ? set.clear() : delete cont1[key];
|
|
546
|
+
})), cont.watcher = void 0, Object.freeze(cont);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
})(path, absolutePath, options, {
|
|
550
|
+
listener,
|
|
551
|
+
errHandler: this._boundHandleError,
|
|
552
|
+
rawEmitter: this.fsw._emitRaw
|
|
553
|
+
});
|
|
554
|
+
return closer;
|
|
555
|
+
}
|
|
556
|
+
_handleFile(file, stats, initialAdd) {
|
|
557
|
+
if (this.fsw.closed) return;
|
|
558
|
+
let dirname = external_node_path_.dirname(file), basename = external_node_path_.basename(file), parent = this.fsw._getWatchedDir(dirname), prevStats = stats;
|
|
559
|
+
if (parent.has(basename)) return;
|
|
560
|
+
let listener = async (path, newStats)=>{
|
|
561
|
+
if (this.fsw._throttle('watch', file, 5)) if (newStats && 0 !== newStats.mtimeMs) {
|
|
562
|
+
if (parent.has(basename)) {
|
|
563
|
+
let at = newStats.atimeMs, mt = newStats.mtimeMs;
|
|
564
|
+
(!at || at <= mt || mt !== prevStats.mtimeMs) && this.fsw._emit(EVENTS_CHANGE, file, newStats), prevStats = newStats;
|
|
565
|
+
}
|
|
566
|
+
} else try {
|
|
567
|
+
let newStats = await promises_stat(file);
|
|
568
|
+
if (this.fsw.closed) return;
|
|
569
|
+
let at = newStats.atimeMs, mt = newStats.mtimeMs;
|
|
570
|
+
if ((!at || at <= mt || mt !== prevStats.mtimeMs) && this.fsw._emit(EVENTS_CHANGE, file, newStats), (isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
|
571
|
+
this.fsw._closeFile(path), prevStats = newStats;
|
|
572
|
+
let closer = this._watchWithNodeFs(file, listener);
|
|
573
|
+
closer && this.fsw._addPathCloser(path, closer);
|
|
574
|
+
} else prevStats = newStats;
|
|
575
|
+
} catch (error) {
|
|
576
|
+
this.fsw._remove(dirname, basename);
|
|
577
|
+
}
|
|
578
|
+
}, closer = this._watchWithNodeFs(file, listener);
|
|
579
|
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
|
580
|
+
if (!this.fsw._throttle(EVENTS_ADD, file, 0)) return;
|
|
581
|
+
this.fsw._emit(EVENTS_ADD, file, stats);
|
|
582
|
+
}
|
|
583
|
+
return closer;
|
|
584
|
+
}
|
|
585
|
+
async _handleSymlink(entry, directory, path, item) {
|
|
586
|
+
if (this.fsw.closed) return;
|
|
587
|
+
let full = entry.fullPath, dir = this.fsw._getWatchedDir(directory);
|
|
588
|
+
if (!this.fsw.options.followSymlinks) {
|
|
589
|
+
let linkPath;
|
|
590
|
+
this.fsw._incrReadyCount();
|
|
591
|
+
try {
|
|
592
|
+
linkPath = await promises_realpath(path);
|
|
593
|
+
} catch (e) {
|
|
594
|
+
return this.fsw._emitReady(), !0;
|
|
595
|
+
}
|
|
596
|
+
if (this.fsw.closed) return;
|
|
597
|
+
return dir.has(item) ? this.fsw._symlinkPaths.get(full) !== linkPath && (this.fsw._symlinkPaths.set(full, linkPath), this.fsw._emit(EVENTS_CHANGE, path, entry.stats)) : (dir.add(item), this.fsw._symlinkPaths.set(full, linkPath), this.fsw._emit(EVENTS_ADD, path, entry.stats)), this.fsw._emitReady(), !0;
|
|
598
|
+
}
|
|
599
|
+
if (this.fsw._symlinkPaths.has(full)) return !0;
|
|
600
|
+
this.fsw._symlinkPaths.set(full, !0);
|
|
601
|
+
}
|
|
602
|
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
|
603
|
+
directory = external_node_path_.join(directory, '');
|
|
604
|
+
let throttleKey = target ? `${directory}:${target}` : directory;
|
|
605
|
+
if (!(throttler = this.fsw._throttle('readdir', throttleKey, 1000))) return;
|
|
606
|
+
let previous = this.fsw._getWatchedDir(wh.path), current = new Set(), stream = this.fsw._readdirp(directory, {
|
|
607
|
+
fileFilter: (entry)=>wh.filterPath(entry),
|
|
608
|
+
directoryFilter: (entry)=>wh.filterDir(entry)
|
|
609
|
+
});
|
|
610
|
+
if (stream) return stream.on('data', async (entry)=>{
|
|
611
|
+
if (this.fsw.closed) {
|
|
612
|
+
stream = void 0;
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
let item = entry.path, path = external_node_path_.join(directory, item);
|
|
616
|
+
if (current.add(item), !(entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item))) {
|
|
617
|
+
if (this.fsw.closed) {
|
|
618
|
+
stream = void 0;
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
item !== target && (target || previous.has(item)) || (this.fsw._incrReadyCount(), path = external_node_path_.join(dir, external_node_path_.relative(dir, path)), this._addToNodeFs(path, initialAdd, wh, depth + 1));
|
|
622
|
+
}
|
|
623
|
+
}).on(EVENTS_ERROR, this._boundHandleError), new Promise((resolve, reject)=>{
|
|
624
|
+
if (!stream) return reject();
|
|
625
|
+
stream.once('end', ()=>{
|
|
626
|
+
if (this.fsw.closed) {
|
|
627
|
+
stream = void 0;
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
let wasThrottled = !!throttler && throttler.clear();
|
|
631
|
+
resolve(void 0), previous.getChildren().filter((item)=>item !== directory && !current.has(item)).forEach((item)=>{
|
|
632
|
+
this.fsw._remove(directory, item);
|
|
633
|
+
}), stream = void 0, wasThrottled && this._handleRead(directory, !1, wh, target, dir, depth, throttler);
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
|
638
|
+
let throttler, closer, parentDir = this.fsw._getWatchedDir(external_node_path_.dirname(dir)), tracked = parentDir.has(external_node_path_.basename(dir));
|
|
639
|
+
initialAdd && this.fsw.options.ignoreInitial || target || tracked || this.fsw._emit(EVENTS_ADD_DIR, dir, stats), parentDir.add(external_node_path_.basename(dir)), this.fsw._getWatchedDir(dir);
|
|
640
|
+
let oDepth = this.fsw.options.depth;
|
|
641
|
+
if ((null == oDepth || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
|
642
|
+
if (!target && (await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler), this.fsw.closed)) return;
|
|
643
|
+
closer = this._watchWithNodeFs(dir, (dirPath, stats)=>{
|
|
644
|
+
stats && 0 === stats.mtimeMs || this._handleRead(dirPath, !1, wh, target, dir, depth, throttler);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
return closer;
|
|
648
|
+
}
|
|
649
|
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
|
650
|
+
let ready = this.fsw._emitReady;
|
|
651
|
+
if (this.fsw._isIgnored(path) || this.fsw.closed) return ready(), !1;
|
|
652
|
+
let wh = this.fsw._getWatchHelpers(path);
|
|
653
|
+
priorWh && (wh.filterPath = (entry)=>priorWh.filterPath(entry), wh.filterDir = (entry)=>priorWh.filterDir(entry));
|
|
654
|
+
try {
|
|
655
|
+
let closer, stats = await statMethods[wh.statMethod](wh.watchPath);
|
|
656
|
+
if (this.fsw.closed) return;
|
|
657
|
+
if (this.fsw._isIgnored(wh.watchPath, stats)) return ready(), !1;
|
|
658
|
+
let follow = this.fsw.options.followSymlinks;
|
|
659
|
+
if (stats.isDirectory()) {
|
|
660
|
+
let absPath = external_node_path_.resolve(path), targetPath = follow ? await promises_realpath(path) : path;
|
|
661
|
+
if (this.fsw.closed || (closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath), this.fsw.closed)) return;
|
|
662
|
+
absPath !== targetPath && void 0 !== targetPath && this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
663
|
+
} else if (stats.isSymbolicLink()) {
|
|
664
|
+
let targetPath = follow ? await promises_realpath(path) : path;
|
|
665
|
+
if (this.fsw.closed) return;
|
|
666
|
+
let parent = external_node_path_.dirname(wh.watchPath);
|
|
667
|
+
if (this.fsw._getWatchedDir(parent).add(wh.watchPath), this.fsw._emit(EVENTS_ADD, wh.watchPath, stats), closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath), this.fsw.closed) return;
|
|
668
|
+
void 0 !== targetPath && this.fsw._symlinkPaths.set(external_node_path_.resolve(path), targetPath);
|
|
669
|
+
} else closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
670
|
+
return ready(), closer && this.fsw._addPathCloser(path, closer), !1;
|
|
671
|
+
} catch (error) {
|
|
672
|
+
if (this.fsw._handleError(error)) return ready(), path;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
let external_node_events_ = __webpack_require__("node:events"), BACK_SLASH_RE = /\\/g, DOUBLE_SLASH_RE = /\/\//g, DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/, REPLACER_RE = /^\.[/\\]/;
|
|
677
|
+
function arrify(item) {
|
|
678
|
+
return Array.isArray(item) ? item : [
|
|
679
|
+
item
|
|
680
|
+
];
|
|
681
|
+
}
|
|
682
|
+
let isMatcherObject = (matcher)=>'object' == typeof matcher && null !== matcher && !(matcher instanceof RegExp);
|
|
683
|
+
function createPattern(matcher) {
|
|
684
|
+
return 'function' == typeof matcher ? matcher : 'string' == typeof matcher ? (string)=>matcher === string : matcher instanceof RegExp ? (string)=>matcher.test(string) : 'object' == typeof matcher && null !== matcher ? (string)=>{
|
|
685
|
+
if (matcher.path === string) return !0;
|
|
686
|
+
if (matcher.recursive) {
|
|
687
|
+
let relative = external_node_path_.relative(matcher.path, string);
|
|
688
|
+
return !!relative && !relative.startsWith('..') && !external_node_path_.isAbsolute(relative);
|
|
689
|
+
}
|
|
690
|
+
return !1;
|
|
691
|
+
} : ()=>!1;
|
|
692
|
+
}
|
|
693
|
+
function normalizePath(path) {
|
|
694
|
+
if ('string' != typeof path) throw Error('string expected');
|
|
695
|
+
path = (path = external_node_path_.normalize(path)).replace(/\\/g, '/');
|
|
696
|
+
let prepend = !1;
|
|
697
|
+
return path.startsWith('//') && (prepend = !0), path = path.replace(DOUBLE_SLASH_RE, '/'), prepend && (path = '/' + path), path;
|
|
698
|
+
}
|
|
699
|
+
function matchPatterns(patterns, testString, stats) {
|
|
700
|
+
let path = normalizePath(testString);
|
|
701
|
+
for(let index = 0; index < patterns.length; index++)if ((0, patterns[index])(path, stats)) return !0;
|
|
702
|
+
return !1;
|
|
703
|
+
}
|
|
704
|
+
function anymatch(matchers, testString) {
|
|
705
|
+
if (null == matchers) throw TypeError('anymatch: specify first argument');
|
|
706
|
+
let patterns = arrify(matchers).map((matcher)=>createPattern(matcher));
|
|
707
|
+
return null == testString ? (testString, stats)=>matchPatterns(patterns, testString, stats) : matchPatterns(patterns, testString);
|
|
708
|
+
}
|
|
709
|
+
let unifyPaths = (paths_)=>{
|
|
710
|
+
let paths = arrify(paths_).flat();
|
|
711
|
+
if (!paths.every((p)=>'string' == typeof p)) throw TypeError(`Non-string provided as watch path: ${paths}`);
|
|
712
|
+
return paths.map(normalizePathToUnix);
|
|
713
|
+
}, toUnix = (string)=>{
|
|
714
|
+
let str = string.replace(BACK_SLASH_RE, '/'), prepend = !1;
|
|
715
|
+
return str.startsWith('//') && (prepend = !0), str = str.replace(DOUBLE_SLASH_RE, '/'), prepend && (str = '/' + str), str;
|
|
716
|
+
}, normalizePathToUnix = (path)=>toUnix(external_node_path_.normalize(toUnix(path))), normalizeIgnored = (cwd = '')=>(path)=>'string' == typeof path ? normalizePathToUnix(external_node_path_.isAbsolute(path) ? path : external_node_path_.join(cwd, path)) : path, EMPTY_SET = Object.freeze(new Set());
|
|
717
|
+
class DirEntry {
|
|
718
|
+
path;
|
|
719
|
+
_removeWatcher;
|
|
720
|
+
items;
|
|
721
|
+
constructor(dir, removeWatcher){
|
|
722
|
+
this.path = dir, this._removeWatcher = removeWatcher, this.items = new Set();
|
|
723
|
+
}
|
|
724
|
+
add(item) {
|
|
725
|
+
let { items } = this;
|
|
726
|
+
items && '.' !== item && '..' !== item && items.add(item);
|
|
727
|
+
}
|
|
728
|
+
async remove(item) {
|
|
729
|
+
let { items } = this;
|
|
730
|
+
if (!items || (items.delete(item), items.size > 0)) return;
|
|
731
|
+
let dir = this.path;
|
|
732
|
+
try {
|
|
733
|
+
await readdir(dir);
|
|
734
|
+
} catch (err) {
|
|
735
|
+
this._removeWatcher && this._removeWatcher(external_node_path_.dirname(dir), external_node_path_.basename(dir));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
has(item) {
|
|
739
|
+
let { items } = this;
|
|
740
|
+
if (items) return items.has(item);
|
|
741
|
+
}
|
|
742
|
+
getChildren() {
|
|
743
|
+
let { items } = this;
|
|
744
|
+
return items ? [
|
|
745
|
+
...items.values()
|
|
746
|
+
] : [];
|
|
747
|
+
}
|
|
748
|
+
dispose() {
|
|
749
|
+
this.items.clear(), this.path = '', this._removeWatcher = EMPTY_FN, this.items = EMPTY_SET, Object.freeze(this);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
class WatchHelper {
|
|
753
|
+
fsw;
|
|
754
|
+
path;
|
|
755
|
+
watchPath;
|
|
756
|
+
fullWatchPath;
|
|
757
|
+
dirParts;
|
|
758
|
+
followSymlinks;
|
|
759
|
+
statMethod;
|
|
760
|
+
constructor(path, follow, fsw){
|
|
761
|
+
this.fsw = fsw;
|
|
762
|
+
let watchPath = path;
|
|
763
|
+
this.path = path = path.replace(REPLACER_RE, ''), this.watchPath = watchPath, this.fullWatchPath = external_node_path_.resolve(watchPath), this.dirParts = [], this.dirParts.forEach((parts)=>{
|
|
764
|
+
parts.length > 1 && parts.pop();
|
|
765
|
+
}), this.followSymlinks = follow, this.statMethod = follow ? 'stat' : 'lstat';
|
|
766
|
+
}
|
|
767
|
+
entryPath(entry) {
|
|
768
|
+
return external_node_path_.join(this.watchPath, external_node_path_.relative(this.watchPath, entry.fullPath));
|
|
769
|
+
}
|
|
770
|
+
filterPath(entry) {
|
|
771
|
+
let { stats } = entry;
|
|
772
|
+
if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
|
|
773
|
+
let resolvedPath = this.entryPath(entry);
|
|
774
|
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
|
775
|
+
}
|
|
776
|
+
filterDir(entry) {
|
|
777
|
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
class FSWatcher extends external_node_events_.EventEmitter {
|
|
781
|
+
closed;
|
|
782
|
+
options;
|
|
783
|
+
_closers;
|
|
784
|
+
_ignoredPaths;
|
|
785
|
+
_throttled;
|
|
786
|
+
_streams;
|
|
787
|
+
_symlinkPaths;
|
|
788
|
+
_watched;
|
|
789
|
+
_pendingWrites;
|
|
790
|
+
_pendingUnlinks;
|
|
791
|
+
_readyCount;
|
|
792
|
+
_emitReady;
|
|
793
|
+
_closePromise;
|
|
794
|
+
_userIgnored;
|
|
795
|
+
_readyEmitted;
|
|
796
|
+
_emitRaw;
|
|
797
|
+
_boundRemove;
|
|
798
|
+
_nodeFsHandler;
|
|
799
|
+
constructor(_opts = {}){
|
|
800
|
+
super(), this.closed = !1, this._closers = new Map(), this._ignoredPaths = new Set(), this._throttled = new Map(), this._streams = new Set(), this._symlinkPaths = new Map(), this._watched = new Map(), this._pendingWrites = new Map(), this._pendingUnlinks = new Map(), this._readyCount = 0, this._readyEmitted = !1;
|
|
801
|
+
let awf = _opts.awaitWriteFinish, DEF_AWF = {
|
|
802
|
+
stabilityThreshold: 2000,
|
|
803
|
+
pollInterval: 100
|
|
804
|
+
}, opts = {
|
|
805
|
+
persistent: !0,
|
|
806
|
+
ignoreInitial: !1,
|
|
807
|
+
ignorePermissionErrors: !1,
|
|
808
|
+
interval: 100,
|
|
809
|
+
binaryInterval: 300,
|
|
810
|
+
followSymlinks: !0,
|
|
811
|
+
usePolling: !1,
|
|
812
|
+
atomic: !0,
|
|
813
|
+
..._opts,
|
|
814
|
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
|
815
|
+
awaitWriteFinish: !0 === awf ? DEF_AWF : 'object' == typeof awf && {
|
|
816
|
+
...DEF_AWF,
|
|
817
|
+
...awf
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
isIBMi && (opts.usePolling = !0), void 0 === opts.atomic && (opts.atomic = !opts.usePolling);
|
|
821
|
+
let envPoll = process.env.CHOKIDAR_USEPOLLING;
|
|
822
|
+
if (void 0 !== envPoll) {
|
|
823
|
+
let envLower = envPoll.toLowerCase();
|
|
824
|
+
'false' === envLower || '0' === envLower ? opts.usePolling = !1 : 'true' === envLower || '1' === envLower ? opts.usePolling = !0 : opts.usePolling = !!envLower;
|
|
825
|
+
}
|
|
826
|
+
let envInterval = process.env.CHOKIDAR_INTERVAL;
|
|
827
|
+
envInterval && (opts.interval = Number.parseInt(envInterval, 10));
|
|
828
|
+
let readyCalls = 0;
|
|
829
|
+
this._emitReady = ()=>{
|
|
830
|
+
++readyCalls >= this._readyCount && (this._emitReady = EMPTY_FN, this._readyEmitted = !0, process.nextTick(()=>this.emit(EVENTS_READY)));
|
|
831
|
+
}, this._emitRaw = (...args)=>this.emit(EVENTS_RAW, ...args), this._boundRemove = this._remove.bind(this), this.options = opts, this._nodeFsHandler = new NodeFsHandler(this), Object.freeze(opts);
|
|
832
|
+
}
|
|
833
|
+
_addIgnoredPath(matcher) {
|
|
834
|
+
if (isMatcherObject(matcher)) {
|
|
835
|
+
for (let ignored of this._ignoredPaths)if (isMatcherObject(ignored) && ignored.path === matcher.path && ignored.recursive === matcher.recursive) return;
|
|
836
|
+
}
|
|
837
|
+
this._ignoredPaths.add(matcher);
|
|
838
|
+
}
|
|
839
|
+
_removeIgnoredPath(matcher) {
|
|
840
|
+
if (this._ignoredPaths.delete(matcher), 'string' == typeof matcher) for (let ignored of this._ignoredPaths)isMatcherObject(ignored) && ignored.path === matcher && this._ignoredPaths.delete(ignored);
|
|
841
|
+
}
|
|
842
|
+
add(paths_, _origAdd, _internal) {
|
|
843
|
+
let { cwd } = this.options;
|
|
844
|
+
this.closed = !1, this._closePromise = void 0;
|
|
845
|
+
let paths = unifyPaths(paths_);
|
|
846
|
+
return cwd && (paths = paths.map((path)=>external_node_path_.isAbsolute(path) ? path : external_node_path_.join(cwd, path))), paths.forEach((path)=>{
|
|
847
|
+
this._removeIgnoredPath(path);
|
|
848
|
+
}), this._userIgnored = void 0, this._readyCount || (this._readyCount = 0), this._readyCount += paths.length, Promise.all(paths.map(async (path)=>{
|
|
849
|
+
let res = await this._nodeFsHandler._addToNodeFs(path, !_internal, void 0, 0, _origAdd);
|
|
850
|
+
return res && this._emitReady(), res;
|
|
851
|
+
})).then((results)=>{
|
|
852
|
+
this.closed || results.forEach((item)=>{
|
|
853
|
+
item && this.add(external_node_path_.dirname(item), external_node_path_.basename(_origAdd || item));
|
|
854
|
+
});
|
|
855
|
+
}), this;
|
|
856
|
+
}
|
|
857
|
+
unwatch(paths_) {
|
|
858
|
+
if (this.closed) return this;
|
|
859
|
+
let paths = unifyPaths(paths_), { cwd } = this.options;
|
|
860
|
+
return paths.forEach((path)=>{
|
|
861
|
+
external_node_path_.isAbsolute(path) || this._closers.has(path) || (cwd && (path = external_node_path_.join(cwd, path)), path = external_node_path_.resolve(path)), this._closePath(path), this._addIgnoredPath(path), this._watched.has(path) && this._addIgnoredPath({
|
|
862
|
+
path,
|
|
863
|
+
recursive: !0
|
|
864
|
+
}), this._userIgnored = void 0;
|
|
865
|
+
}), this;
|
|
866
|
+
}
|
|
867
|
+
close() {
|
|
868
|
+
if (this._closePromise) return this._closePromise;
|
|
869
|
+
this.closed = !0, this.removeAllListeners();
|
|
870
|
+
let closers = [];
|
|
871
|
+
return this._closers.forEach((closerList)=>closerList.forEach((closer)=>{
|
|
872
|
+
let promise = closer();
|
|
873
|
+
promise instanceof Promise && closers.push(promise);
|
|
874
|
+
})), this._streams.forEach((stream)=>stream.destroy()), this._userIgnored = void 0, this._readyCount = 0, this._readyEmitted = !1, this._watched.forEach((dirent)=>dirent.dispose()), this._closers.clear(), this._watched.clear(), this._streams.clear(), this._symlinkPaths.clear(), this._throttled.clear(), this._closePromise = closers.length ? Promise.all(closers).then(()=>void 0) : Promise.resolve(), this._closePromise;
|
|
875
|
+
}
|
|
876
|
+
getWatched() {
|
|
877
|
+
let watchList = {};
|
|
878
|
+
return this._watched.forEach((entry, dir)=>{
|
|
879
|
+
watchList[(this.options.cwd ? external_node_path_.relative(this.options.cwd, dir) : dir) || '.'] = entry.getChildren().sort();
|
|
880
|
+
}), watchList;
|
|
881
|
+
}
|
|
882
|
+
emitWithAll(event, args) {
|
|
883
|
+
this.emit(event, ...args), event !== EVENTS_ERROR && this.emit(EVENTS_ALL, event, ...args);
|
|
884
|
+
}
|
|
885
|
+
async _emit(event, path, stats) {
|
|
886
|
+
let pw;
|
|
887
|
+
if (this.closed) return;
|
|
888
|
+
let opts = this.options;
|
|
889
|
+
isWindows && (path = external_node_path_.normalize(path)), opts.cwd && (path = external_node_path_.relative(opts.cwd, path));
|
|
890
|
+
let args = [
|
|
891
|
+
path
|
|
892
|
+
];
|
|
893
|
+
null != stats && args.push(stats);
|
|
894
|
+
let awf = opts.awaitWriteFinish;
|
|
895
|
+
if (awf && (pw = this._pendingWrites.get(path))) return pw.lastChange = new Date(), this;
|
|
896
|
+
if (opts.atomic) {
|
|
897
|
+
if (event === EVENTS_UNLINK) return this._pendingUnlinks.set(path, [
|
|
898
|
+
event,
|
|
899
|
+
...args
|
|
900
|
+
]), setTimeout(()=>{
|
|
901
|
+
this._pendingUnlinks.forEach((entry, path)=>{
|
|
902
|
+
this.emit(...entry), this.emit(EVENTS_ALL, ...entry), this._pendingUnlinks.delete(path);
|
|
903
|
+
});
|
|
904
|
+
}, 'number' == typeof opts.atomic ? opts.atomic : 100), this;
|
|
905
|
+
event === EVENTS_ADD && this._pendingUnlinks.has(path) && (event = EVENTS_CHANGE, this._pendingUnlinks.delete(path));
|
|
906
|
+
}
|
|
907
|
+
if (awf && (event === EVENTS_ADD || event === EVENTS_CHANGE) && this._readyEmitted) {
|
|
908
|
+
let awfEmit = (err, stats)=>{
|
|
909
|
+
err ? (event = EVENTS_ERROR, args[0] = err, this.emitWithAll(event, args)) : stats && (args.length > 1 ? args[1] = stats : args.push(stats), this.emitWithAll(event, args));
|
|
910
|
+
};
|
|
911
|
+
return this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit), this;
|
|
912
|
+
}
|
|
913
|
+
if (event === EVENTS_CHANGE && !this._throttle(EVENTS_CHANGE, path, 50)) return this;
|
|
914
|
+
if (opts.alwaysStat && void 0 === stats && (event === EVENTS_ADD || event === EVENTS_ADD_DIR || event === EVENTS_CHANGE)) {
|
|
915
|
+
let stats, fullPath = opts.cwd ? external_node_path_.join(opts.cwd, path) : path;
|
|
916
|
+
try {
|
|
917
|
+
stats = await promises_stat(fullPath);
|
|
918
|
+
} catch (err) {}
|
|
919
|
+
if (!stats || this.closed) return;
|
|
920
|
+
args.push(stats);
|
|
921
|
+
}
|
|
922
|
+
return this.emitWithAll(event, args), this;
|
|
923
|
+
}
|
|
924
|
+
_handleError(error) {
|
|
925
|
+
let code = error && error.code;
|
|
926
|
+
return error && 'ENOENT' !== code && 'ENOTDIR' !== code && (!this.options.ignorePermissionErrors || 'EPERM' !== code && 'EACCES' !== code) && this.emit(EVENTS_ERROR, error), error || this.closed;
|
|
927
|
+
}
|
|
928
|
+
_throttle(actionType, path, timeout) {
|
|
929
|
+
let timeoutObject;
|
|
930
|
+
this._throttled.has(actionType) || this._throttled.set(actionType, new Map());
|
|
931
|
+
let action = this._throttled.get(actionType);
|
|
932
|
+
if (!action) throw Error('invalid throttle');
|
|
933
|
+
let actionPath = action.get(path);
|
|
934
|
+
if (actionPath) return actionPath.count++, !1;
|
|
935
|
+
let clear = ()=>{
|
|
936
|
+
let item = action.get(path), count = item ? item.count : 0;
|
|
937
|
+
return action.delete(path), clearTimeout(timeoutObject), item && clearTimeout(item.timeoutObject), count;
|
|
938
|
+
}, thr = {
|
|
939
|
+
timeoutObject: timeoutObject = setTimeout(clear, timeout),
|
|
940
|
+
clear,
|
|
941
|
+
count: 0
|
|
942
|
+
};
|
|
943
|
+
return action.set(path, thr), thr;
|
|
944
|
+
}
|
|
945
|
+
_incrReadyCount() {
|
|
946
|
+
return this._readyCount++;
|
|
947
|
+
}
|
|
948
|
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
|
949
|
+
let timeoutHandler, awf = this.options.awaitWriteFinish;
|
|
950
|
+
if ('object' != typeof awf) return;
|
|
951
|
+
let pollInterval = awf.pollInterval, fullPath = path;
|
|
952
|
+
this.options.cwd && !external_node_path_.isAbsolute(path) && (fullPath = external_node_path_.join(this.options.cwd, path));
|
|
953
|
+
let now = new Date(), writes = this._pendingWrites;
|
|
954
|
+
function awaitWriteFinishFn(prevStat) {
|
|
955
|
+
(0, external_node_fs_.stat)(fullPath, (err, curStat)=>{
|
|
956
|
+
if (err || !writes.has(path)) {
|
|
957
|
+
err && 'ENOENT' !== err.code && awfEmit(err);
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
let now = Number(new Date());
|
|
961
|
+
prevStat && curStat.size !== prevStat.size && (writes.get(path).lastChange = now), now - writes.get(path).lastChange >= threshold ? (writes.delete(path), awfEmit(void 0, curStat)) : timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
writes.has(path) || (writes.set(path, {
|
|
965
|
+
lastChange: now,
|
|
966
|
+
cancelWait: ()=>(writes.delete(path), clearTimeout(timeoutHandler), event)
|
|
967
|
+
}), timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval));
|
|
968
|
+
}
|
|
969
|
+
_isIgnored(path, stats) {
|
|
970
|
+
if (this.options.atomic && DOT_RE.test(path)) return !0;
|
|
971
|
+
if (!this._userIgnored) {
|
|
972
|
+
let { cwd } = this.options, ignored = (this.options.ignored || []).map(normalizeIgnored(cwd)), list = [
|
|
973
|
+
...[
|
|
974
|
+
...this._ignoredPaths
|
|
975
|
+
].map(normalizeIgnored(cwd)),
|
|
976
|
+
...ignored
|
|
977
|
+
];
|
|
978
|
+
this._userIgnored = anymatch(list, void 0);
|
|
979
|
+
}
|
|
980
|
+
return this._userIgnored(path, stats);
|
|
981
|
+
}
|
|
982
|
+
_isntIgnored(path, stat) {
|
|
983
|
+
return !this._isIgnored(path, stat);
|
|
984
|
+
}
|
|
985
|
+
_getWatchHelpers(path) {
|
|
986
|
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
|
987
|
+
}
|
|
988
|
+
_getWatchedDir(directory) {
|
|
989
|
+
let dir = external_node_path_.resolve(directory);
|
|
990
|
+
return this._watched.has(dir) || this._watched.set(dir, new DirEntry(dir, this._boundRemove)), this._watched.get(dir);
|
|
991
|
+
}
|
|
992
|
+
_hasReadPermissions(stats) {
|
|
993
|
+
return !!this.options.ignorePermissionErrors || !!(256 & Number(stats.mode));
|
|
994
|
+
}
|
|
995
|
+
_remove(directory, item, isDirectory) {
|
|
996
|
+
let path = external_node_path_.join(directory, item), fullPath = external_node_path_.resolve(path);
|
|
997
|
+
if (isDirectory = null != isDirectory ? isDirectory : this._watched.has(path) || this._watched.has(fullPath), !this._throttle('remove', path, 100)) return;
|
|
998
|
+
isDirectory || 1 !== this._watched.size || this.add(directory, item, !0), this._getWatchedDir(path).getChildren().forEach((nested)=>this._remove(path, nested));
|
|
999
|
+
let parent = this._getWatchedDir(directory), wasTracked = parent.has(item);
|
|
1000
|
+
parent.remove(item), this._symlinkPaths.has(fullPath) && this._symlinkPaths.delete(fullPath);
|
|
1001
|
+
let relPath = path;
|
|
1002
|
+
if (this.options.cwd && (relPath = external_node_path_.relative(this.options.cwd, path)), this.options.awaitWriteFinish && this._pendingWrites.has(relPath) && this._pendingWrites.get(relPath).cancelWait() === EVENTS_ADD) return;
|
|
1003
|
+
this._watched.delete(path), this._watched.delete(fullPath);
|
|
1004
|
+
let eventName = isDirectory ? EVENTS_UNLINK_DIR : EVENTS_UNLINK;
|
|
1005
|
+
wasTracked && !this._isIgnored(path) && this._emit(eventName, path), this._closePath(path);
|
|
1006
|
+
}
|
|
1007
|
+
_closePath(path) {
|
|
1008
|
+
this._closeFile(path);
|
|
1009
|
+
let dir = external_node_path_.dirname(path);
|
|
1010
|
+
this._getWatchedDir(dir).remove(external_node_path_.basename(path));
|
|
1011
|
+
}
|
|
1012
|
+
_closeFile(path) {
|
|
1013
|
+
let closers = this._closers.get(path);
|
|
1014
|
+
closers && (closers.forEach((closer)=>closer()), this._closers.delete(path));
|
|
1015
|
+
}
|
|
1016
|
+
_addPathCloser(path, closer) {
|
|
1017
|
+
if (!closer) return;
|
|
1018
|
+
let list = this._closers.get(path);
|
|
1019
|
+
list || (list = [], this._closers.set(path, list)), list.push(closer);
|
|
1020
|
+
}
|
|
1021
|
+
_readdirp(root, opts) {
|
|
1022
|
+
if (this.closed) return;
|
|
1023
|
+
let stream = readdirp(root, {
|
|
1024
|
+
type: EVENTS_ALL,
|
|
1025
|
+
alwaysStat: !0,
|
|
1026
|
+
lstat: !0,
|
|
1027
|
+
...opts,
|
|
1028
|
+
depth: 0
|
|
1029
|
+
});
|
|
1030
|
+
return this._streams.add(stream), stream.once('close', ()=>{
|
|
1031
|
+
stream = void 0;
|
|
1032
|
+
}), stream.once('end', ()=>{
|
|
1033
|
+
stream && (this._streams.delete(stream), stream = void 0);
|
|
1034
|
+
}), stream;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
let chokidar = {
|
|
1038
|
+
watch: function watch(paths, options = {}) {
|
|
1039
|
+
let watcher = new FSWatcher(options);
|
|
1040
|
+
return watcher.add(paths), watcher;
|
|
1041
|
+
},
|
|
1042
|
+
FSWatcher: FSWatcher
|
|
1043
|
+
};
|
|
1044
|
+
export { chokidar };
|