minimatch 9.0.6 → 9.0.7
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/commonjs/ast.d.ts.map +1 -1
- package/dist/commonjs/ast.js +168 -20
- package/dist/commonjs/ast.js.map +1 -1
- package/dist/commonjs/index.d.ts +4 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +120 -118
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/ast.d.ts.map +1 -1
- package/dist/esm/ast.js +168 -20
- package/dist/esm/ast.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +120 -118
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/commonjs/index.js
CHANGED
|
@@ -202,11 +202,13 @@ class Minimatch {
|
|
|
202
202
|
isWindows;
|
|
203
203
|
platform;
|
|
204
204
|
windowsNoMagicRoot;
|
|
205
|
+
maxGlobstarRecursion;
|
|
205
206
|
regexp;
|
|
206
207
|
constructor(pattern, options = {}) {
|
|
207
208
|
(0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
|
|
208
209
|
options = options || {};
|
|
209
210
|
this.options = options;
|
|
211
|
+
this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? 200;
|
|
210
212
|
this.pattern = pattern;
|
|
211
213
|
this.platform = options.platform || defaultPlatform;
|
|
212
214
|
this.isWindows = this.platform === 'win32';
|
|
@@ -606,7 +608,8 @@ class Minimatch {
|
|
|
606
608
|
// out of pattern, then that's fine, as long as all
|
|
607
609
|
// the parts match.
|
|
608
610
|
matchOne(file, pattern, partial = false) {
|
|
609
|
-
|
|
611
|
+
let fileStartIndex = 0;
|
|
612
|
+
let patternStartIndex = 0;
|
|
610
613
|
// UNC paths like //?/X:/... can match X:/... and vice versa
|
|
611
614
|
// Drive letters in absolute drive or unc paths are always compared
|
|
612
615
|
// case-insensitively.
|
|
@@ -627,15 +630,14 @@ class Minimatch {
|
|
|
627
630
|
const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined;
|
|
628
631
|
const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined;
|
|
629
632
|
if (typeof fdi === 'number' && typeof pdi === 'number') {
|
|
630
|
-
const [fd, pd] = [
|
|
633
|
+
const [fd, pd] = [
|
|
634
|
+
file[fdi],
|
|
635
|
+
pattern[pdi],
|
|
636
|
+
];
|
|
631
637
|
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
632
638
|
pattern[pdi] = fd;
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
else if (fdi > pdi) {
|
|
637
|
-
file = file.slice(fdi);
|
|
638
|
-
}
|
|
639
|
+
patternStartIndex = pdi;
|
|
640
|
+
fileStartIndex = fdi;
|
|
639
641
|
}
|
|
640
642
|
}
|
|
641
643
|
}
|
|
@@ -645,102 +647,123 @@ class Minimatch {
|
|
|
645
647
|
if (optimizationLevel >= 2) {
|
|
646
648
|
file = this.levelTwoFileOptimize(file);
|
|
647
649
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
650
|
+
if (pattern.includes(exports.GLOBSTAR)) {
|
|
651
|
+
return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
652
|
+
}
|
|
653
|
+
return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
654
|
+
}
|
|
655
|
+
#matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
|
|
656
|
+
const firstgs = pattern.indexOf(exports.GLOBSTAR, patternIndex);
|
|
657
|
+
const lastgs = pattern.lastIndexOf(exports.GLOBSTAR);
|
|
658
|
+
const [head, body, tail] = [
|
|
659
|
+
pattern.slice(patternIndex, firstgs),
|
|
660
|
+
pattern.slice(firstgs + 1, lastgs),
|
|
661
|
+
pattern.slice(lastgs + 1),
|
|
662
|
+
];
|
|
663
|
+
if (head.length) {
|
|
664
|
+
const fileHead = file.slice(fileIndex, fileIndex + head.length);
|
|
665
|
+
if (!this.#matchOne(fileHead, head, partial, 0, 0))
|
|
659
666
|
return false;
|
|
667
|
+
fileIndex += head.length;
|
|
668
|
+
}
|
|
669
|
+
let fileTailMatch = 0;
|
|
670
|
+
if (tail.length) {
|
|
671
|
+
if (tail.length + fileIndex > file.length)
|
|
672
|
+
return false;
|
|
673
|
+
let tailStart = file.length - tail.length;
|
|
674
|
+
if (this.#matchOne(file, tail, partial, tailStart, 0)) {
|
|
675
|
+
fileTailMatch = tail.length;
|
|
660
676
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
// a/**/b/**/c would match the following:
|
|
666
|
-
// a/b/x/y/z/c
|
|
667
|
-
// a/x/y/z/b/c
|
|
668
|
-
// a/b/x/b/x/c
|
|
669
|
-
// a/b/c
|
|
670
|
-
// To do this, take the rest of the pattern after
|
|
671
|
-
// the **, and see if it would match the file remainder.
|
|
672
|
-
// If so, return success.
|
|
673
|
-
// If not, the ** "swallows" a segment, and try again.
|
|
674
|
-
// This is recursively awful.
|
|
675
|
-
//
|
|
676
|
-
// a/**/b/**/c matching a/b/x/y/z/c
|
|
677
|
-
// - a matches a
|
|
678
|
-
// - doublestar
|
|
679
|
-
// - matchOne(b/x/y/z/c, b/**/c)
|
|
680
|
-
// - b matches b
|
|
681
|
-
// - doublestar
|
|
682
|
-
// - matchOne(x/y/z/c, c) -> no
|
|
683
|
-
// - matchOne(y/z/c, c) -> no
|
|
684
|
-
// - matchOne(z/c, c) -> no
|
|
685
|
-
// - matchOne(c, c) yes, hit
|
|
686
|
-
var fr = fi;
|
|
687
|
-
var pr = pi + 1;
|
|
688
|
-
if (pr === pl) {
|
|
689
|
-
this.debug('** at the end');
|
|
690
|
-
// a ** at the end will just swallow the rest.
|
|
691
|
-
// We have found a match.
|
|
692
|
-
// however, it will not swallow /.x, unless
|
|
693
|
-
// options.dot is set.
|
|
694
|
-
// . and .. are *never* matched by **, for explosively
|
|
695
|
-
// exponential reasons.
|
|
696
|
-
for (; fi < fl; fi++) {
|
|
697
|
-
if (file[fi] === '.' ||
|
|
698
|
-
file[fi] === '..' ||
|
|
699
|
-
(!options.dot && file[fi].charAt(0) === '.'))
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
return true;
|
|
677
|
+
else {
|
|
678
|
+
if (file[file.length - 1] !== '' ||
|
|
679
|
+
fileIndex + tail.length === file.length) {
|
|
680
|
+
return false;
|
|
703
681
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
swallowee === '..' ||
|
|
719
|
-
(!options.dot && swallowee.charAt(0) === '.')) {
|
|
720
|
-
this.debug('dot detected!', file, fr, pattern, pr);
|
|
721
|
-
break;
|
|
722
|
-
}
|
|
723
|
-
// ** swallows a segment, and continue.
|
|
724
|
-
this.debug('globstar swallow a segment, and continue');
|
|
725
|
-
fr++;
|
|
726
|
-
}
|
|
682
|
+
tailStart--;
|
|
683
|
+
if (!this.#matchOne(file, tail, partial, tailStart, 0))
|
|
684
|
+
return false;
|
|
685
|
+
fileTailMatch = tail.length + 1;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (!body.length) {
|
|
689
|
+
let sawSome = !!fileTailMatch;
|
|
690
|
+
for (let i = fileIndex; i < file.length - fileTailMatch; i++) {
|
|
691
|
+
const f = String(file[i]);
|
|
692
|
+
sawSome = true;
|
|
693
|
+
if (f === '.' || f === '..' ||
|
|
694
|
+
(!this.options.dot && f.startsWith('.'))) {
|
|
695
|
+
return false;
|
|
727
696
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
697
|
+
}
|
|
698
|
+
return sawSome;
|
|
699
|
+
}
|
|
700
|
+
const bodySegments = [[[], 0]];
|
|
701
|
+
let currentBody = bodySegments[0];
|
|
702
|
+
let nonGsParts = 0;
|
|
703
|
+
const nonGsPartsSums = [0];
|
|
704
|
+
for (const b of body) {
|
|
705
|
+
if (b === exports.GLOBSTAR) {
|
|
706
|
+
nonGsPartsSums.push(nonGsParts);
|
|
707
|
+
currentBody = [[], 0];
|
|
708
|
+
bodySegments.push(currentBody);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
currentBody[0].push(b);
|
|
712
|
+
nonGsParts++;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
let i = bodySegments.length - 1;
|
|
716
|
+
const fileLength = file.length - fileTailMatch;
|
|
717
|
+
for (const b of bodySegments) {
|
|
718
|
+
b[1] = fileLength - (nonGsPartsSums[i--] + b[0].length);
|
|
719
|
+
}
|
|
720
|
+
return !!this.#matchGlobStarBodySections(file, bodySegments, fileIndex, 0, partial, 0, !!fileTailMatch);
|
|
721
|
+
}
|
|
722
|
+
#matchGlobStarBodySections(file, bodySegments, fileIndex, bodyIndex, partial, globStarDepth, sawTail) {
|
|
723
|
+
const bs = bodySegments[bodyIndex];
|
|
724
|
+
if (!bs) {
|
|
725
|
+
for (let i = fileIndex; i < file.length; i++) {
|
|
726
|
+
sawTail = true;
|
|
727
|
+
const f = file[i];
|
|
728
|
+
if (f === '.' || f === '..' ||
|
|
729
|
+
(!this.options.dot && f.startsWith('.'))) {
|
|
730
|
+
return false;
|
|
737
731
|
}
|
|
738
|
-
|
|
732
|
+
}
|
|
733
|
+
return sawTail;
|
|
734
|
+
}
|
|
735
|
+
const [body, after] = bs;
|
|
736
|
+
while (fileIndex <= after) {
|
|
737
|
+
const m = this.#matchOne(file.slice(0, fileIndex + body.length), body, partial, fileIndex, 0);
|
|
738
|
+
if (m && globStarDepth < this.maxGlobstarRecursion) {
|
|
739
|
+
const sub = this.#matchGlobStarBodySections(file, bodySegments, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail);
|
|
740
|
+
if (sub !== false)
|
|
741
|
+
return sub;
|
|
742
|
+
}
|
|
743
|
+
const f = file[fileIndex];
|
|
744
|
+
if (f === '.' || f === '..' ||
|
|
745
|
+
(!this.options.dot && f.startsWith('.'))) {
|
|
739
746
|
return false;
|
|
740
747
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
748
|
+
fileIndex++;
|
|
749
|
+
}
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
#matchOne(file, pattern, partial, fileIndex, patternIndex) {
|
|
753
|
+
let fi;
|
|
754
|
+
let pi;
|
|
755
|
+
let pl;
|
|
756
|
+
let fl;
|
|
757
|
+
for (fi = fileIndex, pi = patternIndex,
|
|
758
|
+
fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
759
|
+
this.debug('matchOne loop');
|
|
760
|
+
let p = pattern[pi];
|
|
761
|
+
let f = file[fi];
|
|
762
|
+
this.debug(pattern, p, f);
|
|
763
|
+
/* c8 ignore start */
|
|
764
|
+
if (p === false || p === exports.GLOBSTAR)
|
|
765
|
+
return false;
|
|
766
|
+
/* c8 ignore stop */
|
|
744
767
|
let hit;
|
|
745
768
|
if (typeof p === 'string') {
|
|
746
769
|
hit = f === p;
|
|
@@ -753,38 +776,17 @@ class Minimatch {
|
|
|
753
776
|
if (!hit)
|
|
754
777
|
return false;
|
|
755
778
|
}
|
|
756
|
-
// Note: ending in / means that we'll get a final ""
|
|
757
|
-
// at the end of the pattern. This can only match a
|
|
758
|
-
// corresponding "" at the end of the file.
|
|
759
|
-
// If the file ends in /, then it can only match a
|
|
760
|
-
// a pattern that ends in /, unless the pattern just
|
|
761
|
-
// doesn't have any more for it. But, a/b/ should *not*
|
|
762
|
-
// match "a/b/*", even though "" matches against the
|
|
763
|
-
// [^/]*? pattern, except in partial mode, where it might
|
|
764
|
-
// simply not be reached yet.
|
|
765
|
-
// However, a/b/ should still satisfy a/*
|
|
766
|
-
// now either we fell off the end of the pattern, or we're done.
|
|
767
779
|
if (fi === fl && pi === pl) {
|
|
768
|
-
// ran out of pattern and filename at the same time.
|
|
769
|
-
// an exact hit!
|
|
770
780
|
return true;
|
|
771
781
|
}
|
|
772
782
|
else if (fi === fl) {
|
|
773
|
-
// ran out of file, but still had pattern left.
|
|
774
|
-
// this is ok if we're doing the match as part of
|
|
775
|
-
// a glob fs traversal.
|
|
776
783
|
return partial;
|
|
777
784
|
}
|
|
778
785
|
else if (pi === pl) {
|
|
779
|
-
// ran out of pattern, still have file left.
|
|
780
|
-
// this is only acceptable if we're on the very last
|
|
781
|
-
// empty segment of a file with a trailing slash.
|
|
782
|
-
// a/* should match a/b/
|
|
783
786
|
return fi === fl - 1 && file[fi] === '';
|
|
784
787
|
/* c8 ignore start */
|
|
785
788
|
}
|
|
786
789
|
else {
|
|
787
|
-
// should be unreachable.
|
|
788
790
|
throw new Error('wtf?');
|
|
789
791
|
}
|
|
790
792
|
/* c8 ignore stop */
|