rollup 2.57.0

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.
@@ -0,0 +1,4457 @@
1
+ /*
2
+ @license
3
+ Rollup.js v2.57.0
4
+ Wed, 22 Sep 2021 04:43:07 GMT - commit b67ef301e8e44f9e0d9b144c0cce441e2a41c3da
5
+
6
+
7
+ https://github.com/rollup/rollup
8
+
9
+ Released under the MIT License.
10
+ */
11
+ 'use strict';
12
+
13
+ var require$$0$1 = require('events');
14
+ var fs$4 = require('fs');
15
+ var path$1 = require('path');
16
+ var require$$2 = require('util');
17
+ var require$$1 = require('stream');
18
+ var rollup = require('./rollup.js');
19
+ var require$$2$1 = require('os');
20
+
21
+ var chokidar$1 = {};
22
+
23
+ const fs$3 = fs$4;
24
+ const { Readable } = require$$1;
25
+ const sysPath$3 = path$1;
26
+ const { promisify: promisify$3 } = require$$2;
27
+ const picomatch$1 = rollup.picomatch;
28
+
29
+ const readdir$1 = promisify$3(fs$3.readdir);
30
+ const stat$3 = promisify$3(fs$3.stat);
31
+ const lstat$2 = promisify$3(fs$3.lstat);
32
+ const realpath$1 = promisify$3(fs$3.realpath);
33
+
34
+ /**
35
+ * @typedef {Object} EntryInfo
36
+ * @property {String} path
37
+ * @property {String} fullPath
38
+ * @property {fs.Stats=} stats
39
+ * @property {fs.Dirent=} dirent
40
+ * @property {String} basename
41
+ */
42
+
43
+ const BANG$2 = '!';
44
+ const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
45
+ const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
46
+ const FILE_TYPE = 'files';
47
+ const DIR_TYPE = 'directories';
48
+ const FILE_DIR_TYPE = 'files_directories';
49
+ const EVERYTHING_TYPE = 'all';
50
+ const ALL_TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE];
51
+
52
+ const isNormalFlowError = error => NORMAL_FLOW_ERRORS.has(error.code);
53
+ const [maj, min] = process.versions.node.split('.').slice(0, 2).map(n => Number.parseInt(n, 10));
54
+ const wantBigintFsStats = process.platform === 'win32' && (maj > 10 || (maj === 10 && min >= 5));
55
+
56
+ const normalizeFilter = filter => {
57
+ if (filter === undefined) return;
58
+ if (typeof filter === 'function') return filter;
59
+
60
+ if (typeof filter === 'string') {
61
+ const glob = picomatch$1(filter.trim());
62
+ return entry => glob(entry.basename);
63
+ }
64
+
65
+ if (Array.isArray(filter)) {
66
+ const positive = [];
67
+ const negative = [];
68
+ for (const item of filter) {
69
+ const trimmed = item.trim();
70
+ if (trimmed.charAt(0) === BANG$2) {
71
+ negative.push(picomatch$1(trimmed.slice(1)));
72
+ } else {
73
+ positive.push(picomatch$1(trimmed));
74
+ }
75
+ }
76
+
77
+ if (negative.length > 0) {
78
+ if (positive.length > 0) {
79
+ return entry =>
80
+ positive.some(f => f(entry.basename)) && !negative.some(f => f(entry.basename));
81
+ }
82
+ return entry => !negative.some(f => f(entry.basename));
83
+ }
84
+ return entry => positive.some(f => f(entry.basename));
85
+ }
86
+ };
87
+
88
+ class ReaddirpStream extends Readable {
89
+ static get defaultOptions() {
90
+ return {
91
+ root: '.',
92
+ /* eslint-disable no-unused-vars */
93
+ fileFilter: (path) => true,
94
+ directoryFilter: (path) => true,
95
+ /* eslint-enable no-unused-vars */
96
+ type: FILE_TYPE,
97
+ lstat: false,
98
+ depth: 2147483648,
99
+ alwaysStat: false
100
+ };
101
+ }
102
+
103
+ constructor(options = {}) {
104
+ super({
105
+ objectMode: true,
106
+ autoDestroy: true,
107
+ highWaterMark: options.highWaterMark || 4096
108
+ });
109
+ const opts = { ...ReaddirpStream.defaultOptions, ...options };
110
+ const { root, type } = opts;
111
+
112
+ this._fileFilter = normalizeFilter(opts.fileFilter);
113
+ this._directoryFilter = normalizeFilter(opts.directoryFilter);
114
+
115
+ const statMethod = opts.lstat ? lstat$2 : stat$3;
116
+ // Use bigint stats if it's windows and stat() supports options (node 10+).
117
+ if (wantBigintFsStats) {
118
+ this._stat = path => statMethod(path, { bigint: true });
119
+ } else {
120
+ this._stat = statMethod;
121
+ }
122
+
123
+ this._maxDepth = opts.depth;
124
+ this._wantsDir = [DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE].includes(type);
125
+ this._wantsFile = [FILE_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE].includes(type);
126
+ this._wantsEverything = type === EVERYTHING_TYPE;
127
+ this._root = sysPath$3.resolve(root);
128
+ this._isDirent = ('Dirent' in fs$3) && !opts.alwaysStat;
129
+ this._statsProp = this._isDirent ? 'dirent' : 'stats';
130
+ this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
131
+
132
+ // Launch stream with one parent, the root dir.
133
+ this.parents = [this._exploreDir(root, 1)];
134
+ this.reading = false;
135
+ this.parent = undefined;
136
+ }
137
+
138
+ async _read(batch) {
139
+ if (this.reading) return;
140
+ this.reading = true;
141
+
142
+ try {
143
+ while (!this.destroyed && batch > 0) {
144
+ const { path, depth, files = [] } = this.parent || {};
145
+
146
+ if (files.length > 0) {
147
+ const slice = files.splice(0, batch).map(dirent => this._formatEntry(dirent, path));
148
+ for (const entry of await Promise.all(slice)) {
149
+ if (this.destroyed) return;
150
+
151
+ const entryType = await this._getEntryType(entry);
152
+ if (entryType === 'directory' && this._directoryFilter(entry)) {
153
+ if (depth <= this._maxDepth) {
154
+ this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
155
+ }
156
+
157
+ if (this._wantsDir) {
158
+ this.push(entry);
159
+ batch--;
160
+ }
161
+ } else if ((entryType === 'file' || this._includeAsFile(entry)) && this._fileFilter(entry)) {
162
+ if (this._wantsFile) {
163
+ this.push(entry);
164
+ batch--;
165
+ }
166
+ }
167
+ }
168
+ } else {
169
+ const parent = this.parents.pop();
170
+ if (!parent) {
171
+ this.push(null);
172
+ break;
173
+ }
174
+ this.parent = await parent;
175
+ if (this.destroyed) return;
176
+ }
177
+ }
178
+ } catch (error) {
179
+ this.destroy(error);
180
+ } finally {
181
+ this.reading = false;
182
+ }
183
+ }
184
+
185
+ async _exploreDir(path, depth) {
186
+ let files;
187
+ try {
188
+ files = await readdir$1(path, this._rdOptions);
189
+ } catch (error) {
190
+ this._onError(error);
191
+ }
192
+ return { files, depth, path };
193
+ }
194
+
195
+ async _formatEntry(dirent, path) {
196
+ let entry;
197
+ try {
198
+ const basename = this._isDirent ? dirent.name : dirent;
199
+ const fullPath = sysPath$3.resolve(sysPath$3.join(path, basename));
200
+ entry = { path: sysPath$3.relative(this._root, fullPath), fullPath, basename };
201
+ entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
202
+ } catch (err) {
203
+ this._onError(err);
204
+ }
205
+ return entry;
206
+ }
207
+
208
+ _onError(err) {
209
+ if (isNormalFlowError(err) && !this.destroyed) {
210
+ this.emit('warn', err);
211
+ } else {
212
+ this.destroy(err);
213
+ }
214
+ }
215
+
216
+ async _getEntryType(entry) {
217
+ // entry may be undefined, because a warning or an error were emitted
218
+ // and the statsProp is undefined
219
+ const stats = entry && entry[this._statsProp];
220
+ if (!stats) {
221
+ return;
222
+ }
223
+ if (stats.isFile()) {
224
+ return 'file';
225
+ }
226
+ if (stats.isDirectory()) {
227
+ return 'directory';
228
+ }
229
+ if (stats && stats.isSymbolicLink()) {
230
+ const full = entry.fullPath;
231
+ try {
232
+ const entryRealPath = await realpath$1(full);
233
+ const entryRealPathStats = await lstat$2(entryRealPath);
234
+ if (entryRealPathStats.isFile()) {
235
+ return 'file';
236
+ }
237
+ if (entryRealPathStats.isDirectory()) {
238
+ const len = entryRealPath.length;
239
+ if (full.startsWith(entryRealPath) && full.substr(len, 1) === sysPath$3.sep) {
240
+ const recursiveError = new Error(
241
+ `Circular symlink detected: "${full}" points to "${entryRealPath}"`
242
+ );
243
+ recursiveError.code = RECURSIVE_ERROR_CODE;
244
+ return this._onError(recursiveError);
245
+ }
246
+ return 'directory';
247
+ }
248
+ } catch (error) {
249
+ this._onError(error);
250
+ }
251
+ }
252
+ }
253
+
254
+ _includeAsFile(entry) {
255
+ const stats = entry && entry[this._statsProp];
256
+
257
+ return stats && this._wantsEverything && !stats.isDirectory();
258
+ }
259
+ }
260
+
261
+ /**
262
+ * @typedef {Object} ReaddirpArguments
263
+ * @property {Function=} fileFilter
264
+ * @property {Function=} directoryFilter
265
+ * @property {String=} type
266
+ * @property {Number=} depth
267
+ * @property {String=} root
268
+ * @property {Boolean=} lstat
269
+ * @property {Boolean=} bigint
270
+ */
271
+
272
+ /**
273
+ * Main function which ends up calling readdirRec and reads all files and directories in given root recursively.
274
+ * @param {String} root Root directory
275
+ * @param {ReaddirpArguments=} options Options to specify root (start directory), filters and recursion depth
276
+ */
277
+ const readdirp$1 = (root, options = {}) => {
278
+ let type = options.entryType || options.type;
279
+ if (type === 'both') type = FILE_DIR_TYPE; // backwards-compatibility
280
+ if (type) options.type = type;
281
+ if (!root) {
282
+ throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
283
+ } else if (typeof root !== 'string') {
284
+ throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
285
+ } else if (type && !ALL_TYPES.includes(type)) {
286
+ throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
287
+ }
288
+
289
+ options.root = root;
290
+ return new ReaddirpStream(options);
291
+ };
292
+
293
+ const readdirpPromise = (root, options = {}) => {
294
+ return new Promise((resolve, reject) => {
295
+ const files = [];
296
+ readdirp$1(root, options)
297
+ .on('data', entry => files.push(entry))
298
+ .on('end', () => resolve(files))
299
+ .on('error', error => reject(error));
300
+ });
301
+ };
302
+
303
+ readdirp$1.promise = readdirpPromise;
304
+ readdirp$1.ReaddirpStream = ReaddirpStream;
305
+ readdirp$1.default = readdirp$1;
306
+
307
+ var readdirp_1 = readdirp$1;
308
+
309
+ var anymatch$2 = {exports: {}};
310
+
311
+ /*!
312
+ * normalize-path <https://github.com/jonschlinkert/normalize-path>
313
+ *
314
+ * Copyright (c) 2014-2018, Jon Schlinkert.
315
+ * Released under the MIT License.
316
+ */
317
+
318
+ var normalizePath$2 = function(path, stripTrailing) {
319
+ if (typeof path !== 'string') {
320
+ throw new TypeError('expected path to be a string');
321
+ }
322
+
323
+ if (path === '\\' || path === '/') return '/';
324
+
325
+ var len = path.length;
326
+ if (len <= 1) return path;
327
+
328
+ // ensure that win32 namespaces has two leading slashes, so that the path is
329
+ // handled properly by the win32 version of path.parse() after being normalized
330
+ // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
331
+ var prefix = '';
332
+ if (len > 4 && path[3] === '\\') {
333
+ var ch = path[2];
334
+ if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
335
+ path = path.slice(2);
336
+ prefix = '//';
337
+ }
338
+ }
339
+
340
+ var segs = path.split(/[/\\]+/);
341
+ if (stripTrailing !== false && segs[segs.length - 1] === '') {
342
+ segs.pop();
343
+ }
344
+ return prefix + segs.join('/');
345
+ };
346
+
347
+ Object.defineProperty(anymatch$2.exports, "__esModule", { value: true });
348
+
349
+ const picomatch = rollup.picomatch;
350
+ const normalizePath$1 = normalizePath$2;
351
+
352
+ /**
353
+ * @typedef {(testString: string) => boolean} AnymatchFn
354
+ * @typedef {string|RegExp|AnymatchFn} AnymatchPattern
355
+ * @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
356
+ */
357
+ const BANG$1 = '!';
358
+ const DEFAULT_OPTIONS = {returnIndex: false};
359
+ const arrify$1 = (item) => Array.isArray(item) ? item : [item];
360
+
361
+ /**
362
+ * @param {AnymatchPattern} matcher
363
+ * @param {object} options
364
+ * @returns {AnymatchFn}
365
+ */
366
+ const createPattern = (matcher, options) => {
367
+ if (typeof matcher === 'function') {
368
+ return matcher;
369
+ }
370
+ if (typeof matcher === 'string') {
371
+ const glob = picomatch(matcher, options);
372
+ return (string) => matcher === string || glob(string);
373
+ }
374
+ if (matcher instanceof RegExp) {
375
+ return (string) => matcher.test(string);
376
+ }
377
+ return (string) => false;
378
+ };
379
+
380
+ /**
381
+ * @param {Array<Function>} patterns
382
+ * @param {Array<Function>} negPatterns
383
+ * @param {String|Array} args
384
+ * @param {Boolean} returnIndex
385
+ * @returns {boolean|number}
386
+ */
387
+ const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
388
+ const isList = Array.isArray(args);
389
+ const _path = isList ? args[0] : args;
390
+ if (!isList && typeof _path !== 'string') {
391
+ throw new TypeError('anymatch: second argument must be a string: got ' +
392
+ Object.prototype.toString.call(_path))
393
+ }
394
+ const path = normalizePath$1(_path);
395
+
396
+ for (let index = 0; index < negPatterns.length; index++) {
397
+ const nglob = negPatterns[index];
398
+ if (nglob(path)) {
399
+ return returnIndex ? -1 : false;
400
+ }
401
+ }
402
+
403
+ const applied = isList && [path].concat(args.slice(1));
404
+ for (let index = 0; index < patterns.length; index++) {
405
+ const pattern = patterns[index];
406
+ if (isList ? pattern(...applied) : pattern(path)) {
407
+ return returnIndex ? index : true;
408
+ }
409
+ }
410
+
411
+ return returnIndex ? -1 : false;
412
+ };
413
+
414
+ /**
415
+ * @param {AnymatchMatcher} matchers
416
+ * @param {Array|string} testString
417
+ * @param {object} options
418
+ * @returns {boolean|number|Function}
419
+ */
420
+ const anymatch$1 = (matchers, testString, options = DEFAULT_OPTIONS) => {
421
+ if (matchers == null) {
422
+ throw new TypeError('anymatch: specify first argument');
423
+ }
424
+ const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
425
+ const returnIndex = opts.returnIndex || false;
426
+
427
+ // Early cache for matchers.
428
+ const mtchers = arrify$1(matchers);
429
+ const negatedGlobs = mtchers
430
+ .filter(item => typeof item === 'string' && item.charAt(0) === BANG$1)
431
+ .map(item => item.slice(1))
432
+ .map(item => picomatch(item, opts));
433
+ const patterns = mtchers
434
+ .filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG$1))
435
+ .map(matcher => createPattern(matcher, opts));
436
+
437
+ if (testString == null) {
438
+ return (testString, ri = false) => {
439
+ const returnIndex = typeof ri === 'boolean' ? ri : false;
440
+ return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
441
+ }
442
+ }
443
+
444
+ return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
445
+ };
446
+
447
+ anymatch$1.default = anymatch$1;
448
+ anymatch$2.exports = anymatch$1;
449
+
450
+ /*!
451
+ * is-extglob <https://github.com/jonschlinkert/is-extglob>
452
+ *
453
+ * Copyright (c) 2014-2016, Jon Schlinkert.
454
+ * Licensed under the MIT License.
455
+ */
456
+
457
+ var isExtglob$1 = function isExtglob(str) {
458
+ if (typeof str !== 'string' || str === '') {
459
+ return false;
460
+ }
461
+
462
+ var match;
463
+ while ((match = /(\\).|([@?!+*]\(.*\))/g.exec(str))) {
464
+ if (match[2]) return true;
465
+ str = str.slice(match.index + match[0].length);
466
+ }
467
+
468
+ return false;
469
+ };
470
+
471
+ /*!
472
+ * is-glob <https://github.com/jonschlinkert/is-glob>
473
+ *
474
+ * Copyright (c) 2014-2017, Jon Schlinkert.
475
+ * Released under the MIT License.
476
+ */
477
+
478
+ var isExtglob = isExtglob$1;
479
+ var chars = { '{': '}', '(': ')', '[': ']'};
480
+ var strictRegex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
481
+ var relaxedRegex = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
482
+
483
+ var isGlob$2 = function isGlob(str, options) {
484
+ if (typeof str !== 'string' || str === '') {
485
+ return false;
486
+ }
487
+
488
+ if (isExtglob(str)) {
489
+ return true;
490
+ }
491
+
492
+ var regex = strictRegex;
493
+ var match;
494
+
495
+ // optionally relax regex
496
+ if (options && options.strict === false) {
497
+ regex = relaxedRegex;
498
+ }
499
+
500
+ while ((match = regex.exec(str))) {
501
+ if (match[2]) return true;
502
+ var idx = match.index + match[0].length;
503
+
504
+ // if an open bracket/brace/paren is escaped,
505
+ // set the index to the next closing character
506
+ var open = match[1];
507
+ var close = open ? chars[open] : null;
508
+ if (open && close) {
509
+ var n = str.indexOf(close, idx);
510
+ if (n !== -1) {
511
+ idx = n + 1;
512
+ }
513
+ }
514
+
515
+ str = str.slice(idx);
516
+ }
517
+ return false;
518
+ };
519
+
520
+ var isGlob$1 = isGlob$2;
521
+ var pathPosixDirname = path$1.posix.dirname;
522
+ var isWin32 = require$$2$1.platform() === 'win32';
523
+
524
+ var slash = '/';
525
+ var backslash = /\\/g;
526
+ var enclosure = /[\{\[].*[\}\]]$/;
527
+ var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
528
+ var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
529
+
530
+ /**
531
+ * @param {string} str
532
+ * @param {Object} opts
533
+ * @param {boolean} [opts.flipBackslashes=true]
534
+ * @returns {string}
535
+ */
536
+ var globParent$1 = function globParent(str, opts) {
537
+ var options = Object.assign({ flipBackslashes: true }, opts);
538
+
539
+ // flip windows path separators
540
+ if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
541
+ str = str.replace(backslash, slash);
542
+ }
543
+
544
+ // special case for strings ending in enclosure containing path separator
545
+ if (enclosure.test(str)) {
546
+ str += slash;
547
+ }
548
+
549
+ // preserves full path in case of trailing path separator
550
+ str += 'a';
551
+
552
+ // remove path parts that are globby
553
+ do {
554
+ str = pathPosixDirname(str);
555
+ } while (isGlob$1(str) || globby.test(str));
556
+
557
+ // remove escape chars and return result
558
+ return str.replace(escaped, '$1');
559
+ };
560
+
561
+ var utils$3 = {};
562
+
563
+ (function (exports) {
564
+
565
+ exports.isInteger = num => {
566
+ if (typeof num === 'number') {
567
+ return Number.isInteger(num);
568
+ }
569
+ if (typeof num === 'string' && num.trim() !== '') {
570
+ return Number.isInteger(Number(num));
571
+ }
572
+ return false;
573
+ };
574
+
575
+ /**
576
+ * Find a node of the given type
577
+ */
578
+
579
+ exports.find = (node, type) => node.nodes.find(node => node.type === type);
580
+
581
+ /**
582
+ * Find a node of the given type
583
+ */
584
+
585
+ exports.exceedsLimit = (min, max, step = 1, limit) => {
586
+ if (limit === false) return false;
587
+ if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
588
+ return ((Number(max) - Number(min)) / Number(step)) >= limit;
589
+ };
590
+
591
+ /**
592
+ * Escape the given node with '\\' before node.value
593
+ */
594
+
595
+ exports.escapeNode = (block, n = 0, type) => {
596
+ let node = block.nodes[n];
597
+ if (!node) return;
598
+
599
+ if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
600
+ if (node.escaped !== true) {
601
+ node.value = '\\' + node.value;
602
+ node.escaped = true;
603
+ }
604
+ }
605
+ };
606
+
607
+ /**
608
+ * Returns true if the given brace node should be enclosed in literal braces
609
+ */
610
+
611
+ exports.encloseBrace = node => {
612
+ if (node.type !== 'brace') return false;
613
+ if ((node.commas >> 0 + node.ranges >> 0) === 0) {
614
+ node.invalid = true;
615
+ return true;
616
+ }
617
+ return false;
618
+ };
619
+
620
+ /**
621
+ * Returns true if a brace node is invalid.
622
+ */
623
+
624
+ exports.isInvalidBrace = block => {
625
+ if (block.type !== 'brace') return false;
626
+ if (block.invalid === true || block.dollar) return true;
627
+ if ((block.commas >> 0 + block.ranges >> 0) === 0) {
628
+ block.invalid = true;
629
+ return true;
630
+ }
631
+ if (block.open !== true || block.close !== true) {
632
+ block.invalid = true;
633
+ return true;
634
+ }
635
+ return false;
636
+ };
637
+
638
+ /**
639
+ * Returns true if a node is an open or close node
640
+ */
641
+
642
+ exports.isOpenOrClose = node => {
643
+ if (node.type === 'open' || node.type === 'close') {
644
+ return true;
645
+ }
646
+ return node.open === true || node.close === true;
647
+ };
648
+
649
+ /**
650
+ * Reduce an array of text nodes.
651
+ */
652
+
653
+ exports.reduce = nodes => nodes.reduce((acc, node) => {
654
+ if (node.type === 'text') acc.push(node.value);
655
+ if (node.type === 'range') node.type = 'text';
656
+ return acc;
657
+ }, []);
658
+
659
+ /**
660
+ * Flatten an array
661
+ */
662
+
663
+ exports.flatten = (...args) => {
664
+ const result = [];
665
+ const flat = arr => {
666
+ for (let i = 0; i < arr.length; i++) {
667
+ let ele = arr[i];
668
+ Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
669
+ }
670
+ return result;
671
+ };
672
+ flat(args);
673
+ return result;
674
+ };
675
+ }(utils$3));
676
+
677
+ const utils$2 = utils$3;
678
+
679
+ var stringify$4 = (ast, options = {}) => {
680
+ let stringify = (node, parent = {}) => {
681
+ let invalidBlock = options.escapeInvalid && utils$2.isInvalidBrace(parent);
682
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
683
+ let output = '';
684
+
685
+ if (node.value) {
686
+ if ((invalidBlock || invalidNode) && utils$2.isOpenOrClose(node)) {
687
+ return '\\' + node.value;
688
+ }
689
+ return node.value;
690
+ }
691
+
692
+ if (node.value) {
693
+ return node.value;
694
+ }
695
+
696
+ if (node.nodes) {
697
+ for (let child of node.nodes) {
698
+ output += stringify(child);
699
+ }
700
+ }
701
+ return output;
702
+ };
703
+
704
+ return stringify(ast);
705
+ };
706
+
707
+ /*!
708
+ * is-number <https://github.com/jonschlinkert/is-number>
709
+ *
710
+ * Copyright (c) 2014-present, Jon Schlinkert.
711
+ * Released under the MIT License.
712
+ */
713
+
714
+ var isNumber$2 = function(num) {
715
+ if (typeof num === 'number') {
716
+ return num - num === 0;
717
+ }
718
+ if (typeof num === 'string' && num.trim() !== '') {
719
+ return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
720
+ }
721
+ return false;
722
+ };
723
+
724
+ /*!
725
+ * to-regex-range <https://github.com/micromatch/to-regex-range>
726
+ *
727
+ * Copyright (c) 2015-present, Jon Schlinkert.
728
+ * Released under the MIT License.
729
+ */
730
+
731
+ const isNumber$1 = isNumber$2;
732
+
733
+ const toRegexRange$1 = (min, max, options) => {
734
+ if (isNumber$1(min) === false) {
735
+ throw new TypeError('toRegexRange: expected the first argument to be a number');
736
+ }
737
+
738
+ if (max === void 0 || min === max) {
739
+ return String(min);
740
+ }
741
+
742
+ if (isNumber$1(max) === false) {
743
+ throw new TypeError('toRegexRange: expected the second argument to be a number.');
744
+ }
745
+
746
+ let opts = { relaxZeros: true, ...options };
747
+ if (typeof opts.strictZeros === 'boolean') {
748
+ opts.relaxZeros = opts.strictZeros === false;
749
+ }
750
+
751
+ let relax = String(opts.relaxZeros);
752
+ let shorthand = String(opts.shorthand);
753
+ let capture = String(opts.capture);
754
+ let wrap = String(opts.wrap);
755
+ let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
756
+
757
+ if (toRegexRange$1.cache.hasOwnProperty(cacheKey)) {
758
+ return toRegexRange$1.cache[cacheKey].result;
759
+ }
760
+
761
+ let a = Math.min(min, max);
762
+ let b = Math.max(min, max);
763
+
764
+ if (Math.abs(a - b) === 1) {
765
+ let result = min + '|' + max;
766
+ if (opts.capture) {
767
+ return `(${result})`;
768
+ }
769
+ if (opts.wrap === false) {
770
+ return result;
771
+ }
772
+ return `(?:${result})`;
773
+ }
774
+
775
+ let isPadded = hasPadding(min) || hasPadding(max);
776
+ let state = { min, max, a, b };
777
+ let positives = [];
778
+ let negatives = [];
779
+
780
+ if (isPadded) {
781
+ state.isPadded = isPadded;
782
+ state.maxLen = String(state.max).length;
783
+ }
784
+
785
+ if (a < 0) {
786
+ let newMin = b < 0 ? Math.abs(b) : 1;
787
+ negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
788
+ a = state.a = 0;
789
+ }
790
+
791
+ if (b >= 0) {
792
+ positives = splitToPatterns(a, b, state, opts);
793
+ }
794
+
795
+ state.negatives = negatives;
796
+ state.positives = positives;
797
+ state.result = collatePatterns(negatives, positives);
798
+
799
+ if (opts.capture === true) {
800
+ state.result = `(${state.result})`;
801
+ } else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
802
+ state.result = `(?:${state.result})`;
803
+ }
804
+
805
+ toRegexRange$1.cache[cacheKey] = state;
806
+ return state.result;
807
+ };
808
+
809
+ function collatePatterns(neg, pos, options) {
810
+ let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
811
+ let onlyPositive = filterPatterns(pos, neg, '', false) || [];
812
+ let intersected = filterPatterns(neg, pos, '-?', true) || [];
813
+ let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
814
+ return subpatterns.join('|');
815
+ }
816
+
817
+ function splitToRanges(min, max) {
818
+ let nines = 1;
819
+ let zeros = 1;
820
+
821
+ let stop = countNines(min, nines);
822
+ let stops = new Set([max]);
823
+
824
+ while (min <= stop && stop <= max) {
825
+ stops.add(stop);
826
+ nines += 1;
827
+ stop = countNines(min, nines);
828
+ }
829
+
830
+ stop = countZeros(max + 1, zeros) - 1;
831
+
832
+ while (min < stop && stop <= max) {
833
+ stops.add(stop);
834
+ zeros += 1;
835
+ stop = countZeros(max + 1, zeros) - 1;
836
+ }
837
+
838
+ stops = [...stops];
839
+ stops.sort(compare);
840
+ return stops;
841
+ }
842
+
843
+ /**
844
+ * Convert a range to a regex pattern
845
+ * @param {Number} `start`
846
+ * @param {Number} `stop`
847
+ * @return {String}
848
+ */
849
+
850
+ function rangeToPattern(start, stop, options) {
851
+ if (start === stop) {
852
+ return { pattern: start, count: [], digits: 0 };
853
+ }
854
+
855
+ let zipped = zip(start, stop);
856
+ let digits = zipped.length;
857
+ let pattern = '';
858
+ let count = 0;
859
+
860
+ for (let i = 0; i < digits; i++) {
861
+ let [startDigit, stopDigit] = zipped[i];
862
+
863
+ if (startDigit === stopDigit) {
864
+ pattern += startDigit;
865
+
866
+ } else if (startDigit !== '0' || stopDigit !== '9') {
867
+ pattern += toCharacterClass(startDigit, stopDigit);
868
+
869
+ } else {
870
+ count++;
871
+ }
872
+ }
873
+
874
+ if (count) {
875
+ pattern += options.shorthand === true ? '\\d' : '[0-9]';
876
+ }
877
+
878
+ return { pattern, count: [count], digits };
879
+ }
880
+
881
+ function splitToPatterns(min, max, tok, options) {
882
+ let ranges = splitToRanges(min, max);
883
+ let tokens = [];
884
+ let start = min;
885
+ let prev;
886
+
887
+ for (let i = 0; i < ranges.length; i++) {
888
+ let max = ranges[i];
889
+ let obj = rangeToPattern(String(start), String(max), options);
890
+ let zeros = '';
891
+
892
+ if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
893
+ if (prev.count.length > 1) {
894
+ prev.count.pop();
895
+ }
896
+
897
+ prev.count.push(obj.count[0]);
898
+ prev.string = prev.pattern + toQuantifier(prev.count);
899
+ start = max + 1;
900
+ continue;
901
+ }
902
+
903
+ if (tok.isPadded) {
904
+ zeros = padZeros(max, tok, options);
905
+ }
906
+
907
+ obj.string = zeros + obj.pattern + toQuantifier(obj.count);
908
+ tokens.push(obj);
909
+ start = max + 1;
910
+ prev = obj;
911
+ }
912
+
913
+ return tokens;
914
+ }
915
+
916
+ function filterPatterns(arr, comparison, prefix, intersection, options) {
917
+ let result = [];
918
+
919
+ for (let ele of arr) {
920
+ let { string } = ele;
921
+
922
+ // only push if _both_ are negative...
923
+ if (!intersection && !contains(comparison, 'string', string)) {
924
+ result.push(prefix + string);
925
+ }
926
+
927
+ // or _both_ are positive
928
+ if (intersection && contains(comparison, 'string', string)) {
929
+ result.push(prefix + string);
930
+ }
931
+ }
932
+ return result;
933
+ }
934
+
935
+ /**
936
+ * Zip strings
937
+ */
938
+
939
+ function zip(a, b) {
940
+ let arr = [];
941
+ for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
942
+ return arr;
943
+ }
944
+
945
+ function compare(a, b) {
946
+ return a > b ? 1 : b > a ? -1 : 0;
947
+ }
948
+
949
+ function contains(arr, key, val) {
950
+ return arr.some(ele => ele[key] === val);
951
+ }
952
+
953
+ function countNines(min, len) {
954
+ return Number(String(min).slice(0, -len) + '9'.repeat(len));
955
+ }
956
+
957
+ function countZeros(integer, zeros) {
958
+ return integer - (integer % Math.pow(10, zeros));
959
+ }
960
+
961
+ function toQuantifier(digits) {
962
+ let [start = 0, stop = ''] = digits;
963
+ if (stop || start > 1) {
964
+ return `{${start + (stop ? ',' + stop : '')}}`;
965
+ }
966
+ return '';
967
+ }
968
+
969
+ function toCharacterClass(a, b, options) {
970
+ return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
971
+ }
972
+
973
+ function hasPadding(str) {
974
+ return /^-?(0+)\d/.test(str);
975
+ }
976
+
977
+ function padZeros(value, tok, options) {
978
+ if (!tok.isPadded) {
979
+ return value;
980
+ }
981
+
982
+ let diff = Math.abs(tok.maxLen - String(value).length);
983
+ let relax = options.relaxZeros !== false;
984
+
985
+ switch (diff) {
986
+ case 0:
987
+ return '';
988
+ case 1:
989
+ return relax ? '0?' : '0';
990
+ case 2:
991
+ return relax ? '0{0,2}' : '00';
992
+ default: {
993
+ return relax ? `0{0,${diff}}` : `0{${diff}}`;
994
+ }
995
+ }
996
+ }
997
+
998
+ /**
999
+ * Cache
1000
+ */
1001
+
1002
+ toRegexRange$1.cache = {};
1003
+ toRegexRange$1.clearCache = () => (toRegexRange$1.cache = {});
1004
+
1005
+ /**
1006
+ * Expose `toRegexRange`
1007
+ */
1008
+
1009
+ var toRegexRange_1 = toRegexRange$1;
1010
+
1011
+ /*!
1012
+ * fill-range <https://github.com/jonschlinkert/fill-range>
1013
+ *
1014
+ * Copyright (c) 2014-present, Jon Schlinkert.
1015
+ * Licensed under the MIT License.
1016
+ */
1017
+
1018
+ const util = require$$2;
1019
+ const toRegexRange = toRegexRange_1;
1020
+
1021
+ const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
1022
+
1023
+ const transform = toNumber => {
1024
+ return value => toNumber === true ? Number(value) : String(value);
1025
+ };
1026
+
1027
+ const isValidValue = value => {
1028
+ return typeof value === 'number' || (typeof value === 'string' && value !== '');
1029
+ };
1030
+
1031
+ const isNumber = num => Number.isInteger(+num);
1032
+
1033
+ const zeros = input => {
1034
+ let value = `${input}`;
1035
+ let index = -1;
1036
+ if (value[0] === '-') value = value.slice(1);
1037
+ if (value === '0') return false;
1038
+ while (value[++index] === '0');
1039
+ return index > 0;
1040
+ };
1041
+
1042
+ const stringify$3 = (start, end, options) => {
1043
+ if (typeof start === 'string' || typeof end === 'string') {
1044
+ return true;
1045
+ }
1046
+ return options.stringify === true;
1047
+ };
1048
+
1049
+ const pad = (input, maxLength, toNumber) => {
1050
+ if (maxLength > 0) {
1051
+ let dash = input[0] === '-' ? '-' : '';
1052
+ if (dash) input = input.slice(1);
1053
+ input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
1054
+ }
1055
+ if (toNumber === false) {
1056
+ return String(input);
1057
+ }
1058
+ return input;
1059
+ };
1060
+
1061
+ const toMaxLen = (input, maxLength) => {
1062
+ let negative = input[0] === '-' ? '-' : '';
1063
+ if (negative) {
1064
+ input = input.slice(1);
1065
+ maxLength--;
1066
+ }
1067
+ while (input.length < maxLength) input = '0' + input;
1068
+ return negative ? ('-' + input) : input;
1069
+ };
1070
+
1071
+ const toSequence = (parts, options) => {
1072
+ parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1073
+ parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1074
+
1075
+ let prefix = options.capture ? '' : '?:';
1076
+ let positives = '';
1077
+ let negatives = '';
1078
+ let result;
1079
+
1080
+ if (parts.positives.length) {
1081
+ positives = parts.positives.join('|');
1082
+ }
1083
+
1084
+ if (parts.negatives.length) {
1085
+ negatives = `-(${prefix}${parts.negatives.join('|')})`;
1086
+ }
1087
+
1088
+ if (positives && negatives) {
1089
+ result = `${positives}|${negatives}`;
1090
+ } else {
1091
+ result = positives || negatives;
1092
+ }
1093
+
1094
+ if (options.wrap) {
1095
+ return `(${prefix}${result})`;
1096
+ }
1097
+
1098
+ return result;
1099
+ };
1100
+
1101
+ const toRange = (a, b, isNumbers, options) => {
1102
+ if (isNumbers) {
1103
+ return toRegexRange(a, b, { wrap: false, ...options });
1104
+ }
1105
+
1106
+ let start = String.fromCharCode(a);
1107
+ if (a === b) return start;
1108
+
1109
+ let stop = String.fromCharCode(b);
1110
+ return `[${start}-${stop}]`;
1111
+ };
1112
+
1113
+ const toRegex = (start, end, options) => {
1114
+ if (Array.isArray(start)) {
1115
+ let wrap = options.wrap === true;
1116
+ let prefix = options.capture ? '' : '?:';
1117
+ return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
1118
+ }
1119
+ return toRegexRange(start, end, options);
1120
+ };
1121
+
1122
+ const rangeError = (...args) => {
1123
+ return new RangeError('Invalid range arguments: ' + util.inspect(...args));
1124
+ };
1125
+
1126
+ const invalidRange = (start, end, options) => {
1127
+ if (options.strictRanges === true) throw rangeError([start, end]);
1128
+ return [];
1129
+ };
1130
+
1131
+ const invalidStep = (step, options) => {
1132
+ if (options.strictRanges === true) {
1133
+ throw new TypeError(`Expected step "${step}" to be a number`);
1134
+ }
1135
+ return [];
1136
+ };
1137
+
1138
+ const fillNumbers = (start, end, step = 1, options = {}) => {
1139
+ let a = Number(start);
1140
+ let b = Number(end);
1141
+
1142
+ if (!Number.isInteger(a) || !Number.isInteger(b)) {
1143
+ if (options.strictRanges === true) throw rangeError([start, end]);
1144
+ return [];
1145
+ }
1146
+
1147
+ // fix negative zero
1148
+ if (a === 0) a = 0;
1149
+ if (b === 0) b = 0;
1150
+
1151
+ let descending = a > b;
1152
+ let startString = String(start);
1153
+ let endString = String(end);
1154
+ let stepString = String(step);
1155
+ step = Math.max(Math.abs(step), 1);
1156
+
1157
+ let padded = zeros(startString) || zeros(endString) || zeros(stepString);
1158
+ let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
1159
+ let toNumber = padded === false && stringify$3(start, end, options) === false;
1160
+ let format = options.transform || transform(toNumber);
1161
+
1162
+ if (options.toRegex && step === 1) {
1163
+ return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
1164
+ }
1165
+
1166
+ let parts = { negatives: [], positives: [] };
1167
+ let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
1168
+ let range = [];
1169
+ let index = 0;
1170
+
1171
+ while (descending ? a >= b : a <= b) {
1172
+ if (options.toRegex === true && step > 1) {
1173
+ push(a);
1174
+ } else {
1175
+ range.push(pad(format(a, index), maxLen, toNumber));
1176
+ }
1177
+ a = descending ? a - step : a + step;
1178
+ index++;
1179
+ }
1180
+
1181
+ if (options.toRegex === true) {
1182
+ return step > 1
1183
+ ? toSequence(parts, options)
1184
+ : toRegex(range, null, { wrap: false, ...options });
1185
+ }
1186
+
1187
+ return range;
1188
+ };
1189
+
1190
+ const fillLetters = (start, end, step = 1, options = {}) => {
1191
+ if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
1192
+ return invalidRange(start, end, options);
1193
+ }
1194
+
1195
+
1196
+ let format = options.transform || (val => String.fromCharCode(val));
1197
+ let a = `${start}`.charCodeAt(0);
1198
+ let b = `${end}`.charCodeAt(0);
1199
+
1200
+ let descending = a > b;
1201
+ let min = Math.min(a, b);
1202
+ let max = Math.max(a, b);
1203
+
1204
+ if (options.toRegex && step === 1) {
1205
+ return toRange(min, max, false, options);
1206
+ }
1207
+
1208
+ let range = [];
1209
+ let index = 0;
1210
+
1211
+ while (descending ? a >= b : a <= b) {
1212
+ range.push(format(a, index));
1213
+ a = descending ? a - step : a + step;
1214
+ index++;
1215
+ }
1216
+
1217
+ if (options.toRegex === true) {
1218
+ return toRegex(range, null, { wrap: false, options });
1219
+ }
1220
+
1221
+ return range;
1222
+ };
1223
+
1224
+ const fill$2 = (start, end, step, options = {}) => {
1225
+ if (end == null && isValidValue(start)) {
1226
+ return [start];
1227
+ }
1228
+
1229
+ if (!isValidValue(start) || !isValidValue(end)) {
1230
+ return invalidRange(start, end, options);
1231
+ }
1232
+
1233
+ if (typeof step === 'function') {
1234
+ return fill$2(start, end, 1, { transform: step });
1235
+ }
1236
+
1237
+ if (isObject(step)) {
1238
+ return fill$2(start, end, 0, step);
1239
+ }
1240
+
1241
+ let opts = { ...options };
1242
+ if (opts.capture === true) opts.wrap = true;
1243
+ step = step || opts.step || 1;
1244
+
1245
+ if (!isNumber(step)) {
1246
+ if (step != null && !isObject(step)) return invalidStep(step, opts);
1247
+ return fill$2(start, end, 1, step);
1248
+ }
1249
+
1250
+ if (isNumber(start) && isNumber(end)) {
1251
+ return fillNumbers(start, end, step, opts);
1252
+ }
1253
+
1254
+ return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
1255
+ };
1256
+
1257
+ var fillRange = fill$2;
1258
+
1259
+ const fill$1 = fillRange;
1260
+ const utils$1 = utils$3;
1261
+
1262
+ const compile$1 = (ast, options = {}) => {
1263
+ let walk = (node, parent = {}) => {
1264
+ let invalidBlock = utils$1.isInvalidBrace(parent);
1265
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
1266
+ let invalid = invalidBlock === true || invalidNode === true;
1267
+ let prefix = options.escapeInvalid === true ? '\\' : '';
1268
+ let output = '';
1269
+
1270
+ if (node.isOpen === true) {
1271
+ return prefix + node.value;
1272
+ }
1273
+ if (node.isClose === true) {
1274
+ return prefix + node.value;
1275
+ }
1276
+
1277
+ if (node.type === 'open') {
1278
+ return invalid ? (prefix + node.value) : '(';
1279
+ }
1280
+
1281
+ if (node.type === 'close') {
1282
+ return invalid ? (prefix + node.value) : ')';
1283
+ }
1284
+
1285
+ if (node.type === 'comma') {
1286
+ return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
1287
+ }
1288
+
1289
+ if (node.value) {
1290
+ return node.value;
1291
+ }
1292
+
1293
+ if (node.nodes && node.ranges > 0) {
1294
+ let args = utils$1.reduce(node.nodes);
1295
+ let range = fill$1(...args, { ...options, wrap: false, toRegex: true });
1296
+
1297
+ if (range.length !== 0) {
1298
+ return args.length > 1 && range.length > 1 ? `(${range})` : range;
1299
+ }
1300
+ }
1301
+
1302
+ if (node.nodes) {
1303
+ for (let child of node.nodes) {
1304
+ output += walk(child, node);
1305
+ }
1306
+ }
1307
+ return output;
1308
+ };
1309
+
1310
+ return walk(ast);
1311
+ };
1312
+
1313
+ var compile_1 = compile$1;
1314
+
1315
+ const fill = fillRange;
1316
+ const stringify$2 = stringify$4;
1317
+ const utils = utils$3;
1318
+
1319
+ const append = (queue = '', stash = '', enclose = false) => {
1320
+ let result = [];
1321
+
1322
+ queue = [].concat(queue);
1323
+ stash = [].concat(stash);
1324
+
1325
+ if (!stash.length) return queue;
1326
+ if (!queue.length) {
1327
+ return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
1328
+ }
1329
+
1330
+ for (let item of queue) {
1331
+ if (Array.isArray(item)) {
1332
+ for (let value of item) {
1333
+ result.push(append(value, stash, enclose));
1334
+ }
1335
+ } else {
1336
+ for (let ele of stash) {
1337
+ if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
1338
+ result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
1339
+ }
1340
+ }
1341
+ }
1342
+ return utils.flatten(result);
1343
+ };
1344
+
1345
+ const expand$1 = (ast, options = {}) => {
1346
+ let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
1347
+
1348
+ let walk = (node, parent = {}) => {
1349
+ node.queue = [];
1350
+
1351
+ let p = parent;
1352
+ let q = parent.queue;
1353
+
1354
+ while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
1355
+ p = p.parent;
1356
+ q = p.queue;
1357
+ }
1358
+
1359
+ if (node.invalid || node.dollar) {
1360
+ q.push(append(q.pop(), stringify$2(node, options)));
1361
+ return;
1362
+ }
1363
+
1364
+ if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
1365
+ q.push(append(q.pop(), ['{}']));
1366
+ return;
1367
+ }
1368
+
1369
+ if (node.nodes && node.ranges > 0) {
1370
+ let args = utils.reduce(node.nodes);
1371
+
1372
+ if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
1373
+ throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
1374
+ }
1375
+
1376
+ let range = fill(...args, options);
1377
+ if (range.length === 0) {
1378
+ range = stringify$2(node, options);
1379
+ }
1380
+
1381
+ q.push(append(q.pop(), range));
1382
+ node.nodes = [];
1383
+ return;
1384
+ }
1385
+
1386
+ let enclose = utils.encloseBrace(node);
1387
+ let queue = node.queue;
1388
+ let block = node;
1389
+
1390
+ while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
1391
+ block = block.parent;
1392
+ queue = block.queue;
1393
+ }
1394
+
1395
+ for (let i = 0; i < node.nodes.length; i++) {
1396
+ let child = node.nodes[i];
1397
+
1398
+ if (child.type === 'comma' && node.type === 'brace') {
1399
+ if (i === 1) queue.push('');
1400
+ queue.push('');
1401
+ continue;
1402
+ }
1403
+
1404
+ if (child.type === 'close') {
1405
+ q.push(append(q.pop(), queue, enclose));
1406
+ continue;
1407
+ }
1408
+
1409
+ if (child.value && child.type !== 'open') {
1410
+ queue.push(append(queue.pop(), child.value));
1411
+ continue;
1412
+ }
1413
+
1414
+ if (child.nodes) {
1415
+ walk(child, node);
1416
+ }
1417
+ }
1418
+
1419
+ return queue;
1420
+ };
1421
+
1422
+ return utils.flatten(walk(ast));
1423
+ };
1424
+
1425
+ var expand_1 = expand$1;
1426
+
1427
+ var constants$1 = {
1428
+ MAX_LENGTH: 1024 * 64,
1429
+
1430
+ // Digits
1431
+ CHAR_0: '0', /* 0 */
1432
+ CHAR_9: '9', /* 9 */
1433
+
1434
+ // Alphabet chars.
1435
+ CHAR_UPPERCASE_A: 'A', /* A */
1436
+ CHAR_LOWERCASE_A: 'a', /* a */
1437
+ CHAR_UPPERCASE_Z: 'Z', /* Z */
1438
+ CHAR_LOWERCASE_Z: 'z', /* z */
1439
+
1440
+ CHAR_LEFT_PARENTHESES: '(', /* ( */
1441
+ CHAR_RIGHT_PARENTHESES: ')', /* ) */
1442
+
1443
+ CHAR_ASTERISK: '*', /* * */
1444
+
1445
+ // Non-alphabetic chars.
1446
+ CHAR_AMPERSAND: '&', /* & */
1447
+ CHAR_AT: '@', /* @ */
1448
+ CHAR_BACKSLASH: '\\', /* \ */
1449
+ CHAR_BACKTICK: '`', /* ` */
1450
+ CHAR_CARRIAGE_RETURN: '\r', /* \r */
1451
+ CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
1452
+ CHAR_COLON: ':', /* : */
1453
+ CHAR_COMMA: ',', /* , */
1454
+ CHAR_DOLLAR: '$', /* . */
1455
+ CHAR_DOT: '.', /* . */
1456
+ CHAR_DOUBLE_QUOTE: '"', /* " */
1457
+ CHAR_EQUAL: '=', /* = */
1458
+ CHAR_EXCLAMATION_MARK: '!', /* ! */
1459
+ CHAR_FORM_FEED: '\f', /* \f */
1460
+ CHAR_FORWARD_SLASH: '/', /* / */
1461
+ CHAR_HASH: '#', /* # */
1462
+ CHAR_HYPHEN_MINUS: '-', /* - */
1463
+ CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
1464
+ CHAR_LEFT_CURLY_BRACE: '{', /* { */
1465
+ CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
1466
+ CHAR_LINE_FEED: '\n', /* \n */
1467
+ CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
1468
+ CHAR_PERCENT: '%', /* % */
1469
+ CHAR_PLUS: '+', /* + */
1470
+ CHAR_QUESTION_MARK: '?', /* ? */
1471
+ CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
1472
+ CHAR_RIGHT_CURLY_BRACE: '}', /* } */
1473
+ CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
1474
+ CHAR_SEMICOLON: ';', /* ; */
1475
+ CHAR_SINGLE_QUOTE: '\'', /* ' */
1476
+ CHAR_SPACE: ' ', /* */
1477
+ CHAR_TAB: '\t', /* \t */
1478
+ CHAR_UNDERSCORE: '_', /* _ */
1479
+ CHAR_VERTICAL_LINE: '|', /* | */
1480
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
1481
+ };
1482
+
1483
+ const stringify$1 = stringify$4;
1484
+
1485
+ /**
1486
+ * Constants
1487
+ */
1488
+
1489
+ const {
1490
+ MAX_LENGTH,
1491
+ CHAR_BACKSLASH, /* \ */
1492
+ CHAR_BACKTICK, /* ` */
1493
+ CHAR_COMMA, /* , */
1494
+ CHAR_DOT, /* . */
1495
+ CHAR_LEFT_PARENTHESES, /* ( */
1496
+ CHAR_RIGHT_PARENTHESES, /* ) */
1497
+ CHAR_LEFT_CURLY_BRACE, /* { */
1498
+ CHAR_RIGHT_CURLY_BRACE, /* } */
1499
+ CHAR_LEFT_SQUARE_BRACKET, /* [ */
1500
+ CHAR_RIGHT_SQUARE_BRACKET, /* ] */
1501
+ CHAR_DOUBLE_QUOTE, /* " */
1502
+ CHAR_SINGLE_QUOTE, /* ' */
1503
+ CHAR_NO_BREAK_SPACE,
1504
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE
1505
+ } = constants$1;
1506
+
1507
+ /**
1508
+ * parse
1509
+ */
1510
+
1511
+ const parse$1 = (input, options = {}) => {
1512
+ if (typeof input !== 'string') {
1513
+ throw new TypeError('Expected a string');
1514
+ }
1515
+
1516
+ let opts = options || {};
1517
+ let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1518
+ if (input.length > max) {
1519
+ throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
1520
+ }
1521
+
1522
+ let ast = { type: 'root', input, nodes: [] };
1523
+ let stack = [ast];
1524
+ let block = ast;
1525
+ let prev = ast;
1526
+ let brackets = 0;
1527
+ let length = input.length;
1528
+ let index = 0;
1529
+ let depth = 0;
1530
+ let value;
1531
+
1532
+ /**
1533
+ * Helpers
1534
+ */
1535
+
1536
+ const advance = () => input[index++];
1537
+ const push = node => {
1538
+ if (node.type === 'text' && prev.type === 'dot') {
1539
+ prev.type = 'text';
1540
+ }
1541
+
1542
+ if (prev && prev.type === 'text' && node.type === 'text') {
1543
+ prev.value += node.value;
1544
+ return;
1545
+ }
1546
+
1547
+ block.nodes.push(node);
1548
+ node.parent = block;
1549
+ node.prev = prev;
1550
+ prev = node;
1551
+ return node;
1552
+ };
1553
+
1554
+ push({ type: 'bos' });
1555
+
1556
+ while (index < length) {
1557
+ block = stack[stack.length - 1];
1558
+ value = advance();
1559
+
1560
+ /**
1561
+ * Invalid chars
1562
+ */
1563
+
1564
+ if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
1565
+ continue;
1566
+ }
1567
+
1568
+ /**
1569
+ * Escaped chars
1570
+ */
1571
+
1572
+ if (value === CHAR_BACKSLASH) {
1573
+ push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
1574
+ continue;
1575
+ }
1576
+
1577
+ /**
1578
+ * Right square bracket (literal): ']'
1579
+ */
1580
+
1581
+ if (value === CHAR_RIGHT_SQUARE_BRACKET) {
1582
+ push({ type: 'text', value: '\\' + value });
1583
+ continue;
1584
+ }
1585
+
1586
+ /**
1587
+ * Left square bracket: '['
1588
+ */
1589
+
1590
+ if (value === CHAR_LEFT_SQUARE_BRACKET) {
1591
+ brackets++;
1592
+ let next;
1593
+
1594
+ while (index < length && (next = advance())) {
1595
+ value += next;
1596
+
1597
+ if (next === CHAR_LEFT_SQUARE_BRACKET) {
1598
+ brackets++;
1599
+ continue;
1600
+ }
1601
+
1602
+ if (next === CHAR_BACKSLASH) {
1603
+ value += advance();
1604
+ continue;
1605
+ }
1606
+
1607
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
1608
+ brackets--;
1609
+
1610
+ if (brackets === 0) {
1611
+ break;
1612
+ }
1613
+ }
1614
+ }
1615
+
1616
+ push({ type: 'text', value });
1617
+ continue;
1618
+ }
1619
+
1620
+ /**
1621
+ * Parentheses
1622
+ */
1623
+
1624
+ if (value === CHAR_LEFT_PARENTHESES) {
1625
+ block = push({ type: 'paren', nodes: [] });
1626
+ stack.push(block);
1627
+ push({ type: 'text', value });
1628
+ continue;
1629
+ }
1630
+
1631
+ if (value === CHAR_RIGHT_PARENTHESES) {
1632
+ if (block.type !== 'paren') {
1633
+ push({ type: 'text', value });
1634
+ continue;
1635
+ }
1636
+ block = stack.pop();
1637
+ push({ type: 'text', value });
1638
+ block = stack[stack.length - 1];
1639
+ continue;
1640
+ }
1641
+
1642
+ /**
1643
+ * Quotes: '|"|`
1644
+ */
1645
+
1646
+ if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
1647
+ let open = value;
1648
+ let next;
1649
+
1650
+ if (options.keepQuotes !== true) {
1651
+ value = '';
1652
+ }
1653
+
1654
+ while (index < length && (next = advance())) {
1655
+ if (next === CHAR_BACKSLASH) {
1656
+ value += next + advance();
1657
+ continue;
1658
+ }
1659
+
1660
+ if (next === open) {
1661
+ if (options.keepQuotes === true) value += next;
1662
+ break;
1663
+ }
1664
+
1665
+ value += next;
1666
+ }
1667
+
1668
+ push({ type: 'text', value });
1669
+ continue;
1670
+ }
1671
+
1672
+ /**
1673
+ * Left curly brace: '{'
1674
+ */
1675
+
1676
+ if (value === CHAR_LEFT_CURLY_BRACE) {
1677
+ depth++;
1678
+
1679
+ let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
1680
+ let brace = {
1681
+ type: 'brace',
1682
+ open: true,
1683
+ close: false,
1684
+ dollar,
1685
+ depth,
1686
+ commas: 0,
1687
+ ranges: 0,
1688
+ nodes: []
1689
+ };
1690
+
1691
+ block = push(brace);
1692
+ stack.push(block);
1693
+ push({ type: 'open', value });
1694
+ continue;
1695
+ }
1696
+
1697
+ /**
1698
+ * Right curly brace: '}'
1699
+ */
1700
+
1701
+ if (value === CHAR_RIGHT_CURLY_BRACE) {
1702
+ if (block.type !== 'brace') {
1703
+ push({ type: 'text', value });
1704
+ continue;
1705
+ }
1706
+
1707
+ let type = 'close';
1708
+ block = stack.pop();
1709
+ block.close = true;
1710
+
1711
+ push({ type, value });
1712
+ depth--;
1713
+
1714
+ block = stack[stack.length - 1];
1715
+ continue;
1716
+ }
1717
+
1718
+ /**
1719
+ * Comma: ','
1720
+ */
1721
+
1722
+ if (value === CHAR_COMMA && depth > 0) {
1723
+ if (block.ranges > 0) {
1724
+ block.ranges = 0;
1725
+ let open = block.nodes.shift();
1726
+ block.nodes = [open, { type: 'text', value: stringify$1(block) }];
1727
+ }
1728
+
1729
+ push({ type: 'comma', value });
1730
+ block.commas++;
1731
+ continue;
1732
+ }
1733
+
1734
+ /**
1735
+ * Dot: '.'
1736
+ */
1737
+
1738
+ if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
1739
+ let siblings = block.nodes;
1740
+
1741
+ if (depth === 0 || siblings.length === 0) {
1742
+ push({ type: 'text', value });
1743
+ continue;
1744
+ }
1745
+
1746
+ if (prev.type === 'dot') {
1747
+ block.range = [];
1748
+ prev.value += value;
1749
+ prev.type = 'range';
1750
+
1751
+ if (block.nodes.length !== 3 && block.nodes.length !== 5) {
1752
+ block.invalid = true;
1753
+ block.ranges = 0;
1754
+ prev.type = 'text';
1755
+ continue;
1756
+ }
1757
+
1758
+ block.ranges++;
1759
+ block.args = [];
1760
+ continue;
1761
+ }
1762
+
1763
+ if (prev.type === 'range') {
1764
+ siblings.pop();
1765
+
1766
+ let before = siblings[siblings.length - 1];
1767
+ before.value += prev.value + value;
1768
+ prev = before;
1769
+ block.ranges--;
1770
+ continue;
1771
+ }
1772
+
1773
+ push({ type: 'dot', value });
1774
+ continue;
1775
+ }
1776
+
1777
+ /**
1778
+ * Text
1779
+ */
1780
+
1781
+ push({ type: 'text', value });
1782
+ }
1783
+
1784
+ // Mark imbalanced braces and brackets as invalid
1785
+ do {
1786
+ block = stack.pop();
1787
+
1788
+ if (block.type !== 'root') {
1789
+ block.nodes.forEach(node => {
1790
+ if (!node.nodes) {
1791
+ if (node.type === 'open') node.isOpen = true;
1792
+ if (node.type === 'close') node.isClose = true;
1793
+ if (!node.nodes) node.type = 'text';
1794
+ node.invalid = true;
1795
+ }
1796
+ });
1797
+
1798
+ // get the location of the block on parent.nodes (block's siblings)
1799
+ let parent = stack[stack.length - 1];
1800
+ let index = parent.nodes.indexOf(block);
1801
+ // replace the (invalid) block with it's nodes
1802
+ parent.nodes.splice(index, 1, ...block.nodes);
1803
+ }
1804
+ } while (stack.length > 0);
1805
+
1806
+ push({ type: 'eos' });
1807
+ return ast;
1808
+ };
1809
+
1810
+ var parse_1 = parse$1;
1811
+
1812
+ const stringify = stringify$4;
1813
+ const compile = compile_1;
1814
+ const expand = expand_1;
1815
+ const parse = parse_1;
1816
+
1817
+ /**
1818
+ * Expand the given pattern or create a regex-compatible string.
1819
+ *
1820
+ * ```js
1821
+ * const braces = require('braces');
1822
+ * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
1823
+ * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
1824
+ * ```
1825
+ * @param {String} `str`
1826
+ * @param {Object} `options`
1827
+ * @return {String}
1828
+ * @api public
1829
+ */
1830
+
1831
+ const braces$1 = (input, options = {}) => {
1832
+ let output = [];
1833
+
1834
+ if (Array.isArray(input)) {
1835
+ for (let pattern of input) {
1836
+ let result = braces$1.create(pattern, options);
1837
+ if (Array.isArray(result)) {
1838
+ output.push(...result);
1839
+ } else {
1840
+ output.push(result);
1841
+ }
1842
+ }
1843
+ } else {
1844
+ output = [].concat(braces$1.create(input, options));
1845
+ }
1846
+
1847
+ if (options && options.expand === true && options.nodupes === true) {
1848
+ output = [...new Set(output)];
1849
+ }
1850
+ return output;
1851
+ };
1852
+
1853
+ /**
1854
+ * Parse the given `str` with the given `options`.
1855
+ *
1856
+ * ```js
1857
+ * // braces.parse(pattern, [, options]);
1858
+ * const ast = braces.parse('a/{b,c}/d');
1859
+ * console.log(ast);
1860
+ * ```
1861
+ * @param {String} pattern Brace pattern to parse
1862
+ * @param {Object} options
1863
+ * @return {Object} Returns an AST
1864
+ * @api public
1865
+ */
1866
+
1867
+ braces$1.parse = (input, options = {}) => parse(input, options);
1868
+
1869
+ /**
1870
+ * Creates a braces string from an AST, or an AST node.
1871
+ *
1872
+ * ```js
1873
+ * const braces = require('braces');
1874
+ * let ast = braces.parse('foo/{a,b}/bar');
1875
+ * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
1876
+ * ```
1877
+ * @param {String} `input` Brace pattern or AST.
1878
+ * @param {Object} `options`
1879
+ * @return {Array} Returns an array of expanded values.
1880
+ * @api public
1881
+ */
1882
+
1883
+ braces$1.stringify = (input, options = {}) => {
1884
+ if (typeof input === 'string') {
1885
+ return stringify(braces$1.parse(input, options), options);
1886
+ }
1887
+ return stringify(input, options);
1888
+ };
1889
+
1890
+ /**
1891
+ * Compiles a brace pattern into a regex-compatible, optimized string.
1892
+ * This method is called by the main [braces](#braces) function by default.
1893
+ *
1894
+ * ```js
1895
+ * const braces = require('braces');
1896
+ * console.log(braces.compile('a/{b,c}/d'));
1897
+ * //=> ['a/(b|c)/d']
1898
+ * ```
1899
+ * @param {String} `input` Brace pattern or AST.
1900
+ * @param {Object} `options`
1901
+ * @return {Array} Returns an array of expanded values.
1902
+ * @api public
1903
+ */
1904
+
1905
+ braces$1.compile = (input, options = {}) => {
1906
+ if (typeof input === 'string') {
1907
+ input = braces$1.parse(input, options);
1908
+ }
1909
+ return compile(input, options);
1910
+ };
1911
+
1912
+ /**
1913
+ * Expands a brace pattern into an array. This method is called by the
1914
+ * main [braces](#braces) function when `options.expand` is true. Before
1915
+ * using this method it's recommended that you read the [performance notes](#performance))
1916
+ * and advantages of using [.compile](#compile) instead.
1917
+ *
1918
+ * ```js
1919
+ * const braces = require('braces');
1920
+ * console.log(braces.expand('a/{b,c}/d'));
1921
+ * //=> ['a/b/d', 'a/c/d'];
1922
+ * ```
1923
+ * @param {String} `pattern` Brace pattern
1924
+ * @param {Object} `options`
1925
+ * @return {Array} Returns an array of expanded values.
1926
+ * @api public
1927
+ */
1928
+
1929
+ braces$1.expand = (input, options = {}) => {
1930
+ if (typeof input === 'string') {
1931
+ input = braces$1.parse(input, options);
1932
+ }
1933
+
1934
+ let result = expand(input, options);
1935
+
1936
+ // filter out empty strings if specified
1937
+ if (options.noempty === true) {
1938
+ result = result.filter(Boolean);
1939
+ }
1940
+
1941
+ // filter out duplicates if specified
1942
+ if (options.nodupes === true) {
1943
+ result = [...new Set(result)];
1944
+ }
1945
+
1946
+ return result;
1947
+ };
1948
+
1949
+ /**
1950
+ * Processes a brace pattern and returns either an expanded array
1951
+ * (if `options.expand` is true), a highly optimized regex-compatible string.
1952
+ * This method is called by the main [braces](#braces) function.
1953
+ *
1954
+ * ```js
1955
+ * const braces = require('braces');
1956
+ * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
1957
+ * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
1958
+ * ```
1959
+ * @param {String} `pattern` Brace pattern
1960
+ * @param {Object} `options`
1961
+ * @return {Array} Returns an array of expanded values.
1962
+ * @api public
1963
+ */
1964
+
1965
+ braces$1.create = (input, options = {}) => {
1966
+ if (input === '' || input.length < 3) {
1967
+ return [input];
1968
+ }
1969
+
1970
+ return options.expand !== true
1971
+ ? braces$1.compile(input, options)
1972
+ : braces$1.expand(input, options);
1973
+ };
1974
+
1975
+ /**
1976
+ * Expose "braces"
1977
+ */
1978
+
1979
+ var braces_1 = braces$1;
1980
+
1981
+ var require$$0 = [
1982
+ "3dm",
1983
+ "3ds",
1984
+ "3g2",
1985
+ "3gp",
1986
+ "7z",
1987
+ "a",
1988
+ "aac",
1989
+ "adp",
1990
+ "ai",
1991
+ "aif",
1992
+ "aiff",
1993
+ "alz",
1994
+ "ape",
1995
+ "apk",
1996
+ "appimage",
1997
+ "ar",
1998
+ "arj",
1999
+ "asf",
2000
+ "au",
2001
+ "avi",
2002
+ "bak",
2003
+ "baml",
2004
+ "bh",
2005
+ "bin",
2006
+ "bk",
2007
+ "bmp",
2008
+ "btif",
2009
+ "bz2",
2010
+ "bzip2",
2011
+ "cab",
2012
+ "caf",
2013
+ "cgm",
2014
+ "class",
2015
+ "cmx",
2016
+ "cpio",
2017
+ "cr2",
2018
+ "cur",
2019
+ "dat",
2020
+ "dcm",
2021
+ "deb",
2022
+ "dex",
2023
+ "djvu",
2024
+ "dll",
2025
+ "dmg",
2026
+ "dng",
2027
+ "doc",
2028
+ "docm",
2029
+ "docx",
2030
+ "dot",
2031
+ "dotm",
2032
+ "dra",
2033
+ "DS_Store",
2034
+ "dsk",
2035
+ "dts",
2036
+ "dtshd",
2037
+ "dvb",
2038
+ "dwg",
2039
+ "dxf",
2040
+ "ecelp4800",
2041
+ "ecelp7470",
2042
+ "ecelp9600",
2043
+ "egg",
2044
+ "eol",
2045
+ "eot",
2046
+ "epub",
2047
+ "exe",
2048
+ "f4v",
2049
+ "fbs",
2050
+ "fh",
2051
+ "fla",
2052
+ "flac",
2053
+ "flatpak",
2054
+ "fli",
2055
+ "flv",
2056
+ "fpx",
2057
+ "fst",
2058
+ "fvt",
2059
+ "g3",
2060
+ "gh",
2061
+ "gif",
2062
+ "graffle",
2063
+ "gz",
2064
+ "gzip",
2065
+ "h261",
2066
+ "h263",
2067
+ "h264",
2068
+ "icns",
2069
+ "ico",
2070
+ "ief",
2071
+ "img",
2072
+ "ipa",
2073
+ "iso",
2074
+ "jar",
2075
+ "jpeg",
2076
+ "jpg",
2077
+ "jpgv",
2078
+ "jpm",
2079
+ "jxr",
2080
+ "key",
2081
+ "ktx",
2082
+ "lha",
2083
+ "lib",
2084
+ "lvp",
2085
+ "lz",
2086
+ "lzh",
2087
+ "lzma",
2088
+ "lzo",
2089
+ "m3u",
2090
+ "m4a",
2091
+ "m4v",
2092
+ "mar",
2093
+ "mdi",
2094
+ "mht",
2095
+ "mid",
2096
+ "midi",
2097
+ "mj2",
2098
+ "mka",
2099
+ "mkv",
2100
+ "mmr",
2101
+ "mng",
2102
+ "mobi",
2103
+ "mov",
2104
+ "movie",
2105
+ "mp3",
2106
+ "mp4",
2107
+ "mp4a",
2108
+ "mpeg",
2109
+ "mpg",
2110
+ "mpga",
2111
+ "mxu",
2112
+ "nef",
2113
+ "npx",
2114
+ "numbers",
2115
+ "nupkg",
2116
+ "o",
2117
+ "odp",
2118
+ "ods",
2119
+ "odt",
2120
+ "oga",
2121
+ "ogg",
2122
+ "ogv",
2123
+ "otf",
2124
+ "ott",
2125
+ "pages",
2126
+ "pbm",
2127
+ "pcx",
2128
+ "pdb",
2129
+ "pdf",
2130
+ "pea",
2131
+ "pgm",
2132
+ "pic",
2133
+ "png",
2134
+ "pnm",
2135
+ "pot",
2136
+ "potm",
2137
+ "potx",
2138
+ "ppa",
2139
+ "ppam",
2140
+ "ppm",
2141
+ "pps",
2142
+ "ppsm",
2143
+ "ppsx",
2144
+ "ppt",
2145
+ "pptm",
2146
+ "pptx",
2147
+ "psd",
2148
+ "pya",
2149
+ "pyc",
2150
+ "pyo",
2151
+ "pyv",
2152
+ "qt",
2153
+ "rar",
2154
+ "ras",
2155
+ "raw",
2156
+ "resources",
2157
+ "rgb",
2158
+ "rip",
2159
+ "rlc",
2160
+ "rmf",
2161
+ "rmvb",
2162
+ "rpm",
2163
+ "rtf",
2164
+ "rz",
2165
+ "s3m",
2166
+ "s7z",
2167
+ "scpt",
2168
+ "sgi",
2169
+ "shar",
2170
+ "snap",
2171
+ "sil",
2172
+ "sketch",
2173
+ "slk",
2174
+ "smv",
2175
+ "snk",
2176
+ "so",
2177
+ "stl",
2178
+ "suo",
2179
+ "sub",
2180
+ "swf",
2181
+ "tar",
2182
+ "tbz",
2183
+ "tbz2",
2184
+ "tga",
2185
+ "tgz",
2186
+ "thmx",
2187
+ "tif",
2188
+ "tiff",
2189
+ "tlz",
2190
+ "ttc",
2191
+ "ttf",
2192
+ "txz",
2193
+ "udf",
2194
+ "uvh",
2195
+ "uvi",
2196
+ "uvm",
2197
+ "uvp",
2198
+ "uvs",
2199
+ "uvu",
2200
+ "viv",
2201
+ "vob",
2202
+ "war",
2203
+ "wav",
2204
+ "wax",
2205
+ "wbmp",
2206
+ "wdp",
2207
+ "weba",
2208
+ "webm",
2209
+ "webp",
2210
+ "whl",
2211
+ "wim",
2212
+ "wm",
2213
+ "wma",
2214
+ "wmv",
2215
+ "wmx",
2216
+ "woff",
2217
+ "woff2",
2218
+ "wrm",
2219
+ "wvx",
2220
+ "xbm",
2221
+ "xif",
2222
+ "xla",
2223
+ "xlam",
2224
+ "xls",
2225
+ "xlsb",
2226
+ "xlsm",
2227
+ "xlsx",
2228
+ "xlt",
2229
+ "xltm",
2230
+ "xltx",
2231
+ "xm",
2232
+ "xmind",
2233
+ "xpi",
2234
+ "xpm",
2235
+ "xwd",
2236
+ "xz",
2237
+ "z",
2238
+ "zip",
2239
+ "zipx"
2240
+ ];
2241
+
2242
+ var binaryExtensions$1 = require$$0;
2243
+
2244
+ const path = path$1;
2245
+ const binaryExtensions = binaryExtensions$1;
2246
+
2247
+ const extensions = new Set(binaryExtensions);
2248
+
2249
+ var isBinaryPath$1 = filePath => extensions.has(path.extname(filePath).slice(1).toLowerCase());
2250
+
2251
+ var constants = {};
2252
+
2253
+ (function (exports) {
2254
+
2255
+ const {sep} = path$1;
2256
+ const {platform} = process;
2257
+ const os = require$$2$1;
2258
+
2259
+ exports.EV_ALL = 'all';
2260
+ exports.EV_READY = 'ready';
2261
+ exports.EV_ADD = 'add';
2262
+ exports.EV_CHANGE = 'change';
2263
+ exports.EV_ADD_DIR = 'addDir';
2264
+ exports.EV_UNLINK = 'unlink';
2265
+ exports.EV_UNLINK_DIR = 'unlinkDir';
2266
+ exports.EV_RAW = 'raw';
2267
+ exports.EV_ERROR = 'error';
2268
+
2269
+ exports.STR_DATA = 'data';
2270
+ exports.STR_END = 'end';
2271
+ exports.STR_CLOSE = 'close';
2272
+
2273
+ exports.FSEVENT_CREATED = 'created';
2274
+ exports.FSEVENT_MODIFIED = 'modified';
2275
+ exports.FSEVENT_DELETED = 'deleted';
2276
+ exports.FSEVENT_MOVED = 'moved';
2277
+ exports.FSEVENT_CLONED = 'cloned';
2278
+ exports.FSEVENT_UNKNOWN = 'unknown';
2279
+ exports.FSEVENT_TYPE_FILE = 'file';
2280
+ exports.FSEVENT_TYPE_DIRECTORY = 'directory';
2281
+ exports.FSEVENT_TYPE_SYMLINK = 'symlink';
2282
+
2283
+ exports.KEY_LISTENERS = 'listeners';
2284
+ exports.KEY_ERR = 'errHandlers';
2285
+ exports.KEY_RAW = 'rawEmitters';
2286
+ exports.HANDLER_KEYS = [exports.KEY_LISTENERS, exports.KEY_ERR, exports.KEY_RAW];
2287
+
2288
+ exports.DOT_SLASH = `.${sep}`;
2289
+
2290
+ exports.BACK_SLASH_RE = /\\/g;
2291
+ exports.DOUBLE_SLASH_RE = /\/\//;
2292
+ exports.SLASH_OR_BACK_SLASH_RE = /[/\\]/;
2293
+ exports.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
2294
+ exports.REPLACER_RE = /^\.[/\\]/;
2295
+
2296
+ exports.SLASH = '/';
2297
+ exports.SLASH_SLASH = '//';
2298
+ exports.BRACE_START = '{';
2299
+ exports.BANG = '!';
2300
+ exports.ONE_DOT = '.';
2301
+ exports.TWO_DOTS = '..';
2302
+ exports.STAR = '*';
2303
+ exports.GLOBSTAR = '**';
2304
+ exports.ROOT_GLOBSTAR = '/**/*';
2305
+ exports.SLASH_GLOBSTAR = '/**';
2306
+ exports.DIR_SUFFIX = 'Dir';
2307
+ exports.ANYMATCH_OPTS = {dot: true};
2308
+ exports.STRING_TYPE = 'string';
2309
+ exports.FUNCTION_TYPE = 'function';
2310
+ exports.EMPTY_STR = '';
2311
+ exports.EMPTY_FN = () => {};
2312
+ exports.IDENTITY_FN = val => val;
2313
+
2314
+ exports.isWindows = platform === 'win32';
2315
+ exports.isMacos = platform === 'darwin';
2316
+ exports.isLinux = platform === 'linux';
2317
+ exports.isIBMi = os.type() === 'OS400';
2318
+ }(constants));
2319
+
2320
+ const fs$2 = fs$4;
2321
+ const sysPath$2 = path$1;
2322
+ const { promisify: promisify$2 } = require$$2;
2323
+ const isBinaryPath = isBinaryPath$1;
2324
+ const {
2325
+ isWindows: isWindows$1,
2326
+ isLinux,
2327
+ EMPTY_FN: EMPTY_FN$2,
2328
+ EMPTY_STR: EMPTY_STR$1,
2329
+ KEY_LISTENERS,
2330
+ KEY_ERR,
2331
+ KEY_RAW,
2332
+ HANDLER_KEYS,
2333
+ EV_CHANGE: EV_CHANGE$2,
2334
+ EV_ADD: EV_ADD$2,
2335
+ EV_ADD_DIR: EV_ADD_DIR$2,
2336
+ EV_ERROR: EV_ERROR$2,
2337
+ STR_DATA: STR_DATA$1,
2338
+ STR_END: STR_END$2,
2339
+ BRACE_START: BRACE_START$1,
2340
+ STAR
2341
+ } = constants;
2342
+
2343
+ const THROTTLE_MODE_WATCH = 'watch';
2344
+
2345
+ const open = promisify$2(fs$2.open);
2346
+ const stat$2 = promisify$2(fs$2.stat);
2347
+ const lstat$1 = promisify$2(fs$2.lstat);
2348
+ const close = promisify$2(fs$2.close);
2349
+ const fsrealpath = promisify$2(fs$2.realpath);
2350
+
2351
+ const statMethods$1 = { lstat: lstat$1, stat: stat$2 };
2352
+
2353
+ // TODO: emit errors properly. Example: EMFILE on Macos.
2354
+ const foreach = (val, fn) => {
2355
+ if (val instanceof Set) {
2356
+ val.forEach(fn);
2357
+ } else {
2358
+ fn(val);
2359
+ }
2360
+ };
2361
+
2362
+ const addAndConvert = (main, prop, item) => {
2363
+ let container = main[prop];
2364
+ if (!(container instanceof Set)) {
2365
+ main[prop] = container = new Set([container]);
2366
+ }
2367
+ container.add(item);
2368
+ };
2369
+
2370
+ const clearItem = cont => key => {
2371
+ const set = cont[key];
2372
+ if (set instanceof Set) {
2373
+ set.clear();
2374
+ } else {
2375
+ delete cont[key];
2376
+ }
2377
+ };
2378
+
2379
+ const delFromSet = (main, prop, item) => {
2380
+ const container = main[prop];
2381
+ if (container instanceof Set) {
2382
+ container.delete(item);
2383
+ } else if (container === item) {
2384
+ delete main[prop];
2385
+ }
2386
+ };
2387
+
2388
+ const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
2389
+
2390
+ /**
2391
+ * @typedef {String} Path
2392
+ */
2393
+
2394
+ // fs_watch helpers
2395
+
2396
+ // object to hold per-process fs_watch instances
2397
+ // (may be shared across chokidar FSWatcher instances)
2398
+
2399
+ /**
2400
+ * @typedef {Object} FsWatchContainer
2401
+ * @property {Set} listeners
2402
+ * @property {Set} errHandlers
2403
+ * @property {Set} rawEmitters
2404
+ * @property {fs.FSWatcher=} watcher
2405
+ * @property {Boolean=} watcherUnusable
2406
+ */
2407
+
2408
+ /**
2409
+ * @type {Map<String,FsWatchContainer>}
2410
+ */
2411
+ const FsWatchInstances = new Map();
2412
+
2413
+ /**
2414
+ * Instantiates the fs_watch interface
2415
+ * @param {String} path to be watched
2416
+ * @param {Object} options to be passed to fs_watch
2417
+ * @param {Function} listener main event handler
2418
+ * @param {Function} errHandler emits info about errors
2419
+ * @param {Function} emitRaw emits raw event data
2420
+ * @returns {fs.FSWatcher} new fsevents instance
2421
+ */
2422
+ function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
2423
+ const handleEvent = (rawEvent, evPath) => {
2424
+ listener(path);
2425
+ emitRaw(rawEvent, evPath, {watchedPath: path});
2426
+
2427
+ // emit based on events occurring for files from a directory's watcher in
2428
+ // case the file's watcher misses it (and rely on throttling to de-dupe)
2429
+ if (evPath && path !== evPath) {
2430
+ fsWatchBroadcast(
2431
+ sysPath$2.resolve(path, evPath), KEY_LISTENERS, sysPath$2.join(path, evPath)
2432
+ );
2433
+ }
2434
+ };
2435
+ try {
2436
+ return fs$2.watch(path, options, handleEvent);
2437
+ } catch (error) {
2438
+ errHandler(error);
2439
+ }
2440
+ }
2441
+
2442
+ /**
2443
+ * Helper for passing fs_watch event data to a collection of listeners
2444
+ * @param {Path} fullPath absolute path bound to fs_watch instance
2445
+ * @param {String} type listener type
2446
+ * @param {*=} val1 arguments to be passed to listeners
2447
+ * @param {*=} val2
2448
+ * @param {*=} val3
2449
+ */
2450
+ const fsWatchBroadcast = (fullPath, type, val1, val2, val3) => {
2451
+ const cont = FsWatchInstances.get(fullPath);
2452
+ if (!cont) return;
2453
+ foreach(cont[type], (listener) => {
2454
+ listener(val1, val2, val3);
2455
+ });
2456
+ };
2457
+
2458
+ /**
2459
+ * Instantiates the fs_watch interface or binds listeners
2460
+ * to an existing one covering the same file system entry
2461
+ * @param {String} path
2462
+ * @param {String} fullPath absolute path
2463
+ * @param {Object} options to be passed to fs_watch
2464
+ * @param {Object} handlers container for event listener functions
2465
+ */
2466
+ const setFsWatchListener = (path, fullPath, options, handlers) => {
2467
+ const {listener, errHandler, rawEmitter} = handlers;
2468
+ let cont = FsWatchInstances.get(fullPath);
2469
+
2470
+ /** @type {fs.FSWatcher=} */
2471
+ let watcher;
2472
+ if (!options.persistent) {
2473
+ watcher = createFsWatchInstance(
2474
+ path, options, listener, errHandler, rawEmitter
2475
+ );
2476
+ return watcher.close.bind(watcher);
2477
+ }
2478
+ if (cont) {
2479
+ addAndConvert(cont, KEY_LISTENERS, listener);
2480
+ addAndConvert(cont, KEY_ERR, errHandler);
2481
+ addAndConvert(cont, KEY_RAW, rawEmitter);
2482
+ } else {
2483
+ watcher = createFsWatchInstance(
2484
+ path,
2485
+ options,
2486
+ fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
2487
+ errHandler, // no need to use broadcast here
2488
+ fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
2489
+ );
2490
+ if (!watcher) return;
2491
+ watcher.on(EV_ERROR$2, async (error) => {
2492
+ const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
2493
+ cont.watcherUnusable = true; // documented since Node 10.4.1
2494
+ // Workaround for https://github.com/joyent/node/issues/4337
2495
+ if (isWindows$1 && error.code === 'EPERM') {
2496
+ try {
2497
+ const fd = await open(path, 'r');
2498
+ await close(fd);
2499
+ broadcastErr(error);
2500
+ } catch (err) {}
2501
+ } else {
2502
+ broadcastErr(error);
2503
+ }
2504
+ });
2505
+ cont = {
2506
+ listeners: listener,
2507
+ errHandlers: errHandler,
2508
+ rawEmitters: rawEmitter,
2509
+ watcher
2510
+ };
2511
+ FsWatchInstances.set(fullPath, cont);
2512
+ }
2513
+ // const index = cont.listeners.indexOf(listener);
2514
+
2515
+ // removes this instance's listeners and closes the underlying fs_watch
2516
+ // instance if there are no more listeners left
2517
+ return () => {
2518
+ delFromSet(cont, KEY_LISTENERS, listener);
2519
+ delFromSet(cont, KEY_ERR, errHandler);
2520
+ delFromSet(cont, KEY_RAW, rawEmitter);
2521
+ if (isEmptySet(cont.listeners)) {
2522
+ // Check to protect against issue gh-730.
2523
+ // if (cont.watcherUnusable) {
2524
+ cont.watcher.close();
2525
+ // }
2526
+ FsWatchInstances.delete(fullPath);
2527
+ HANDLER_KEYS.forEach(clearItem(cont));
2528
+ cont.watcher = undefined;
2529
+ Object.freeze(cont);
2530
+ }
2531
+ };
2532
+ };
2533
+
2534
+ // fs_watchFile helpers
2535
+
2536
+ // object to hold per-process fs_watchFile instances
2537
+ // (may be shared across chokidar FSWatcher instances)
2538
+ const FsWatchFileInstances = new Map();
2539
+
2540
+ /**
2541
+ * Instantiates the fs_watchFile interface or binds listeners
2542
+ * to an existing one covering the same file system entry
2543
+ * @param {String} path to be watched
2544
+ * @param {String} fullPath absolute path
2545
+ * @param {Object} options options to be passed to fs_watchFile
2546
+ * @param {Object} handlers container for event listener functions
2547
+ * @returns {Function} closer
2548
+ */
2549
+ const setFsWatchFileListener = (path, fullPath, options, handlers) => {
2550
+ const {listener, rawEmitter} = handlers;
2551
+ let cont = FsWatchFileInstances.get(fullPath);
2552
+
2553
+ const copts = cont && cont.options;
2554
+ if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
2555
+ fs$2.unwatchFile(fullPath);
2556
+ cont = undefined;
2557
+ }
2558
+
2559
+ /* eslint-enable no-unused-vars, prefer-destructuring */
2560
+
2561
+ if (cont) {
2562
+ addAndConvert(cont, KEY_LISTENERS, listener);
2563
+ addAndConvert(cont, KEY_RAW, rawEmitter);
2564
+ } else {
2565
+ // TODO
2566
+ // listeners.add(listener);
2567
+ // rawEmitters.add(rawEmitter);
2568
+ cont = {
2569
+ listeners: listener,
2570
+ rawEmitters: rawEmitter,
2571
+ options,
2572
+ watcher: fs$2.watchFile(fullPath, options, (curr, prev) => {
2573
+ foreach(cont.rawEmitters, (rawEmitter) => {
2574
+ rawEmitter(EV_CHANGE$2, fullPath, {curr, prev});
2575
+ });
2576
+ const currmtime = curr.mtimeMs;
2577
+ if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
2578
+ foreach(cont.listeners, (listener) => listener(path, curr));
2579
+ }
2580
+ })
2581
+ };
2582
+ FsWatchFileInstances.set(fullPath, cont);
2583
+ }
2584
+ // const index = cont.listeners.indexOf(listener);
2585
+
2586
+ // Removes this instance's listeners and closes the underlying fs_watchFile
2587
+ // instance if there are no more listeners left.
2588
+ return () => {
2589
+ delFromSet(cont, KEY_LISTENERS, listener);
2590
+ delFromSet(cont, KEY_RAW, rawEmitter);
2591
+ if (isEmptySet(cont.listeners)) {
2592
+ FsWatchFileInstances.delete(fullPath);
2593
+ fs$2.unwatchFile(fullPath);
2594
+ cont.options = cont.watcher = undefined;
2595
+ Object.freeze(cont);
2596
+ }
2597
+ };
2598
+ };
2599
+
2600
+ /**
2601
+ * @mixin
2602
+ */
2603
+ class NodeFsHandler$1 {
2604
+
2605
+ /**
2606
+ * @param {import("../index").FSWatcher} fsW
2607
+ */
2608
+ constructor(fsW) {
2609
+ this.fsw = fsW;
2610
+ this._boundHandleError = (error) => fsW._handleError(error);
2611
+ }
2612
+
2613
+ /**
2614
+ * Watch file for changes with fs_watchFile or fs_watch.
2615
+ * @param {String} path to file or dir
2616
+ * @param {Function} listener on fs change
2617
+ * @returns {Function} closer for the watcher instance
2618
+ */
2619
+ _watchWithNodeFs(path, listener) {
2620
+ const opts = this.fsw.options;
2621
+ const directory = sysPath$2.dirname(path);
2622
+ const basename = sysPath$2.basename(path);
2623
+ const parent = this.fsw._getWatchedDir(directory);
2624
+ parent.add(basename);
2625
+ const absolutePath = sysPath$2.resolve(path);
2626
+ const options = {persistent: opts.persistent};
2627
+ if (!listener) listener = EMPTY_FN$2;
2628
+
2629
+ let closer;
2630
+ if (opts.usePolling) {
2631
+ options.interval = opts.enableBinaryInterval && isBinaryPath(basename) ?
2632
+ opts.binaryInterval : opts.interval;
2633
+ closer = setFsWatchFileListener(path, absolutePath, options, {
2634
+ listener,
2635
+ rawEmitter: this.fsw._emitRaw
2636
+ });
2637
+ } else {
2638
+ closer = setFsWatchListener(path, absolutePath, options, {
2639
+ listener,
2640
+ errHandler: this._boundHandleError,
2641
+ rawEmitter: this.fsw._emitRaw
2642
+ });
2643
+ }
2644
+ return closer;
2645
+ }
2646
+
2647
+ /**
2648
+ * Watch a file and emit add event if warranted.
2649
+ * @param {Path} file Path
2650
+ * @param {fs.Stats} stats result of fs_stat
2651
+ * @param {Boolean} initialAdd was the file added at watch instantiation?
2652
+ * @returns {Function} closer for the watcher instance
2653
+ */
2654
+ _handleFile(file, stats, initialAdd) {
2655
+ if (this.fsw.closed) {
2656
+ return;
2657
+ }
2658
+ const dirname = sysPath$2.dirname(file);
2659
+ const basename = sysPath$2.basename(file);
2660
+ const parent = this.fsw._getWatchedDir(dirname);
2661
+ // stats is always present
2662
+ let prevStats = stats;
2663
+
2664
+ // if the file is already being watched, do nothing
2665
+ if (parent.has(basename)) return;
2666
+
2667
+ const listener = async (path, newStats) => {
2668
+ if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
2669
+ if (!newStats || newStats.mtimeMs === 0) {
2670
+ try {
2671
+ const newStats = await stat$2(file);
2672
+ if (this.fsw.closed) return;
2673
+ // Check that change event was not fired because of changed only accessTime.
2674
+ const at = newStats.atimeMs;
2675
+ const mt = newStats.mtimeMs;
2676
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) {
2677
+ this.fsw._emit(EV_CHANGE$2, file, newStats);
2678
+ }
2679
+ if (isLinux && prevStats.ino !== newStats.ino) {
2680
+ this.fsw._closeFile(path);
2681
+ prevStats = newStats;
2682
+ this.fsw._addPathCloser(path, this._watchWithNodeFs(file, listener));
2683
+ } else {
2684
+ prevStats = newStats;
2685
+ }
2686
+ } catch (error) {
2687
+ // Fix issues where mtime is null but file is still present
2688
+ this.fsw._remove(dirname, basename);
2689
+ }
2690
+ // add is about to be emitted if file not already tracked in parent
2691
+ } else if (parent.has(basename)) {
2692
+ // Check that change event was not fired because of changed only accessTime.
2693
+ const at = newStats.atimeMs;
2694
+ const mt = newStats.mtimeMs;
2695
+ if (!at || at <= mt || mt !== prevStats.mtimeMs) {
2696
+ this.fsw._emit(EV_CHANGE$2, file, newStats);
2697
+ }
2698
+ prevStats = newStats;
2699
+ }
2700
+ };
2701
+ // kick off the watcher
2702
+ const closer = this._watchWithNodeFs(file, listener);
2703
+
2704
+ // emit an add event if we're supposed to
2705
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
2706
+ if (!this.fsw._throttle(EV_ADD$2, file, 0)) return;
2707
+ this.fsw._emit(EV_ADD$2, file, stats);
2708
+ }
2709
+
2710
+ return closer;
2711
+ }
2712
+
2713
+ /**
2714
+ * Handle symlinks encountered while reading a dir.
2715
+ * @param {Object} entry returned by readdirp
2716
+ * @param {String} directory path of dir being read
2717
+ * @param {String} path of this item
2718
+ * @param {String} item basename of this item
2719
+ * @returns {Promise<Boolean>} true if no more processing is needed for this entry.
2720
+ */
2721
+ async _handleSymlink(entry, directory, path, item) {
2722
+ if (this.fsw.closed) {
2723
+ return;
2724
+ }
2725
+ const full = entry.fullPath;
2726
+ const dir = this.fsw._getWatchedDir(directory);
2727
+
2728
+ if (!this.fsw.options.followSymlinks) {
2729
+ // watch symlink directly (don't follow) and detect changes
2730
+ this.fsw._incrReadyCount();
2731
+ const linkPath = await fsrealpath(path);
2732
+ if (this.fsw.closed) return;
2733
+ if (dir.has(item)) {
2734
+ if (this.fsw._symlinkPaths.get(full) !== linkPath) {
2735
+ this.fsw._symlinkPaths.set(full, linkPath);
2736
+ this.fsw._emit(EV_CHANGE$2, path, entry.stats);
2737
+ }
2738
+ } else {
2739
+ dir.add(item);
2740
+ this.fsw._symlinkPaths.set(full, linkPath);
2741
+ this.fsw._emit(EV_ADD$2, path, entry.stats);
2742
+ }
2743
+ this.fsw._emitReady();
2744
+ return true;
2745
+ }
2746
+
2747
+ // don't follow the same symlink more than once
2748
+ if (this.fsw._symlinkPaths.has(full)) {
2749
+ return true;
2750
+ }
2751
+
2752
+ this.fsw._symlinkPaths.set(full, true);
2753
+ }
2754
+
2755
+ _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
2756
+ // Normalize the directory name on Windows
2757
+ directory = sysPath$2.join(directory, EMPTY_STR$1);
2758
+
2759
+ if (!wh.hasGlob) {
2760
+ throttler = this.fsw._throttle('readdir', directory, 1000);
2761
+ if (!throttler) return;
2762
+ }
2763
+
2764
+ const previous = this.fsw._getWatchedDir(wh.path);
2765
+ const current = new Set();
2766
+
2767
+ let stream = this.fsw._readdirp(directory, {
2768
+ fileFilter: entry => wh.filterPath(entry),
2769
+ directoryFilter: entry => wh.filterDir(entry),
2770
+ depth: 0
2771
+ }).on(STR_DATA$1, async (entry) => {
2772
+ if (this.fsw.closed) {
2773
+ stream = undefined;
2774
+ return;
2775
+ }
2776
+ const item = entry.path;
2777
+ let path = sysPath$2.join(directory, item);
2778
+ current.add(item);
2779
+
2780
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
2781
+ return;
2782
+ }
2783
+
2784
+ if (this.fsw.closed) {
2785
+ stream = undefined;
2786
+ return;
2787
+ }
2788
+ // Files that present in current directory snapshot
2789
+ // but absent in previous are added to watch list and
2790
+ // emit `add` event.
2791
+ if (item === target || !target && !previous.has(item)) {
2792
+ this.fsw._incrReadyCount();
2793
+
2794
+ // ensure relativeness of path is preserved in case of watcher reuse
2795
+ path = sysPath$2.join(dir, sysPath$2.relative(dir, path));
2796
+
2797
+ this._addToNodeFs(path, initialAdd, wh, depth + 1);
2798
+ }
2799
+ }).on(EV_ERROR$2, this._boundHandleError);
2800
+
2801
+ return new Promise(resolve =>
2802
+ stream.once(STR_END$2, () => {
2803
+ if (this.fsw.closed) {
2804
+ stream = undefined;
2805
+ return;
2806
+ }
2807
+ const wasThrottled = throttler ? throttler.clear() : false;
2808
+
2809
+ resolve();
2810
+
2811
+ // Files that absent in current directory snapshot
2812
+ // but present in previous emit `remove` event
2813
+ // and are removed from @watched[directory].
2814
+ previous.getChildren().filter((item) => {
2815
+ return item !== directory &&
2816
+ !current.has(item) &&
2817
+ // in case of intersecting globs;
2818
+ // a path may have been filtered out of this readdir, but
2819
+ // shouldn't be removed because it matches a different glob
2820
+ (!wh.hasGlob || wh.filterPath({
2821
+ fullPath: sysPath$2.resolve(directory, item)
2822
+ }));
2823
+ }).forEach((item) => {
2824
+ this.fsw._remove(directory, item);
2825
+ });
2826
+
2827
+ stream = undefined;
2828
+
2829
+ // one more time for any missed in case changes came in extremely quickly
2830
+ if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
2831
+ })
2832
+ );
2833
+ }
2834
+
2835
+ /**
2836
+ * Read directory to add / remove files from `@watched` list and re-read it on change.
2837
+ * @param {String} dir fs path
2838
+ * @param {fs.Stats} stats
2839
+ * @param {Boolean} initialAdd
2840
+ * @param {Number} depth relative to user-supplied path
2841
+ * @param {String} target child path targeted for watch
2842
+ * @param {Object} wh Common watch helpers for this path
2843
+ * @param {String} realpath
2844
+ * @returns {Promise<Function>} closer for the watcher instance.
2845
+ */
2846
+ async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
2847
+ const parentDir = this.fsw._getWatchedDir(sysPath$2.dirname(dir));
2848
+ const tracked = parentDir.has(sysPath$2.basename(dir));
2849
+ if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
2850
+ if (!wh.hasGlob || wh.globFilter(dir)) this.fsw._emit(EV_ADD_DIR$2, dir, stats);
2851
+ }
2852
+
2853
+ // ensure dir is tracked (harmless if redundant)
2854
+ parentDir.add(sysPath$2.basename(dir));
2855
+ this.fsw._getWatchedDir(dir);
2856
+ let throttler;
2857
+ let closer;
2858
+
2859
+ const oDepth = this.fsw.options.depth;
2860
+ if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
2861
+ if (!target) {
2862
+ await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
2863
+ if (this.fsw.closed) return;
2864
+ }
2865
+
2866
+ closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
2867
+ // if current directory is removed, do nothing
2868
+ if (stats && stats.mtimeMs === 0) return;
2869
+
2870
+ this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
2871
+ });
2872
+ }
2873
+ return closer;
2874
+ }
2875
+
2876
+ /**
2877
+ * Handle added file, directory, or glob pattern.
2878
+ * Delegates call to _handleFile / _handleDir after checks.
2879
+ * @param {String} path to file or ir
2880
+ * @param {Boolean} initialAdd was the file added at watch instantiation?
2881
+ * @param {Object} priorWh depth relative to user-supplied path
2882
+ * @param {Number} depth Child path actually targeted for watch
2883
+ * @param {String=} target Child path actually targeted for watch
2884
+ * @returns {Promise}
2885
+ */
2886
+ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
2887
+ const ready = this.fsw._emitReady;
2888
+ if (this.fsw._isIgnored(path) || this.fsw.closed) {
2889
+ ready();
2890
+ return false;
2891
+ }
2892
+
2893
+ const wh = this.fsw._getWatchHelpers(path, depth);
2894
+ if (!wh.hasGlob && priorWh) {
2895
+ wh.hasGlob = priorWh.hasGlob;
2896
+ wh.globFilter = priorWh.globFilter;
2897
+ wh.filterPath = entry => priorWh.filterPath(entry);
2898
+ wh.filterDir = entry => priorWh.filterDir(entry);
2899
+ }
2900
+
2901
+ // evaluate what is at the path we're being asked to watch
2902
+ try {
2903
+ const stats = await statMethods$1[wh.statMethod](wh.watchPath);
2904
+ if (this.fsw.closed) return;
2905
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
2906
+ ready();
2907
+ return false;
2908
+ }
2909
+
2910
+ const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START$1);
2911
+ let closer;
2912
+ if (stats.isDirectory()) {
2913
+ const absPath = sysPath$2.resolve(path);
2914
+ const targetPath = follow ? await fsrealpath(path) : path;
2915
+ if (this.fsw.closed) return;
2916
+ closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
2917
+ if (this.fsw.closed) return;
2918
+ // preserve this symlink's target path
2919
+ if (absPath !== targetPath && targetPath !== undefined) {
2920
+ this.fsw._symlinkPaths.set(absPath, targetPath);
2921
+ }
2922
+ } else if (stats.isSymbolicLink()) {
2923
+ const targetPath = follow ? await fsrealpath(path) : path;
2924
+ if (this.fsw.closed) return;
2925
+ const parent = sysPath$2.dirname(wh.watchPath);
2926
+ this.fsw._getWatchedDir(parent).add(wh.watchPath);
2927
+ this.fsw._emit(EV_ADD$2, wh.watchPath, stats);
2928
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
2929
+ if (this.fsw.closed) return;
2930
+
2931
+ // preserve this symlink's target path
2932
+ if (targetPath !== undefined) {
2933
+ this.fsw._symlinkPaths.set(sysPath$2.resolve(path), targetPath);
2934
+ }
2935
+ } else {
2936
+ closer = this._handleFile(wh.watchPath, stats, initialAdd);
2937
+ }
2938
+ ready();
2939
+
2940
+ this.fsw._addPathCloser(path, closer);
2941
+ return false;
2942
+
2943
+ } catch (error) {
2944
+ if (this.fsw._handleError(error)) {
2945
+ ready();
2946
+ return path;
2947
+ }
2948
+ }
2949
+ }
2950
+
2951
+ }
2952
+
2953
+ var nodefsHandler = NodeFsHandler$1;
2954
+
2955
+ var fseventsHandler = {exports: {}};
2956
+
2957
+ var require$$3 = /*@__PURE__*/rollup.getAugmentedNamespace(rollup.fseventsImporter);
2958
+
2959
+ const fs$1 = fs$4;
2960
+ const sysPath$1 = path$1;
2961
+ const { promisify: promisify$1 } = require$$2;
2962
+
2963
+ let fsevents;
2964
+ try {
2965
+ fsevents = require$$3.getFsEvents();
2966
+ } catch (error) {
2967
+ if (process.env.CHOKIDAR_PRINT_FSEVENTS_REQUIRE_ERROR) console.error(error);
2968
+ }
2969
+
2970
+ if (fsevents) {
2971
+ // TODO: real check
2972
+ const mtch = process.version.match(/v(\d+)\.(\d+)/);
2973
+ if (mtch && mtch[1] && mtch[2]) {
2974
+ const maj = Number.parseInt(mtch[1], 10);
2975
+ const min = Number.parseInt(mtch[2], 10);
2976
+ if (maj === 8 && min < 16) {
2977
+ fsevents = undefined;
2978
+ }
2979
+ }
2980
+ }
2981
+
2982
+ const {
2983
+ EV_ADD: EV_ADD$1,
2984
+ EV_CHANGE: EV_CHANGE$1,
2985
+ EV_ADD_DIR: EV_ADD_DIR$1,
2986
+ EV_UNLINK: EV_UNLINK$1,
2987
+ EV_ERROR: EV_ERROR$1,
2988
+ STR_DATA,
2989
+ STR_END: STR_END$1,
2990
+ FSEVENT_CREATED,
2991
+ FSEVENT_MODIFIED,
2992
+ FSEVENT_DELETED,
2993
+ FSEVENT_MOVED,
2994
+ // FSEVENT_CLONED,
2995
+ FSEVENT_UNKNOWN,
2996
+ FSEVENT_TYPE_FILE,
2997
+ FSEVENT_TYPE_DIRECTORY,
2998
+ FSEVENT_TYPE_SYMLINK,
2999
+
3000
+ ROOT_GLOBSTAR,
3001
+ DIR_SUFFIX,
3002
+ DOT_SLASH,
3003
+ FUNCTION_TYPE: FUNCTION_TYPE$1,
3004
+ EMPTY_FN: EMPTY_FN$1,
3005
+ IDENTITY_FN
3006
+ } = constants;
3007
+
3008
+ const Depth = (value) => isNaN(value) ? {} : {depth: value};
3009
+
3010
+ const stat$1 = promisify$1(fs$1.stat);
3011
+ const lstat = promisify$1(fs$1.lstat);
3012
+ const realpath = promisify$1(fs$1.realpath);
3013
+
3014
+ const statMethods = { stat: stat$1, lstat };
3015
+
3016
+ /**
3017
+ * @typedef {String} Path
3018
+ */
3019
+
3020
+ /**
3021
+ * @typedef {Object} FsEventsWatchContainer
3022
+ * @property {Set<Function>} listeners
3023
+ * @property {Function} rawEmitter
3024
+ * @property {{stop: Function}} watcher
3025
+ */
3026
+
3027
+ // fsevents instance helper functions
3028
+ /**
3029
+ * Object to hold per-process fsevents instances (may be shared across chokidar FSWatcher instances)
3030
+ * @type {Map<Path,FsEventsWatchContainer>}
3031
+ */
3032
+ const FSEventsWatchers = new Map();
3033
+
3034
+ // Threshold of duplicate path prefixes at which to start
3035
+ // consolidating going forward
3036
+ const consolidateThreshhold = 10;
3037
+
3038
+ const wrongEventFlags = new Set([
3039
+ 69888, 70400, 71424, 72704, 73472, 131328, 131840, 262912
3040
+ ]);
3041
+
3042
+ /**
3043
+ * Instantiates the fsevents interface
3044
+ * @param {Path} path path to be watched
3045
+ * @param {Function} callback called when fsevents is bound and ready
3046
+ * @returns {{stop: Function}} new fsevents instance
3047
+ */
3048
+ const createFSEventsInstance = (path, callback) => {
3049
+ const stop = fsevents.watch(path, callback);
3050
+ return {stop};
3051
+ };
3052
+
3053
+ /**
3054
+ * Instantiates the fsevents interface or binds listeners to an existing one covering
3055
+ * the same file tree.
3056
+ * @param {Path} path - to be watched
3057
+ * @param {Path} realPath - real path for symlinks
3058
+ * @param {Function} listener - called when fsevents emits events
3059
+ * @param {Function} rawEmitter - passes data to listeners of the 'raw' event
3060
+ * @returns {Function} closer
3061
+ */
3062
+ function setFSEventsListener(path, realPath, listener, rawEmitter) {
3063
+ let watchPath = sysPath$1.extname(realPath) ? sysPath$1.dirname(realPath) : realPath;
3064
+
3065
+ const parentPath = sysPath$1.dirname(watchPath);
3066
+ let cont = FSEventsWatchers.get(watchPath);
3067
+
3068
+ // If we've accumulated a substantial number of paths that
3069
+ // could have been consolidated by watching one directory
3070
+ // above the current one, create a watcher on the parent
3071
+ // path instead, so that we do consolidate going forward.
3072
+ if (couldConsolidate(parentPath)) {
3073
+ watchPath = parentPath;
3074
+ }
3075
+
3076
+ const resolvedPath = sysPath$1.resolve(path);
3077
+ const hasSymlink = resolvedPath !== realPath;
3078
+
3079
+ const filteredListener = (fullPath, flags, info) => {
3080
+ if (hasSymlink) fullPath = fullPath.replace(realPath, resolvedPath);
3081
+ if (
3082
+ fullPath === resolvedPath ||
3083
+ !fullPath.indexOf(resolvedPath + sysPath$1.sep)
3084
+ ) listener(fullPath, flags, info);
3085
+ };
3086
+
3087
+ // check if there is already a watcher on a parent path
3088
+ // modifies `watchPath` to the parent path when it finds a match
3089
+ let watchedParent = false;
3090
+ for (const watchedPath of FSEventsWatchers.keys()) {
3091
+ if (realPath.indexOf(sysPath$1.resolve(watchedPath) + sysPath$1.sep) === 0) {
3092
+ watchPath = watchedPath;
3093
+ cont = FSEventsWatchers.get(watchPath);
3094
+ watchedParent = true;
3095
+ break;
3096
+ }
3097
+ }
3098
+
3099
+ if (cont || watchedParent) {
3100
+ cont.listeners.add(filteredListener);
3101
+ } else {
3102
+ cont = {
3103
+ listeners: new Set([filteredListener]),
3104
+ rawEmitter,
3105
+ watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
3106
+ if (!cont.listeners.size) return;
3107
+ const info = fsevents.getInfo(fullPath, flags);
3108
+ cont.listeners.forEach(list => {
3109
+ list(fullPath, flags, info);
3110
+ });
3111
+
3112
+ cont.rawEmitter(info.event, fullPath, info);
3113
+ })
3114
+ };
3115
+ FSEventsWatchers.set(watchPath, cont);
3116
+ }
3117
+
3118
+ // removes this instance's listeners and closes the underlying fsevents
3119
+ // instance if there are no more listeners left
3120
+ return () => {
3121
+ const lst = cont.listeners;
3122
+
3123
+ lst.delete(filteredListener);
3124
+ if (!lst.size) {
3125
+ FSEventsWatchers.delete(watchPath);
3126
+ if (cont.watcher) return cont.watcher.stop().then(() => {
3127
+ cont.rawEmitter = cont.watcher = undefined;
3128
+ Object.freeze(cont);
3129
+ });
3130
+ }
3131
+ };
3132
+ }
3133
+
3134
+ // Decide whether or not we should start a new higher-level
3135
+ // parent watcher
3136
+ const couldConsolidate = (path) => {
3137
+ let count = 0;
3138
+ for (const watchPath of FSEventsWatchers.keys()) {
3139
+ if (watchPath.indexOf(path) === 0) {
3140
+ count++;
3141
+ if (count >= consolidateThreshhold) {
3142
+ return true;
3143
+ }
3144
+ }
3145
+ }
3146
+
3147
+ return false;
3148
+ };
3149
+
3150
+ // returns boolean indicating whether fsevents can be used
3151
+ const canUse = () => fsevents && FSEventsWatchers.size < 128;
3152
+
3153
+ // determines subdirectory traversal levels from root to path
3154
+ const calcDepth = (path, root) => {
3155
+ let i = 0;
3156
+ while (!path.indexOf(root) && (path = sysPath$1.dirname(path)) !== root) i++;
3157
+ return i;
3158
+ };
3159
+
3160
+ // returns boolean indicating whether the fsevents' event info has the same type
3161
+ // as the one returned by fs.stat
3162
+ const sameTypes = (info, stats) => (
3163
+ info.type === FSEVENT_TYPE_DIRECTORY && stats.isDirectory() ||
3164
+ info.type === FSEVENT_TYPE_SYMLINK && stats.isSymbolicLink() ||
3165
+ info.type === FSEVENT_TYPE_FILE && stats.isFile()
3166
+ );
3167
+
3168
+ /**
3169
+ * @mixin
3170
+ */
3171
+ class FsEventsHandler$1 {
3172
+
3173
+ /**
3174
+ * @param {import('../index').FSWatcher} fsw
3175
+ */
3176
+ constructor(fsw) {
3177
+ this.fsw = fsw;
3178
+ }
3179
+ checkIgnored(path, stats) {
3180
+ const ipaths = this.fsw._ignoredPaths;
3181
+ if (this.fsw._isIgnored(path, stats)) {
3182
+ ipaths.add(path);
3183
+ if (stats && stats.isDirectory()) {
3184
+ ipaths.add(path + ROOT_GLOBSTAR);
3185
+ }
3186
+ return true;
3187
+ }
3188
+
3189
+ ipaths.delete(path);
3190
+ ipaths.delete(path + ROOT_GLOBSTAR);
3191
+ }
3192
+
3193
+ addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
3194
+ const event = watchedDir.has(item) ? EV_CHANGE$1 : EV_ADD$1;
3195
+ this.handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3196
+ }
3197
+
3198
+ async checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
3199
+ try {
3200
+ const stats = await stat$1(path);
3201
+ if (this.fsw.closed) return;
3202
+ if (sameTypes(info, stats)) {
3203
+ this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3204
+ } else {
3205
+ this.handleEvent(EV_UNLINK$1, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3206
+ }
3207
+ } catch (error) {
3208
+ if (error.code === 'EACCES') {
3209
+ this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3210
+ } else {
3211
+ this.handleEvent(EV_UNLINK$1, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3212
+ }
3213
+ }
3214
+ }
3215
+
3216
+ handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts) {
3217
+ if (this.fsw.closed || this.checkIgnored(path)) return;
3218
+
3219
+ if (event === EV_UNLINK$1) {
3220
+ const isDirectory = info.type === FSEVENT_TYPE_DIRECTORY;
3221
+ // suppress unlink events on never before seen files
3222
+ if (isDirectory || watchedDir.has(item)) {
3223
+ this.fsw._remove(parent, item, isDirectory);
3224
+ }
3225
+ } else {
3226
+ if (event === EV_ADD$1) {
3227
+ // track new directories
3228
+ if (info.type === FSEVENT_TYPE_DIRECTORY) this.fsw._getWatchedDir(path);
3229
+
3230
+ if (info.type === FSEVENT_TYPE_SYMLINK && opts.followSymlinks) {
3231
+ // push symlinks back to the top of the stack to get handled
3232
+ const curDepth = opts.depth === undefined ?
3233
+ undefined : calcDepth(fullPath, realPath) + 1;
3234
+ return this._addToFsEvents(path, false, true, curDepth);
3235
+ }
3236
+
3237
+ // track new paths
3238
+ // (other than symlinks being followed, which will be tracked soon)
3239
+ this.fsw._getWatchedDir(parent).add(item);
3240
+ }
3241
+ /**
3242
+ * @type {'add'|'addDir'|'unlink'|'unlinkDir'}
3243
+ */
3244
+ const eventName = info.type === FSEVENT_TYPE_DIRECTORY ? event + DIR_SUFFIX : event;
3245
+ this.fsw._emit(eventName, path);
3246
+ if (eventName === EV_ADD_DIR$1) this._addToFsEvents(path, false, true);
3247
+ }
3248
+ }
3249
+
3250
+ /**
3251
+ * Handle symlinks encountered during directory scan
3252
+ * @param {String} watchPath - file/dir path to be watched with fsevents
3253
+ * @param {String} realPath - real path (in case of symlinks)
3254
+ * @param {Function} transform - path transformer
3255
+ * @param {Function} globFilter - path filter in case a glob pattern was provided
3256
+ * @returns {Function} closer for the watcher instance
3257
+ */
3258
+ _watchWithFsEvents(watchPath, realPath, transform, globFilter) {
3259
+ if (this.fsw.closed || this.fsw._isIgnored(watchPath)) return;
3260
+ const opts = this.fsw.options;
3261
+ const watchCallback = async (fullPath, flags, info) => {
3262
+ if (this.fsw.closed) return;
3263
+ if (
3264
+ opts.depth !== undefined &&
3265
+ calcDepth(fullPath, realPath) > opts.depth
3266
+ ) return;
3267
+ const path = transform(sysPath$1.join(
3268
+ watchPath, sysPath$1.relative(watchPath, fullPath)
3269
+ ));
3270
+ if (globFilter && !globFilter(path)) return;
3271
+ // ensure directories are tracked
3272
+ const parent = sysPath$1.dirname(path);
3273
+ const item = sysPath$1.basename(path);
3274
+ const watchedDir = this.fsw._getWatchedDir(
3275
+ info.type === FSEVENT_TYPE_DIRECTORY ? path : parent
3276
+ );
3277
+
3278
+ // correct for wrong events emitted
3279
+ if (wrongEventFlags.has(flags) || info.event === FSEVENT_UNKNOWN) {
3280
+ if (typeof opts.ignored === FUNCTION_TYPE$1) {
3281
+ let stats;
3282
+ try {
3283
+ stats = await stat$1(path);
3284
+ } catch (error) {}
3285
+ if (this.fsw.closed) return;
3286
+ if (this.checkIgnored(path, stats)) return;
3287
+ if (sameTypes(info, stats)) {
3288
+ this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3289
+ } else {
3290
+ this.handleEvent(EV_UNLINK$1, path, fullPath, realPath, parent, watchedDir, item, info, opts);
3291
+ }
3292
+ } else {
3293
+ this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3294
+ }
3295
+ } else {
3296
+ switch (info.event) {
3297
+ case FSEVENT_CREATED:
3298
+ case FSEVENT_MODIFIED:
3299
+ return this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3300
+ case FSEVENT_DELETED:
3301
+ case FSEVENT_MOVED:
3302
+ return this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
3303
+ }
3304
+ }
3305
+ };
3306
+
3307
+ const closer = setFSEventsListener(
3308
+ watchPath,
3309
+ realPath,
3310
+ watchCallback,
3311
+ this.fsw._emitRaw
3312
+ );
3313
+
3314
+ this.fsw._emitReady();
3315
+ return closer;
3316
+ }
3317
+
3318
+ /**
3319
+ * Handle symlinks encountered during directory scan
3320
+ * @param {String} linkPath path to symlink
3321
+ * @param {String} fullPath absolute path to the symlink
3322
+ * @param {Function} transform pre-existing path transformer
3323
+ * @param {Number} curDepth level of subdirectories traversed to where symlink is
3324
+ * @returns {Promise<void>}
3325
+ */
3326
+ async _handleFsEventsSymlink(linkPath, fullPath, transform, curDepth) {
3327
+ // don't follow the same symlink more than once
3328
+ if (this.fsw.closed || this.fsw._symlinkPaths.has(fullPath)) return;
3329
+
3330
+ this.fsw._symlinkPaths.set(fullPath, true);
3331
+ this.fsw._incrReadyCount();
3332
+
3333
+ try {
3334
+ const linkTarget = await realpath(linkPath);
3335
+ if (this.fsw.closed) return;
3336
+ if (this.fsw._isIgnored(linkTarget)) {
3337
+ return this.fsw._emitReady();
3338
+ }
3339
+
3340
+ this.fsw._incrReadyCount();
3341
+
3342
+ // add the linkTarget for watching with a wrapper for transform
3343
+ // that causes emitted paths to incorporate the link's path
3344
+ this._addToFsEvents(linkTarget || linkPath, (path) => {
3345
+ let aliasedPath = linkPath;
3346
+ if (linkTarget && linkTarget !== DOT_SLASH) {
3347
+ aliasedPath = path.replace(linkTarget, linkPath);
3348
+ } else if (path !== DOT_SLASH) {
3349
+ aliasedPath = sysPath$1.join(linkPath, path);
3350
+ }
3351
+ return transform(aliasedPath);
3352
+ }, false, curDepth);
3353
+ } catch(error) {
3354
+ if (this.fsw._handleError(error)) {
3355
+ return this.fsw._emitReady();
3356
+ }
3357
+ }
3358
+ }
3359
+
3360
+ /**
3361
+ *
3362
+ * @param {Path} newPath
3363
+ * @param {fs.Stats} stats
3364
+ */
3365
+ emitAdd(newPath, stats, processPath, opts, forceAdd) {
3366
+ const pp = processPath(newPath);
3367
+ const isDir = stats.isDirectory();
3368
+ const dirObj = this.fsw._getWatchedDir(sysPath$1.dirname(pp));
3369
+ const base = sysPath$1.basename(pp);
3370
+
3371
+ // ensure empty dirs get tracked
3372
+ if (isDir) this.fsw._getWatchedDir(pp);
3373
+ if (dirObj.has(base)) return;
3374
+ dirObj.add(base);
3375
+
3376
+ if (!opts.ignoreInitial || forceAdd === true) {
3377
+ this.fsw._emit(isDir ? EV_ADD_DIR$1 : EV_ADD$1, pp, stats);
3378
+ }
3379
+ }
3380
+
3381
+ initWatch(realPath, path, wh, processPath) {
3382
+ if (this.fsw.closed) return;
3383
+ const closer = this._watchWithFsEvents(
3384
+ wh.watchPath,
3385
+ sysPath$1.resolve(realPath || wh.watchPath),
3386
+ processPath,
3387
+ wh.globFilter
3388
+ );
3389
+ this.fsw._addPathCloser(path, closer);
3390
+ }
3391
+
3392
+ /**
3393
+ * Handle added path with fsevents
3394
+ * @param {String} path file/dir path or glob pattern
3395
+ * @param {Function|Boolean=} transform converts working path to what the user expects
3396
+ * @param {Boolean=} forceAdd ensure add is emitted
3397
+ * @param {Number=} priorDepth Level of subdirectories already traversed.
3398
+ * @returns {Promise<void>}
3399
+ */
3400
+ async _addToFsEvents(path, transform, forceAdd, priorDepth) {
3401
+ if (this.fsw.closed) {
3402
+ return;
3403
+ }
3404
+ const opts = this.fsw.options;
3405
+ const processPath = typeof transform === FUNCTION_TYPE$1 ? transform : IDENTITY_FN;
3406
+
3407
+ const wh = this.fsw._getWatchHelpers(path);
3408
+
3409
+ // evaluate what is at the path we're being asked to watch
3410
+ try {
3411
+ const stats = await statMethods[wh.statMethod](wh.watchPath);
3412
+ if (this.fsw.closed) return;
3413
+ if (this.fsw._isIgnored(wh.watchPath, stats)) {
3414
+ throw null;
3415
+ }
3416
+ if (stats.isDirectory()) {
3417
+ // emit addDir unless this is a glob parent
3418
+ if (!wh.globFilter) this.emitAdd(processPath(path), stats, processPath, opts, forceAdd);
3419
+
3420
+ // don't recurse further if it would exceed depth setting
3421
+ if (priorDepth && priorDepth > opts.depth) return;
3422
+
3423
+ // scan the contents of the dir
3424
+ this.fsw._readdirp(wh.watchPath, {
3425
+ fileFilter: entry => wh.filterPath(entry),
3426
+ directoryFilter: entry => wh.filterDir(entry),
3427
+ ...Depth(opts.depth - (priorDepth || 0))
3428
+ }).on(STR_DATA, (entry) => {
3429
+ // need to check filterPath on dirs b/c filterDir is less restrictive
3430
+ if (this.fsw.closed) {
3431
+ return;
3432
+ }
3433
+ if (entry.stats.isDirectory() && !wh.filterPath(entry)) return;
3434
+
3435
+ const joinedPath = sysPath$1.join(wh.watchPath, entry.path);
3436
+ const {fullPath} = entry;
3437
+
3438
+ if (wh.followSymlinks && entry.stats.isSymbolicLink()) {
3439
+ // preserve the current depth here since it can't be derived from
3440
+ // real paths past the symlink
3441
+ const curDepth = opts.depth === undefined ?
3442
+ undefined : calcDepth(joinedPath, sysPath$1.resolve(wh.watchPath)) + 1;
3443
+
3444
+ this._handleFsEventsSymlink(joinedPath, fullPath, processPath, curDepth);
3445
+ } else {
3446
+ this.emitAdd(joinedPath, entry.stats, processPath, opts, forceAdd);
3447
+ }
3448
+ }).on(EV_ERROR$1, EMPTY_FN$1).on(STR_END$1, () => {
3449
+ this.fsw._emitReady();
3450
+ });
3451
+ } else {
3452
+ this.emitAdd(wh.watchPath, stats, processPath, opts, forceAdd);
3453
+ this.fsw._emitReady();
3454
+ }
3455
+ } catch (error) {
3456
+ if (!error || this.fsw._handleError(error)) {
3457
+ // TODO: Strange thing: "should not choke on an ignored watch path" will be failed without 2 ready calls -__-
3458
+ this.fsw._emitReady();
3459
+ this.fsw._emitReady();
3460
+ }
3461
+ }
3462
+
3463
+ if (opts.persistent && forceAdd !== true) {
3464
+ if (typeof transform === FUNCTION_TYPE$1) {
3465
+ // realpath has already been resolved
3466
+ this.initWatch(undefined, path, wh, processPath);
3467
+ } else {
3468
+ let realPath;
3469
+ try {
3470
+ realPath = await realpath(wh.watchPath);
3471
+ } catch (e) {}
3472
+ this.initWatch(realPath, path, wh, processPath);
3473
+ }
3474
+ }
3475
+ }
3476
+
3477
+ }
3478
+
3479
+ fseventsHandler.exports = FsEventsHandler$1;
3480
+ fseventsHandler.exports.canUse = canUse;
3481
+
3482
+ const { EventEmitter } = require$$0$1;
3483
+ const fs = fs$4;
3484
+ const sysPath = path$1;
3485
+ const { promisify } = require$$2;
3486
+ const readdirp = readdirp_1;
3487
+ const anymatch = anymatch$2.exports.default;
3488
+ const globParent = globParent$1;
3489
+ const isGlob = isGlob$2;
3490
+ const braces = braces_1;
3491
+ const normalizePath = normalizePath$2;
3492
+
3493
+ const NodeFsHandler = nodefsHandler;
3494
+ const FsEventsHandler = fseventsHandler.exports;
3495
+ const {
3496
+ EV_ALL,
3497
+ EV_READY,
3498
+ EV_ADD,
3499
+ EV_CHANGE,
3500
+ EV_UNLINK,
3501
+ EV_ADD_DIR,
3502
+ EV_UNLINK_DIR,
3503
+ EV_RAW,
3504
+ EV_ERROR,
3505
+
3506
+ STR_CLOSE,
3507
+ STR_END,
3508
+
3509
+ BACK_SLASH_RE,
3510
+ DOUBLE_SLASH_RE,
3511
+ SLASH_OR_BACK_SLASH_RE,
3512
+ DOT_RE,
3513
+ REPLACER_RE,
3514
+
3515
+ SLASH,
3516
+ SLASH_SLASH,
3517
+ BRACE_START,
3518
+ BANG,
3519
+ ONE_DOT,
3520
+ TWO_DOTS,
3521
+ GLOBSTAR,
3522
+ SLASH_GLOBSTAR,
3523
+ ANYMATCH_OPTS,
3524
+ STRING_TYPE,
3525
+ FUNCTION_TYPE,
3526
+ EMPTY_STR,
3527
+ EMPTY_FN,
3528
+
3529
+ isWindows,
3530
+ isMacos,
3531
+ isIBMi
3532
+ } = constants;
3533
+
3534
+ const stat = promisify(fs.stat);
3535
+ const readdir = promisify(fs.readdir);
3536
+
3537
+ /**
3538
+ * @typedef {String} Path
3539
+ * @typedef {'all'|'add'|'addDir'|'change'|'unlink'|'unlinkDir'|'raw'|'error'|'ready'} EventName
3540
+ * @typedef {'readdir'|'watch'|'add'|'remove'|'change'} ThrottleType
3541
+ */
3542
+
3543
+ /**
3544
+ *
3545
+ * @typedef {Object} WatchHelpers
3546
+ * @property {Boolean} followSymlinks
3547
+ * @property {'stat'|'lstat'} statMethod
3548
+ * @property {Path} path
3549
+ * @property {Path} watchPath
3550
+ * @property {Function} entryPath
3551
+ * @property {Boolean} hasGlob
3552
+ * @property {Object} globFilter
3553
+ * @property {Function} filterPath
3554
+ * @property {Function} filterDir
3555
+ */
3556
+
3557
+ const arrify = (value = []) => Array.isArray(value) ? value : [value];
3558
+ const flatten = (list, result = []) => {
3559
+ list.forEach(item => {
3560
+ if (Array.isArray(item)) {
3561
+ flatten(item, result);
3562
+ } else {
3563
+ result.push(item);
3564
+ }
3565
+ });
3566
+ return result;
3567
+ };
3568
+
3569
+ const unifyPaths = (paths_) => {
3570
+ /**
3571
+ * @type {Array<String>}
3572
+ */
3573
+ const paths = flatten(arrify(paths_));
3574
+ if (!paths.every(p => typeof p === STRING_TYPE)) {
3575
+ throw new TypeError(`Non-string provided as watch path: ${paths}`);
3576
+ }
3577
+ return paths.map(normalizePathToUnix);
3578
+ };
3579
+
3580
+ // If SLASH_SLASH occurs at the beginning of path, it is not replaced
3581
+ // because "//StoragePC/DrivePool/Movies" is a valid network path
3582
+ const toUnix = (string) => {
3583
+ let str = string.replace(BACK_SLASH_RE, SLASH);
3584
+ let prepend = false;
3585
+ if (str.startsWith(SLASH_SLASH)) {
3586
+ prepend = true;
3587
+ }
3588
+ while (str.match(DOUBLE_SLASH_RE)) {
3589
+ str = str.replace(DOUBLE_SLASH_RE, SLASH);
3590
+ }
3591
+ if (prepend) {
3592
+ str = SLASH + str;
3593
+ }
3594
+ return str;
3595
+ };
3596
+
3597
+ // Our version of upath.normalize
3598
+ // TODO: this is not equal to path-normalize module - investigate why
3599
+ const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
3600
+
3601
+ const normalizeIgnored = (cwd = EMPTY_STR) => (path) => {
3602
+ if (typeof path !== STRING_TYPE) return path;
3603
+ return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
3604
+ };
3605
+
3606
+ const getAbsolutePath = (path, cwd) => {
3607
+ if (sysPath.isAbsolute(path)) {
3608
+ return path;
3609
+ }
3610
+ if (path.startsWith(BANG)) {
3611
+ return BANG + sysPath.join(cwd, path.slice(1));
3612
+ }
3613
+ return sysPath.join(cwd, path);
3614
+ };
3615
+
3616
+ const undef = (opts, key) => opts[key] === undefined;
3617
+
3618
+ /**
3619
+ * Directory entry.
3620
+ * @property {Path} path
3621
+ * @property {Set<Path>} items
3622
+ */
3623
+ class DirEntry {
3624
+ /**
3625
+ * @param {Path} dir
3626
+ * @param {Function} removeWatcher
3627
+ */
3628
+ constructor(dir, removeWatcher) {
3629
+ this.path = dir;
3630
+ this._removeWatcher = removeWatcher;
3631
+ /** @type {Set<Path>} */
3632
+ this.items = new Set();
3633
+ }
3634
+
3635
+ add(item) {
3636
+ const {items} = this;
3637
+ if (!items) return;
3638
+ if (item !== ONE_DOT && item !== TWO_DOTS) items.add(item);
3639
+ }
3640
+
3641
+ async remove(item) {
3642
+ const {items} = this;
3643
+ if (!items) return;
3644
+ items.delete(item);
3645
+ if (items.size > 0) return;
3646
+
3647
+ const dir = this.path;
3648
+ try {
3649
+ await readdir(dir);
3650
+ } catch (err) {
3651
+ if (this._removeWatcher) {
3652
+ this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
3653
+ }
3654
+ }
3655
+ }
3656
+
3657
+ has(item) {
3658
+ const {items} = this;
3659
+ if (!items) return;
3660
+ return items.has(item);
3661
+ }
3662
+
3663
+ /**
3664
+ * @returns {Array<String>}
3665
+ */
3666
+ getChildren() {
3667
+ const {items} = this;
3668
+ if (!items) return;
3669
+ return [...items.values()];
3670
+ }
3671
+
3672
+ dispose() {
3673
+ this.items.clear();
3674
+ delete this.path;
3675
+ delete this._removeWatcher;
3676
+ delete this.items;
3677
+ Object.freeze(this);
3678
+ }
3679
+ }
3680
+
3681
+ const STAT_METHOD_F = 'stat';
3682
+ const STAT_METHOD_L = 'lstat';
3683
+ class WatchHelper {
3684
+ constructor(path, watchPath, follow, fsw) {
3685
+ this.fsw = fsw;
3686
+ this.path = path = path.replace(REPLACER_RE, EMPTY_STR);
3687
+ this.watchPath = watchPath;
3688
+ this.fullWatchPath = sysPath.resolve(watchPath);
3689
+ this.hasGlob = watchPath !== path;
3690
+ /** @type {object|boolean} */
3691
+ if (path === EMPTY_STR) this.hasGlob = false;
3692
+ this.globSymlink = this.hasGlob && follow ? undefined : false;
3693
+ this.globFilter = this.hasGlob ? anymatch(path, undefined, ANYMATCH_OPTS) : false;
3694
+ this.dirParts = this.getDirParts(path);
3695
+ this.dirParts.forEach((parts) => {
3696
+ if (parts.length > 1) parts.pop();
3697
+ });
3698
+ this.followSymlinks = follow;
3699
+ this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
3700
+ }
3701
+
3702
+ checkGlobSymlink(entry) {
3703
+ // only need to resolve once
3704
+ // first entry should always have entry.parentDir === EMPTY_STR
3705
+ if (this.globSymlink === undefined) {
3706
+ this.globSymlink = entry.fullParentDir === this.fullWatchPath ?
3707
+ false : {realPath: entry.fullParentDir, linkPath: this.fullWatchPath};
3708
+ }
3709
+
3710
+ if (this.globSymlink) {
3711
+ return entry.fullPath.replace(this.globSymlink.realPath, this.globSymlink.linkPath);
3712
+ }
3713
+
3714
+ return entry.fullPath;
3715
+ }
3716
+
3717
+ entryPath(entry) {
3718
+ return sysPath.join(this.watchPath,
3719
+ sysPath.relative(this.watchPath, this.checkGlobSymlink(entry))
3720
+ );
3721
+ }
3722
+
3723
+ filterPath(entry) {
3724
+ const {stats} = entry;
3725
+ if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
3726
+ const resolvedPath = this.entryPath(entry);
3727
+ const matchesGlob = this.hasGlob && typeof this.globFilter === FUNCTION_TYPE ?
3728
+ this.globFilter(resolvedPath) : true;
3729
+ return matchesGlob &&
3730
+ this.fsw._isntIgnored(resolvedPath, stats) &&
3731
+ this.fsw._hasReadPermissions(stats);
3732
+ }
3733
+
3734
+ getDirParts(path) {
3735
+ if (!this.hasGlob) return [];
3736
+ const parts = [];
3737
+ const expandedPath = path.includes(BRACE_START) ? braces.expand(path) : [path];
3738
+ expandedPath.forEach((path) => {
3739
+ parts.push(sysPath.relative(this.watchPath, path).split(SLASH_OR_BACK_SLASH_RE));
3740
+ });
3741
+ return parts;
3742
+ }
3743
+
3744
+ filterDir(entry) {
3745
+ if (this.hasGlob) {
3746
+ const entryParts = this.getDirParts(this.checkGlobSymlink(entry));
3747
+ let globstar = false;
3748
+ this.unmatchedGlob = !this.dirParts.some((parts) => {
3749
+ return parts.every((part, i) => {
3750
+ if (part === GLOBSTAR) globstar = true;
3751
+ return globstar || !entryParts[0][i] || anymatch(part, entryParts[0][i], ANYMATCH_OPTS);
3752
+ });
3753
+ });
3754
+ }
3755
+ return !this.unmatchedGlob && this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
3756
+ }
3757
+ }
3758
+
3759
+ /**
3760
+ * Watches files & directories for changes. Emitted events:
3761
+ * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
3762
+ *
3763
+ * new FSWatcher()
3764
+ * .add(directories)
3765
+ * .on('add', path => log('File', path, 'was added'))
3766
+ */
3767
+ class FSWatcher extends EventEmitter {
3768
+ // Not indenting methods for history sake; for now.
3769
+ constructor(_opts) {
3770
+ super();
3771
+
3772
+ const opts = {};
3773
+ if (_opts) Object.assign(opts, _opts); // for frozen objects
3774
+
3775
+ /** @type {Map<String, DirEntry>} */
3776
+ this._watched = new Map();
3777
+ /** @type {Map<String, Array>} */
3778
+ this._closers = new Map();
3779
+ /** @type {Set<String>} */
3780
+ this._ignoredPaths = new Set();
3781
+
3782
+ /** @type {Map<ThrottleType, Map>} */
3783
+ this._throttled = new Map();
3784
+
3785
+ /** @type {Map<Path, String|Boolean>} */
3786
+ this._symlinkPaths = new Map();
3787
+
3788
+ this._streams = new Set();
3789
+ this.closed = false;
3790
+
3791
+ // Set up default options.
3792
+ if (undef(opts, 'persistent')) opts.persistent = true;
3793
+ if (undef(opts, 'ignoreInitial')) opts.ignoreInitial = false;
3794
+ if (undef(opts, 'ignorePermissionErrors')) opts.ignorePermissionErrors = false;
3795
+ if (undef(opts, 'interval')) opts.interval = 100;
3796
+ if (undef(opts, 'binaryInterval')) opts.binaryInterval = 300;
3797
+ if (undef(opts, 'disableGlobbing')) opts.disableGlobbing = false;
3798
+ opts.enableBinaryInterval = opts.binaryInterval !== opts.interval;
3799
+
3800
+ // Enable fsevents on OS X when polling isn't explicitly enabled.
3801
+ if (undef(opts, 'useFsEvents')) opts.useFsEvents = !opts.usePolling;
3802
+
3803
+ // If we can't use fsevents, ensure the options reflect it's disabled.
3804
+ const canUseFsEvents = FsEventsHandler.canUse();
3805
+ if (!canUseFsEvents) opts.useFsEvents = false;
3806
+
3807
+ // Use polling on Mac if not using fsevents.
3808
+ // Other platforms use non-polling fs_watch.
3809
+ if (undef(opts, 'usePolling') && !opts.useFsEvents) {
3810
+ opts.usePolling = isMacos;
3811
+ }
3812
+
3813
+ // Always default to polling on IBM i because fs.watch() is not available on IBM i.
3814
+ if(isIBMi) {
3815
+ opts.usePolling = true;
3816
+ }
3817
+
3818
+ // Global override (useful for end-developers that need to force polling for all
3819
+ // instances of chokidar, regardless of usage/dependency depth)
3820
+ const envPoll = process.env.CHOKIDAR_USEPOLLING;
3821
+ if (envPoll !== undefined) {
3822
+ const envLower = envPoll.toLowerCase();
3823
+
3824
+ if (envLower === 'false' || envLower === '0') {
3825
+ opts.usePolling = false;
3826
+ } else if (envLower === 'true' || envLower === '1') {
3827
+ opts.usePolling = true;
3828
+ } else {
3829
+ opts.usePolling = !!envLower;
3830
+ }
3831
+ }
3832
+ const envInterval = process.env.CHOKIDAR_INTERVAL;
3833
+ if (envInterval) {
3834
+ opts.interval = Number.parseInt(envInterval, 10);
3835
+ }
3836
+
3837
+ // Editor atomic write normalization enabled by default with fs.watch
3838
+ if (undef(opts, 'atomic')) opts.atomic = !opts.usePolling && !opts.useFsEvents;
3839
+ if (opts.atomic) this._pendingUnlinks = new Map();
3840
+
3841
+ if (undef(opts, 'followSymlinks')) opts.followSymlinks = true;
3842
+
3843
+ if (undef(opts, 'awaitWriteFinish')) opts.awaitWriteFinish = false;
3844
+ if (opts.awaitWriteFinish === true) opts.awaitWriteFinish = {};
3845
+ const awf = opts.awaitWriteFinish;
3846
+ if (awf) {
3847
+ if (!awf.stabilityThreshold) awf.stabilityThreshold = 2000;
3848
+ if (!awf.pollInterval) awf.pollInterval = 100;
3849
+ this._pendingWrites = new Map();
3850
+ }
3851
+ if (opts.ignored) opts.ignored = arrify(opts.ignored);
3852
+
3853
+ let readyCalls = 0;
3854
+ this._emitReady = () => {
3855
+ readyCalls++;
3856
+ if (readyCalls >= this._readyCount) {
3857
+ this._emitReady = EMPTY_FN;
3858
+ this._readyEmitted = true;
3859
+ // use process.nextTick to allow time for listener to be bound
3860
+ process.nextTick(() => this.emit(EV_READY));
3861
+ }
3862
+ };
3863
+ this._emitRaw = (...args) => this.emit(EV_RAW, ...args);
3864
+ this._readyEmitted = false;
3865
+ this.options = opts;
3866
+
3867
+ // Initialize with proper watcher.
3868
+ if (opts.useFsEvents) {
3869
+ this._fsEventsHandler = new FsEventsHandler(this);
3870
+ } else {
3871
+ this._nodeFsHandler = new NodeFsHandler(this);
3872
+ }
3873
+
3874
+ // You’re frozen when your heart’s not open.
3875
+ Object.freeze(opts);
3876
+ }
3877
+
3878
+ // Public methods
3879
+
3880
+ /**
3881
+ * Adds paths to be watched on an existing FSWatcher instance
3882
+ * @param {Path|Array<Path>} paths_
3883
+ * @param {String=} _origAdd private; for handling non-existent paths to be watched
3884
+ * @param {Boolean=} _internal private; indicates a non-user add
3885
+ * @returns {FSWatcher} for chaining
3886
+ */
3887
+ add(paths_, _origAdd, _internal) {
3888
+ const {cwd, disableGlobbing} = this.options;
3889
+ this.closed = false;
3890
+ let paths = unifyPaths(paths_);
3891
+ if (cwd) {
3892
+ paths = paths.map((path) => {
3893
+ const absPath = getAbsolutePath(path, cwd);
3894
+
3895
+ // Check `path` instead of `absPath` because the cwd portion can't be a glob
3896
+ if (disableGlobbing || !isGlob(path)) {
3897
+ return absPath;
3898
+ }
3899
+ return normalizePath(absPath);
3900
+ });
3901
+ }
3902
+
3903
+ // set aside negated glob strings
3904
+ paths = paths.filter((path) => {
3905
+ if (path.startsWith(BANG)) {
3906
+ this._ignoredPaths.add(path.slice(1));
3907
+ return false;
3908
+ }
3909
+
3910
+ // if a path is being added that was previously ignored, stop ignoring it
3911
+ this._ignoredPaths.delete(path);
3912
+ this._ignoredPaths.delete(path + SLASH_GLOBSTAR);
3913
+
3914
+ // reset the cached userIgnored anymatch fn
3915
+ // to make ignoredPaths changes effective
3916
+ this._userIgnored = undefined;
3917
+
3918
+ return true;
3919
+ });
3920
+
3921
+ if (this.options.useFsEvents && this._fsEventsHandler) {
3922
+ if (!this._readyCount) this._readyCount = paths.length;
3923
+ if (this.options.persistent) this._readyCount *= 2;
3924
+ paths.forEach((path) => this._fsEventsHandler._addToFsEvents(path));
3925
+ } else {
3926
+ if (!this._readyCount) this._readyCount = 0;
3927
+ this._readyCount += paths.length;
3928
+ Promise.all(
3929
+ paths.map(async path => {
3930
+ const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, 0, 0, _origAdd);
3931
+ if (res) this._emitReady();
3932
+ return res;
3933
+ })
3934
+ ).then(results => {
3935
+ if (this.closed) return;
3936
+ results.filter(item => item).forEach(item => {
3937
+ this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
3938
+ });
3939
+ });
3940
+ }
3941
+
3942
+ return this;
3943
+ }
3944
+
3945
+ /**
3946
+ * Close watchers or start ignoring events from specified paths.
3947
+ * @param {Path|Array<Path>} paths_ - string or array of strings, file/directory paths and/or globs
3948
+ * @returns {FSWatcher} for chaining
3949
+ */
3950
+ unwatch(paths_) {
3951
+ if (this.closed) return this;
3952
+ const paths = unifyPaths(paths_);
3953
+ const {cwd} = this.options;
3954
+
3955
+ paths.forEach((path) => {
3956
+ // convert to absolute path unless relative path already matches
3957
+ if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
3958
+ if (cwd) path = sysPath.join(cwd, path);
3959
+ path = sysPath.resolve(path);
3960
+ }
3961
+
3962
+ this._closePath(path);
3963
+
3964
+ this._ignoredPaths.add(path);
3965
+ if (this._watched.has(path)) {
3966
+ this._ignoredPaths.add(path + SLASH_GLOBSTAR);
3967
+ }
3968
+
3969
+ // reset the cached userIgnored anymatch fn
3970
+ // to make ignoredPaths changes effective
3971
+ this._userIgnored = undefined;
3972
+ });
3973
+
3974
+ return this;
3975
+ }
3976
+
3977
+ /**
3978
+ * Close watchers and remove all listeners from watched paths.
3979
+ * @returns {Promise<void>}.
3980
+ */
3981
+ close() {
3982
+ if (this.closed) return this._closePromise;
3983
+ this.closed = true;
3984
+
3985
+ // Memory management.
3986
+ this.removeAllListeners();
3987
+ const closers = [];
3988
+ this._closers.forEach(closerList => closerList.forEach(closer => {
3989
+ const promise = closer();
3990
+ if (promise instanceof Promise) closers.push(promise);
3991
+ }));
3992
+ this._streams.forEach(stream => stream.destroy());
3993
+ this._userIgnored = undefined;
3994
+ this._readyCount = 0;
3995
+ this._readyEmitted = false;
3996
+ this._watched.forEach(dirent => dirent.dispose());
3997
+ ['closers', 'watched', 'streams', 'symlinkPaths', 'throttled'].forEach(key => {
3998
+ this[`_${key}`].clear();
3999
+ });
4000
+
4001
+ this._closePromise = closers.length ? Promise.all(closers).then(() => undefined) : Promise.resolve();
4002
+ return this._closePromise;
4003
+ }
4004
+
4005
+ /**
4006
+ * Expose list of watched paths
4007
+ * @returns {Object} for chaining
4008
+ */
4009
+ getWatched() {
4010
+ const watchList = {};
4011
+ this._watched.forEach((entry, dir) => {
4012
+ const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
4013
+ watchList[key || ONE_DOT] = entry.getChildren().sort();
4014
+ });
4015
+ return watchList;
4016
+ }
4017
+
4018
+ emitWithAll(event, args) {
4019
+ this.emit(...args);
4020
+ if (event !== EV_ERROR) this.emit(EV_ALL, ...args);
4021
+ }
4022
+
4023
+ // Common helpers
4024
+ // --------------
4025
+
4026
+ /**
4027
+ * Normalize and emit events.
4028
+ * Calling _emit DOES NOT MEAN emit() would be called!
4029
+ * @param {EventName} event Type of event
4030
+ * @param {Path} path File or directory path
4031
+ * @param {*=} val1 arguments to be passed with event
4032
+ * @param {*=} val2
4033
+ * @param {*=} val3
4034
+ * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
4035
+ */
4036
+ async _emit(event, path, val1, val2, val3) {
4037
+ if (this.closed) return;
4038
+
4039
+ const opts = this.options;
4040
+ if (isWindows) path = sysPath.normalize(path);
4041
+ if (opts.cwd) path = sysPath.relative(opts.cwd, path);
4042
+ /** @type Array<any> */
4043
+ const args = [event, path];
4044
+ if (val3 !== undefined) args.push(val1, val2, val3);
4045
+ else if (val2 !== undefined) args.push(val1, val2);
4046
+ else if (val1 !== undefined) args.push(val1);
4047
+
4048
+ const awf = opts.awaitWriteFinish;
4049
+ let pw;
4050
+ if (awf && (pw = this._pendingWrites.get(path))) {
4051
+ pw.lastChange = new Date();
4052
+ return this;
4053
+ }
4054
+
4055
+ if (opts.atomic) {
4056
+ if (event === EV_UNLINK) {
4057
+ this._pendingUnlinks.set(path, args);
4058
+ setTimeout(() => {
4059
+ this._pendingUnlinks.forEach((entry, path) => {
4060
+ this.emit(...entry);
4061
+ this.emit(EV_ALL, ...entry);
4062
+ this._pendingUnlinks.delete(path);
4063
+ });
4064
+ }, typeof opts.atomic === 'number' ? opts.atomic : 100);
4065
+ return this;
4066
+ }
4067
+ if (event === EV_ADD && this._pendingUnlinks.has(path)) {
4068
+ event = args[0] = EV_CHANGE;
4069
+ this._pendingUnlinks.delete(path);
4070
+ }
4071
+ }
4072
+
4073
+ if (awf && (event === EV_ADD || event === EV_CHANGE) && this._readyEmitted) {
4074
+ const awfEmit = (err, stats) => {
4075
+ if (err) {
4076
+ event = args[0] = EV_ERROR;
4077
+ args[1] = err;
4078
+ this.emitWithAll(event, args);
4079
+ } else if (stats) {
4080
+ // if stats doesn't exist the file must have been deleted
4081
+ if (args.length > 2) {
4082
+ args[2] = stats;
4083
+ } else {
4084
+ args.push(stats);
4085
+ }
4086
+ this.emitWithAll(event, args);
4087
+ }
4088
+ };
4089
+
4090
+ this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
4091
+ return this;
4092
+ }
4093
+
4094
+ if (event === EV_CHANGE) {
4095
+ const isThrottled = !this._throttle(EV_CHANGE, path, 50);
4096
+ if (isThrottled) return this;
4097
+ }
4098
+
4099
+ if (opts.alwaysStat && val1 === undefined &&
4100
+ (event === EV_ADD || event === EV_ADD_DIR || event === EV_CHANGE)
4101
+ ) {
4102
+ const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
4103
+ let stats;
4104
+ try {
4105
+ stats = await stat(fullPath);
4106
+ } catch (err) {}
4107
+ // Suppress event when fs_stat fails, to avoid sending undefined 'stat'
4108
+ if (!stats || this.closed) return;
4109
+ args.push(stats);
4110
+ }
4111
+ this.emitWithAll(event, args);
4112
+
4113
+ return this;
4114
+ }
4115
+
4116
+ /**
4117
+ * Common handler for errors
4118
+ * @param {Error} error
4119
+ * @returns {Error|Boolean} The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
4120
+ */
4121
+ _handleError(error) {
4122
+ const code = error && error.code;
4123
+ if (error && code !== 'ENOENT' && code !== 'ENOTDIR' &&
4124
+ (!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))
4125
+ ) {
4126
+ this.emit(EV_ERROR, error);
4127
+ }
4128
+ return error || this.closed;
4129
+ }
4130
+
4131
+ /**
4132
+ * Helper utility for throttling
4133
+ * @param {ThrottleType} actionType type being throttled
4134
+ * @param {Path} path being acted upon
4135
+ * @param {Number} timeout duration of time to suppress duplicate actions
4136
+ * @returns {Object|false} tracking object or false if action should be suppressed
4137
+ */
4138
+ _throttle(actionType, path, timeout) {
4139
+ if (!this._throttled.has(actionType)) {
4140
+ this._throttled.set(actionType, new Map());
4141
+ }
4142
+
4143
+ /** @type {Map<Path, Object>} */
4144
+ const action = this._throttled.get(actionType);
4145
+ /** @type {Object} */
4146
+ const actionPath = action.get(path);
4147
+
4148
+ if (actionPath) {
4149
+ actionPath.count++;
4150
+ return false;
4151
+ }
4152
+
4153
+ let timeoutObject;
4154
+ const clear = () => {
4155
+ const item = action.get(path);
4156
+ const count = item ? item.count : 0;
4157
+ action.delete(path);
4158
+ clearTimeout(timeoutObject);
4159
+ if (item) clearTimeout(item.timeoutObject);
4160
+ return count;
4161
+ };
4162
+ timeoutObject = setTimeout(clear, timeout);
4163
+ const thr = {timeoutObject, clear, count: 0};
4164
+ action.set(path, thr);
4165
+ return thr;
4166
+ }
4167
+
4168
+ _incrReadyCount() {
4169
+ return this._readyCount++;
4170
+ }
4171
+
4172
+ /**
4173
+ * Awaits write operation to finish.
4174
+ * Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
4175
+ * @param {Path} path being acted upon
4176
+ * @param {Number} threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
4177
+ * @param {EventName} event
4178
+ * @param {Function} awfEmit Callback to be called when ready for event to be emitted.
4179
+ */
4180
+ _awaitWriteFinish(path, threshold, event, awfEmit) {
4181
+ let timeoutHandler;
4182
+
4183
+ let fullPath = path;
4184
+ if (this.options.cwd && !sysPath.isAbsolute(path)) {
4185
+ fullPath = sysPath.join(this.options.cwd, path);
4186
+ }
4187
+
4188
+ const now = new Date();
4189
+
4190
+ const awaitWriteFinish = (prevStat) => {
4191
+ fs.stat(fullPath, (err, curStat) => {
4192
+ if (err || !this._pendingWrites.has(path)) {
4193
+ if (err && err.code !== 'ENOENT') awfEmit(err);
4194
+ return;
4195
+ }
4196
+
4197
+ const now = Number(new Date());
4198
+
4199
+ if (prevStat && curStat.size !== prevStat.size) {
4200
+ this._pendingWrites.get(path).lastChange = now;
4201
+ }
4202
+ const pw = this._pendingWrites.get(path);
4203
+ const df = now - pw.lastChange;
4204
+
4205
+ if (df >= threshold) {
4206
+ this._pendingWrites.delete(path);
4207
+ awfEmit(undefined, curStat);
4208
+ } else {
4209
+ timeoutHandler = setTimeout(
4210
+ awaitWriteFinish,
4211
+ this.options.awaitWriteFinish.pollInterval,
4212
+ curStat
4213
+ );
4214
+ }
4215
+ });
4216
+ };
4217
+
4218
+ if (!this._pendingWrites.has(path)) {
4219
+ this._pendingWrites.set(path, {
4220
+ lastChange: now,
4221
+ cancelWait: () => {
4222
+ this._pendingWrites.delete(path);
4223
+ clearTimeout(timeoutHandler);
4224
+ return event;
4225
+ }
4226
+ });
4227
+ timeoutHandler = setTimeout(
4228
+ awaitWriteFinish,
4229
+ this.options.awaitWriteFinish.pollInterval
4230
+ );
4231
+ }
4232
+ }
4233
+
4234
+ _getGlobIgnored() {
4235
+ return [...this._ignoredPaths.values()];
4236
+ }
4237
+
4238
+ /**
4239
+ * Determines whether user has asked to ignore this path.
4240
+ * @param {Path} path filepath or dir
4241
+ * @param {fs.Stats=} stats result of fs.stat
4242
+ * @returns {Boolean}
4243
+ */
4244
+ _isIgnored(path, stats) {
4245
+ if (this.options.atomic && DOT_RE.test(path)) return true;
4246
+ if (!this._userIgnored) {
4247
+ const {cwd} = this.options;
4248
+ const ign = this.options.ignored;
4249
+
4250
+ const ignored = ign && ign.map(normalizeIgnored(cwd));
4251
+ const paths = arrify(ignored)
4252
+ .filter((path) => typeof path === STRING_TYPE && !isGlob(path))
4253
+ .map((path) => path + SLASH_GLOBSTAR);
4254
+ const list = this._getGlobIgnored().map(normalizeIgnored(cwd)).concat(ignored, paths);
4255
+ this._userIgnored = anymatch(list, undefined, ANYMATCH_OPTS);
4256
+ }
4257
+
4258
+ return this._userIgnored([path, stats]);
4259
+ }
4260
+
4261
+ _isntIgnored(path, stat) {
4262
+ return !this._isIgnored(path, stat);
4263
+ }
4264
+
4265
+ /**
4266
+ * Provides a set of common helpers and properties relating to symlink and glob handling.
4267
+ * @param {Path} path file, directory, or glob pattern being watched
4268
+ * @param {Number=} depth at any depth > 0, this isn't a glob
4269
+ * @returns {WatchHelper} object containing helpers for this path
4270
+ */
4271
+ _getWatchHelpers(path, depth) {
4272
+ const watchPath = depth || this.options.disableGlobbing || !isGlob(path) ? path : globParent(path);
4273
+ const follow = this.options.followSymlinks;
4274
+
4275
+ return new WatchHelper(path, watchPath, follow, this);
4276
+ }
4277
+
4278
+ // Directory helpers
4279
+ // -----------------
4280
+
4281
+ /**
4282
+ * Provides directory tracking objects
4283
+ * @param {String} directory path of the directory
4284
+ * @returns {DirEntry} the directory's tracking object
4285
+ */
4286
+ _getWatchedDir(directory) {
4287
+ if (!this._boundRemove) this._boundRemove = this._remove.bind(this);
4288
+ const dir = sysPath.resolve(directory);
4289
+ if (!this._watched.has(dir)) this._watched.set(dir, new DirEntry(dir, this._boundRemove));
4290
+ return this._watched.get(dir);
4291
+ }
4292
+
4293
+ // File helpers
4294
+ // ------------
4295
+
4296
+ /**
4297
+ * Check for read permissions.
4298
+ * Based on this answer on SO: https://stackoverflow.com/a/11781404/1358405
4299
+ * @param {fs.Stats} stats - object, result of fs_stat
4300
+ * @returns {Boolean} indicates whether the file can be read
4301
+ */
4302
+ _hasReadPermissions(stats) {
4303
+ if (this.options.ignorePermissionErrors) return true;
4304
+
4305
+ // stats.mode may be bigint
4306
+ const md = stats && Number.parseInt(stats.mode, 10);
4307
+ const st = md & 0o777;
4308
+ const it = Number.parseInt(st.toString(8)[0], 10);
4309
+ return Boolean(4 & it);
4310
+ }
4311
+
4312
+ /**
4313
+ * Handles emitting unlink events for
4314
+ * files and directories, and via recursion, for
4315
+ * files and directories within directories that are unlinked
4316
+ * @param {String} directory within which the following item is located
4317
+ * @param {String} item base path of item/directory
4318
+ * @returns {void}
4319
+ */
4320
+ _remove(directory, item, isDirectory) {
4321
+ // if what is being deleted is a directory, get that directory's paths
4322
+ // for recursive deleting and cleaning of watched object
4323
+ // if it is not a directory, nestedDirectoryChildren will be empty array
4324
+ const path = sysPath.join(directory, item);
4325
+ const fullPath = sysPath.resolve(path);
4326
+ isDirectory = isDirectory != null
4327
+ ? isDirectory
4328
+ : this._watched.has(path) || this._watched.has(fullPath);
4329
+
4330
+ // prevent duplicate handling in case of arriving here nearly simultaneously
4331
+ // via multiple paths (such as _handleFile and _handleDir)
4332
+ if (!this._throttle('remove', path, 100)) return;
4333
+
4334
+ // if the only watched file is removed, watch for its return
4335
+ if (!isDirectory && !this.options.useFsEvents && this._watched.size === 1) {
4336
+ this.add(directory, item, true);
4337
+ }
4338
+
4339
+ // This will create a new entry in the watched object in either case
4340
+ // so we got to do the directory check beforehand
4341
+ const wp = this._getWatchedDir(path);
4342
+ const nestedDirectoryChildren = wp.getChildren();
4343
+
4344
+ // Recursively remove children directories / files.
4345
+ nestedDirectoryChildren.forEach(nested => this._remove(path, nested));
4346
+
4347
+ // Check if item was on the watched list and remove it
4348
+ const parent = this._getWatchedDir(directory);
4349
+ const wasTracked = parent.has(item);
4350
+ parent.remove(item);
4351
+
4352
+ // Fixes issue #1042 -> Relative paths were detected and added as symlinks
4353
+ // (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
4354
+ // but never removed from the map in case the path was deleted.
4355
+ // This leads to an incorrect state if the path was recreated:
4356
+ // https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
4357
+ if (this._symlinkPaths.has(fullPath)) {
4358
+ this._symlinkPaths.delete(fullPath);
4359
+ }
4360
+
4361
+ // If we wait for this file to be fully written, cancel the wait.
4362
+ let relPath = path;
4363
+ if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
4364
+ if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
4365
+ const event = this._pendingWrites.get(relPath).cancelWait();
4366
+ if (event === EV_ADD) return;
4367
+ }
4368
+
4369
+ // The Entry will either be a directory that just got removed
4370
+ // or a bogus entry to a file, in either case we have to remove it
4371
+ this._watched.delete(path);
4372
+ this._watched.delete(fullPath);
4373
+ const eventName = isDirectory ? EV_UNLINK_DIR : EV_UNLINK;
4374
+ if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);
4375
+
4376
+ // Avoid conflicts if we later create another file with the same name
4377
+ if (!this.options.useFsEvents) {
4378
+ this._closePath(path);
4379
+ }
4380
+ }
4381
+
4382
+ /**
4383
+ * Closes all watchers for a path
4384
+ * @param {Path} path
4385
+ */
4386
+ _closePath(path) {
4387
+ this._closeFile(path);
4388
+ const dir = sysPath.dirname(path);
4389
+ this._getWatchedDir(dir).remove(sysPath.basename(path));
4390
+ }
4391
+
4392
+ /**
4393
+ * Closes only file-specific watchers
4394
+ * @param {Path} path
4395
+ */
4396
+ _closeFile(path) {
4397
+ const closers = this._closers.get(path);
4398
+ if (!closers) return;
4399
+ closers.forEach(closer => closer());
4400
+ this._closers.delete(path);
4401
+ }
4402
+
4403
+ /**
4404
+ *
4405
+ * @param {Path} path
4406
+ * @param {Function} closer
4407
+ */
4408
+ _addPathCloser(path, closer) {
4409
+ if (!closer) return;
4410
+ let list = this._closers.get(path);
4411
+ if (!list) {
4412
+ list = [];
4413
+ this._closers.set(path, list);
4414
+ }
4415
+ list.push(closer);
4416
+ }
4417
+
4418
+ _readdirp(root, opts) {
4419
+ if (this.closed) return;
4420
+ const options = {type: EV_ALL, alwaysStat: true, lstat: true, ...opts};
4421
+ let stream = readdirp(root, options);
4422
+ this._streams.add(stream);
4423
+ stream.once(STR_CLOSE, () => {
4424
+ stream = undefined;
4425
+ });
4426
+ stream.once(STR_END, () => {
4427
+ if (stream) {
4428
+ this._streams.delete(stream);
4429
+ stream = undefined;
4430
+ }
4431
+ });
4432
+ return stream;
4433
+ }
4434
+
4435
+ }
4436
+
4437
+ // Export FSWatcher class
4438
+ chokidar$1.FSWatcher = FSWatcher;
4439
+
4440
+ /**
4441
+ * Instantiates watcher with paths to be tracked.
4442
+ * @param {String|Array<String>} paths file/directory paths and/or globs
4443
+ * @param {Object=} options chokidar opts
4444
+ * @returns an instance of FSWatcher for chaining.
4445
+ */
4446
+ const watch = (paths, options) => {
4447
+ const watcher = new FSWatcher(options);
4448
+ watcher.add(paths);
4449
+ return watcher;
4450
+ };
4451
+
4452
+ chokidar$1.watch = watch;
4453
+
4454
+ var chokidar = chokidar$1;
4455
+
4456
+ exports.chokidar = chokidar;
4457
+ //# sourceMappingURL=index.js.map