@lynx-js/rspeedy-canary 0.13.0-canary-20260105-ec1caf1a → 0.13.0-canary-20260105-03ea61ec

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