@sanity/pkg-utils 1.12.0 → 1.13.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.
- package/dist/_chunks/{build-8b5bd627.js → build-36a16057.js} +2 -2
- package/dist/_chunks/build-36a16057.js.map +1 -0
- package/dist/_chunks/{buildAction-87c64945.js → buildAction-d4c2a5d2.js} +4 -6
- package/dist/_chunks/{buildAction-87c64945.js.map → buildAction-d4c2a5d2.js.map} +1 -1
- package/dist/_chunks/index-340fbb6a.js +774 -0
- package/dist/_chunks/index-340fbb6a.js.map +1 -0
- package/dist/_chunks/{watch-ccb7daf2.js → watch-41c2ea71.js} +2 -2
- package/dist/_chunks/watch-41c2ea71.js.map +1 -0
- package/dist/_chunks/{watchAction-b7c1e241.js → watchAction-fea46c01.js} +4 -6
- package/dist/_chunks/{watchAction-b7c1e241.js.map → watchAction-fea46c01.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +10 -0
- package/dist/index.esm.js +74 -3532
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/node/_core/config/types.ts +12 -0
- package/src/node/_resolveBuildTasks.ts +1 -1
- package/src/node/_resolveWatchTasks.ts +1 -1
- package/src/node/_tasks/dts/_extractTypes.ts +14 -14
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +2 -0
- package/dist/_chunks/build-8b5bd627.js.map +0 -1
- package/dist/_chunks/index-4a1fe6d6.js +0 -4239
- package/dist/_chunks/index-4a1fe6d6.js.map +0 -1
- package/dist/_chunks/watch-ccb7daf2.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -10,19 +10,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
10
10
|
|
|
11
11
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
12
|
|
|
13
|
-
import path
|
|
13
|
+
import path from 'path';
|
|
14
14
|
import { register } from 'esbuild-register/dist/node';
|
|
15
15
|
import pkgUp from 'pkg-up';
|
|
16
|
-
import fs
|
|
16
|
+
import fs, { stat, readFile } from 'fs/promises';
|
|
17
17
|
import findConfig from 'find-config';
|
|
18
18
|
import { z, ZodError } from 'zod';
|
|
19
19
|
import chalk from 'chalk';
|
|
20
20
|
import ts from 'typescript';
|
|
21
|
-
import fs$
|
|
21
|
+
import fs$1, { statSync } from 'fs';
|
|
22
22
|
import { Observable, switchMap } from 'rxjs';
|
|
23
23
|
import { promisify } from 'util';
|
|
24
|
-
import
|
|
25
|
-
import require$$3 from 'events';
|
|
24
|
+
import rimrafCallback from 'rimraf';
|
|
26
25
|
import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
|
|
27
26
|
import mkdirp from 'mkdirp';
|
|
28
27
|
import prettier from 'prettier';
|
|
@@ -69,10 +68,10 @@ async function _findConfigFile(cwd) {
|
|
|
69
68
|
cwd
|
|
70
69
|
});
|
|
71
70
|
if (!pkgJsonPath) return void 0;
|
|
72
|
-
const pkgPath = path
|
|
71
|
+
const pkgPath = path.dirname(pkgJsonPath);
|
|
73
72
|
|
|
74
73
|
for (const fileName of CONFIG_FILE_NAMES) {
|
|
75
|
-
const configPath = path
|
|
74
|
+
const configPath = path.resolve(pkgPath, fileName);
|
|
76
75
|
const exists = await _fileExists$1(configPath);
|
|
77
76
|
|
|
78
77
|
if (exists) {
|
|
@@ -100,7 +99,7 @@ async function _loadConfig(options) {
|
|
|
100
99
|
cwd
|
|
101
100
|
});
|
|
102
101
|
if (!pkgPath) return void 0;
|
|
103
|
-
const root = path
|
|
102
|
+
const root = path.dirname(pkgPath);
|
|
104
103
|
const configFile = await _findConfigFile(root);
|
|
105
104
|
|
|
106
105
|
if (!configFile) {
|
|
@@ -190,7 +189,7 @@ async function _loadPkg(options) {
|
|
|
190
189
|
cwd
|
|
191
190
|
});
|
|
192
191
|
if (!pkgPath) throw new Error("no package.json found");
|
|
193
|
-
const buf = await fs
|
|
192
|
+
const buf = await fs.readFile(pkgPath);
|
|
194
193
|
return _validatePkg(JSON.parse(buf.toString()));
|
|
195
194
|
}
|
|
196
195
|
|
|
@@ -364,7 +363,7 @@ function _resolveBuildTasks(ctx) {
|
|
|
364
363
|
}
|
|
365
364
|
|
|
366
365
|
for (const exp of exports) {
|
|
367
|
-
const importId = path
|
|
366
|
+
const importId = path.join(pkg.name, exp._path);
|
|
368
367
|
|
|
369
368
|
if (exp.types) {
|
|
370
369
|
dtsTask.entries.push({
|
|
@@ -450,7 +449,7 @@ function _resolveBuildTasks(ctx) {
|
|
|
450
449
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
451
450
|
|
|
452
451
|
if (relativeTargetPath) {
|
|
453
|
-
fs$
|
|
452
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
454
453
|
}
|
|
455
454
|
}
|
|
456
455
|
}
|
|
@@ -471,7 +470,7 @@ function _printExtractMessages(ctx, messages) {
|
|
|
471
470
|
}
|
|
472
471
|
|
|
473
472
|
for (const msg of warnings) {
|
|
474
|
-
const sourceFilePath = msg.sourceFilePath && path
|
|
473
|
+
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
475
474
|
|
|
476
475
|
if (msg.messageId === "TS6307") {
|
|
477
476
|
continue;
|
|
@@ -487,7 +486,7 @@ function _printExtractMessages(ctx, messages) {
|
|
|
487
486
|
}
|
|
488
487
|
|
|
489
488
|
for (const msg of errors) {
|
|
490
|
-
const sourceFilePath = msg.sourceFilePath && path
|
|
489
|
+
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
491
490
|
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.red("error"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
492
491
|
}
|
|
493
492
|
|
|
@@ -496,3475 +495,6 @@ function _printExtractMessages(ctx, messages) {
|
|
|
496
495
|
}
|
|
497
496
|
}
|
|
498
497
|
|
|
499
|
-
var old = {};
|
|
500
|
-
var hasRequiredOld;
|
|
501
|
-
|
|
502
|
-
function requireOld() {
|
|
503
|
-
if (hasRequiredOld) return old;
|
|
504
|
-
hasRequiredOld = 1; // Copyright Joyent, Inc. and other Node contributors.
|
|
505
|
-
//
|
|
506
|
-
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
507
|
-
// copy of this software and associated documentation files (the
|
|
508
|
-
// "Software"), to deal in the Software without restriction, including
|
|
509
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
|
510
|
-
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
511
|
-
// persons to whom the Software is furnished to do so, subject to the
|
|
512
|
-
// following conditions:
|
|
513
|
-
//
|
|
514
|
-
// The above copyright notice and this permission notice shall be included
|
|
515
|
-
// in all copies or substantial portions of the Software.
|
|
516
|
-
//
|
|
517
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
518
|
-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
519
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
520
|
-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
521
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
522
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
523
|
-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
524
|
-
|
|
525
|
-
var pathModule = path$1;
|
|
526
|
-
var isWindows = process.platform === 'win32';
|
|
527
|
-
var fs = fs$2; // JavaScript implementation of realpath, ported from node pre-v6
|
|
528
|
-
|
|
529
|
-
var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
|
|
530
|
-
|
|
531
|
-
function rethrow() {
|
|
532
|
-
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
|
|
533
|
-
// is fairly slow to generate.
|
|
534
|
-
var callback;
|
|
535
|
-
|
|
536
|
-
if (DEBUG) {
|
|
537
|
-
var backtrace = new Error();
|
|
538
|
-
callback = debugCallback;
|
|
539
|
-
} else callback = missingCallback;
|
|
540
|
-
|
|
541
|
-
return callback;
|
|
542
|
-
|
|
543
|
-
function debugCallback(err) {
|
|
544
|
-
if (err) {
|
|
545
|
-
backtrace.message = err.message;
|
|
546
|
-
err = backtrace;
|
|
547
|
-
missingCallback(err);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
function missingCallback(err) {
|
|
552
|
-
if (err) {
|
|
553
|
-
if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
|
|
554
|
-
else if (!process.noDeprecation) {
|
|
555
|
-
var msg = 'fs: missing callback ' + (err.stack || err.message);
|
|
556
|
-
if (process.traceDeprecation) console.trace(msg);else console.error(msg);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
function maybeCallback(cb) {
|
|
563
|
-
return typeof cb === 'function' ? cb : rethrow();
|
|
564
|
-
} // Regexp that finds the next partion of a (partial) path
|
|
565
|
-
// result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (isWindows) {
|
|
569
|
-
var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
|
|
570
|
-
} else {
|
|
571
|
-
var nextPartRe = /(.*?)(?:[\/]+|$)/g;
|
|
572
|
-
} // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (isWindows) {
|
|
576
|
-
var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
|
|
577
|
-
} else {
|
|
578
|
-
var splitRootRe = /^[\/]*/;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
old.realpathSync = function realpathSync(p, cache) {
|
|
582
|
-
// make p is absolute
|
|
583
|
-
p = pathModule.resolve(p);
|
|
584
|
-
|
|
585
|
-
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
|
|
586
|
-
return cache[p];
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
var original = p,
|
|
590
|
-
seenLinks = {},
|
|
591
|
-
knownHard = {}; // current character position in p
|
|
592
|
-
|
|
593
|
-
var pos; // the partial path so far, including a trailing slash if any
|
|
594
|
-
|
|
595
|
-
var current; // the partial path without a trailing slash (except when pointing at a root)
|
|
596
|
-
|
|
597
|
-
var base; // the partial path scanned in the previous round, with slash
|
|
598
|
-
|
|
599
|
-
var previous;
|
|
600
|
-
start();
|
|
601
|
-
|
|
602
|
-
function start() {
|
|
603
|
-
// Skip over roots
|
|
604
|
-
var m = splitRootRe.exec(p);
|
|
605
|
-
pos = m[0].length;
|
|
606
|
-
current = m[0];
|
|
607
|
-
base = m[0];
|
|
608
|
-
previous = ''; // On windows, check that the root exists. On unix there is no need.
|
|
609
|
-
|
|
610
|
-
if (isWindows && !knownHard[base]) {
|
|
611
|
-
fs.lstatSync(base);
|
|
612
|
-
knownHard[base] = true;
|
|
613
|
-
}
|
|
614
|
-
} // walk down the path, swapping out linked pathparts for their real
|
|
615
|
-
// values
|
|
616
|
-
// NB: p.length changes.
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
while (pos < p.length) {
|
|
620
|
-
// find the next part
|
|
621
|
-
nextPartRe.lastIndex = pos;
|
|
622
|
-
var result = nextPartRe.exec(p);
|
|
623
|
-
previous = current;
|
|
624
|
-
current += result[0];
|
|
625
|
-
base = previous + result[1];
|
|
626
|
-
pos = nextPartRe.lastIndex; // continue if not a symlink
|
|
627
|
-
|
|
628
|
-
if (knownHard[base] || cache && cache[base] === base) {
|
|
629
|
-
continue;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
var resolvedLink;
|
|
633
|
-
|
|
634
|
-
if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
|
|
635
|
-
// some known symbolic link. no need to stat again.
|
|
636
|
-
resolvedLink = cache[base];
|
|
637
|
-
} else {
|
|
638
|
-
var stat = fs.lstatSync(base);
|
|
639
|
-
|
|
640
|
-
if (!stat.isSymbolicLink()) {
|
|
641
|
-
knownHard[base] = true;
|
|
642
|
-
if (cache) cache[base] = base;
|
|
643
|
-
continue;
|
|
644
|
-
} // read the link if it wasn't read before
|
|
645
|
-
// dev/ino always return 0 on windows, so skip the check.
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
var linkTarget = null;
|
|
649
|
-
|
|
650
|
-
if (!isWindows) {
|
|
651
|
-
var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
|
|
652
|
-
|
|
653
|
-
if (seenLinks.hasOwnProperty(id)) {
|
|
654
|
-
linkTarget = seenLinks[id];
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
if (linkTarget === null) {
|
|
659
|
-
fs.statSync(base);
|
|
660
|
-
linkTarget = fs.readlinkSync(base);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
resolvedLink = pathModule.resolve(previous, linkTarget); // track this, if given a cache.
|
|
664
|
-
|
|
665
|
-
if (cache) cache[base] = resolvedLink;
|
|
666
|
-
if (!isWindows) seenLinks[id] = linkTarget;
|
|
667
|
-
} // resolve the link, then start over
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
p = pathModule.resolve(resolvedLink, p.slice(pos));
|
|
671
|
-
start();
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
if (cache) cache[original] = p;
|
|
675
|
-
return p;
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
old.realpath = function realpath(p, cache, cb) {
|
|
679
|
-
if (typeof cb !== 'function') {
|
|
680
|
-
cb = maybeCallback(cache);
|
|
681
|
-
cache = null;
|
|
682
|
-
} // make p is absolute
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
p = pathModule.resolve(p);
|
|
686
|
-
|
|
687
|
-
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
|
|
688
|
-
return process.nextTick(cb.bind(null, null, cache[p]));
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
var original = p,
|
|
692
|
-
seenLinks = {},
|
|
693
|
-
knownHard = {}; // current character position in p
|
|
694
|
-
|
|
695
|
-
var pos; // the partial path so far, including a trailing slash if any
|
|
696
|
-
|
|
697
|
-
var current; // the partial path without a trailing slash (except when pointing at a root)
|
|
698
|
-
|
|
699
|
-
var base; // the partial path scanned in the previous round, with slash
|
|
700
|
-
|
|
701
|
-
var previous;
|
|
702
|
-
start();
|
|
703
|
-
|
|
704
|
-
function start() {
|
|
705
|
-
// Skip over roots
|
|
706
|
-
var m = splitRootRe.exec(p);
|
|
707
|
-
pos = m[0].length;
|
|
708
|
-
current = m[0];
|
|
709
|
-
base = m[0];
|
|
710
|
-
previous = ''; // On windows, check that the root exists. On unix there is no need.
|
|
711
|
-
|
|
712
|
-
if (isWindows && !knownHard[base]) {
|
|
713
|
-
fs.lstat(base, function (err) {
|
|
714
|
-
if (err) return cb(err);
|
|
715
|
-
knownHard[base] = true;
|
|
716
|
-
LOOP();
|
|
717
|
-
});
|
|
718
|
-
} else {
|
|
719
|
-
process.nextTick(LOOP);
|
|
720
|
-
}
|
|
721
|
-
} // walk down the path, swapping out linked pathparts for their real
|
|
722
|
-
// values
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
function LOOP() {
|
|
726
|
-
// stop if scanned past end of path
|
|
727
|
-
if (pos >= p.length) {
|
|
728
|
-
if (cache) cache[original] = p;
|
|
729
|
-
return cb(null, p);
|
|
730
|
-
} // find the next part
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
nextPartRe.lastIndex = pos;
|
|
734
|
-
var result = nextPartRe.exec(p);
|
|
735
|
-
previous = current;
|
|
736
|
-
current += result[0];
|
|
737
|
-
base = previous + result[1];
|
|
738
|
-
pos = nextPartRe.lastIndex; // continue if not a symlink
|
|
739
|
-
|
|
740
|
-
if (knownHard[base] || cache && cache[base] === base) {
|
|
741
|
-
return process.nextTick(LOOP);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
|
|
745
|
-
// known symbolic link. no need to stat again.
|
|
746
|
-
return gotResolvedLink(cache[base]);
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
return fs.lstat(base, gotStat);
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
function gotStat(err, stat) {
|
|
753
|
-
if (err) return cb(err); // if not a symlink, skip to the next path part
|
|
754
|
-
|
|
755
|
-
if (!stat.isSymbolicLink()) {
|
|
756
|
-
knownHard[base] = true;
|
|
757
|
-
if (cache) cache[base] = base;
|
|
758
|
-
return process.nextTick(LOOP);
|
|
759
|
-
} // stat & read the link if not read before
|
|
760
|
-
// call gotTarget as soon as the link target is known
|
|
761
|
-
// dev/ino always return 0 on windows, so skip the check.
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
if (!isWindows) {
|
|
765
|
-
var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
|
|
766
|
-
|
|
767
|
-
if (seenLinks.hasOwnProperty(id)) {
|
|
768
|
-
return gotTarget(null, seenLinks[id], base);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
fs.stat(base, function (err) {
|
|
773
|
-
if (err) return cb(err);
|
|
774
|
-
fs.readlink(base, function (err, target) {
|
|
775
|
-
if (!isWindows) seenLinks[id] = target;
|
|
776
|
-
gotTarget(err, target);
|
|
777
|
-
});
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
function gotTarget(err, target, base) {
|
|
782
|
-
if (err) return cb(err);
|
|
783
|
-
var resolvedLink = pathModule.resolve(previous, target);
|
|
784
|
-
if (cache) cache[base] = resolvedLink;
|
|
785
|
-
gotResolvedLink(resolvedLink);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
function gotResolvedLink(resolvedLink) {
|
|
789
|
-
// resolve the link, then start over
|
|
790
|
-
p = pathModule.resolve(resolvedLink, p.slice(pos));
|
|
791
|
-
start();
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
return old;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
var fs_realpath;
|
|
799
|
-
var hasRequiredFs_realpath;
|
|
800
|
-
|
|
801
|
-
function requireFs_realpath() {
|
|
802
|
-
if (hasRequiredFs_realpath) return fs_realpath;
|
|
803
|
-
hasRequiredFs_realpath = 1;
|
|
804
|
-
fs_realpath = realpath;
|
|
805
|
-
realpath.realpath = realpath;
|
|
806
|
-
realpath.sync = realpathSync;
|
|
807
|
-
realpath.realpathSync = realpathSync;
|
|
808
|
-
realpath.monkeypatch = monkeypatch;
|
|
809
|
-
realpath.unmonkeypatch = unmonkeypatch;
|
|
810
|
-
var fs = fs$2;
|
|
811
|
-
var origRealpath = fs.realpath;
|
|
812
|
-
var origRealpathSync = fs.realpathSync;
|
|
813
|
-
var version = process.version;
|
|
814
|
-
var ok = /^v[0-5]\./.test(version);
|
|
815
|
-
var old = requireOld();
|
|
816
|
-
|
|
817
|
-
function newError(er) {
|
|
818
|
-
return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
function realpath(p, cache, cb) {
|
|
822
|
-
if (ok) {
|
|
823
|
-
return origRealpath(p, cache, cb);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
if (typeof cache === 'function') {
|
|
827
|
-
cb = cache;
|
|
828
|
-
cache = null;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
origRealpath(p, cache, function (er, result) {
|
|
832
|
-
if (newError(er)) {
|
|
833
|
-
old.realpath(p, cache, cb);
|
|
834
|
-
} else {
|
|
835
|
-
cb(er, result);
|
|
836
|
-
}
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
function realpathSync(p, cache) {
|
|
841
|
-
if (ok) {
|
|
842
|
-
return origRealpathSync(p, cache);
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
try {
|
|
846
|
-
return origRealpathSync(p, cache);
|
|
847
|
-
} catch (er) {
|
|
848
|
-
if (newError(er)) {
|
|
849
|
-
return old.realpathSync(p, cache);
|
|
850
|
-
} else {
|
|
851
|
-
throw er;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
function monkeypatch() {
|
|
857
|
-
fs.realpath = realpath;
|
|
858
|
-
fs.realpathSync = realpathSync;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
function unmonkeypatch() {
|
|
862
|
-
fs.realpath = origRealpath;
|
|
863
|
-
fs.realpathSync = origRealpathSync;
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
return fs_realpath;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
var concatMap;
|
|
870
|
-
var hasRequiredConcatMap;
|
|
871
|
-
|
|
872
|
-
function requireConcatMap() {
|
|
873
|
-
if (hasRequiredConcatMap) return concatMap;
|
|
874
|
-
hasRequiredConcatMap = 1;
|
|
875
|
-
|
|
876
|
-
concatMap = function (xs, fn) {
|
|
877
|
-
var res = [];
|
|
878
|
-
|
|
879
|
-
for (var i = 0; i < xs.length; i++) {
|
|
880
|
-
var x = fn(xs[i], i);
|
|
881
|
-
if (isArray(x)) res.push.apply(res, x);else res.push(x);
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
return res;
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
var isArray = Array.isArray || function (xs) {
|
|
888
|
-
return Object.prototype.toString.call(xs) === '[object Array]';
|
|
889
|
-
};
|
|
890
|
-
|
|
891
|
-
return concatMap;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
var balancedMatch;
|
|
895
|
-
var hasRequiredBalancedMatch;
|
|
896
|
-
|
|
897
|
-
function requireBalancedMatch() {
|
|
898
|
-
if (hasRequiredBalancedMatch) return balancedMatch;
|
|
899
|
-
hasRequiredBalancedMatch = 1;
|
|
900
|
-
balancedMatch = balanced;
|
|
901
|
-
|
|
902
|
-
function balanced(a, b, str) {
|
|
903
|
-
if (a instanceof RegExp) a = maybeMatch(a, str);
|
|
904
|
-
if (b instanceof RegExp) b = maybeMatch(b, str);
|
|
905
|
-
var r = range(a, b, str);
|
|
906
|
-
return r && {
|
|
907
|
-
start: r[0],
|
|
908
|
-
end: r[1],
|
|
909
|
-
pre: str.slice(0, r[0]),
|
|
910
|
-
body: str.slice(r[0] + a.length, r[1]),
|
|
911
|
-
post: str.slice(r[1] + b.length)
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
function maybeMatch(reg, str) {
|
|
916
|
-
var m = str.match(reg);
|
|
917
|
-
return m ? m[0] : null;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
balanced.range = range;
|
|
921
|
-
|
|
922
|
-
function range(a, b, str) {
|
|
923
|
-
var begs, beg, left, right, result;
|
|
924
|
-
var ai = str.indexOf(a);
|
|
925
|
-
var bi = str.indexOf(b, ai + 1);
|
|
926
|
-
var i = ai;
|
|
927
|
-
|
|
928
|
-
if (ai >= 0 && bi > 0) {
|
|
929
|
-
if (a === b) {
|
|
930
|
-
return [ai, bi];
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
begs = [];
|
|
934
|
-
left = str.length;
|
|
935
|
-
|
|
936
|
-
while (i >= 0 && !result) {
|
|
937
|
-
if (i == ai) {
|
|
938
|
-
begs.push(i);
|
|
939
|
-
ai = str.indexOf(a, i + 1);
|
|
940
|
-
} else if (begs.length == 1) {
|
|
941
|
-
result = [begs.pop(), bi];
|
|
942
|
-
} else {
|
|
943
|
-
beg = begs.pop();
|
|
944
|
-
|
|
945
|
-
if (beg < left) {
|
|
946
|
-
left = beg;
|
|
947
|
-
right = bi;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
bi = str.indexOf(b, i + 1);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
i = ai < bi && ai >= 0 ? ai : bi;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
if (begs.length) {
|
|
957
|
-
result = [left, right];
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
return result;
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
return balancedMatch;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
var braceExpansion;
|
|
968
|
-
var hasRequiredBraceExpansion;
|
|
969
|
-
|
|
970
|
-
function requireBraceExpansion() {
|
|
971
|
-
if (hasRequiredBraceExpansion) return braceExpansion;
|
|
972
|
-
hasRequiredBraceExpansion = 1;
|
|
973
|
-
var concatMap = requireConcatMap();
|
|
974
|
-
var balanced = requireBalancedMatch();
|
|
975
|
-
braceExpansion = expandTop;
|
|
976
|
-
var escSlash = '\0SLASH' + Math.random() + '\0';
|
|
977
|
-
var escOpen = '\0OPEN' + Math.random() + '\0';
|
|
978
|
-
var escClose = '\0CLOSE' + Math.random() + '\0';
|
|
979
|
-
var escComma = '\0COMMA' + Math.random() + '\0';
|
|
980
|
-
var escPeriod = '\0PERIOD' + Math.random() + '\0';
|
|
981
|
-
|
|
982
|
-
function numeric(str) {
|
|
983
|
-
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
function escapeBraces(str) {
|
|
987
|
-
return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
function unescapeBraces(str) {
|
|
991
|
-
return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
|
|
992
|
-
} // Basically just str.split(","), but handling cases
|
|
993
|
-
// where we have nested braced sections, which should be
|
|
994
|
-
// treated as individual members, like {a,{b,c},d}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
function parseCommaParts(str) {
|
|
998
|
-
if (!str) return [''];
|
|
999
|
-
var parts = [];
|
|
1000
|
-
var m = balanced('{', '}', str);
|
|
1001
|
-
if (!m) return str.split(',');
|
|
1002
|
-
var pre = m.pre;
|
|
1003
|
-
var body = m.body;
|
|
1004
|
-
var post = m.post;
|
|
1005
|
-
var p = pre.split(',');
|
|
1006
|
-
p[p.length - 1] += '{' + body + '}';
|
|
1007
|
-
var postParts = parseCommaParts(post);
|
|
1008
|
-
|
|
1009
|
-
if (post.length) {
|
|
1010
|
-
p[p.length - 1] += postParts.shift();
|
|
1011
|
-
p.push.apply(p, postParts);
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
parts.push.apply(parts, p);
|
|
1015
|
-
return parts;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
function expandTop(str) {
|
|
1019
|
-
if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
|
|
1020
|
-
// Anything starting with {} will have the first two bytes preserved
|
|
1021
|
-
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
1022
|
-
// but a{},b}c will be expanded to [a}c,abc].
|
|
1023
|
-
// One could argue that this is a bug in Bash, but since the goal of
|
|
1024
|
-
// this module is to match Bash's rules, we escape a leading {}
|
|
1025
|
-
|
|
1026
|
-
if (str.substr(0, 2) === '{}') {
|
|
1027
|
-
str = '\\{\\}' + str.substr(2);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
return expand(escapeBraces(str), true).map(unescapeBraces);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
function embrace(str) {
|
|
1034
|
-
return '{' + str + '}';
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
function isPadded(el) {
|
|
1038
|
-
return /^-?0\d/.test(el);
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
function lte(i, y) {
|
|
1042
|
-
return i <= y;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
function gte(i, y) {
|
|
1046
|
-
return i >= y;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
function expand(str, isTop) {
|
|
1050
|
-
var expansions = [];
|
|
1051
|
-
var m = balanced('{', '}', str);
|
|
1052
|
-
if (!m || /\$$/.test(m.pre)) return [str];
|
|
1053
|
-
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
1054
|
-
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
1055
|
-
var isSequence = isNumericSequence || isAlphaSequence;
|
|
1056
|
-
var isOptions = m.body.indexOf(',') >= 0;
|
|
1057
|
-
|
|
1058
|
-
if (!isSequence && !isOptions) {
|
|
1059
|
-
// {a},b}
|
|
1060
|
-
if (m.post.match(/,.*\}/)) {
|
|
1061
|
-
str = m.pre + '{' + m.body + escClose + m.post;
|
|
1062
|
-
return expand(str);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
return [str];
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
var n;
|
|
1069
|
-
|
|
1070
|
-
if (isSequence) {
|
|
1071
|
-
n = m.body.split(/\.\./);
|
|
1072
|
-
} else {
|
|
1073
|
-
n = parseCommaParts(m.body);
|
|
1074
|
-
|
|
1075
|
-
if (n.length === 1) {
|
|
1076
|
-
// x{{a,b}}y ==> x{a}y x{b}y
|
|
1077
|
-
n = expand(n[0], false).map(embrace);
|
|
1078
|
-
|
|
1079
|
-
if (n.length === 1) {
|
|
1080
|
-
var post = m.post.length ? expand(m.post, false) : [''];
|
|
1081
|
-
return post.map(function (p) {
|
|
1082
|
-
return m.pre + n[0] + p;
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
} // at this point, n is the parts, and we know it's not a comma set
|
|
1087
|
-
// with a single entry.
|
|
1088
|
-
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
var pre = m.pre;
|
|
1092
|
-
var post = m.post.length ? expand(m.post, false) : [''];
|
|
1093
|
-
var N;
|
|
1094
|
-
|
|
1095
|
-
if (isSequence) {
|
|
1096
|
-
var x = numeric(n[0]);
|
|
1097
|
-
var y = numeric(n[1]);
|
|
1098
|
-
var width = Math.max(n[0].length, n[1].length);
|
|
1099
|
-
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
|
|
1100
|
-
var test = lte;
|
|
1101
|
-
var reverse = y < x;
|
|
1102
|
-
|
|
1103
|
-
if (reverse) {
|
|
1104
|
-
incr *= -1;
|
|
1105
|
-
test = gte;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
var pad = n.some(isPadded);
|
|
1109
|
-
N = [];
|
|
1110
|
-
|
|
1111
|
-
for (var i = x; test(i, y); i += incr) {
|
|
1112
|
-
var c;
|
|
1113
|
-
|
|
1114
|
-
if (isAlphaSequence) {
|
|
1115
|
-
c = String.fromCharCode(i);
|
|
1116
|
-
if (c === '\\') c = '';
|
|
1117
|
-
} else {
|
|
1118
|
-
c = String(i);
|
|
1119
|
-
|
|
1120
|
-
if (pad) {
|
|
1121
|
-
var need = width - c.length;
|
|
1122
|
-
|
|
1123
|
-
if (need > 0) {
|
|
1124
|
-
var z = new Array(need + 1).join('0');
|
|
1125
|
-
if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
N.push(c);
|
|
1131
|
-
}
|
|
1132
|
-
} else {
|
|
1133
|
-
N = concatMap(n, function (el) {
|
|
1134
|
-
return expand(el, false);
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
for (var j = 0; j < N.length; j++) {
|
|
1139
|
-
for (var k = 0; k < post.length; k++) {
|
|
1140
|
-
var expansion = pre + N[j] + post[k];
|
|
1141
|
-
if (!isTop || isSequence || expansion) expansions.push(expansion);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
return expansions;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
return braceExpansion;
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
var minimatch_1;
|
|
1152
|
-
var hasRequiredMinimatch;
|
|
1153
|
-
|
|
1154
|
-
function requireMinimatch() {
|
|
1155
|
-
if (hasRequiredMinimatch) return minimatch_1;
|
|
1156
|
-
hasRequiredMinimatch = 1;
|
|
1157
|
-
minimatch_1 = minimatch;
|
|
1158
|
-
minimatch.Minimatch = Minimatch;
|
|
1159
|
-
|
|
1160
|
-
var path = function () {
|
|
1161
|
-
try {
|
|
1162
|
-
return require('path');
|
|
1163
|
-
} catch (e) {}
|
|
1164
|
-
}() || {
|
|
1165
|
-
sep: '/'
|
|
1166
|
-
};
|
|
1167
|
-
|
|
1168
|
-
minimatch.sep = path.sep;
|
|
1169
|
-
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
|
|
1170
|
-
var expand = requireBraceExpansion();
|
|
1171
|
-
var plTypes = {
|
|
1172
|
-
'!': {
|
|
1173
|
-
open: '(?:(?!(?:',
|
|
1174
|
-
close: '))[^/]*?)'
|
|
1175
|
-
},
|
|
1176
|
-
'?': {
|
|
1177
|
-
open: '(?:',
|
|
1178
|
-
close: ')?'
|
|
1179
|
-
},
|
|
1180
|
-
'+': {
|
|
1181
|
-
open: '(?:',
|
|
1182
|
-
close: ')+'
|
|
1183
|
-
},
|
|
1184
|
-
'*': {
|
|
1185
|
-
open: '(?:',
|
|
1186
|
-
close: ')*'
|
|
1187
|
-
},
|
|
1188
|
-
'@': {
|
|
1189
|
-
open: '(?:',
|
|
1190
|
-
close: ')'
|
|
1191
|
-
}
|
|
1192
|
-
}; // any single thing other than /
|
|
1193
|
-
// don't need to escape / when using new RegExp()
|
|
1194
|
-
|
|
1195
|
-
var qmark = '[^/]'; // * => any number of characters
|
|
1196
|
-
|
|
1197
|
-
var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
|
|
1198
|
-
// not (^ or / followed by one or two dots followed by $ or /),
|
|
1199
|
-
// followed by anything, any number of times.
|
|
1200
|
-
|
|
1201
|
-
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
|
|
1202
|
-
// followed by anything, any number of times.
|
|
1203
|
-
|
|
1204
|
-
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
|
|
1205
|
-
|
|
1206
|
-
var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
|
|
1207
|
-
|
|
1208
|
-
function charSet(s) {
|
|
1209
|
-
return s.split('').reduce(function (set, c) {
|
|
1210
|
-
set[c] = true;
|
|
1211
|
-
return set;
|
|
1212
|
-
}, {});
|
|
1213
|
-
} // normalizes slashes.
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
var slashSplit = /\/+/;
|
|
1217
|
-
minimatch.filter = filter;
|
|
1218
|
-
|
|
1219
|
-
function filter(pattern, options) {
|
|
1220
|
-
options = options || {};
|
|
1221
|
-
return function (p, i, list) {
|
|
1222
|
-
return minimatch(p, pattern, options);
|
|
1223
|
-
};
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
function ext(a, b) {
|
|
1227
|
-
b = b || {};
|
|
1228
|
-
var t = {};
|
|
1229
|
-
Object.keys(a).forEach(function (k) {
|
|
1230
|
-
t[k] = a[k];
|
|
1231
|
-
});
|
|
1232
|
-
Object.keys(b).forEach(function (k) {
|
|
1233
|
-
t[k] = b[k];
|
|
1234
|
-
});
|
|
1235
|
-
return t;
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
minimatch.defaults = function (def) {
|
|
1239
|
-
if (!def || typeof def !== 'object' || !Object.keys(def).length) {
|
|
1240
|
-
return minimatch;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
var orig = minimatch;
|
|
1244
|
-
|
|
1245
|
-
var m = function minimatch(p, pattern, options) {
|
|
1246
|
-
return orig(p, pattern, ext(def, options));
|
|
1247
|
-
};
|
|
1248
|
-
|
|
1249
|
-
m.Minimatch = function Minimatch(pattern, options) {
|
|
1250
|
-
return new orig.Minimatch(pattern, ext(def, options));
|
|
1251
|
-
};
|
|
1252
|
-
|
|
1253
|
-
m.Minimatch.defaults = function defaults(options) {
|
|
1254
|
-
return orig.defaults(ext(def, options)).Minimatch;
|
|
1255
|
-
};
|
|
1256
|
-
|
|
1257
|
-
m.filter = function filter(pattern, options) {
|
|
1258
|
-
return orig.filter(pattern, ext(def, options));
|
|
1259
|
-
};
|
|
1260
|
-
|
|
1261
|
-
m.defaults = function defaults(options) {
|
|
1262
|
-
return orig.defaults(ext(def, options));
|
|
1263
|
-
};
|
|
1264
|
-
|
|
1265
|
-
m.makeRe = function makeRe(pattern, options) {
|
|
1266
|
-
return orig.makeRe(pattern, ext(def, options));
|
|
1267
|
-
};
|
|
1268
|
-
|
|
1269
|
-
m.braceExpand = function braceExpand(pattern, options) {
|
|
1270
|
-
return orig.braceExpand(pattern, ext(def, options));
|
|
1271
|
-
};
|
|
1272
|
-
|
|
1273
|
-
m.match = function (list, pattern, options) {
|
|
1274
|
-
return orig.match(list, pattern, ext(def, options));
|
|
1275
|
-
};
|
|
1276
|
-
|
|
1277
|
-
return m;
|
|
1278
|
-
};
|
|
1279
|
-
|
|
1280
|
-
Minimatch.defaults = function (def) {
|
|
1281
|
-
return minimatch.defaults(def).Minimatch;
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1284
|
-
function minimatch(p, pattern, options) {
|
|
1285
|
-
assertValidPattern(pattern);
|
|
1286
|
-
if (!options) options = {}; // shortcut: comments match nothing.
|
|
1287
|
-
|
|
1288
|
-
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
1289
|
-
return false;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
return new Minimatch(pattern, options).match(p);
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
function Minimatch(pattern, options) {
|
|
1296
|
-
if (!(this instanceof Minimatch)) {
|
|
1297
|
-
return new Minimatch(pattern, options);
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
assertValidPattern(pattern);
|
|
1301
|
-
if (!options) options = {};
|
|
1302
|
-
pattern = pattern.trim(); // windows support: need to use /, not \
|
|
1303
|
-
|
|
1304
|
-
if (!options.allowWindowsEscape && path.sep !== '/') {
|
|
1305
|
-
pattern = pattern.split(path.sep).join('/');
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
this.options = options;
|
|
1309
|
-
this.set = [];
|
|
1310
|
-
this.pattern = pattern;
|
|
1311
|
-
this.regexp = null;
|
|
1312
|
-
this.negate = false;
|
|
1313
|
-
this.comment = false;
|
|
1314
|
-
this.empty = false;
|
|
1315
|
-
this.partial = !!options.partial; // make the set of regexps etc.
|
|
1316
|
-
|
|
1317
|
-
this.make();
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
Minimatch.prototype.debug = function () {};
|
|
1321
|
-
|
|
1322
|
-
Minimatch.prototype.make = make;
|
|
1323
|
-
|
|
1324
|
-
function make() {
|
|
1325
|
-
var pattern = this.pattern;
|
|
1326
|
-
var options = this.options; // empty patterns and comments match nothing.
|
|
1327
|
-
|
|
1328
|
-
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
1329
|
-
this.comment = true;
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
if (!pattern) {
|
|
1334
|
-
this.empty = true;
|
|
1335
|
-
return;
|
|
1336
|
-
} // step 1: figure out negation, etc.
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
this.parseNegate(); // step 2: expand braces
|
|
1340
|
-
|
|
1341
|
-
var set = this.globSet = this.braceExpand();
|
|
1342
|
-
if (options.debug) this.debug = function debug() {
|
|
1343
|
-
console.error.apply(console, arguments);
|
|
1344
|
-
};
|
|
1345
|
-
this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
|
|
1346
|
-
// matching patterns.
|
|
1347
|
-
// These will be regexps, except in the case of "**", which is
|
|
1348
|
-
// set to the GLOBSTAR object for globstar behavior,
|
|
1349
|
-
// and will not contain any / characters
|
|
1350
|
-
|
|
1351
|
-
set = this.globParts = set.map(function (s) {
|
|
1352
|
-
return s.split(slashSplit);
|
|
1353
|
-
});
|
|
1354
|
-
this.debug(this.pattern, set); // glob --> regexps
|
|
1355
|
-
|
|
1356
|
-
set = set.map(function (s, si, set) {
|
|
1357
|
-
return s.map(this.parse, this);
|
|
1358
|
-
}, this);
|
|
1359
|
-
this.debug(this.pattern, set); // filter out everything that didn't compile properly.
|
|
1360
|
-
|
|
1361
|
-
set = set.filter(function (s) {
|
|
1362
|
-
return s.indexOf(false) === -1;
|
|
1363
|
-
});
|
|
1364
|
-
this.debug(this.pattern, set);
|
|
1365
|
-
this.set = set;
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
Minimatch.prototype.parseNegate = parseNegate;
|
|
1369
|
-
|
|
1370
|
-
function parseNegate() {
|
|
1371
|
-
var pattern = this.pattern;
|
|
1372
|
-
var negate = false;
|
|
1373
|
-
var options = this.options;
|
|
1374
|
-
var negateOffset = 0;
|
|
1375
|
-
if (options.nonegate) return;
|
|
1376
|
-
|
|
1377
|
-
for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
|
|
1378
|
-
negate = !negate;
|
|
1379
|
-
negateOffset++;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
if (negateOffset) this.pattern = pattern.substr(negateOffset);
|
|
1383
|
-
this.negate = negate;
|
|
1384
|
-
} // Brace expansion:
|
|
1385
|
-
// a{b,c}d -> abd acd
|
|
1386
|
-
// a{b,}c -> abc ac
|
|
1387
|
-
// a{0..3}d -> a0d a1d a2d a3d
|
|
1388
|
-
// a{b,c{d,e}f}g -> abg acdfg acefg
|
|
1389
|
-
// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
|
|
1390
|
-
//
|
|
1391
|
-
// Invalid sets are not expanded.
|
|
1392
|
-
// a{2..}b -> a{2..}b
|
|
1393
|
-
// a{b}c -> a{b}c
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
minimatch.braceExpand = function (pattern, options) {
|
|
1397
|
-
return braceExpand(pattern, options);
|
|
1398
|
-
};
|
|
1399
|
-
|
|
1400
|
-
Minimatch.prototype.braceExpand = braceExpand;
|
|
1401
|
-
|
|
1402
|
-
function braceExpand(pattern, options) {
|
|
1403
|
-
if (!options) {
|
|
1404
|
-
if (this instanceof Minimatch) {
|
|
1405
|
-
options = this.options;
|
|
1406
|
-
} else {
|
|
1407
|
-
options = {};
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
|
|
1412
|
-
assertValidPattern(pattern); // Thanks to Yeting Li <https://github.com/yetingli> for
|
|
1413
|
-
// improving this regexp to avoid a ReDOS vulnerability.
|
|
1414
|
-
|
|
1415
|
-
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
1416
|
-
// shortcut. no need to expand.
|
|
1417
|
-
return [pattern];
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
return expand(pattern);
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
1424
|
-
|
|
1425
|
-
var assertValidPattern = function (pattern) {
|
|
1426
|
-
if (typeof pattern !== 'string') {
|
|
1427
|
-
throw new TypeError('invalid pattern');
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
1431
|
-
throw new TypeError('pattern is too long');
|
|
1432
|
-
}
|
|
1433
|
-
}; // parse a component of the expanded set.
|
|
1434
|
-
// At this point, no pattern may contain "/" in it
|
|
1435
|
-
// so we're going to return a 2d array, where each entry is the full
|
|
1436
|
-
// pattern, split on '/', and then turned into a regular expression.
|
|
1437
|
-
// A regexp is made at the end which joins each array with an
|
|
1438
|
-
// escaped /, and another full one which joins each regexp with |.
|
|
1439
|
-
//
|
|
1440
|
-
// Following the lead of Bash 4.1, note that "**" only has special meaning
|
|
1441
|
-
// when it is the *only* thing in a path portion. Otherwise, any series
|
|
1442
|
-
// of * is equivalent to a single *. Globstar behavior is enabled by
|
|
1443
|
-
// default, and can be disabled by setting options.noglobstar.
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
Minimatch.prototype.parse = parse;
|
|
1447
|
-
var SUBPARSE = {};
|
|
1448
|
-
|
|
1449
|
-
function parse(pattern, isSub) {
|
|
1450
|
-
assertValidPattern(pattern);
|
|
1451
|
-
var options = this.options; // shortcuts
|
|
1452
|
-
|
|
1453
|
-
if (pattern === '**') {
|
|
1454
|
-
if (!options.noglobstar) return GLOBSTAR;else pattern = '*';
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
if (pattern === '') return '';
|
|
1458
|
-
var re = '';
|
|
1459
|
-
var hasMagic = !!options.nocase;
|
|
1460
|
-
var escaping = false; // ? => one single character
|
|
1461
|
-
|
|
1462
|
-
var patternListStack = [];
|
|
1463
|
-
var negativeLists = [];
|
|
1464
|
-
var stateChar;
|
|
1465
|
-
var inClass = false;
|
|
1466
|
-
var reClassStart = -1;
|
|
1467
|
-
var classStart = -1; // . and .. never match anything that doesn't start with .,
|
|
1468
|
-
// even when options.dot is set.
|
|
1469
|
-
|
|
1470
|
-
var patternStart = pattern.charAt(0) === '.' ? '' // anything
|
|
1471
|
-
// not (start or / followed by . or .. followed by / or end)
|
|
1472
|
-
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
|
|
1473
|
-
var self = this;
|
|
1474
|
-
|
|
1475
|
-
function clearStateChar() {
|
|
1476
|
-
if (stateChar) {
|
|
1477
|
-
// we had some state-tracking character
|
|
1478
|
-
// that wasn't consumed by this pass.
|
|
1479
|
-
switch (stateChar) {
|
|
1480
|
-
case '*':
|
|
1481
|
-
re += star;
|
|
1482
|
-
hasMagic = true;
|
|
1483
|
-
break;
|
|
1484
|
-
|
|
1485
|
-
case '?':
|
|
1486
|
-
re += qmark;
|
|
1487
|
-
hasMagic = true;
|
|
1488
|
-
break;
|
|
1489
|
-
|
|
1490
|
-
default:
|
|
1491
|
-
re += '\\' + stateChar;
|
|
1492
|
-
break;
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
self.debug('clearStateChar %j %j', stateChar, re);
|
|
1496
|
-
stateChar = false;
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
|
|
1501
|
-
this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
|
|
1502
|
-
|
|
1503
|
-
if (escaping && reSpecials[c]) {
|
|
1504
|
-
re += '\\' + c;
|
|
1505
|
-
escaping = false;
|
|
1506
|
-
continue;
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
switch (c) {
|
|
1510
|
-
/* istanbul ignore next */
|
|
1511
|
-
case '/':
|
|
1512
|
-
{
|
|
1513
|
-
// completely not allowed, even escaped.
|
|
1514
|
-
// Should already be path-split by now.
|
|
1515
|
-
return false;
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
case '\\':
|
|
1519
|
-
clearStateChar();
|
|
1520
|
-
escaping = true;
|
|
1521
|
-
continue;
|
|
1522
|
-
// the various stateChar values
|
|
1523
|
-
// for the "extglob" stuff.
|
|
1524
|
-
|
|
1525
|
-
case '?':
|
|
1526
|
-
case '*':
|
|
1527
|
-
case '+':
|
|
1528
|
-
case '@':
|
|
1529
|
-
case '!':
|
|
1530
|
-
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
|
|
1531
|
-
// the glob [!a] means [^a] in regexp
|
|
1532
|
-
|
|
1533
|
-
if (inClass) {
|
|
1534
|
-
this.debug(' in class');
|
|
1535
|
-
if (c === '!' && i === classStart + 1) c = '^';
|
|
1536
|
-
re += c;
|
|
1537
|
-
continue;
|
|
1538
|
-
} // if we already have a stateChar, then it means
|
|
1539
|
-
// that there was something like ** or +? in there.
|
|
1540
|
-
// Handle the stateChar, then proceed with this one.
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
self.debug('call clearStateChar %j', stateChar);
|
|
1544
|
-
clearStateChar();
|
|
1545
|
-
stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
|
|
1546
|
-
// just clear the statechar *now*, rather than even diving into
|
|
1547
|
-
// the patternList stuff.
|
|
1548
|
-
|
|
1549
|
-
if (options.noext) clearStateChar();
|
|
1550
|
-
continue;
|
|
1551
|
-
|
|
1552
|
-
case '(':
|
|
1553
|
-
if (inClass) {
|
|
1554
|
-
re += '(';
|
|
1555
|
-
continue;
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
if (!stateChar) {
|
|
1559
|
-
re += '\\(';
|
|
1560
|
-
continue;
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
patternListStack.push({
|
|
1564
|
-
type: stateChar,
|
|
1565
|
-
start: i - 1,
|
|
1566
|
-
reStart: re.length,
|
|
1567
|
-
open: plTypes[stateChar].open,
|
|
1568
|
-
close: plTypes[stateChar].close
|
|
1569
|
-
}); // negation is (?:(?!js)[^/]*)
|
|
1570
|
-
|
|
1571
|
-
re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
|
|
1572
|
-
this.debug('plType %j %j', stateChar, re);
|
|
1573
|
-
stateChar = false;
|
|
1574
|
-
continue;
|
|
1575
|
-
|
|
1576
|
-
case ')':
|
|
1577
|
-
if (inClass || !patternListStack.length) {
|
|
1578
|
-
re += '\\)';
|
|
1579
|
-
continue;
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
clearStateChar();
|
|
1583
|
-
hasMagic = true;
|
|
1584
|
-
var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
|
|
1585
|
-
// The others are (?:<pattern>)<type>
|
|
1586
|
-
|
|
1587
|
-
re += pl.close;
|
|
1588
|
-
|
|
1589
|
-
if (pl.type === '!') {
|
|
1590
|
-
negativeLists.push(pl);
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
pl.reEnd = re.length;
|
|
1594
|
-
continue;
|
|
1595
|
-
|
|
1596
|
-
case '|':
|
|
1597
|
-
if (inClass || !patternListStack.length || escaping) {
|
|
1598
|
-
re += '\\|';
|
|
1599
|
-
escaping = false;
|
|
1600
|
-
continue;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
clearStateChar();
|
|
1604
|
-
re += '|';
|
|
1605
|
-
continue;
|
|
1606
|
-
// these are mostly the same in regexp and glob
|
|
1607
|
-
|
|
1608
|
-
case '[':
|
|
1609
|
-
// swallow any state-tracking char before the [
|
|
1610
|
-
clearStateChar();
|
|
1611
|
-
|
|
1612
|
-
if (inClass) {
|
|
1613
|
-
re += '\\' + c;
|
|
1614
|
-
continue;
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
inClass = true;
|
|
1618
|
-
classStart = i;
|
|
1619
|
-
reClassStart = re.length;
|
|
1620
|
-
re += c;
|
|
1621
|
-
continue;
|
|
1622
|
-
|
|
1623
|
-
case ']':
|
|
1624
|
-
// a right bracket shall lose its special
|
|
1625
|
-
// meaning and represent itself in
|
|
1626
|
-
// a bracket expression if it occurs
|
|
1627
|
-
// first in the list. -- POSIX.2 2.8.3.2
|
|
1628
|
-
if (i === classStart + 1 || !inClass) {
|
|
1629
|
-
re += '\\' + c;
|
|
1630
|
-
escaping = false;
|
|
1631
|
-
continue;
|
|
1632
|
-
} // handle the case where we left a class open.
|
|
1633
|
-
// "[z-a]" is valid, equivalent to "\[z-a\]"
|
|
1634
|
-
// split where the last [ was, make sure we don't have
|
|
1635
|
-
// an invalid re. if so, re-walk the contents of the
|
|
1636
|
-
// would-be class to re-translate any characters that
|
|
1637
|
-
// were passed through as-is
|
|
1638
|
-
// TODO: It would probably be faster to determine this
|
|
1639
|
-
// without a try/catch and a new RegExp, but it's tricky
|
|
1640
|
-
// to do safely. For now, this is safe and works.
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
var cs = pattern.substring(classStart + 1, i);
|
|
1644
|
-
|
|
1645
|
-
try {
|
|
1646
|
-
RegExp('[' + cs + ']');
|
|
1647
|
-
} catch (er) {
|
|
1648
|
-
// not a valid class!
|
|
1649
|
-
var sp = this.parse(cs, SUBPARSE);
|
|
1650
|
-
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
|
|
1651
|
-
hasMagic = hasMagic || sp[1];
|
|
1652
|
-
inClass = false;
|
|
1653
|
-
continue;
|
|
1654
|
-
} // finish up the class.
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
hasMagic = true;
|
|
1658
|
-
inClass = false;
|
|
1659
|
-
re += c;
|
|
1660
|
-
continue;
|
|
1661
|
-
|
|
1662
|
-
default:
|
|
1663
|
-
// swallow any state char that wasn't consumed
|
|
1664
|
-
clearStateChar();
|
|
1665
|
-
|
|
1666
|
-
if (escaping) {
|
|
1667
|
-
// no need
|
|
1668
|
-
escaping = false;
|
|
1669
|
-
} else if (reSpecials[c] && !(c === '^' && inClass)) {
|
|
1670
|
-
re += '\\';
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
re += c;
|
|
1674
|
-
} // switch
|
|
1675
|
-
|
|
1676
|
-
} // for
|
|
1677
|
-
// handle the case where we left a class open.
|
|
1678
|
-
// "[abc" is valid, equivalent to "\[abc"
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
if (inClass) {
|
|
1682
|
-
// split where the last [ was, and escape it
|
|
1683
|
-
// this is a huge pita. We now have to re-walk
|
|
1684
|
-
// the contents of the would-be class to re-translate
|
|
1685
|
-
// any characters that were passed through as-is
|
|
1686
|
-
cs = pattern.substr(classStart + 1);
|
|
1687
|
-
sp = this.parse(cs, SUBPARSE);
|
|
1688
|
-
re = re.substr(0, reClassStart) + '\\[' + sp[0];
|
|
1689
|
-
hasMagic = hasMagic || sp[1];
|
|
1690
|
-
} // handle the case where we had a +( thing at the *end*
|
|
1691
|
-
// of the pattern.
|
|
1692
|
-
// each pattern list stack adds 3 chars, and we need to go through
|
|
1693
|
-
// and escape any | chars that were passed through as-is for the regexp.
|
|
1694
|
-
// Go through and escape them, taking care not to double-escape any
|
|
1695
|
-
// | chars that were already escaped.
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
|
|
1699
|
-
var tail = re.slice(pl.reStart + pl.open.length);
|
|
1700
|
-
this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
|
|
1701
|
-
|
|
1702
|
-
tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
|
|
1703
|
-
if (!$2) {
|
|
1704
|
-
// the | isn't already escaped, so escape it.
|
|
1705
|
-
$2 = '\\';
|
|
1706
|
-
} // need to escape all those slashes *again*, without escaping the
|
|
1707
|
-
// one that we need for escaping the | character. As it works out,
|
|
1708
|
-
// escaping an even number of slashes can be done by simply repeating
|
|
1709
|
-
// it exactly after itself. That's why this trick works.
|
|
1710
|
-
//
|
|
1711
|
-
// I am sorry that you have to see this.
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
return $1 + $1 + $2 + '|';
|
|
1715
|
-
});
|
|
1716
|
-
this.debug('tail=%j\n %s', tail, tail, pl, re);
|
|
1717
|
-
var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
|
|
1718
|
-
hasMagic = true;
|
|
1719
|
-
re = re.slice(0, pl.reStart) + t + '\\(' + tail;
|
|
1720
|
-
} // handle trailing things that only matter at the very end.
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
clearStateChar();
|
|
1724
|
-
|
|
1725
|
-
if (escaping) {
|
|
1726
|
-
// trailing \\
|
|
1727
|
-
re += '\\\\';
|
|
1728
|
-
} // only need to apply the nodot start if the re starts with
|
|
1729
|
-
// something that could conceivably capture a dot
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
var addPatternStart = false;
|
|
1733
|
-
|
|
1734
|
-
switch (re.charAt(0)) {
|
|
1735
|
-
case '[':
|
|
1736
|
-
case '.':
|
|
1737
|
-
case '(':
|
|
1738
|
-
addPatternStart = true;
|
|
1739
|
-
} // Hack to work around lack of negative lookbehind in JS
|
|
1740
|
-
// A pattern like: *.!(x).!(y|z) needs to ensure that a name
|
|
1741
|
-
// like 'a.xyz.yz' doesn't match. So, the first negative
|
|
1742
|
-
// lookahead, has to look ALL the way ahead, to the end of
|
|
1743
|
-
// the pattern.
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
for (var n = negativeLists.length - 1; n > -1; n--) {
|
|
1747
|
-
var nl = negativeLists[n];
|
|
1748
|
-
var nlBefore = re.slice(0, nl.reStart);
|
|
1749
|
-
var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
|
|
1750
|
-
var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
|
|
1751
|
-
var nlAfter = re.slice(nl.reEnd);
|
|
1752
|
-
nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
|
|
1753
|
-
// mean that we should *not* include the ) in the bit that is considered
|
|
1754
|
-
// "after" the negated section.
|
|
1755
|
-
|
|
1756
|
-
var openParensBefore = nlBefore.split('(').length - 1;
|
|
1757
|
-
var cleanAfter = nlAfter;
|
|
1758
|
-
|
|
1759
|
-
for (i = 0; i < openParensBefore; i++) {
|
|
1760
|
-
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
nlAfter = cleanAfter;
|
|
1764
|
-
var dollar = '';
|
|
1765
|
-
|
|
1766
|
-
if (nlAfter === '' && isSub !== SUBPARSE) {
|
|
1767
|
-
dollar = '$';
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
|
|
1771
|
-
re = newRe;
|
|
1772
|
-
} // if the re is not "" at this point, then we need to make sure
|
|
1773
|
-
// it doesn't match against an empty path part.
|
|
1774
|
-
// Otherwise a/* will match a/, which it should not.
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
if (re !== '' && hasMagic) {
|
|
1778
|
-
re = '(?=.)' + re;
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
if (addPatternStart) {
|
|
1782
|
-
re = patternStart + re;
|
|
1783
|
-
} // parsing just a piece of a larger pattern.
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
if (isSub === SUBPARSE) {
|
|
1787
|
-
return [re, hasMagic];
|
|
1788
|
-
} // skip the regexp for non-magical patterns
|
|
1789
|
-
// unescape anything in it, though, so that it'll be
|
|
1790
|
-
// an exact match against a file etc.
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
if (!hasMagic) {
|
|
1794
|
-
return globUnescape(pattern);
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
var flags = options.nocase ? 'i' : '';
|
|
1798
|
-
|
|
1799
|
-
try {
|
|
1800
|
-
var regExp = new RegExp('^' + re + '$', flags);
|
|
1801
|
-
} catch (er)
|
|
1802
|
-
/* istanbul ignore next - should be impossible */
|
|
1803
|
-
{
|
|
1804
|
-
// If it was an invalid regular expression, then it can't match
|
|
1805
|
-
// anything. This trick looks for a character after the end of
|
|
1806
|
-
// the string, which is of course impossible, except in multi-line
|
|
1807
|
-
// mode, but it's not a /m regex.
|
|
1808
|
-
return new RegExp('$.');
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
regExp._glob = pattern;
|
|
1812
|
-
regExp._src = re;
|
|
1813
|
-
return regExp;
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
minimatch.makeRe = function (pattern, options) {
|
|
1817
|
-
return new Minimatch(pattern, options || {}).makeRe();
|
|
1818
|
-
};
|
|
1819
|
-
|
|
1820
|
-
Minimatch.prototype.makeRe = makeRe;
|
|
1821
|
-
|
|
1822
|
-
function makeRe() {
|
|
1823
|
-
if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
|
|
1824
|
-
// pattern strings, or "**".
|
|
1825
|
-
//
|
|
1826
|
-
// It's better to use .match(). This function shouldn't
|
|
1827
|
-
// be used, really, but it's pretty convenient sometimes,
|
|
1828
|
-
// when you just want to work with a regex.
|
|
1829
|
-
|
|
1830
|
-
var set = this.set;
|
|
1831
|
-
|
|
1832
|
-
if (!set.length) {
|
|
1833
|
-
this.regexp = false;
|
|
1834
|
-
return this.regexp;
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
var options = this.options;
|
|
1838
|
-
var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
|
|
1839
|
-
var flags = options.nocase ? 'i' : '';
|
|
1840
|
-
var re = set.map(function (pattern) {
|
|
1841
|
-
return pattern.map(function (p) {
|
|
1842
|
-
return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
|
|
1843
|
-
}).join('\\\/');
|
|
1844
|
-
}).join('|'); // must match entire pattern
|
|
1845
|
-
// ending in a * or ** will make it less strict.
|
|
1846
|
-
|
|
1847
|
-
re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
|
|
1848
|
-
|
|
1849
|
-
if (this.negate) re = '^(?!' + re + ').*$';
|
|
1850
|
-
|
|
1851
|
-
try {
|
|
1852
|
-
this.regexp = new RegExp(re, flags);
|
|
1853
|
-
} catch (ex)
|
|
1854
|
-
/* istanbul ignore next - should be impossible */
|
|
1855
|
-
{
|
|
1856
|
-
this.regexp = false;
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
return this.regexp;
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
minimatch.match = function (list, pattern, options) {
|
|
1863
|
-
options = options || {};
|
|
1864
|
-
var mm = new Minimatch(pattern, options);
|
|
1865
|
-
list = list.filter(function (f) {
|
|
1866
|
-
return mm.match(f);
|
|
1867
|
-
});
|
|
1868
|
-
|
|
1869
|
-
if (mm.options.nonull && !list.length) {
|
|
1870
|
-
list.push(pattern);
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
return list;
|
|
1874
|
-
};
|
|
1875
|
-
|
|
1876
|
-
Minimatch.prototype.match = function match(f, partial) {
|
|
1877
|
-
if (typeof partial === 'undefined') partial = this.partial;
|
|
1878
|
-
this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
|
|
1879
|
-
// comments, etc.
|
|
1880
|
-
|
|
1881
|
-
if (this.comment) return false;
|
|
1882
|
-
if (this.empty) return f === '';
|
|
1883
|
-
if (f === '/' && partial) return true;
|
|
1884
|
-
var options = this.options; // windows: need to use /, not \
|
|
1885
|
-
|
|
1886
|
-
if (path.sep !== '/') {
|
|
1887
|
-
f = f.split(path.sep).join('/');
|
|
1888
|
-
} // treat the test path as a set of pathparts.
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
f = f.split(slashSplit);
|
|
1892
|
-
this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
|
|
1893
|
-
// in order for it to be valid. If negating, then just one
|
|
1894
|
-
// match means that we have failed.
|
|
1895
|
-
// Either way, return on the first hit.
|
|
1896
|
-
|
|
1897
|
-
var set = this.set;
|
|
1898
|
-
this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
|
|
1899
|
-
|
|
1900
|
-
var filename;
|
|
1901
|
-
var i;
|
|
1902
|
-
|
|
1903
|
-
for (i = f.length - 1; i >= 0; i--) {
|
|
1904
|
-
filename = f[i];
|
|
1905
|
-
if (filename) break;
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
for (i = 0; i < set.length; i++) {
|
|
1909
|
-
var pattern = set[i];
|
|
1910
|
-
var file = f;
|
|
1911
|
-
|
|
1912
|
-
if (options.matchBase && pattern.length === 1) {
|
|
1913
|
-
file = [filename];
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
var hit = this.matchOne(file, pattern, partial);
|
|
1917
|
-
|
|
1918
|
-
if (hit) {
|
|
1919
|
-
if (options.flipNegate) return true;
|
|
1920
|
-
return !this.negate;
|
|
1921
|
-
}
|
|
1922
|
-
} // didn't get any hits. this is success if it's a negative
|
|
1923
|
-
// pattern, failure otherwise.
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
if (options.flipNegate) return false;
|
|
1927
|
-
return this.negate;
|
|
1928
|
-
}; // set partial to true to test if, for example,
|
|
1929
|
-
// "/a/b" matches the start of "/*/b/*/d"
|
|
1930
|
-
// Partial means, if you run out of file before you run
|
|
1931
|
-
// out of pattern, then that's fine, as long as all
|
|
1932
|
-
// the parts match.
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
Minimatch.prototype.matchOne = function (file, pattern, partial) {
|
|
1936
|
-
var options = this.options;
|
|
1937
|
-
this.debug('matchOne', {
|
|
1938
|
-
'this': this,
|
|
1939
|
-
file: file,
|
|
1940
|
-
pattern: pattern
|
|
1941
|
-
});
|
|
1942
|
-
this.debug('matchOne', file.length, pattern.length);
|
|
1943
|
-
|
|
1944
|
-
for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
1945
|
-
this.debug('matchOne loop');
|
|
1946
|
-
var p = pattern[pi];
|
|
1947
|
-
var f = file[fi];
|
|
1948
|
-
this.debug(pattern, p, f); // should be impossible.
|
|
1949
|
-
// some invalid regexp stuff in the set.
|
|
1950
|
-
|
|
1951
|
-
/* istanbul ignore if */
|
|
1952
|
-
|
|
1953
|
-
if (p === false) return false;
|
|
1954
|
-
|
|
1955
|
-
if (p === GLOBSTAR) {
|
|
1956
|
-
this.debug('GLOBSTAR', [pattern, p, f]); // "**"
|
|
1957
|
-
// a/**/b/**/c would match the following:
|
|
1958
|
-
// a/b/x/y/z/c
|
|
1959
|
-
// a/x/y/z/b/c
|
|
1960
|
-
// a/b/x/b/x/c
|
|
1961
|
-
// a/b/c
|
|
1962
|
-
// To do this, take the rest of the pattern after
|
|
1963
|
-
// the **, and see if it would match the file remainder.
|
|
1964
|
-
// If so, return success.
|
|
1965
|
-
// If not, the ** "swallows" a segment, and try again.
|
|
1966
|
-
// This is recursively awful.
|
|
1967
|
-
//
|
|
1968
|
-
// a/**/b/**/c matching a/b/x/y/z/c
|
|
1969
|
-
// - a matches a
|
|
1970
|
-
// - doublestar
|
|
1971
|
-
// - matchOne(b/x/y/z/c, b/**/c)
|
|
1972
|
-
// - b matches b
|
|
1973
|
-
// - doublestar
|
|
1974
|
-
// - matchOne(x/y/z/c, c) -> no
|
|
1975
|
-
// - matchOne(y/z/c, c) -> no
|
|
1976
|
-
// - matchOne(z/c, c) -> no
|
|
1977
|
-
// - matchOne(c, c) yes, hit
|
|
1978
|
-
|
|
1979
|
-
var fr = fi;
|
|
1980
|
-
var pr = pi + 1;
|
|
1981
|
-
|
|
1982
|
-
if (pr === pl) {
|
|
1983
|
-
this.debug('** at the end'); // a ** at the end will just swallow the rest.
|
|
1984
|
-
// We have found a match.
|
|
1985
|
-
// however, it will not swallow /.x, unless
|
|
1986
|
-
// options.dot is set.
|
|
1987
|
-
// . and .. are *never* matched by **, for explosively
|
|
1988
|
-
// exponential reasons.
|
|
1989
|
-
|
|
1990
|
-
for (; fi < fl; fi++) {
|
|
1991
|
-
if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
return true;
|
|
1995
|
-
} // ok, let's see if we can swallow whatever we can.
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
while (fr < fl) {
|
|
1999
|
-
var swallowee = file[fr];
|
|
2000
|
-
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
|
|
2001
|
-
|
|
2002
|
-
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
2003
|
-
this.debug('globstar found match!', fr, fl, swallowee); // found a match.
|
|
2004
|
-
|
|
2005
|
-
return true;
|
|
2006
|
-
} else {
|
|
2007
|
-
// can't swallow "." or ".." ever.
|
|
2008
|
-
// can only swallow ".foo" when explicitly asked.
|
|
2009
|
-
if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
|
|
2010
|
-
this.debug('dot detected!', file, fr, pattern, pr);
|
|
2011
|
-
break;
|
|
2012
|
-
} // ** swallows a segment, and continue.
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
this.debug('globstar swallow a segment, and continue');
|
|
2016
|
-
fr++;
|
|
2017
|
-
}
|
|
2018
|
-
} // no match was found.
|
|
2019
|
-
// However, in partial mode, we can't say this is necessarily over.
|
|
2020
|
-
// If there's more *pattern* left, then
|
|
2021
|
-
|
|
2022
|
-
/* istanbul ignore if */
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
if (partial) {
|
|
2026
|
-
// ran out of file
|
|
2027
|
-
this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
|
|
2028
|
-
if (fr === fl) return true;
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
return false;
|
|
2032
|
-
} // something other than **
|
|
2033
|
-
// non-magic patterns just have to match exactly
|
|
2034
|
-
// patterns with magic have been turned into regexps.
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
var hit;
|
|
2038
|
-
|
|
2039
|
-
if (typeof p === 'string') {
|
|
2040
|
-
hit = f === p;
|
|
2041
|
-
this.debug('string match', p, f, hit);
|
|
2042
|
-
} else {
|
|
2043
|
-
hit = f.match(p);
|
|
2044
|
-
this.debug('pattern match', p, f, hit);
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
|
-
if (!hit) return false;
|
|
2048
|
-
} // Note: ending in / means that we'll get a final ""
|
|
2049
|
-
// at the end of the pattern. This can only match a
|
|
2050
|
-
// corresponding "" at the end of the file.
|
|
2051
|
-
// If the file ends in /, then it can only match a
|
|
2052
|
-
// a pattern that ends in /, unless the pattern just
|
|
2053
|
-
// doesn't have any more for it. But, a/b/ should *not*
|
|
2054
|
-
// match "a/b/*", even though "" matches against the
|
|
2055
|
-
// [^/]*? pattern, except in partial mode, where it might
|
|
2056
|
-
// simply not be reached yet.
|
|
2057
|
-
// However, a/b/ should still satisfy a/*
|
|
2058
|
-
// now either we fell off the end of the pattern, or we're done.
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
if (fi === fl && pi === pl) {
|
|
2062
|
-
// ran out of pattern and filename at the same time.
|
|
2063
|
-
// an exact hit!
|
|
2064
|
-
return true;
|
|
2065
|
-
} else if (fi === fl) {
|
|
2066
|
-
// ran out of file, but still had pattern left.
|
|
2067
|
-
// this is ok if we're doing the match as part of
|
|
2068
|
-
// a glob fs traversal.
|
|
2069
|
-
return partial;
|
|
2070
|
-
} else
|
|
2071
|
-
/* istanbul ignore else */
|
|
2072
|
-
if (pi === pl) {
|
|
2073
|
-
// ran out of pattern, still have file left.
|
|
2074
|
-
// this is only acceptable if we're on the very last
|
|
2075
|
-
// empty segment of a file with a trailing slash.
|
|
2076
|
-
// a/* should match a/b/
|
|
2077
|
-
return fi === fl - 1 && file[fi] === '';
|
|
2078
|
-
} // should be unreachable.
|
|
2079
|
-
|
|
2080
|
-
/* istanbul ignore next */
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
throw new Error('wtf?');
|
|
2084
|
-
}; // replace stuff like \* with *
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
function globUnescape(s) {
|
|
2088
|
-
return s.replace(/\\(.)/g, '$1');
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
function regExpEscape(s) {
|
|
2092
|
-
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
return minimatch_1;
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
var inherits = {
|
|
2099
|
-
exports: {}
|
|
2100
|
-
};
|
|
2101
|
-
var inherits_browser = {
|
|
2102
|
-
exports: {}
|
|
2103
|
-
};
|
|
2104
|
-
var hasRequiredInherits_browser;
|
|
2105
|
-
|
|
2106
|
-
function requireInherits_browser() {
|
|
2107
|
-
if (hasRequiredInherits_browser) return inherits_browser.exports;
|
|
2108
|
-
hasRequiredInherits_browser = 1;
|
|
2109
|
-
|
|
2110
|
-
if (typeof Object.create === 'function') {
|
|
2111
|
-
// implementation from standard node.js 'util' module
|
|
2112
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
2113
|
-
if (superCtor) {
|
|
2114
|
-
ctor.super_ = superCtor;
|
|
2115
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
2116
|
-
constructor: {
|
|
2117
|
-
value: ctor,
|
|
2118
|
-
enumerable: false,
|
|
2119
|
-
writable: true,
|
|
2120
|
-
configurable: true
|
|
2121
|
-
}
|
|
2122
|
-
});
|
|
2123
|
-
}
|
|
2124
|
-
};
|
|
2125
|
-
} else {
|
|
2126
|
-
// old school shim for old browsers
|
|
2127
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
2128
|
-
if (superCtor) {
|
|
2129
|
-
ctor.super_ = superCtor;
|
|
2130
|
-
|
|
2131
|
-
var TempCtor = function () {};
|
|
2132
|
-
|
|
2133
|
-
TempCtor.prototype = superCtor.prototype;
|
|
2134
|
-
ctor.prototype = new TempCtor();
|
|
2135
|
-
ctor.prototype.constructor = ctor;
|
|
2136
|
-
}
|
|
2137
|
-
};
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
return inherits_browser.exports;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
var hasRequiredInherits;
|
|
2144
|
-
|
|
2145
|
-
function requireInherits() {
|
|
2146
|
-
if (hasRequiredInherits) return inherits.exports;
|
|
2147
|
-
hasRequiredInherits = 1;
|
|
2148
|
-
|
|
2149
|
-
(function (module) {
|
|
2150
|
-
try {
|
|
2151
|
-
var util = require('util');
|
|
2152
|
-
/* istanbul ignore next */
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
if (typeof util.inherits !== 'function') throw '';
|
|
2156
|
-
module.exports = util.inherits;
|
|
2157
|
-
} catch (e) {
|
|
2158
|
-
/* istanbul ignore next */
|
|
2159
|
-
module.exports = requireInherits_browser();
|
|
2160
|
-
}
|
|
2161
|
-
})(inherits);
|
|
2162
|
-
|
|
2163
|
-
return inherits.exports;
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
var pathIsAbsolute = {
|
|
2167
|
-
exports: {}
|
|
2168
|
-
};
|
|
2169
|
-
var hasRequiredPathIsAbsolute;
|
|
2170
|
-
|
|
2171
|
-
function requirePathIsAbsolute() {
|
|
2172
|
-
if (hasRequiredPathIsAbsolute) return pathIsAbsolute.exports;
|
|
2173
|
-
hasRequiredPathIsAbsolute = 1;
|
|
2174
|
-
|
|
2175
|
-
function posix(path) {
|
|
2176
|
-
return path.charAt(0) === '/';
|
|
2177
|
-
}
|
|
2178
|
-
|
|
2179
|
-
function win32(path) {
|
|
2180
|
-
// https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
|
|
2181
|
-
var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
|
|
2182
|
-
var result = splitDeviceRe.exec(path);
|
|
2183
|
-
var device = result[1] || '';
|
|
2184
|
-
var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
|
|
2185
|
-
|
|
2186
|
-
return Boolean(result[2] || isUnc);
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
pathIsAbsolute.exports = process.platform === 'win32' ? win32 : posix;
|
|
2190
|
-
pathIsAbsolute.exports.posix = posix;
|
|
2191
|
-
pathIsAbsolute.exports.win32 = win32;
|
|
2192
|
-
return pathIsAbsolute.exports;
|
|
2193
|
-
}
|
|
2194
|
-
|
|
2195
|
-
var common = {};
|
|
2196
|
-
var hasRequiredCommon;
|
|
2197
|
-
|
|
2198
|
-
function requireCommon() {
|
|
2199
|
-
if (hasRequiredCommon) return common;
|
|
2200
|
-
hasRequiredCommon = 1;
|
|
2201
|
-
common.setopts = setopts;
|
|
2202
|
-
common.ownProp = ownProp;
|
|
2203
|
-
common.makeAbs = makeAbs;
|
|
2204
|
-
common.finish = finish;
|
|
2205
|
-
common.mark = mark;
|
|
2206
|
-
common.isIgnored = isIgnored;
|
|
2207
|
-
common.childrenIgnored = childrenIgnored;
|
|
2208
|
-
|
|
2209
|
-
function ownProp(obj, field) {
|
|
2210
|
-
return Object.prototype.hasOwnProperty.call(obj, field);
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
|
-
var fs = fs$2;
|
|
2214
|
-
var path = path$1;
|
|
2215
|
-
var minimatch = requireMinimatch();
|
|
2216
|
-
var isAbsolute = requirePathIsAbsolute();
|
|
2217
|
-
var Minimatch = minimatch.Minimatch;
|
|
2218
|
-
|
|
2219
|
-
function alphasort(a, b) {
|
|
2220
|
-
return a.localeCompare(b, 'en');
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
|
-
function setupIgnores(self, options) {
|
|
2224
|
-
self.ignore = options.ignore || [];
|
|
2225
|
-
if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
|
|
2226
|
-
|
|
2227
|
-
if (self.ignore.length) {
|
|
2228
|
-
self.ignore = self.ignore.map(ignoreMap);
|
|
2229
|
-
}
|
|
2230
|
-
} // ignore patterns are always in dot:true mode.
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
function ignoreMap(pattern) {
|
|
2234
|
-
var gmatcher = null;
|
|
2235
|
-
|
|
2236
|
-
if (pattern.slice(-3) === '/**') {
|
|
2237
|
-
var gpattern = pattern.replace(/(\/\*\*)+$/, '');
|
|
2238
|
-
gmatcher = new Minimatch(gpattern, {
|
|
2239
|
-
dot: true
|
|
2240
|
-
});
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
return {
|
|
2244
|
-
matcher: new Minimatch(pattern, {
|
|
2245
|
-
dot: true
|
|
2246
|
-
}),
|
|
2247
|
-
gmatcher: gmatcher
|
|
2248
|
-
};
|
|
2249
|
-
}
|
|
2250
|
-
|
|
2251
|
-
function setopts(self, pattern, options) {
|
|
2252
|
-
if (!options) options = {}; // base-matching: just use globstar for that.
|
|
2253
|
-
|
|
2254
|
-
if (options.matchBase && -1 === pattern.indexOf("/")) {
|
|
2255
|
-
if (options.noglobstar) {
|
|
2256
|
-
throw new Error("base matching requires globstar");
|
|
2257
|
-
}
|
|
2258
|
-
|
|
2259
|
-
pattern = "**/" + pattern;
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
self.silent = !!options.silent;
|
|
2263
|
-
self.pattern = pattern;
|
|
2264
|
-
self.strict = options.strict !== false;
|
|
2265
|
-
self.realpath = !!options.realpath;
|
|
2266
|
-
self.realpathCache = options.realpathCache || Object.create(null);
|
|
2267
|
-
self.follow = !!options.follow;
|
|
2268
|
-
self.dot = !!options.dot;
|
|
2269
|
-
self.mark = !!options.mark;
|
|
2270
|
-
self.nodir = !!options.nodir;
|
|
2271
|
-
if (self.nodir) self.mark = true;
|
|
2272
|
-
self.sync = !!options.sync;
|
|
2273
|
-
self.nounique = !!options.nounique;
|
|
2274
|
-
self.nonull = !!options.nonull;
|
|
2275
|
-
self.nosort = !!options.nosort;
|
|
2276
|
-
self.nocase = !!options.nocase;
|
|
2277
|
-
self.stat = !!options.stat;
|
|
2278
|
-
self.noprocess = !!options.noprocess;
|
|
2279
|
-
self.absolute = !!options.absolute;
|
|
2280
|
-
self.fs = options.fs || fs;
|
|
2281
|
-
self.maxLength = options.maxLength || Infinity;
|
|
2282
|
-
self.cache = options.cache || Object.create(null);
|
|
2283
|
-
self.statCache = options.statCache || Object.create(null);
|
|
2284
|
-
self.symlinks = options.symlinks || Object.create(null);
|
|
2285
|
-
setupIgnores(self, options);
|
|
2286
|
-
self.changedCwd = false;
|
|
2287
|
-
var cwd = process.cwd();
|
|
2288
|
-
if (!ownProp(options, "cwd")) self.cwd = cwd;else {
|
|
2289
|
-
self.cwd = path.resolve(options.cwd);
|
|
2290
|
-
self.changedCwd = self.cwd !== cwd;
|
|
2291
|
-
}
|
|
2292
|
-
self.root = options.root || path.resolve(self.cwd, "/");
|
|
2293
|
-
self.root = path.resolve(self.root);
|
|
2294
|
-
if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
|
|
2295
|
-
// e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
|
|
2296
|
-
|
|
2297
|
-
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
|
|
2298
|
-
if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
|
|
2299
|
-
self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
|
|
2300
|
-
// Note that they are not supported in Glob itself anyway.
|
|
2301
|
-
|
|
2302
|
-
options.nonegate = true;
|
|
2303
|
-
options.nocomment = true; // always treat \ in patterns as escapes, not path separators
|
|
2304
|
-
|
|
2305
|
-
options.allowWindowsEscape = false;
|
|
2306
|
-
self.minimatch = new Minimatch(pattern, options);
|
|
2307
|
-
self.options = self.minimatch.options;
|
|
2308
|
-
}
|
|
2309
|
-
|
|
2310
|
-
function finish(self) {
|
|
2311
|
-
var nou = self.nounique;
|
|
2312
|
-
var all = nou ? [] : Object.create(null);
|
|
2313
|
-
|
|
2314
|
-
for (var i = 0, l = self.matches.length; i < l; i++) {
|
|
2315
|
-
var matches = self.matches[i];
|
|
2316
|
-
|
|
2317
|
-
if (!matches || Object.keys(matches).length === 0) {
|
|
2318
|
-
if (self.nonull) {
|
|
2319
|
-
// do like the shell, and spit out the literal glob
|
|
2320
|
-
var literal = self.minimatch.globSet[i];
|
|
2321
|
-
if (nou) all.push(literal);else all[literal] = true;
|
|
2322
|
-
}
|
|
2323
|
-
} else {
|
|
2324
|
-
// had matches
|
|
2325
|
-
var m = Object.keys(matches);
|
|
2326
|
-
if (nou) all.push.apply(all, m);else m.forEach(function (m) {
|
|
2327
|
-
all[m] = true;
|
|
2328
|
-
});
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
if (!nou) all = Object.keys(all);
|
|
2333
|
-
if (!self.nosort) all = all.sort(alphasort); // at *some* point we statted all of these
|
|
2334
|
-
|
|
2335
|
-
if (self.mark) {
|
|
2336
|
-
for (var i = 0; i < all.length; i++) {
|
|
2337
|
-
all[i] = self._mark(all[i]);
|
|
2338
|
-
}
|
|
2339
|
-
|
|
2340
|
-
if (self.nodir) {
|
|
2341
|
-
all = all.filter(function (e) {
|
|
2342
|
-
var notDir = !/\/$/.test(e);
|
|
2343
|
-
var c = self.cache[e] || self.cache[makeAbs(self, e)];
|
|
2344
|
-
if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
|
|
2345
|
-
return notDir;
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
|
|
2350
|
-
if (self.ignore.length) all = all.filter(function (m) {
|
|
2351
|
-
return !isIgnored(self, m);
|
|
2352
|
-
});
|
|
2353
|
-
self.found = all;
|
|
2354
|
-
}
|
|
2355
|
-
|
|
2356
|
-
function mark(self, p) {
|
|
2357
|
-
var abs = makeAbs(self, p);
|
|
2358
|
-
var c = self.cache[abs];
|
|
2359
|
-
var m = p;
|
|
2360
|
-
|
|
2361
|
-
if (c) {
|
|
2362
|
-
var isDir = c === 'DIR' || Array.isArray(c);
|
|
2363
|
-
var slash = p.slice(-1) === '/';
|
|
2364
|
-
if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
|
|
2365
|
-
|
|
2366
|
-
if (m !== p) {
|
|
2367
|
-
var mabs = makeAbs(self, m);
|
|
2368
|
-
self.statCache[mabs] = self.statCache[abs];
|
|
2369
|
-
self.cache[mabs] = self.cache[abs];
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
return m;
|
|
2374
|
-
} // lotta situps...
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
function makeAbs(self, f) {
|
|
2378
|
-
var abs = f;
|
|
2379
|
-
|
|
2380
|
-
if (f.charAt(0) === '/') {
|
|
2381
|
-
abs = path.join(self.root, f);
|
|
2382
|
-
} else if (isAbsolute(f) || f === '') {
|
|
2383
|
-
abs = f;
|
|
2384
|
-
} else if (self.changedCwd) {
|
|
2385
|
-
abs = path.resolve(self.cwd, f);
|
|
2386
|
-
} else {
|
|
2387
|
-
abs = path.resolve(f);
|
|
2388
|
-
}
|
|
2389
|
-
|
|
2390
|
-
if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
|
|
2391
|
-
return abs;
|
|
2392
|
-
} // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
|
|
2393
|
-
// Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
function isIgnored(self, path) {
|
|
2397
|
-
if (!self.ignore.length) return false;
|
|
2398
|
-
return self.ignore.some(function (item) {
|
|
2399
|
-
return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path));
|
|
2400
|
-
});
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
function childrenIgnored(self, path) {
|
|
2404
|
-
if (!self.ignore.length) return false;
|
|
2405
|
-
return self.ignore.some(function (item) {
|
|
2406
|
-
return !!(item.gmatcher && item.gmatcher.match(path));
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
return common;
|
|
2411
|
-
}
|
|
2412
|
-
|
|
2413
|
-
var sync;
|
|
2414
|
-
var hasRequiredSync;
|
|
2415
|
-
|
|
2416
|
-
function requireSync() {
|
|
2417
|
-
if (hasRequiredSync) return sync;
|
|
2418
|
-
hasRequiredSync = 1;
|
|
2419
|
-
sync = globSync;
|
|
2420
|
-
globSync.GlobSync = GlobSync;
|
|
2421
|
-
var rp = requireFs_realpath();
|
|
2422
|
-
var minimatch = requireMinimatch();
|
|
2423
|
-
requireGlob().Glob;
|
|
2424
|
-
var path = path$1;
|
|
2425
|
-
var assert = require$$5;
|
|
2426
|
-
var isAbsolute = requirePathIsAbsolute();
|
|
2427
|
-
var common = requireCommon();
|
|
2428
|
-
var setopts = common.setopts;
|
|
2429
|
-
var ownProp = common.ownProp;
|
|
2430
|
-
var childrenIgnored = common.childrenIgnored;
|
|
2431
|
-
var isIgnored = common.isIgnored;
|
|
2432
|
-
|
|
2433
|
-
function globSync(pattern, options) {
|
|
2434
|
-
if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
|
|
2435
|
-
return new GlobSync(pattern, options).found;
|
|
2436
|
-
}
|
|
2437
|
-
|
|
2438
|
-
function GlobSync(pattern, options) {
|
|
2439
|
-
if (!pattern) throw new Error('must provide pattern');
|
|
2440
|
-
if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
|
|
2441
|
-
if (!(this instanceof GlobSync)) return new GlobSync(pattern, options);
|
|
2442
|
-
setopts(this, pattern, options);
|
|
2443
|
-
if (this.noprocess) return this;
|
|
2444
|
-
var n = this.minimatch.set.length;
|
|
2445
|
-
this.matches = new Array(n);
|
|
2446
|
-
|
|
2447
|
-
for (var i = 0; i < n; i++) {
|
|
2448
|
-
this._process(this.minimatch.set[i], i, false);
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2451
|
-
this._finish();
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
GlobSync.prototype._finish = function () {
|
|
2455
|
-
assert.ok(this instanceof GlobSync);
|
|
2456
|
-
|
|
2457
|
-
if (this.realpath) {
|
|
2458
|
-
var self = this;
|
|
2459
|
-
this.matches.forEach(function (matchset, index) {
|
|
2460
|
-
var set = self.matches[index] = Object.create(null);
|
|
2461
|
-
|
|
2462
|
-
for (var p in matchset) {
|
|
2463
|
-
try {
|
|
2464
|
-
p = self._makeAbs(p);
|
|
2465
|
-
var real = rp.realpathSync(p, self.realpathCache);
|
|
2466
|
-
set[real] = true;
|
|
2467
|
-
} catch (er) {
|
|
2468
|
-
if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
});
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
common.finish(this);
|
|
2475
|
-
};
|
|
2476
|
-
|
|
2477
|
-
GlobSync.prototype._process = function (pattern, index, inGlobStar) {
|
|
2478
|
-
assert.ok(this instanceof GlobSync); // Get the first [n] parts of pattern that are all strings.
|
|
2479
|
-
|
|
2480
|
-
var n = 0;
|
|
2481
|
-
|
|
2482
|
-
while (typeof pattern[n] === 'string') {
|
|
2483
|
-
n++;
|
|
2484
|
-
} // now n is the index of the first one that is *not* a string.
|
|
2485
|
-
// See if there's anything else
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
var prefix;
|
|
2489
|
-
|
|
2490
|
-
switch (n) {
|
|
2491
|
-
// if not, then this is rather simple
|
|
2492
|
-
case pattern.length:
|
|
2493
|
-
this._processSimple(pattern.join('/'), index);
|
|
2494
|
-
|
|
2495
|
-
return;
|
|
2496
|
-
|
|
2497
|
-
case 0:
|
|
2498
|
-
// pattern *starts* with some non-trivial item.
|
|
2499
|
-
// going to readdir(cwd), but not include the prefix in matches.
|
|
2500
|
-
prefix = null;
|
|
2501
|
-
break;
|
|
2502
|
-
|
|
2503
|
-
default:
|
|
2504
|
-
// pattern has some string bits in the front.
|
|
2505
|
-
// whatever it starts with, whether that's 'absolute' like /foo/bar,
|
|
2506
|
-
// or 'relative' like '../baz'
|
|
2507
|
-
prefix = pattern.slice(0, n).join('/');
|
|
2508
|
-
break;
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
|
-
var remain = pattern.slice(n); // get the list of entries.
|
|
2512
|
-
|
|
2513
|
-
var read;
|
|
2514
|
-
if (prefix === null) read = '.';else if (isAbsolute(prefix) || isAbsolute(pattern.map(function (p) {
|
|
2515
|
-
return typeof p === 'string' ? p : '[*]';
|
|
2516
|
-
}).join('/'))) {
|
|
2517
|
-
if (!prefix || !isAbsolute(prefix)) prefix = '/' + prefix;
|
|
2518
|
-
read = prefix;
|
|
2519
|
-
} else read = prefix;
|
|
2520
|
-
|
|
2521
|
-
var abs = this._makeAbs(read); //if ignored, skip processing
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
if (childrenIgnored(this, read)) return;
|
|
2525
|
-
var isGlobStar = remain[0] === minimatch.GLOBSTAR;
|
|
2526
|
-
if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
|
|
2527
|
-
};
|
|
2528
|
-
|
|
2529
|
-
GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
|
|
2530
|
-
var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
if (!entries) return; // It will only match dot entries if it starts with a dot, or if
|
|
2534
|
-
// dot is set. Stuff like @(.foo|.bar) isn't allowed.
|
|
2535
|
-
|
|
2536
|
-
var pn = remain[0];
|
|
2537
|
-
var negate = !!this.minimatch.negate;
|
|
2538
|
-
var rawGlob = pn._glob;
|
|
2539
|
-
var dotOk = this.dot || rawGlob.charAt(0) === '.';
|
|
2540
|
-
var matchedEntries = [];
|
|
2541
|
-
|
|
2542
|
-
for (var i = 0; i < entries.length; i++) {
|
|
2543
|
-
var e = entries[i];
|
|
2544
|
-
|
|
2545
|
-
if (e.charAt(0) !== '.' || dotOk) {
|
|
2546
|
-
var m;
|
|
2547
|
-
|
|
2548
|
-
if (negate && !prefix) {
|
|
2549
|
-
m = !e.match(pn);
|
|
2550
|
-
} else {
|
|
2551
|
-
m = e.match(pn);
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
|
-
if (m) matchedEntries.push(e);
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
|
|
2558
|
-
var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
|
|
2559
|
-
|
|
2560
|
-
if (len === 0) return; // if this is the last remaining pattern bit, then no need for
|
|
2561
|
-
// an additional stat *unless* the user has specified mark or
|
|
2562
|
-
// stat explicitly. We know they exist, since readdir returned
|
|
2563
|
-
// them.
|
|
2564
|
-
|
|
2565
|
-
if (remain.length === 1 && !this.mark && !this.stat) {
|
|
2566
|
-
if (!this.matches[index]) this.matches[index] = Object.create(null);
|
|
2567
|
-
|
|
2568
|
-
for (var i = 0; i < len; i++) {
|
|
2569
|
-
var e = matchedEntries[i];
|
|
2570
|
-
|
|
2571
|
-
if (prefix) {
|
|
2572
|
-
if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
|
|
2573
|
-
}
|
|
2574
|
-
|
|
2575
|
-
if (e.charAt(0) === '/' && !this.nomount) {
|
|
2576
|
-
e = path.join(this.root, e);
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
this._emitMatch(index, e);
|
|
2580
|
-
} // This was the last one, and no stats were needed
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
return;
|
|
2584
|
-
} // now test all matched entries as stand-ins for that part
|
|
2585
|
-
// of the pattern.
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
remain.shift();
|
|
2589
|
-
|
|
2590
|
-
for (var i = 0; i < len; i++) {
|
|
2591
|
-
var e = matchedEntries[i];
|
|
2592
|
-
var newPattern;
|
|
2593
|
-
if (prefix) newPattern = [prefix, e];else newPattern = [e];
|
|
2594
|
-
|
|
2595
|
-
this._process(newPattern.concat(remain), index, inGlobStar);
|
|
2596
|
-
}
|
|
2597
|
-
};
|
|
2598
|
-
|
|
2599
|
-
GlobSync.prototype._emitMatch = function (index, e) {
|
|
2600
|
-
if (isIgnored(this, e)) return;
|
|
2601
|
-
|
|
2602
|
-
var abs = this._makeAbs(e);
|
|
2603
|
-
|
|
2604
|
-
if (this.mark) e = this._mark(e);
|
|
2605
|
-
|
|
2606
|
-
if (this.absolute) {
|
|
2607
|
-
e = abs;
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
|
-
if (this.matches[index][e]) return;
|
|
2611
|
-
|
|
2612
|
-
if (this.nodir) {
|
|
2613
|
-
var c = this.cache[abs];
|
|
2614
|
-
if (c === 'DIR' || Array.isArray(c)) return;
|
|
2615
|
-
}
|
|
2616
|
-
|
|
2617
|
-
this.matches[index][e] = true;
|
|
2618
|
-
if (this.stat) this._stat(e);
|
|
2619
|
-
};
|
|
2620
|
-
|
|
2621
|
-
GlobSync.prototype._readdirInGlobStar = function (abs) {
|
|
2622
|
-
// follow all symlinked directories forever
|
|
2623
|
-
// just proceed as if this is a non-globstar situation
|
|
2624
|
-
if (this.follow) return this._readdir(abs, false);
|
|
2625
|
-
var entries;
|
|
2626
|
-
var lstat;
|
|
2627
|
-
|
|
2628
|
-
try {
|
|
2629
|
-
lstat = this.fs.lstatSync(abs);
|
|
2630
|
-
} catch (er) {
|
|
2631
|
-
if (er.code === 'ENOENT') {
|
|
2632
|
-
// lstat failed, doesn't exist
|
|
2633
|
-
return null;
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
|
-
var isSym = lstat && lstat.isSymbolicLink();
|
|
2638
|
-
this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
|
|
2639
|
-
// don't bother doing a readdir in that case.
|
|
2640
|
-
|
|
2641
|
-
if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
|
|
2642
|
-
return entries;
|
|
2643
|
-
};
|
|
2644
|
-
|
|
2645
|
-
GlobSync.prototype._readdir = function (abs, inGlobStar) {
|
|
2646
|
-
if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs);
|
|
2647
|
-
|
|
2648
|
-
if (ownProp(this.cache, abs)) {
|
|
2649
|
-
var c = this.cache[abs];
|
|
2650
|
-
if (!c || c === 'FILE') return null;
|
|
2651
|
-
if (Array.isArray(c)) return c;
|
|
2652
|
-
}
|
|
2653
|
-
|
|
2654
|
-
try {
|
|
2655
|
-
return this._readdirEntries(abs, this.fs.readdirSync(abs));
|
|
2656
|
-
} catch (er) {
|
|
2657
|
-
this._readdirError(abs, er);
|
|
2658
|
-
|
|
2659
|
-
return null;
|
|
2660
|
-
}
|
|
2661
|
-
};
|
|
2662
|
-
|
|
2663
|
-
GlobSync.prototype._readdirEntries = function (abs, entries) {
|
|
2664
|
-
// if we haven't asked to stat everything, then just
|
|
2665
|
-
// assume that everything in there exists, so we can avoid
|
|
2666
|
-
// having to stat it a second time.
|
|
2667
|
-
if (!this.mark && !this.stat) {
|
|
2668
|
-
for (var i = 0; i < entries.length; i++) {
|
|
2669
|
-
var e = entries[i];
|
|
2670
|
-
if (abs === '/') e = abs + e;else e = abs + '/' + e;
|
|
2671
|
-
this.cache[e] = true;
|
|
2672
|
-
}
|
|
2673
|
-
}
|
|
2674
|
-
|
|
2675
|
-
this.cache[abs] = entries; // mark and cache dir-ness
|
|
2676
|
-
|
|
2677
|
-
return entries;
|
|
2678
|
-
};
|
|
2679
|
-
|
|
2680
|
-
GlobSync.prototype._readdirError = function (f, er) {
|
|
2681
|
-
// handle errors, and cache the information
|
|
2682
|
-
switch (er.code) {
|
|
2683
|
-
case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
|
|
2684
|
-
|
|
2685
|
-
case 'ENOTDIR':
|
|
2686
|
-
// totally normal. means it *does* exist.
|
|
2687
|
-
var abs = this._makeAbs(f);
|
|
2688
|
-
|
|
2689
|
-
this.cache[abs] = 'FILE';
|
|
2690
|
-
|
|
2691
|
-
if (abs === this.cwdAbs) {
|
|
2692
|
-
var error = new Error(er.code + ' invalid cwd ' + this.cwd);
|
|
2693
|
-
error.path = this.cwd;
|
|
2694
|
-
error.code = er.code;
|
|
2695
|
-
throw error;
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
|
-
break;
|
|
2699
|
-
|
|
2700
|
-
case 'ENOENT': // not terribly unusual
|
|
2701
|
-
|
|
2702
|
-
case 'ELOOP':
|
|
2703
|
-
case 'ENAMETOOLONG':
|
|
2704
|
-
case 'UNKNOWN':
|
|
2705
|
-
this.cache[this._makeAbs(f)] = false;
|
|
2706
|
-
break;
|
|
2707
|
-
|
|
2708
|
-
default:
|
|
2709
|
-
// some unusual error. Treat as failure.
|
|
2710
|
-
this.cache[this._makeAbs(f)] = false;
|
|
2711
|
-
if (this.strict) throw er;
|
|
2712
|
-
if (!this.silent) console.error('glob error', er);
|
|
2713
|
-
break;
|
|
2714
|
-
}
|
|
2715
|
-
};
|
|
2716
|
-
|
|
2717
|
-
GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
|
|
2718
|
-
var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
|
|
2719
|
-
// foo.txt/** doesn't match foo.txt
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
if (!entries) return; // test without the globstar, and with every child both below
|
|
2723
|
-
// and replacing the globstar.
|
|
2724
|
-
|
|
2725
|
-
var remainWithoutGlobStar = remain.slice(1);
|
|
2726
|
-
var gspref = prefix ? [prefix] : [];
|
|
2727
|
-
var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
|
|
2728
|
-
|
|
2729
|
-
this._process(noGlobStar, index, false);
|
|
2730
|
-
|
|
2731
|
-
var len = entries.length;
|
|
2732
|
-
var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
|
|
2733
|
-
|
|
2734
|
-
if (isSym && inGlobStar) return;
|
|
2735
|
-
|
|
2736
|
-
for (var i = 0; i < len; i++) {
|
|
2737
|
-
var e = entries[i];
|
|
2738
|
-
if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
|
|
2739
|
-
|
|
2740
|
-
var instead = gspref.concat(entries[i], remainWithoutGlobStar);
|
|
2741
|
-
|
|
2742
|
-
this._process(instead, index, true);
|
|
2743
|
-
|
|
2744
|
-
var below = gspref.concat(entries[i], remain);
|
|
2745
|
-
|
|
2746
|
-
this._process(below, index, true);
|
|
2747
|
-
}
|
|
2748
|
-
};
|
|
2749
|
-
|
|
2750
|
-
GlobSync.prototype._processSimple = function (prefix, index) {
|
|
2751
|
-
// XXX review this. Shouldn't it be doing the mounting etc
|
|
2752
|
-
// before doing stat? kinda weird?
|
|
2753
|
-
var exists = this._stat(prefix);
|
|
2754
|
-
|
|
2755
|
-
if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
|
|
2756
|
-
|
|
2757
|
-
if (!exists) return;
|
|
2758
|
-
|
|
2759
|
-
if (prefix && isAbsolute(prefix) && !this.nomount) {
|
|
2760
|
-
var trail = /[\/\\]$/.test(prefix);
|
|
2761
|
-
|
|
2762
|
-
if (prefix.charAt(0) === '/') {
|
|
2763
|
-
prefix = path.join(this.root, prefix);
|
|
2764
|
-
} else {
|
|
2765
|
-
prefix = path.resolve(this.root, prefix);
|
|
2766
|
-
if (trail) prefix += '/';
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2770
|
-
if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
|
|
2771
|
-
|
|
2772
|
-
this._emitMatch(index, prefix);
|
|
2773
|
-
}; // Returns either 'DIR', 'FILE', or false
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
GlobSync.prototype._stat = function (f) {
|
|
2777
|
-
var abs = this._makeAbs(f);
|
|
2778
|
-
|
|
2779
|
-
var needDir = f.slice(-1) === '/';
|
|
2780
|
-
if (f.length > this.maxLength) return false;
|
|
2781
|
-
|
|
2782
|
-
if (!this.stat && ownProp(this.cache, abs)) {
|
|
2783
|
-
var c = this.cache[abs];
|
|
2784
|
-
if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
|
|
2785
|
-
|
|
2786
|
-
if (!needDir || c === 'DIR') return c;
|
|
2787
|
-
if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
|
|
2788
|
-
// if we know it exists, but not what it is.
|
|
2789
|
-
}
|
|
2790
|
-
|
|
2791
|
-
var stat = this.statCache[abs];
|
|
2792
|
-
|
|
2793
|
-
if (!stat) {
|
|
2794
|
-
var lstat;
|
|
2795
|
-
|
|
2796
|
-
try {
|
|
2797
|
-
lstat = this.fs.lstatSync(abs);
|
|
2798
|
-
} catch (er) {
|
|
2799
|
-
if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
|
|
2800
|
-
this.statCache[abs] = false;
|
|
2801
|
-
return false;
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
if (lstat && lstat.isSymbolicLink()) {
|
|
2806
|
-
try {
|
|
2807
|
-
stat = this.fs.statSync(abs);
|
|
2808
|
-
} catch (er) {
|
|
2809
|
-
stat = lstat;
|
|
2810
|
-
}
|
|
2811
|
-
} else {
|
|
2812
|
-
stat = lstat;
|
|
2813
|
-
}
|
|
2814
|
-
}
|
|
2815
|
-
|
|
2816
|
-
this.statCache[abs] = stat;
|
|
2817
|
-
var c = true;
|
|
2818
|
-
if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
|
|
2819
|
-
this.cache[abs] = this.cache[abs] || c;
|
|
2820
|
-
if (needDir && c === 'FILE') return false;
|
|
2821
|
-
return c;
|
|
2822
|
-
};
|
|
2823
|
-
|
|
2824
|
-
GlobSync.prototype._mark = function (p) {
|
|
2825
|
-
return common.mark(this, p);
|
|
2826
|
-
};
|
|
2827
|
-
|
|
2828
|
-
GlobSync.prototype._makeAbs = function (f) {
|
|
2829
|
-
return common.makeAbs(this, f);
|
|
2830
|
-
};
|
|
2831
|
-
|
|
2832
|
-
return sync;
|
|
2833
|
-
}
|
|
2834
|
-
|
|
2835
|
-
var wrappy_1;
|
|
2836
|
-
var hasRequiredWrappy;
|
|
2837
|
-
|
|
2838
|
-
function requireWrappy() {
|
|
2839
|
-
if (hasRequiredWrappy) return wrappy_1;
|
|
2840
|
-
hasRequiredWrappy = 1; // Returns a wrapper function that returns a wrapped callback
|
|
2841
|
-
// The wrapper function should do some stuff, and return a
|
|
2842
|
-
// presumably different callback function.
|
|
2843
|
-
// This makes sure that own properties are retained, so that
|
|
2844
|
-
// decorations and such are not lost along the way.
|
|
2845
|
-
|
|
2846
|
-
wrappy_1 = wrappy;
|
|
2847
|
-
|
|
2848
|
-
function wrappy(fn, cb) {
|
|
2849
|
-
if (fn && cb) return wrappy(fn)(cb);
|
|
2850
|
-
if (typeof fn !== 'function') throw new TypeError('need wrapper function');
|
|
2851
|
-
Object.keys(fn).forEach(function (k) {
|
|
2852
|
-
wrapper[k] = fn[k];
|
|
2853
|
-
});
|
|
2854
|
-
return wrapper;
|
|
2855
|
-
|
|
2856
|
-
function wrapper() {
|
|
2857
|
-
var args = new Array(arguments.length);
|
|
2858
|
-
|
|
2859
|
-
for (var i = 0; i < args.length; i++) {
|
|
2860
|
-
args[i] = arguments[i];
|
|
2861
|
-
}
|
|
2862
|
-
|
|
2863
|
-
var ret = fn.apply(this, args);
|
|
2864
|
-
var cb = args[args.length - 1];
|
|
2865
|
-
|
|
2866
|
-
if (typeof ret === 'function' && ret !== cb) {
|
|
2867
|
-
Object.keys(cb).forEach(function (k) {
|
|
2868
|
-
ret[k] = cb[k];
|
|
2869
|
-
});
|
|
2870
|
-
}
|
|
2871
|
-
|
|
2872
|
-
return ret;
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
|
|
2876
|
-
return wrappy_1;
|
|
2877
|
-
}
|
|
2878
|
-
|
|
2879
|
-
var once = {
|
|
2880
|
-
exports: {}
|
|
2881
|
-
};
|
|
2882
|
-
var hasRequiredOnce;
|
|
2883
|
-
|
|
2884
|
-
function requireOnce() {
|
|
2885
|
-
if (hasRequiredOnce) return once.exports;
|
|
2886
|
-
hasRequiredOnce = 1;
|
|
2887
|
-
var wrappy = requireWrappy();
|
|
2888
|
-
once.exports = wrappy(once$1);
|
|
2889
|
-
once.exports.strict = wrappy(onceStrict);
|
|
2890
|
-
once$1.proto = once$1(function () {
|
|
2891
|
-
Object.defineProperty(Function.prototype, 'once', {
|
|
2892
|
-
value: function () {
|
|
2893
|
-
return once$1(this);
|
|
2894
|
-
},
|
|
2895
|
-
configurable: true
|
|
2896
|
-
});
|
|
2897
|
-
Object.defineProperty(Function.prototype, 'onceStrict', {
|
|
2898
|
-
value: function () {
|
|
2899
|
-
return onceStrict(this);
|
|
2900
|
-
},
|
|
2901
|
-
configurable: true
|
|
2902
|
-
});
|
|
2903
|
-
});
|
|
2904
|
-
|
|
2905
|
-
function once$1(fn) {
|
|
2906
|
-
var f = function () {
|
|
2907
|
-
if (f.called) return f.value;
|
|
2908
|
-
f.called = true;
|
|
2909
|
-
return f.value = fn.apply(this, arguments);
|
|
2910
|
-
};
|
|
2911
|
-
|
|
2912
|
-
f.called = false;
|
|
2913
|
-
return f;
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
function onceStrict(fn) {
|
|
2917
|
-
var f = function () {
|
|
2918
|
-
if (f.called) throw new Error(f.onceError);
|
|
2919
|
-
f.called = true;
|
|
2920
|
-
return f.value = fn.apply(this, arguments);
|
|
2921
|
-
};
|
|
2922
|
-
|
|
2923
|
-
var name = fn.name || 'Function wrapped with `once`';
|
|
2924
|
-
f.onceError = name + " shouldn't be called more than once";
|
|
2925
|
-
f.called = false;
|
|
2926
|
-
return f;
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
return once.exports;
|
|
2930
|
-
}
|
|
2931
|
-
|
|
2932
|
-
var inflight_1;
|
|
2933
|
-
var hasRequiredInflight;
|
|
2934
|
-
|
|
2935
|
-
function requireInflight() {
|
|
2936
|
-
if (hasRequiredInflight) return inflight_1;
|
|
2937
|
-
hasRequiredInflight = 1;
|
|
2938
|
-
var wrappy = requireWrappy();
|
|
2939
|
-
var reqs = Object.create(null);
|
|
2940
|
-
var once = requireOnce();
|
|
2941
|
-
inflight_1 = wrappy(inflight);
|
|
2942
|
-
|
|
2943
|
-
function inflight(key, cb) {
|
|
2944
|
-
if (reqs[key]) {
|
|
2945
|
-
reqs[key].push(cb);
|
|
2946
|
-
return null;
|
|
2947
|
-
} else {
|
|
2948
|
-
reqs[key] = [cb];
|
|
2949
|
-
return makeres(key);
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
|
|
2953
|
-
function makeres(key) {
|
|
2954
|
-
return once(function RES() {
|
|
2955
|
-
var cbs = reqs[key];
|
|
2956
|
-
var len = cbs.length;
|
|
2957
|
-
var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
|
|
2958
|
-
// pass should be queued for later execution if something in the
|
|
2959
|
-
// list of callbacks throws, or if it should just be discarded.
|
|
2960
|
-
// However, it's such an edge case that it hardly matters, and either
|
|
2961
|
-
// choice is likely as surprising as the other.
|
|
2962
|
-
// As it happens, we do go ahead and schedule it for later execution.
|
|
2963
|
-
|
|
2964
|
-
try {
|
|
2965
|
-
for (var i = 0; i < len; i++) {
|
|
2966
|
-
cbs[i].apply(null, args);
|
|
2967
|
-
}
|
|
2968
|
-
} finally {
|
|
2969
|
-
if (cbs.length > len) {
|
|
2970
|
-
// added more in the interim.
|
|
2971
|
-
// de-zalgo, just in case, but don't call again.
|
|
2972
|
-
cbs.splice(0, len);
|
|
2973
|
-
process.nextTick(function () {
|
|
2974
|
-
RES.apply(null, args);
|
|
2975
|
-
});
|
|
2976
|
-
} else {
|
|
2977
|
-
delete reqs[key];
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
});
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
function slice(args) {
|
|
2984
|
-
var length = args.length;
|
|
2985
|
-
var array = [];
|
|
2986
|
-
|
|
2987
|
-
for (var i = 0; i < length; i++) array[i] = args[i];
|
|
2988
|
-
|
|
2989
|
-
return array;
|
|
2990
|
-
}
|
|
2991
|
-
|
|
2992
|
-
return inflight_1;
|
|
2993
|
-
}
|
|
2994
|
-
|
|
2995
|
-
var glob_1;
|
|
2996
|
-
var hasRequiredGlob;
|
|
2997
|
-
|
|
2998
|
-
function requireGlob() {
|
|
2999
|
-
if (hasRequiredGlob) return glob_1;
|
|
3000
|
-
hasRequiredGlob = 1; // Approach:
|
|
3001
|
-
//
|
|
3002
|
-
// 1. Get the minimatch set
|
|
3003
|
-
// 2. For each pattern in the set, PROCESS(pattern, false)
|
|
3004
|
-
// 3. Store matches per-set, then uniq them
|
|
3005
|
-
//
|
|
3006
|
-
// PROCESS(pattern, inGlobStar)
|
|
3007
|
-
// Get the first [n] items from pattern that are all strings
|
|
3008
|
-
// Join these together. This is PREFIX.
|
|
3009
|
-
// If there is no more remaining, then stat(PREFIX) and
|
|
3010
|
-
// add to matches if it succeeds. END.
|
|
3011
|
-
//
|
|
3012
|
-
// If inGlobStar and PREFIX is symlink and points to dir
|
|
3013
|
-
// set ENTRIES = []
|
|
3014
|
-
// else readdir(PREFIX) as ENTRIES
|
|
3015
|
-
// If fail, END
|
|
3016
|
-
//
|
|
3017
|
-
// with ENTRIES
|
|
3018
|
-
// If pattern[n] is GLOBSTAR
|
|
3019
|
-
// // handle the case where the globstar match is empty
|
|
3020
|
-
// // by pruning it out, and testing the resulting pattern
|
|
3021
|
-
// PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
|
|
3022
|
-
// // handle other cases.
|
|
3023
|
-
// for ENTRY in ENTRIES (not dotfiles)
|
|
3024
|
-
// // attach globstar + tail onto the entry
|
|
3025
|
-
// // Mark that this entry is a globstar match
|
|
3026
|
-
// PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
|
|
3027
|
-
//
|
|
3028
|
-
// else // not globstar
|
|
3029
|
-
// for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
|
|
3030
|
-
// Test ENTRY against pattern[n]
|
|
3031
|
-
// If fails, continue
|
|
3032
|
-
// If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
|
|
3033
|
-
//
|
|
3034
|
-
// Caveat:
|
|
3035
|
-
// Cache all stats and readdirs results to minimize syscall. Since all
|
|
3036
|
-
// we ever care about is existence and directory-ness, we can just keep
|
|
3037
|
-
// `true` for files, and [children,...] for directories, or `false` for
|
|
3038
|
-
// things that don't exist.
|
|
3039
|
-
|
|
3040
|
-
glob_1 = glob;
|
|
3041
|
-
var rp = requireFs_realpath();
|
|
3042
|
-
var minimatch = requireMinimatch();
|
|
3043
|
-
var inherits = requireInherits();
|
|
3044
|
-
var EE = require$$3.EventEmitter;
|
|
3045
|
-
var path = path$1;
|
|
3046
|
-
var assert = require$$5;
|
|
3047
|
-
var isAbsolute = requirePathIsAbsolute();
|
|
3048
|
-
var globSync = requireSync();
|
|
3049
|
-
var common = requireCommon();
|
|
3050
|
-
var setopts = common.setopts;
|
|
3051
|
-
var ownProp = common.ownProp;
|
|
3052
|
-
var inflight = requireInflight();
|
|
3053
|
-
var childrenIgnored = common.childrenIgnored;
|
|
3054
|
-
var isIgnored = common.isIgnored;
|
|
3055
|
-
var once = requireOnce();
|
|
3056
|
-
|
|
3057
|
-
function glob(pattern, options, cb) {
|
|
3058
|
-
if (typeof options === 'function') cb = options, options = {};
|
|
3059
|
-
if (!options) options = {};
|
|
3060
|
-
|
|
3061
|
-
if (options.sync) {
|
|
3062
|
-
if (cb) throw new TypeError('callback provided to sync glob');
|
|
3063
|
-
return globSync(pattern, options);
|
|
3064
|
-
}
|
|
3065
|
-
|
|
3066
|
-
return new Glob(pattern, options, cb);
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
glob.sync = globSync;
|
|
3070
|
-
var GlobSync = glob.GlobSync = globSync.GlobSync; // old api surface
|
|
3071
|
-
|
|
3072
|
-
glob.glob = glob;
|
|
3073
|
-
|
|
3074
|
-
function extend(origin, add) {
|
|
3075
|
-
if (add === null || typeof add !== 'object') {
|
|
3076
|
-
return origin;
|
|
3077
|
-
}
|
|
3078
|
-
|
|
3079
|
-
var keys = Object.keys(add);
|
|
3080
|
-
var i = keys.length;
|
|
3081
|
-
|
|
3082
|
-
while (i--) {
|
|
3083
|
-
origin[keys[i]] = add[keys[i]];
|
|
3084
|
-
}
|
|
3085
|
-
|
|
3086
|
-
return origin;
|
|
3087
|
-
}
|
|
3088
|
-
|
|
3089
|
-
glob.hasMagic = function (pattern, options_) {
|
|
3090
|
-
var options = extend({}, options_);
|
|
3091
|
-
options.noprocess = true;
|
|
3092
|
-
var g = new Glob(pattern, options);
|
|
3093
|
-
var set = g.minimatch.set;
|
|
3094
|
-
if (!pattern) return false;
|
|
3095
|
-
if (set.length > 1) return true;
|
|
3096
|
-
|
|
3097
|
-
for (var j = 0; j < set[0].length; j++) {
|
|
3098
|
-
if (typeof set[0][j] !== 'string') return true;
|
|
3099
|
-
}
|
|
3100
|
-
|
|
3101
|
-
return false;
|
|
3102
|
-
};
|
|
3103
|
-
|
|
3104
|
-
glob.Glob = Glob;
|
|
3105
|
-
inherits(Glob, EE);
|
|
3106
|
-
|
|
3107
|
-
function Glob(pattern, options, cb) {
|
|
3108
|
-
if (typeof options === 'function') {
|
|
3109
|
-
cb = options;
|
|
3110
|
-
options = null;
|
|
3111
|
-
}
|
|
3112
|
-
|
|
3113
|
-
if (options && options.sync) {
|
|
3114
|
-
if (cb) throw new TypeError('callback provided to sync glob');
|
|
3115
|
-
return new GlobSync(pattern, options);
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
|
-
if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
|
|
3119
|
-
setopts(this, pattern, options);
|
|
3120
|
-
this._didRealPath = false; // process each pattern in the minimatch set
|
|
3121
|
-
|
|
3122
|
-
var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
|
|
3123
|
-
// duplicates are automagically pruned.
|
|
3124
|
-
// Later, we do an Object.keys() on these.
|
|
3125
|
-
// Keep them as a list so we can fill in when nonull is set.
|
|
3126
|
-
|
|
3127
|
-
this.matches = new Array(n);
|
|
3128
|
-
|
|
3129
|
-
if (typeof cb === 'function') {
|
|
3130
|
-
cb = once(cb);
|
|
3131
|
-
this.on('error', cb);
|
|
3132
|
-
this.on('end', function (matches) {
|
|
3133
|
-
cb(null, matches);
|
|
3134
|
-
});
|
|
3135
|
-
}
|
|
3136
|
-
|
|
3137
|
-
var self = this;
|
|
3138
|
-
this._processing = 0;
|
|
3139
|
-
this._emitQueue = [];
|
|
3140
|
-
this._processQueue = [];
|
|
3141
|
-
this.paused = false;
|
|
3142
|
-
if (this.noprocess) return this;
|
|
3143
|
-
if (n === 0) return done();
|
|
3144
|
-
var sync = true;
|
|
3145
|
-
|
|
3146
|
-
for (var i = 0; i < n; i++) {
|
|
3147
|
-
this._process(this.minimatch.set[i], i, false, done);
|
|
3148
|
-
}
|
|
3149
|
-
|
|
3150
|
-
sync = false;
|
|
3151
|
-
|
|
3152
|
-
function done() {
|
|
3153
|
-
--self._processing;
|
|
3154
|
-
|
|
3155
|
-
if (self._processing <= 0) {
|
|
3156
|
-
if (sync) {
|
|
3157
|
-
process.nextTick(function () {
|
|
3158
|
-
self._finish();
|
|
3159
|
-
});
|
|
3160
|
-
} else {
|
|
3161
|
-
self._finish();
|
|
3162
|
-
}
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
|
|
3167
|
-
Glob.prototype._finish = function () {
|
|
3168
|
-
assert(this instanceof Glob);
|
|
3169
|
-
if (this.aborted) return;
|
|
3170
|
-
if (this.realpath && !this._didRealpath) return this._realpath();
|
|
3171
|
-
common.finish(this);
|
|
3172
|
-
this.emit('end', this.found);
|
|
3173
|
-
};
|
|
3174
|
-
|
|
3175
|
-
Glob.prototype._realpath = function () {
|
|
3176
|
-
if (this._didRealpath) return;
|
|
3177
|
-
this._didRealpath = true;
|
|
3178
|
-
var n = this.matches.length;
|
|
3179
|
-
if (n === 0) return this._finish();
|
|
3180
|
-
var self = this;
|
|
3181
|
-
|
|
3182
|
-
for (var i = 0; i < this.matches.length; i++) this._realpathSet(i, next);
|
|
3183
|
-
|
|
3184
|
-
function next() {
|
|
3185
|
-
if (--n === 0) self._finish();
|
|
3186
|
-
}
|
|
3187
|
-
};
|
|
3188
|
-
|
|
3189
|
-
Glob.prototype._realpathSet = function (index, cb) {
|
|
3190
|
-
var matchset = this.matches[index];
|
|
3191
|
-
if (!matchset) return cb();
|
|
3192
|
-
var found = Object.keys(matchset);
|
|
3193
|
-
var self = this;
|
|
3194
|
-
var n = found.length;
|
|
3195
|
-
if (n === 0) return cb();
|
|
3196
|
-
var set = this.matches[index] = Object.create(null);
|
|
3197
|
-
found.forEach(function (p, i) {
|
|
3198
|
-
// If there's a problem with the stat, then it means that
|
|
3199
|
-
// one or more of the links in the realpath couldn't be
|
|
3200
|
-
// resolved. just return the abs value in that case.
|
|
3201
|
-
p = self._makeAbs(p);
|
|
3202
|
-
rp.realpath(p, self.realpathCache, function (er, real) {
|
|
3203
|
-
if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
|
|
3204
|
-
|
|
3205
|
-
if (--n === 0) {
|
|
3206
|
-
self.matches[index] = set;
|
|
3207
|
-
cb();
|
|
3208
|
-
}
|
|
3209
|
-
});
|
|
3210
|
-
});
|
|
3211
|
-
};
|
|
3212
|
-
|
|
3213
|
-
Glob.prototype._mark = function (p) {
|
|
3214
|
-
return common.mark(this, p);
|
|
3215
|
-
};
|
|
3216
|
-
|
|
3217
|
-
Glob.prototype._makeAbs = function (f) {
|
|
3218
|
-
return common.makeAbs(this, f);
|
|
3219
|
-
};
|
|
3220
|
-
|
|
3221
|
-
Glob.prototype.abort = function () {
|
|
3222
|
-
this.aborted = true;
|
|
3223
|
-
this.emit('abort');
|
|
3224
|
-
};
|
|
3225
|
-
|
|
3226
|
-
Glob.prototype.pause = function () {
|
|
3227
|
-
if (!this.paused) {
|
|
3228
|
-
this.paused = true;
|
|
3229
|
-
this.emit('pause');
|
|
3230
|
-
}
|
|
3231
|
-
};
|
|
3232
|
-
|
|
3233
|
-
Glob.prototype.resume = function () {
|
|
3234
|
-
if (this.paused) {
|
|
3235
|
-
this.emit('resume');
|
|
3236
|
-
this.paused = false;
|
|
3237
|
-
|
|
3238
|
-
if (this._emitQueue.length) {
|
|
3239
|
-
var eq = this._emitQueue.slice(0);
|
|
3240
|
-
|
|
3241
|
-
this._emitQueue.length = 0;
|
|
3242
|
-
|
|
3243
|
-
for (var i = 0; i < eq.length; i++) {
|
|
3244
|
-
var e = eq[i];
|
|
3245
|
-
|
|
3246
|
-
this._emitMatch(e[0], e[1]);
|
|
3247
|
-
}
|
|
3248
|
-
}
|
|
3249
|
-
|
|
3250
|
-
if (this._processQueue.length) {
|
|
3251
|
-
var pq = this._processQueue.slice(0);
|
|
3252
|
-
|
|
3253
|
-
this._processQueue.length = 0;
|
|
3254
|
-
|
|
3255
|
-
for (var i = 0; i < pq.length; i++) {
|
|
3256
|
-
var p = pq[i];
|
|
3257
|
-
this._processing--;
|
|
3258
|
-
|
|
3259
|
-
this._process(p[0], p[1], p[2], p[3]);
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3263
|
-
};
|
|
3264
|
-
|
|
3265
|
-
Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
|
|
3266
|
-
assert(this instanceof Glob);
|
|
3267
|
-
assert(typeof cb === 'function');
|
|
3268
|
-
if (this.aborted) return;
|
|
3269
|
-
this._processing++;
|
|
3270
|
-
|
|
3271
|
-
if (this.paused) {
|
|
3272
|
-
this._processQueue.push([pattern, index, inGlobStar, cb]);
|
|
3273
|
-
|
|
3274
|
-
return;
|
|
3275
|
-
} //console.error('PROCESS %d', this._processing, pattern)
|
|
3276
|
-
// Get the first [n] parts of pattern that are all strings.
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
var n = 0;
|
|
3280
|
-
|
|
3281
|
-
while (typeof pattern[n] === 'string') {
|
|
3282
|
-
n++;
|
|
3283
|
-
} // now n is the index of the first one that is *not* a string.
|
|
3284
|
-
// see if there's anything else
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
var prefix;
|
|
3288
|
-
|
|
3289
|
-
switch (n) {
|
|
3290
|
-
// if not, then this is rather simple
|
|
3291
|
-
case pattern.length:
|
|
3292
|
-
this._processSimple(pattern.join('/'), index, cb);
|
|
3293
|
-
|
|
3294
|
-
return;
|
|
3295
|
-
|
|
3296
|
-
case 0:
|
|
3297
|
-
// pattern *starts* with some non-trivial item.
|
|
3298
|
-
// going to readdir(cwd), but not include the prefix in matches.
|
|
3299
|
-
prefix = null;
|
|
3300
|
-
break;
|
|
3301
|
-
|
|
3302
|
-
default:
|
|
3303
|
-
// pattern has some string bits in the front.
|
|
3304
|
-
// whatever it starts with, whether that's 'absolute' like /foo/bar,
|
|
3305
|
-
// or 'relative' like '../baz'
|
|
3306
|
-
prefix = pattern.slice(0, n).join('/');
|
|
3307
|
-
break;
|
|
3308
|
-
}
|
|
3309
|
-
|
|
3310
|
-
var remain = pattern.slice(n); // get the list of entries.
|
|
3311
|
-
|
|
3312
|
-
var read;
|
|
3313
|
-
if (prefix === null) read = '.';else if (isAbsolute(prefix) || isAbsolute(pattern.map(function (p) {
|
|
3314
|
-
return typeof p === 'string' ? p : '[*]';
|
|
3315
|
-
}).join('/'))) {
|
|
3316
|
-
if (!prefix || !isAbsolute(prefix)) prefix = '/' + prefix;
|
|
3317
|
-
read = prefix;
|
|
3318
|
-
} else read = prefix;
|
|
3319
|
-
|
|
3320
|
-
var abs = this._makeAbs(read); //if ignored, skip _processing
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
if (childrenIgnored(this, read)) return cb();
|
|
3324
|
-
var isGlobStar = remain[0] === minimatch.GLOBSTAR;
|
|
3325
|
-
if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
|
|
3326
|
-
};
|
|
3327
|
-
|
|
3328
|
-
Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
|
|
3329
|
-
var self = this;
|
|
3330
|
-
|
|
3331
|
-
this._readdir(abs, inGlobStar, function (er, entries) {
|
|
3332
|
-
return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
|
|
3333
|
-
});
|
|
3334
|
-
};
|
|
3335
|
-
|
|
3336
|
-
Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
|
|
3337
|
-
// if the abs isn't a dir, then nothing can match!
|
|
3338
|
-
if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
|
|
3339
|
-
// dot is set. Stuff like @(.foo|.bar) isn't allowed.
|
|
3340
|
-
|
|
3341
|
-
var pn = remain[0];
|
|
3342
|
-
var negate = !!this.minimatch.negate;
|
|
3343
|
-
var rawGlob = pn._glob;
|
|
3344
|
-
var dotOk = this.dot || rawGlob.charAt(0) === '.';
|
|
3345
|
-
var matchedEntries = [];
|
|
3346
|
-
|
|
3347
|
-
for (var i = 0; i < entries.length; i++) {
|
|
3348
|
-
var e = entries[i];
|
|
3349
|
-
|
|
3350
|
-
if (e.charAt(0) !== '.' || dotOk) {
|
|
3351
|
-
var m;
|
|
3352
|
-
|
|
3353
|
-
if (negate && !prefix) {
|
|
3354
|
-
m = !e.match(pn);
|
|
3355
|
-
} else {
|
|
3356
|
-
m = e.match(pn);
|
|
3357
|
-
}
|
|
3358
|
-
|
|
3359
|
-
if (m) matchedEntries.push(e);
|
|
3360
|
-
}
|
|
3361
|
-
} //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
|
|
3365
|
-
|
|
3366
|
-
if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
|
|
3367
|
-
// an additional stat *unless* the user has specified mark or
|
|
3368
|
-
// stat explicitly. We know they exist, since readdir returned
|
|
3369
|
-
// them.
|
|
3370
|
-
|
|
3371
|
-
if (remain.length === 1 && !this.mark && !this.stat) {
|
|
3372
|
-
if (!this.matches[index]) this.matches[index] = Object.create(null);
|
|
3373
|
-
|
|
3374
|
-
for (var i = 0; i < len; i++) {
|
|
3375
|
-
var e = matchedEntries[i];
|
|
3376
|
-
|
|
3377
|
-
if (prefix) {
|
|
3378
|
-
if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
|
|
3379
|
-
}
|
|
3380
|
-
|
|
3381
|
-
if (e.charAt(0) === '/' && !this.nomount) {
|
|
3382
|
-
e = path.join(this.root, e);
|
|
3383
|
-
}
|
|
3384
|
-
|
|
3385
|
-
this._emitMatch(index, e);
|
|
3386
|
-
} // This was the last one, and no stats were needed
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
return cb();
|
|
3390
|
-
} // now test all matched entries as stand-ins for that part
|
|
3391
|
-
// of the pattern.
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
remain.shift();
|
|
3395
|
-
|
|
3396
|
-
for (var i = 0; i < len; i++) {
|
|
3397
|
-
var e = matchedEntries[i];
|
|
3398
|
-
|
|
3399
|
-
if (prefix) {
|
|
3400
|
-
if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
this._process([e].concat(remain), index, inGlobStar, cb);
|
|
3404
|
-
}
|
|
3405
|
-
|
|
3406
|
-
cb();
|
|
3407
|
-
};
|
|
3408
|
-
|
|
3409
|
-
Glob.prototype._emitMatch = function (index, e) {
|
|
3410
|
-
if (this.aborted) return;
|
|
3411
|
-
if (isIgnored(this, e)) return;
|
|
3412
|
-
|
|
3413
|
-
if (this.paused) {
|
|
3414
|
-
this._emitQueue.push([index, e]);
|
|
3415
|
-
|
|
3416
|
-
return;
|
|
3417
|
-
}
|
|
3418
|
-
|
|
3419
|
-
var abs = isAbsolute(e) ? e : this._makeAbs(e);
|
|
3420
|
-
if (this.mark) e = this._mark(e);
|
|
3421
|
-
if (this.absolute) e = abs;
|
|
3422
|
-
if (this.matches[index][e]) return;
|
|
3423
|
-
|
|
3424
|
-
if (this.nodir) {
|
|
3425
|
-
var c = this.cache[abs];
|
|
3426
|
-
if (c === 'DIR' || Array.isArray(c)) return;
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
this.matches[index][e] = true;
|
|
3430
|
-
var st = this.statCache[abs];
|
|
3431
|
-
if (st) this.emit('stat', e, st);
|
|
3432
|
-
this.emit('match', e);
|
|
3433
|
-
};
|
|
3434
|
-
|
|
3435
|
-
Glob.prototype._readdirInGlobStar = function (abs, cb) {
|
|
3436
|
-
if (this.aborted) return; // follow all symlinked directories forever
|
|
3437
|
-
// just proceed as if this is a non-globstar situation
|
|
3438
|
-
|
|
3439
|
-
if (this.follow) return this._readdir(abs, false, cb);
|
|
3440
|
-
var lstatkey = 'lstat\0' + abs;
|
|
3441
|
-
var self = this;
|
|
3442
|
-
var lstatcb = inflight(lstatkey, lstatcb_);
|
|
3443
|
-
if (lstatcb) self.fs.lstat(abs, lstatcb);
|
|
3444
|
-
|
|
3445
|
-
function lstatcb_(er, lstat) {
|
|
3446
|
-
if (er && er.code === 'ENOENT') return cb();
|
|
3447
|
-
var isSym = lstat && lstat.isSymbolicLink();
|
|
3448
|
-
self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
|
|
3449
|
-
// don't bother doing a readdir in that case.
|
|
3450
|
-
|
|
3451
|
-
if (!isSym && lstat && !lstat.isDirectory()) {
|
|
3452
|
-
self.cache[abs] = 'FILE';
|
|
3453
|
-
cb();
|
|
3454
|
-
} else self._readdir(abs, false, cb);
|
|
3455
|
-
}
|
|
3456
|
-
};
|
|
3457
|
-
|
|
3458
|
-
Glob.prototype._readdir = function (abs, inGlobStar, cb) {
|
|
3459
|
-
if (this.aborted) return;
|
|
3460
|
-
cb = inflight('readdir\0' + abs + '\0' + inGlobStar, cb);
|
|
3461
|
-
if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
|
|
3462
|
-
|
|
3463
|
-
if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
|
|
3464
|
-
|
|
3465
|
-
if (ownProp(this.cache, abs)) {
|
|
3466
|
-
var c = this.cache[abs];
|
|
3467
|
-
if (!c || c === 'FILE') return cb();
|
|
3468
|
-
if (Array.isArray(c)) return cb(null, c);
|
|
3469
|
-
}
|
|
3470
|
-
|
|
3471
|
-
var self = this;
|
|
3472
|
-
self.fs.readdir(abs, readdirCb(this, abs, cb));
|
|
3473
|
-
};
|
|
3474
|
-
|
|
3475
|
-
function readdirCb(self, abs, cb) {
|
|
3476
|
-
return function (er, entries) {
|
|
3477
|
-
if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
|
|
3478
|
-
};
|
|
3479
|
-
}
|
|
3480
|
-
|
|
3481
|
-
Glob.prototype._readdirEntries = function (abs, entries, cb) {
|
|
3482
|
-
if (this.aborted) return; // if we haven't asked to stat everything, then just
|
|
3483
|
-
// assume that everything in there exists, so we can avoid
|
|
3484
|
-
// having to stat it a second time.
|
|
3485
|
-
|
|
3486
|
-
if (!this.mark && !this.stat) {
|
|
3487
|
-
for (var i = 0; i < entries.length; i++) {
|
|
3488
|
-
var e = entries[i];
|
|
3489
|
-
if (abs === '/') e = abs + e;else e = abs + '/' + e;
|
|
3490
|
-
this.cache[e] = true;
|
|
3491
|
-
}
|
|
3492
|
-
}
|
|
3493
|
-
|
|
3494
|
-
this.cache[abs] = entries;
|
|
3495
|
-
return cb(null, entries);
|
|
3496
|
-
};
|
|
3497
|
-
|
|
3498
|
-
Glob.prototype._readdirError = function (f, er, cb) {
|
|
3499
|
-
if (this.aborted) return; // handle errors, and cache the information
|
|
3500
|
-
|
|
3501
|
-
switch (er.code) {
|
|
3502
|
-
case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
|
|
3503
|
-
|
|
3504
|
-
case 'ENOTDIR':
|
|
3505
|
-
// totally normal. means it *does* exist.
|
|
3506
|
-
var abs = this._makeAbs(f);
|
|
3507
|
-
|
|
3508
|
-
this.cache[abs] = 'FILE';
|
|
3509
|
-
|
|
3510
|
-
if (abs === this.cwdAbs) {
|
|
3511
|
-
var error = new Error(er.code + ' invalid cwd ' + this.cwd);
|
|
3512
|
-
error.path = this.cwd;
|
|
3513
|
-
error.code = er.code;
|
|
3514
|
-
this.emit('error', error);
|
|
3515
|
-
this.abort();
|
|
3516
|
-
}
|
|
3517
|
-
|
|
3518
|
-
break;
|
|
3519
|
-
|
|
3520
|
-
case 'ENOENT': // not terribly unusual
|
|
3521
|
-
|
|
3522
|
-
case 'ELOOP':
|
|
3523
|
-
case 'ENAMETOOLONG':
|
|
3524
|
-
case 'UNKNOWN':
|
|
3525
|
-
this.cache[this._makeAbs(f)] = false;
|
|
3526
|
-
break;
|
|
3527
|
-
|
|
3528
|
-
default:
|
|
3529
|
-
// some unusual error. Treat as failure.
|
|
3530
|
-
this.cache[this._makeAbs(f)] = false;
|
|
3531
|
-
|
|
3532
|
-
if (this.strict) {
|
|
3533
|
-
this.emit('error', er); // If the error is handled, then we abort
|
|
3534
|
-
// if not, we threw out of here
|
|
3535
|
-
|
|
3536
|
-
this.abort();
|
|
3537
|
-
}
|
|
3538
|
-
|
|
3539
|
-
if (!this.silent) console.error('glob error', er);
|
|
3540
|
-
break;
|
|
3541
|
-
}
|
|
3542
|
-
|
|
3543
|
-
return cb();
|
|
3544
|
-
};
|
|
3545
|
-
|
|
3546
|
-
Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
|
|
3547
|
-
var self = this;
|
|
3548
|
-
|
|
3549
|
-
this._readdir(abs, inGlobStar, function (er, entries) {
|
|
3550
|
-
self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
|
|
3551
|
-
});
|
|
3552
|
-
};
|
|
3553
|
-
|
|
3554
|
-
Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
|
|
3555
|
-
//console.error('pgs2', prefix, remain[0], entries)
|
|
3556
|
-
// no entries means not a dir, so it can never have matches
|
|
3557
|
-
// foo.txt/** doesn't match foo.txt
|
|
3558
|
-
if (!entries) return cb(); // test without the globstar, and with every child both below
|
|
3559
|
-
// and replacing the globstar.
|
|
3560
|
-
|
|
3561
|
-
var remainWithoutGlobStar = remain.slice(1);
|
|
3562
|
-
var gspref = prefix ? [prefix] : [];
|
|
3563
|
-
var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
|
|
3564
|
-
|
|
3565
|
-
this._process(noGlobStar, index, false, cb);
|
|
3566
|
-
|
|
3567
|
-
var isSym = this.symlinks[abs];
|
|
3568
|
-
var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
|
|
3569
|
-
|
|
3570
|
-
if (isSym && inGlobStar) return cb();
|
|
3571
|
-
|
|
3572
|
-
for (var i = 0; i < len; i++) {
|
|
3573
|
-
var e = entries[i];
|
|
3574
|
-
if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
|
|
3575
|
-
|
|
3576
|
-
var instead = gspref.concat(entries[i], remainWithoutGlobStar);
|
|
3577
|
-
|
|
3578
|
-
this._process(instead, index, true, cb);
|
|
3579
|
-
|
|
3580
|
-
var below = gspref.concat(entries[i], remain);
|
|
3581
|
-
|
|
3582
|
-
this._process(below, index, true, cb);
|
|
3583
|
-
}
|
|
3584
|
-
|
|
3585
|
-
cb();
|
|
3586
|
-
};
|
|
3587
|
-
|
|
3588
|
-
Glob.prototype._processSimple = function (prefix, index, cb) {
|
|
3589
|
-
// XXX review this. Shouldn't it be doing the mounting etc
|
|
3590
|
-
// before doing stat? kinda weird?
|
|
3591
|
-
var self = this;
|
|
3592
|
-
|
|
3593
|
-
this._stat(prefix, function (er, exists) {
|
|
3594
|
-
self._processSimple2(prefix, index, er, exists, cb);
|
|
3595
|
-
});
|
|
3596
|
-
};
|
|
3597
|
-
|
|
3598
|
-
Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
|
|
3599
|
-
//console.error('ps2', prefix, exists)
|
|
3600
|
-
if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
|
|
3601
|
-
|
|
3602
|
-
if (!exists) return cb();
|
|
3603
|
-
|
|
3604
|
-
if (prefix && isAbsolute(prefix) && !this.nomount) {
|
|
3605
|
-
var trail = /[\/\\]$/.test(prefix);
|
|
3606
|
-
|
|
3607
|
-
if (prefix.charAt(0) === '/') {
|
|
3608
|
-
prefix = path.join(this.root, prefix);
|
|
3609
|
-
} else {
|
|
3610
|
-
prefix = path.resolve(this.root, prefix);
|
|
3611
|
-
if (trail) prefix += '/';
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
|
|
3615
|
-
if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
|
|
3616
|
-
|
|
3617
|
-
this._emitMatch(index, prefix);
|
|
3618
|
-
|
|
3619
|
-
cb();
|
|
3620
|
-
}; // Returns either 'DIR', 'FILE', or false
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
Glob.prototype._stat = function (f, cb) {
|
|
3624
|
-
var abs = this._makeAbs(f);
|
|
3625
|
-
|
|
3626
|
-
var needDir = f.slice(-1) === '/';
|
|
3627
|
-
if (f.length > this.maxLength) return cb();
|
|
3628
|
-
|
|
3629
|
-
if (!this.stat && ownProp(this.cache, abs)) {
|
|
3630
|
-
var c = this.cache[abs];
|
|
3631
|
-
if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
|
|
3632
|
-
|
|
3633
|
-
if (!needDir || c === 'DIR') return cb(null, c);
|
|
3634
|
-
if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
|
|
3635
|
-
// if we know it exists, but not what it is.
|
|
3636
|
-
}
|
|
3637
|
-
|
|
3638
|
-
var stat = this.statCache[abs];
|
|
3639
|
-
|
|
3640
|
-
if (stat !== undefined) {
|
|
3641
|
-
if (stat === false) return cb(null, stat);else {
|
|
3642
|
-
var type = stat.isDirectory() ? 'DIR' : 'FILE';
|
|
3643
|
-
if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
|
|
3647
|
-
var self = this;
|
|
3648
|
-
var statcb = inflight('stat\0' + abs, lstatcb_);
|
|
3649
|
-
if (statcb) self.fs.lstat(abs, statcb);
|
|
3650
|
-
|
|
3651
|
-
function lstatcb_(er, lstat) {
|
|
3652
|
-
if (lstat && lstat.isSymbolicLink()) {
|
|
3653
|
-
// If it's a symlink, then treat it as the target, unless
|
|
3654
|
-
// the target does not exist, then treat it as a file.
|
|
3655
|
-
return self.fs.stat(abs, function (er, stat) {
|
|
3656
|
-
if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
|
|
3657
|
-
});
|
|
3658
|
-
} else {
|
|
3659
|
-
self._stat2(f, abs, er, lstat, cb);
|
|
3660
|
-
}
|
|
3661
|
-
}
|
|
3662
|
-
};
|
|
3663
|
-
|
|
3664
|
-
Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
|
|
3665
|
-
if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
|
|
3666
|
-
this.statCache[abs] = false;
|
|
3667
|
-
return cb();
|
|
3668
|
-
}
|
|
3669
|
-
|
|
3670
|
-
var needDir = f.slice(-1) === '/';
|
|
3671
|
-
this.statCache[abs] = stat;
|
|
3672
|
-
if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
|
|
3673
|
-
var c = true;
|
|
3674
|
-
if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
|
|
3675
|
-
this.cache[abs] = this.cache[abs] || c;
|
|
3676
|
-
if (needDir && c === 'FILE') return cb();
|
|
3677
|
-
return cb(null, c, stat);
|
|
3678
|
-
};
|
|
3679
|
-
|
|
3680
|
-
return glob_1;
|
|
3681
|
-
}
|
|
3682
|
-
|
|
3683
|
-
const assert = require$$5;
|
|
3684
|
-
const path = path$1;
|
|
3685
|
-
const fs = fs$2;
|
|
3686
|
-
let glob = undefined;
|
|
3687
|
-
|
|
3688
|
-
try {
|
|
3689
|
-
glob = requireGlob();
|
|
3690
|
-
} catch (_err) {// treat glob as optional.
|
|
3691
|
-
}
|
|
3692
|
-
|
|
3693
|
-
const defaultGlobOpts = {
|
|
3694
|
-
nosort: true,
|
|
3695
|
-
silent: true
|
|
3696
|
-
}; // for EMFILE handling
|
|
3697
|
-
|
|
3698
|
-
let timeout = 0;
|
|
3699
|
-
const isWindows = process.platform === "win32";
|
|
3700
|
-
|
|
3701
|
-
const defaults = options => {
|
|
3702
|
-
const methods = ['unlink', 'chmod', 'stat', 'lstat', 'rmdir', 'readdir'];
|
|
3703
|
-
methods.forEach(m => {
|
|
3704
|
-
options[m] = options[m] || fs[m];
|
|
3705
|
-
m = m + 'Sync';
|
|
3706
|
-
options[m] = options[m] || fs[m];
|
|
3707
|
-
});
|
|
3708
|
-
options.maxBusyTries = options.maxBusyTries || 3;
|
|
3709
|
-
options.emfileWait = options.emfileWait || 1000;
|
|
3710
|
-
|
|
3711
|
-
if (options.glob === false) {
|
|
3712
|
-
options.disableGlob = true;
|
|
3713
|
-
}
|
|
3714
|
-
|
|
3715
|
-
if (options.disableGlob !== true && glob === undefined) {
|
|
3716
|
-
throw Error('glob dependency not found, set `options.disableGlob = true` if intentional');
|
|
3717
|
-
}
|
|
3718
|
-
|
|
3719
|
-
options.disableGlob = options.disableGlob || false;
|
|
3720
|
-
options.glob = options.glob || defaultGlobOpts;
|
|
3721
|
-
};
|
|
3722
|
-
|
|
3723
|
-
const rimraf$1 = (p, options, cb) => {
|
|
3724
|
-
if (typeof options === 'function') {
|
|
3725
|
-
cb = options;
|
|
3726
|
-
options = {};
|
|
3727
|
-
}
|
|
3728
|
-
|
|
3729
|
-
assert(p, 'rimraf: missing path');
|
|
3730
|
-
assert.equal(typeof p, 'string', 'rimraf: path should be a string');
|
|
3731
|
-
assert.equal(typeof cb, 'function', 'rimraf: callback function required');
|
|
3732
|
-
assert(options, 'rimraf: invalid options argument provided');
|
|
3733
|
-
assert.equal(typeof options, 'object', 'rimraf: options should be object');
|
|
3734
|
-
defaults(options);
|
|
3735
|
-
let busyTries = 0;
|
|
3736
|
-
let errState = null;
|
|
3737
|
-
let n = 0;
|
|
3738
|
-
|
|
3739
|
-
const next = er => {
|
|
3740
|
-
errState = errState || er;
|
|
3741
|
-
if (--n === 0) cb(errState);
|
|
3742
|
-
};
|
|
3743
|
-
|
|
3744
|
-
const afterGlob = (er, results) => {
|
|
3745
|
-
if (er) return cb(er);
|
|
3746
|
-
n = results.length;
|
|
3747
|
-
if (n === 0) return cb();
|
|
3748
|
-
results.forEach(p => {
|
|
3749
|
-
const CB = er => {
|
|
3750
|
-
if (er) {
|
|
3751
|
-
if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") && busyTries < options.maxBusyTries) {
|
|
3752
|
-
busyTries++; // try again, with the same exact callback as this one.
|
|
3753
|
-
|
|
3754
|
-
return setTimeout(() => rimraf_(p, options, CB), busyTries * 100);
|
|
3755
|
-
} // this one won't happen if graceful-fs is used.
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
if (er.code === "EMFILE" && timeout < options.emfileWait) {
|
|
3759
|
-
return setTimeout(() => rimraf_(p, options, CB), timeout++);
|
|
3760
|
-
} // already gone
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
if (er.code === "ENOENT") er = null;
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
timeout = 0;
|
|
3767
|
-
next(er);
|
|
3768
|
-
};
|
|
3769
|
-
|
|
3770
|
-
rimraf_(p, options, CB);
|
|
3771
|
-
});
|
|
3772
|
-
};
|
|
3773
|
-
|
|
3774
|
-
if (options.disableGlob || !glob.hasMagic(p)) return afterGlob(null, [p]);
|
|
3775
|
-
options.lstat(p, (er, stat) => {
|
|
3776
|
-
if (!er) return afterGlob(null, [p]);
|
|
3777
|
-
glob(p, options.glob, afterGlob);
|
|
3778
|
-
});
|
|
3779
|
-
}; // Two possible strategies.
|
|
3780
|
-
// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
|
|
3781
|
-
// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
|
|
3782
|
-
//
|
|
3783
|
-
// Both result in an extra syscall when you guess wrong. However, there
|
|
3784
|
-
// are likely far more normal files in the world than directories. This
|
|
3785
|
-
// is based on the assumption that a the average number of files per
|
|
3786
|
-
// directory is >= 1.
|
|
3787
|
-
//
|
|
3788
|
-
// If anyone ever complains about this, then I guess the strategy could
|
|
3789
|
-
// be made configurable somehow. But until then, YAGNI.
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
const rimraf_ = (p, options, cb) => {
|
|
3793
|
-
assert(p);
|
|
3794
|
-
assert(options);
|
|
3795
|
-
assert(typeof cb === 'function'); // sunos lets the root user unlink directories, which is... weird.
|
|
3796
|
-
// so we have to lstat here and make sure it's not a dir.
|
|
3797
|
-
|
|
3798
|
-
options.lstat(p, (er, st) => {
|
|
3799
|
-
if (er && er.code === "ENOENT") return cb(null); // Windows can EPERM on stat. Life is suffering.
|
|
3800
|
-
|
|
3801
|
-
if (er && er.code === "EPERM" && isWindows) fixWinEPERM(p, options, er, cb);
|
|
3802
|
-
if (st && st.isDirectory()) return rmdir(p, options, er, cb);
|
|
3803
|
-
options.unlink(p, er => {
|
|
3804
|
-
if (er) {
|
|
3805
|
-
if (er.code === "ENOENT") return cb(null);
|
|
3806
|
-
if (er.code === "EPERM") return isWindows ? fixWinEPERM(p, options, er, cb) : rmdir(p, options, er, cb);
|
|
3807
|
-
if (er.code === "EISDIR") return rmdir(p, options, er, cb);
|
|
3808
|
-
}
|
|
3809
|
-
|
|
3810
|
-
return cb(er);
|
|
3811
|
-
});
|
|
3812
|
-
});
|
|
3813
|
-
};
|
|
3814
|
-
|
|
3815
|
-
const fixWinEPERM = (p, options, er, cb) => {
|
|
3816
|
-
assert(p);
|
|
3817
|
-
assert(options);
|
|
3818
|
-
assert(typeof cb === 'function');
|
|
3819
|
-
options.chmod(p, 0o666, er2 => {
|
|
3820
|
-
if (er2) cb(er2.code === "ENOENT" ? null : er);else options.stat(p, (er3, stats) => {
|
|
3821
|
-
if (er3) cb(er3.code === "ENOENT" ? null : er);else if (stats.isDirectory()) rmdir(p, options, er, cb);else options.unlink(p, cb);
|
|
3822
|
-
});
|
|
3823
|
-
});
|
|
3824
|
-
};
|
|
3825
|
-
|
|
3826
|
-
const fixWinEPERMSync = (p, options, er) => {
|
|
3827
|
-
assert(p);
|
|
3828
|
-
assert(options);
|
|
3829
|
-
|
|
3830
|
-
try {
|
|
3831
|
-
options.chmodSync(p, 0o666);
|
|
3832
|
-
} catch (er2) {
|
|
3833
|
-
if (er2.code === "ENOENT") return;else throw er;
|
|
3834
|
-
}
|
|
3835
|
-
|
|
3836
|
-
let stats;
|
|
3837
|
-
|
|
3838
|
-
try {
|
|
3839
|
-
stats = options.statSync(p);
|
|
3840
|
-
} catch (er3) {
|
|
3841
|
-
if (er3.code === "ENOENT") return;else throw er;
|
|
3842
|
-
}
|
|
3843
|
-
|
|
3844
|
-
if (stats.isDirectory()) rmdirSync(p, options, er);else options.unlinkSync(p);
|
|
3845
|
-
};
|
|
3846
|
-
|
|
3847
|
-
const rmdir = (p, options, originalEr, cb) => {
|
|
3848
|
-
assert(p);
|
|
3849
|
-
assert(options);
|
|
3850
|
-
assert(typeof cb === 'function'); // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
|
|
3851
|
-
// if we guessed wrong, and it's not a directory, then
|
|
3852
|
-
// raise the original error.
|
|
3853
|
-
|
|
3854
|
-
options.rmdir(p, er => {
|
|
3855
|
-
if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")) rmkids(p, options, cb);else if (er && er.code === "ENOTDIR") cb(originalEr);else cb(er);
|
|
3856
|
-
});
|
|
3857
|
-
};
|
|
3858
|
-
|
|
3859
|
-
const rmkids = (p, options, cb) => {
|
|
3860
|
-
assert(p);
|
|
3861
|
-
assert(options);
|
|
3862
|
-
assert(typeof cb === 'function');
|
|
3863
|
-
options.readdir(p, (er, files) => {
|
|
3864
|
-
if (er) return cb(er);
|
|
3865
|
-
let n = files.length;
|
|
3866
|
-
if (n === 0) return options.rmdir(p, cb);
|
|
3867
|
-
let errState;
|
|
3868
|
-
files.forEach(f => {
|
|
3869
|
-
rimraf$1(path.join(p, f), options, er => {
|
|
3870
|
-
if (errState) return;
|
|
3871
|
-
if (er) return cb(errState = er);
|
|
3872
|
-
if (--n === 0) options.rmdir(p, cb);
|
|
3873
|
-
});
|
|
3874
|
-
});
|
|
3875
|
-
});
|
|
3876
|
-
}; // this looks simpler, and is strictly *faster*, but will
|
|
3877
|
-
// tie up the JavaScript thread and fail on excessively
|
|
3878
|
-
// deep directory trees.
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
const rimrafSync = (p, options) => {
|
|
3882
|
-
options = options || {};
|
|
3883
|
-
defaults(options);
|
|
3884
|
-
assert(p, 'rimraf: missing path');
|
|
3885
|
-
assert.equal(typeof p, 'string', 'rimraf: path should be a string');
|
|
3886
|
-
assert(options, 'rimraf: missing options');
|
|
3887
|
-
assert.equal(typeof options, 'object', 'rimraf: options should be object');
|
|
3888
|
-
let results;
|
|
3889
|
-
|
|
3890
|
-
if (options.disableGlob || !glob.hasMagic(p)) {
|
|
3891
|
-
results = [p];
|
|
3892
|
-
} else {
|
|
3893
|
-
try {
|
|
3894
|
-
options.lstatSync(p);
|
|
3895
|
-
results = [p];
|
|
3896
|
-
} catch (er) {
|
|
3897
|
-
results = glob.sync(p, options.glob);
|
|
3898
|
-
}
|
|
3899
|
-
}
|
|
3900
|
-
|
|
3901
|
-
if (!results.length) return;
|
|
3902
|
-
|
|
3903
|
-
for (let i = 0; i < results.length; i++) {
|
|
3904
|
-
const p = results[i];
|
|
3905
|
-
let st;
|
|
3906
|
-
|
|
3907
|
-
try {
|
|
3908
|
-
st = options.lstatSync(p);
|
|
3909
|
-
} catch (er) {
|
|
3910
|
-
if (er.code === "ENOENT") return; // Windows can EPERM on stat. Life is suffering.
|
|
3911
|
-
|
|
3912
|
-
if (er.code === "EPERM" && isWindows) fixWinEPERMSync(p, options, er);
|
|
3913
|
-
}
|
|
3914
|
-
|
|
3915
|
-
try {
|
|
3916
|
-
// sunos lets the root user unlink directories, which is... weird.
|
|
3917
|
-
if (st && st.isDirectory()) rmdirSync(p, options, null);else options.unlinkSync(p);
|
|
3918
|
-
} catch (er) {
|
|
3919
|
-
if (er.code === "ENOENT") return;
|
|
3920
|
-
if (er.code === "EPERM") return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er);
|
|
3921
|
-
if (er.code !== "EISDIR") throw er;
|
|
3922
|
-
rmdirSync(p, options, er);
|
|
3923
|
-
}
|
|
3924
|
-
}
|
|
3925
|
-
};
|
|
3926
|
-
|
|
3927
|
-
const rmdirSync = (p, options, originalEr) => {
|
|
3928
|
-
assert(p);
|
|
3929
|
-
assert(options);
|
|
3930
|
-
|
|
3931
|
-
try {
|
|
3932
|
-
options.rmdirSync(p);
|
|
3933
|
-
} catch (er) {
|
|
3934
|
-
if (er.code === "ENOENT") return;
|
|
3935
|
-
if (er.code === "ENOTDIR") throw originalEr;
|
|
3936
|
-
if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM") rmkidsSync(p, options);
|
|
3937
|
-
}
|
|
3938
|
-
};
|
|
3939
|
-
|
|
3940
|
-
const rmkidsSync = (p, options) => {
|
|
3941
|
-
assert(p);
|
|
3942
|
-
assert(options);
|
|
3943
|
-
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options)); // We only end up here once we got ENOTEMPTY at least once, and
|
|
3944
|
-
// at this point, we are guaranteed to have removed all the kids.
|
|
3945
|
-
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
|
|
3946
|
-
// try really hard to delete stuff on windows, because it has a
|
|
3947
|
-
// PROFOUNDLY annoying habit of not closing handles promptly when
|
|
3948
|
-
// files are deleted, resulting in spurious ENOTEMPTY errors.
|
|
3949
|
-
|
|
3950
|
-
const retries = isWindows ? 100 : 1;
|
|
3951
|
-
let i = 0;
|
|
3952
|
-
|
|
3953
|
-
do {
|
|
3954
|
-
let threw = true;
|
|
3955
|
-
|
|
3956
|
-
try {
|
|
3957
|
-
const ret = options.rmdirSync(p, options);
|
|
3958
|
-
threw = false;
|
|
3959
|
-
return ret;
|
|
3960
|
-
} finally {
|
|
3961
|
-
if (++i < retries && threw) continue;
|
|
3962
|
-
}
|
|
3963
|
-
} while (true);
|
|
3964
|
-
};
|
|
3965
|
-
|
|
3966
|
-
var rimraf_1 = rimraf$1;
|
|
3967
|
-
rimraf$1.sync = rimrafSync;
|
|
3968
498
|
const formatHost = {
|
|
3969
499
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
3970
500
|
getNewLine: () => ts.sys.newLine,
|
|
@@ -4039,11 +569,11 @@ function _createApiExtractorConfig(options) {
|
|
|
4039
569
|
},
|
|
4040
570
|
docModel: {
|
|
4041
571
|
enabled: false,
|
|
4042
|
-
apiJsonFilePath: path
|
|
572
|
+
apiJsonFilePath: path.resolve(distPath, "".concat(exportPath, ".api.json"))
|
|
4043
573
|
},
|
|
4044
574
|
dtsRollup: {
|
|
4045
575
|
enabled: true,
|
|
4046
|
-
untrimmedFilePath: path
|
|
576
|
+
untrimmedFilePath: path.resolve(distPath, filePath)
|
|
4047
577
|
},
|
|
4048
578
|
tsdocMetadata: {
|
|
4049
579
|
enabled: false
|
|
@@ -4147,6 +677,18 @@ async function _extractTypes(options) {
|
|
|
4147
677
|
default: {
|
|
4148
678
|
logLevel: "warning",
|
|
4149
679
|
addToApiReportFile: false
|
|
680
|
+
},
|
|
681
|
+
"tsdoc-link-tag-unescaped-text": {
|
|
682
|
+
logLevel: _ruleToLogLevel("tsdoc-link-tag-unescaped-text", "warning"),
|
|
683
|
+
addToApiReportFile: false
|
|
684
|
+
},
|
|
685
|
+
"tsdoc-undefined-tag": {
|
|
686
|
+
logLevel: _ruleToLogLevel("tsdoc-undefined-tag", "error"),
|
|
687
|
+
addToApiReportFile: false
|
|
688
|
+
},
|
|
689
|
+
"tsdoc-unsupported-tag": {
|
|
690
|
+
logLevel: _ruleToLogLevel("tsdoc-unsupported-tag", "none"),
|
|
691
|
+
addToApiReportFile: false
|
|
4150
692
|
}
|
|
4151
693
|
}
|
|
4152
694
|
};
|
|
@@ -4162,7 +704,7 @@ async function _extractTypes(options) {
|
|
|
4162
704
|
}),
|
|
4163
705
|
configObjectFullPath: void 0,
|
|
4164
706
|
tsdocConfigFile,
|
|
4165
|
-
packageJsonFullPath: path
|
|
707
|
+
packageJsonFullPath: path.resolve(projectPath, "package.json")
|
|
4166
708
|
});
|
|
4167
709
|
const messages = [];
|
|
4168
710
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
@@ -4175,11 +717,11 @@ async function _extractTypes(options) {
|
|
|
4175
717
|
}
|
|
4176
718
|
|
|
4177
719
|
});
|
|
4178
|
-
const typesPath = path
|
|
4179
|
-
const typesBuf = await fs
|
|
720
|
+
const typesPath = path.resolve(distPath, filePath);
|
|
721
|
+
const typesBuf = await fs.readFile(typesPath);
|
|
4180
722
|
const prettierConfig = await prettier.resolveConfig(typesPath);
|
|
4181
|
-
await mkdirp(path
|
|
4182
|
-
await fs
|
|
723
|
+
await mkdirp(path.dirname(typesPath));
|
|
724
|
+
await fs.writeFile(typesPath, prettier.format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
4183
725
|
filepath: typesPath
|
|
4184
726
|
})));
|
|
4185
727
|
files.push({
|
|
@@ -4192,7 +734,7 @@ async function _extractTypes(options) {
|
|
|
4192
734
|
};
|
|
4193
735
|
}
|
|
4194
736
|
|
|
4195
|
-
const rimraf = promisify(
|
|
737
|
+
const rimraf = promisify(rimrafCallback);
|
|
4196
738
|
|
|
4197
739
|
async function _doExtract(ctx, task) {
|
|
4198
740
|
var _a;
|
|
@@ -4221,7 +763,7 @@ async function _doExtract(ctx, task) {
|
|
|
4221
763
|
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
4222
764
|
}
|
|
4223
765
|
|
|
4224
|
-
const tmpPath = path
|
|
766
|
+
const tmpPath = path.resolve(outDir, "__tmp__");
|
|
4225
767
|
await _buildTypes({
|
|
4226
768
|
cwd,
|
|
4227
769
|
outDir: tmpPath,
|
|
@@ -4232,17 +774,17 @@ async function _doExtract(ctx, task) {
|
|
|
4232
774
|
|
|
4233
775
|
for (const entry of task.entries) {
|
|
4234
776
|
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
4235
|
-
const sourceTypesPath = path
|
|
4236
|
-
const targetPath = path
|
|
777
|
+
const sourceTypesPath = path.resolve(tmpPath, path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
|
|
778
|
+
const targetPath = path.resolve(cwd, entry.targetPath);
|
|
4237
779
|
const result = await _extractTypes({
|
|
4238
780
|
cwd,
|
|
4239
781
|
exportPath,
|
|
4240
782
|
files,
|
|
4241
|
-
filePath: path
|
|
783
|
+
filePath: path.relative(outDir, targetPath),
|
|
4242
784
|
projectPath: cwd,
|
|
4243
785
|
rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
|
|
4244
786
|
sourceTypesPath,
|
|
4245
|
-
tsconfigPath: path
|
|
787
|
+
tsconfigPath: path.resolve(cwd, ts.configPath || "tsconfig.json"),
|
|
4246
788
|
distPath: outDir
|
|
4247
789
|
});
|
|
4248
790
|
messages.push(...result.messages);
|
|
@@ -4253,7 +795,7 @@ async function _doExtract(ctx, task) {
|
|
|
4253
795
|
}
|
|
4254
796
|
|
|
4255
797
|
results.push({
|
|
4256
|
-
sourcePath: path
|
|
798
|
+
sourcePath: path.resolve(cwd, entry.sourcePath),
|
|
4257
799
|
filePath: targetPath
|
|
4258
800
|
});
|
|
4259
801
|
}
|
|
@@ -4329,7 +871,7 @@ const _dtsWatchTask = {
|
|
|
4329
871
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
4330
872
|
var _ref2, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
4331
873
|
|
|
4332
|
-
var _a;
|
|
874
|
+
var _a, _b;
|
|
4333
875
|
|
|
4334
876
|
const {
|
|
4335
877
|
format,
|
|
@@ -4348,23 +890,23 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
4348
890
|
} = ctx;
|
|
4349
891
|
const outputExt = _MODULE_EXT[pkg.type][format];
|
|
4350
892
|
const minify = (_ref2 = config == null ? void 0 : config.minify) !== null && _ref2 !== void 0 ? _ref2 : true;
|
|
4351
|
-
const outDir = path
|
|
893
|
+
const outDir = path.relative(cwd, distPath);
|
|
4352
894
|
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref3 => {
|
|
4353
895
|
let [key, val] = _ref3;
|
|
4354
896
|
|
|
4355
897
|
var _a2;
|
|
4356
898
|
|
|
4357
|
-
return [key, path
|
|
899
|
+
return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
4358
900
|
}));
|
|
4359
901
|
const entries = buildTask.entries.map(entry => {
|
|
4360
902
|
return _objectSpread(_objectSpread({}, entry), {}, {
|
|
4361
|
-
name: path
|
|
903
|
+
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
4362
904
|
});
|
|
4363
905
|
}, {});
|
|
4364
906
|
|
|
4365
|
-
const exportIds = _exports && Object.keys(_exports).map(exportPath => path
|
|
907
|
+
const exportIds = _exports && Object.keys(_exports).map(exportPath => path.join(pkg.name, exportPath));
|
|
4366
908
|
|
|
4367
|
-
const sourcePaths = _exports && Object.values(_exports).map(e => path
|
|
909
|
+
const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
|
|
4368
910
|
|
|
4369
911
|
return {
|
|
4370
912
|
inputOptions: {
|
|
@@ -4375,10 +917,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
4375
917
|
}
|
|
4376
918
|
|
|
4377
919
|
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
4378
|
-
const idPath = path
|
|
920
|
+
const idPath = path.resolve(path.dirname(importer), id);
|
|
4379
921
|
|
|
4380
922
|
if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
|
|
4381
|
-
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path
|
|
923
|
+
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path.relative(cwd, idPath)));
|
|
4382
924
|
return true;
|
|
4383
925
|
}
|
|
4384
926
|
}
|
|
@@ -4408,14 +950,14 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
4408
950
|
preventAssignment: true,
|
|
4409
951
|
values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
|
|
4410
952
|
"process.env.PKG_FILE_PATH": arg => {
|
|
4411
|
-
const sourcePath = "./" + path
|
|
953
|
+
const sourcePath = "./" + path.relative(cwd, arg);
|
|
4412
954
|
const entry = entries.find(e => e.source === sourcePath);
|
|
4413
955
|
|
|
4414
956
|
if (!entry) {
|
|
4415
957
|
throw new Error("could not find source entry: ".concat(sourcePath));
|
|
4416
958
|
}
|
|
4417
959
|
|
|
4418
|
-
return JSON.stringify(path
|
|
960
|
+
return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
|
|
4419
961
|
},
|
|
4420
962
|
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
4421
963
|
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
@@ -4456,7 +998,7 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
4456
998
|
return false;
|
|
4457
999
|
}
|
|
4458
1000
|
}
|
|
4459
|
-
})].filter(Boolean),
|
|
1001
|
+
}), ...(((_b = config == null ? void 0 : config.rollup) == null ? void 0 : _b.plugins) || [])].filter(Boolean),
|
|
4460
1002
|
treeshake: {
|
|
4461
1003
|
propertyReadSideEffects: false
|
|
4462
1004
|
}
|
|
@@ -4473,7 +1015,7 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
4473
1015
|
}
|
|
4474
1016
|
|
|
4475
1017
|
const _rollupTask = {
|
|
4476
|
-
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path
|
|
1018
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
4477
1019
|
exec: (ctx, task) => {
|
|
4478
1020
|
return new Observable(observer => {
|
|
4479
1021
|
_execPromise(ctx, task).then(result => {
|
|
@@ -4495,7 +1037,7 @@ async function _execPromise(ctx, task) {
|
|
|
4495
1037
|
files,
|
|
4496
1038
|
distPath
|
|
4497
1039
|
} = ctx;
|
|
4498
|
-
const outDir = path
|
|
1040
|
+
const outDir = path.relative(ctx.cwd, distPath);
|
|
4499
1041
|
|
|
4500
1042
|
const {
|
|
4501
1043
|
inputOptions,
|
|
@@ -4511,12 +1053,12 @@ async function _execPromise(ctx, task) {
|
|
|
4511
1053
|
if (chunkOrAsset.type === "asset") {
|
|
4512
1054
|
files.push({
|
|
4513
1055
|
type: "asset",
|
|
4514
|
-
path: path
|
|
1056
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
4515
1057
|
});
|
|
4516
1058
|
} else {
|
|
4517
1059
|
files.push({
|
|
4518
1060
|
type: "chunk",
|
|
4519
|
-
path: path
|
|
1061
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
4520
1062
|
});
|
|
4521
1063
|
}
|
|
4522
1064
|
}
|
|
@@ -4526,7 +1068,7 @@ async function _execPromise(ctx, task) {
|
|
|
4526
1068
|
}
|
|
4527
1069
|
|
|
4528
1070
|
const _rollupWatchTask = {
|
|
4529
|
-
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path
|
|
1071
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
4530
1072
|
exec: (ctx, task) => {
|
|
4531
1073
|
const {
|
|
4532
1074
|
inputOptions,
|
|
@@ -4553,7 +1095,7 @@ const _rollupWatchTask = {
|
|
|
4553
1095
|
} = ctx;
|
|
4554
1096
|
|
|
4555
1097
|
if (event.code === "BUNDLE_END") {
|
|
4556
|
-
logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path
|
|
1098
|
+
logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
|
|
4557
1099
|
logger.log("");
|
|
4558
1100
|
return;
|
|
4559
1101
|
}
|
|
@@ -4595,14 +1137,14 @@ const _watchTaskHandlers = {
|
|
|
4595
1137
|
};
|
|
4596
1138
|
|
|
4597
1139
|
function _pathContains(containerPath, itemPath) {
|
|
4598
|
-
return !path
|
|
1140
|
+
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
4599
1141
|
}
|
|
4600
1142
|
|
|
4601
1143
|
function _findCommonDirPath(filePaths) {
|
|
4602
1144
|
let ret = void 0;
|
|
4603
1145
|
|
|
4604
1146
|
for (const filePath of filePaths) {
|
|
4605
|
-
let dirPath = path
|
|
1147
|
+
let dirPath = path.dirname(filePath);
|
|
4606
1148
|
|
|
4607
1149
|
if (!ret) {
|
|
4608
1150
|
ret = dirPath;
|
|
@@ -4610,7 +1152,7 @@ function _findCommonDirPath(filePaths) {
|
|
|
4610
1152
|
}
|
|
4611
1153
|
|
|
4612
1154
|
while (dirPath !== ret) {
|
|
4613
|
-
dirPath = path
|
|
1155
|
+
dirPath = path.dirname(dirPath);
|
|
4614
1156
|
|
|
4615
1157
|
if (dirPath === ret) {
|
|
4616
1158
|
break;
|
|
@@ -4815,7 +1357,7 @@ async function _resolveBuildContext(options) {
|
|
|
4815
1357
|
var _a, _b, _c, _d;
|
|
4816
1358
|
|
|
4817
1359
|
return [exportEntry.import, exportEntry.require, (_a = exportEntry.browser) == null ? void 0 : _a.import, (_b = exportEntry.browser) == null ? void 0 : _b.require, (_c = exportEntry.node) == null ? void 0 : _c.import, (_d = exportEntry.node) == null ? void 0 : _d.require].filter(Boolean);
|
|
4818
|
-
}).map(p => path
|
|
1360
|
+
}).map(p => path.resolve(cwd, p));
|
|
4819
1361
|
|
|
4820
1362
|
const commonDistPath = _findCommonDirPath(outputPaths);
|
|
4821
1363
|
|
|
@@ -4827,10 +1369,10 @@ async function _resolveBuildContext(options) {
|
|
|
4827
1369
|
throw new Error("all output files must be located within the package");
|
|
4828
1370
|
}
|
|
4829
1371
|
|
|
4830
|
-
const configDistPath = (config == null ? void 0 : config.dist) ? path
|
|
1372
|
+
const configDistPath = (config == null ? void 0 : config.dist) ? path.resolve(cwd, config.dist) : void 0;
|
|
4831
1373
|
|
|
4832
1374
|
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !_pathContains(configDistPath, commonDistPath)) {
|
|
4833
|
-
logger.log("did you mean to configure `dist: './".concat(path
|
|
1375
|
+
logger.log("did you mean to configure `dist: './".concat(path.relative(cwd, commonDistPath), "'`?"));
|
|
4834
1376
|
throw new Error("all output files must be located with the configured `dist` path");
|
|
4835
1377
|
}
|
|
4836
1378
|
|
|
@@ -4925,7 +1467,7 @@ function _getFilesize(file) {
|
|
|
4925
1467
|
|
|
4926
1468
|
function _fileExists(file) {
|
|
4927
1469
|
try {
|
|
4928
|
-
fs$
|
|
1470
|
+
fs$1.accessSync(file);
|
|
4929
1471
|
return true;
|
|
4930
1472
|
} catch (_) {
|
|
4931
1473
|
return false;
|
|
@@ -4933,7 +1475,7 @@ function _fileExists(file) {
|
|
|
4933
1475
|
}
|
|
4934
1476
|
|
|
4935
1477
|
function _getFileInfo(cwd, filePath) {
|
|
4936
|
-
const p = path
|
|
1478
|
+
const p = path.resolve(cwd, filePath);
|
|
4937
1479
|
|
|
4938
1480
|
const exists = _fileExists(p);
|
|
4939
1481
|
|
|
@@ -5023,7 +1565,7 @@ function _printPackageTree(ctx) {
|
|
|
5023
1565
|
}
|
|
5024
1566
|
|
|
5025
1567
|
exp.default = _fileInfo(entry.default);
|
|
5026
|
-
return [chalk.green(path
|
|
1568
|
+
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
5027
1569
|
}));
|
|
5028
1570
|
logger.log(treeify.asTree(tree, true, true));
|
|
5029
1571
|
}
|
|
@@ -5056,19 +1598,19 @@ async function check(options) {
|
|
|
5056
1598
|
const missingFiles = [];
|
|
5057
1599
|
|
|
5058
1600
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
5059
|
-
if (exp.source && !_fileExists(path
|
|
1601
|
+
if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
|
|
5060
1602
|
missingFiles.push(exp.source);
|
|
5061
1603
|
}
|
|
5062
1604
|
|
|
5063
|
-
if (exp.require && !_fileExists(path
|
|
1605
|
+
if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
|
|
5064
1606
|
missingFiles.push(exp.require);
|
|
5065
1607
|
}
|
|
5066
1608
|
|
|
5067
|
-
if (exp.import && !_fileExists(path
|
|
1609
|
+
if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
|
|
5068
1610
|
missingFiles.push(exp.import);
|
|
5069
1611
|
}
|
|
5070
1612
|
|
|
5071
|
-
if (exp.types && !_fileExists(path
|
|
1613
|
+
if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
|
|
5072
1614
|
missingFiles.push(exp.types);
|
|
5073
1615
|
}
|
|
5074
1616
|
}
|
|
@@ -5201,7 +1743,7 @@ function _resolveWatchTasks(ctx) {
|
|
|
5201
1743
|
}
|
|
5202
1744
|
|
|
5203
1745
|
for (const exp of exports) {
|
|
5204
|
-
const importId = path
|
|
1746
|
+
const importId = path.join(pkg.name, exp._path);
|
|
5205
1747
|
|
|
5206
1748
|
if (exp.types) {
|
|
5207
1749
|
dtsTask.entries.push({
|
|
@@ -5269,7 +1811,7 @@ function _resolveWatchTasks(ctx) {
|
|
|
5269
1811
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
5270
1812
|
|
|
5271
1813
|
if (relativeTargetPath) {
|
|
5272
|
-
fs$
|
|
1814
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
5273
1815
|
}
|
|
5274
1816
|
}
|
|
5275
1817
|
}
|
|
@@ -5307,9 +1849,9 @@ async function _watchConfigFiles(options) {
|
|
|
5307
1849
|
const {
|
|
5308
1850
|
cwd
|
|
5309
1851
|
} = options;
|
|
5310
|
-
const initialFiles = await _globFiles([path
|
|
1852
|
+
const initialFiles = await _globFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
5311
1853
|
|
|
5312
|
-
const fileEvent$ = _watchFiles([path
|
|
1854
|
+
const fileEvent$ = _watchFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
5313
1855
|
|
|
5314
1856
|
return fileEvent$.pipe(scan((files, fileEvent) => {
|
|
5315
1857
|
if (fileEvent.type === "add") {
|
|
@@ -5322,7 +1864,7 @@ async function _watchConfigFiles(options) {
|
|
|
5322
1864
|
|
|
5323
1865
|
if (fileEvent.type === "change") {
|
|
5324
1866
|
console.log("--------------------------------------------------------------------------------");
|
|
5325
|
-
console.log(chalk.blue("info "), path
|
|
1867
|
+
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
5326
1868
|
console.log("");
|
|
5327
1869
|
return files.slice(0);
|
|
5328
1870
|
}
|
|
@@ -5340,7 +1882,7 @@ async function watch(options) {
|
|
|
5340
1882
|
cwd
|
|
5341
1883
|
});
|
|
5342
1884
|
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
5343
|
-
const _files = configFiles.map(f => path
|
|
1885
|
+
const _files = configFiles.map(f => path.relative(cwd, f));
|
|
5344
1886
|
|
|
5345
1887
|
const packageJsonPath = _files.find(f => f === "package.json");
|
|
5346
1888
|
|