Skip to content

Commit 678c6bf

Browse files
committed
1 parent 9b4b366 commit 678c6bf

16 files changed

+299
-108
lines changed

node_modules/minimatch/dist/cjs/comparator.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

node_modules/minimatch/dist/cjs/comparator.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

node_modules/minimatch/dist/cjs/comparator.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/minimatch/dist/cjs/index-cjs.d.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ declare const _default: {
55
filter: (pattern: string, options?: import("./index.js").MinimatchOptions) => (p: string) => boolean;
66
defaults: (def: import("./index.js").MinimatchOptions) => any;
77
braceExpand: (pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
8-
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | (RegExp & {
9-
_src?: string | undefined;
10-
_glob?: string | undefined;
11-
});
8+
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
129
match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
1310
Minimatch: typeof import("./index.js").Minimatch;
1411
} & {
@@ -19,10 +16,7 @@ declare const _default: {
1916
filter: (pattern: string, options?: import("./index.js").MinimatchOptions) => (p: string) => boolean;
2017
defaults: (def: import("./index.js").MinimatchOptions) => any;
2118
braceExpand: (pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
22-
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | (RegExp & {
23-
_src?: string | undefined;
24-
_glob?: string | undefined;
25-
});
19+
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
2620
match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
2721
Minimatch: typeof import("./index.js").Minimatch;
2822
};
@@ -33,10 +27,7 @@ declare const _default: {
3327
filter: (pattern: string, options?: import("./index.js").MinimatchOptions) => (p: string) => boolean;
3428
defaults: (def: import("./index.js").MinimatchOptions) => any;
3529
braceExpand: (pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
36-
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | (RegExp & {
37-
_src?: string | undefined;
38-
_glob?: string | undefined;
39-
});
30+
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
4031
match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
4132
Minimatch: typeof import("./index.js").Minimatch;
4233
};

node_modules/minimatch/dist/cjs/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface MinimatchOptions {
1111
partial?: boolean;
1212
dot?: boolean;
1313
nocase?: boolean;
14+
nocaseMagicOnly?: boolean;
1415
matchBase?: boolean;
1516
flipNegate?: boolean;
1617
preserveMultipleSlashes?: boolean;
@@ -35,7 +36,7 @@ export declare const braceExpand: (pattern: string, options?: MinimatchOptions)
3536
declare const SUBPARSE: unique symbol;
3637
export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
3738
export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
38-
type MMRegExp = RegExp & {
39+
export type MMRegExp = RegExp & {
3940
_src?: string;
4041
_glob?: string;
4142
};

node_modules/minimatch/dist/cjs/index.js

Lines changed: 142 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,57 @@ const minimatch = (p, pattern, options = {}) => {
1414
};
1515
exports.minimatch = minimatch;
1616
exports.default = exports.minimatch;
17+
// Optimized checking for the most common glob patterns.
18+
const starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
19+
const starDotExtTest = (ext) => (f) => !f.startsWith('.') && f.endsWith(ext);
20+
const starDotExtTestDot = (ext) => (f) => f.endsWith(ext);
21+
const starDotExtTestNocase = (ext) => {
22+
ext = ext.toLowerCase();
23+
return (f) => !f.startsWith('.') && f.toLowerCase().endsWith(ext);
24+
};
25+
const starDotExtTestNocaseDot = (ext) => {
26+
ext = ext.toLowerCase();
27+
return (f) => f.toLowerCase().endsWith(ext);
28+
};
29+
const starDotStarRE = /^\*+\.\*+$/;
30+
const starDotStarTest = (f) => !f.startsWith('.') && f.includes('.');
31+
const starDotStarTestDot = (f) => f !== '.' && f !== '..' && f.includes('.');
32+
const dotStarRE = /^\.\*+$/;
33+
const dotStarTest = (f) => f !== '.' && f !== '..' && f.startsWith('.');
34+
const starRE = /^\*+$/;
35+
const starTest = (f) => f.length !== 0 && !f.startsWith('.');
36+
const starTestDot = (f) => f.length !== 0 && f !== '.' && f !== '..';
37+
const qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
38+
const qmarksTestNocase = ([$0, ext = '']) => {
39+
const noext = qmarksTestNoExt([$0]);
40+
if (!ext)
41+
return noext;
42+
ext = ext.toLowerCase();
43+
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
44+
};
45+
const qmarksTestNocaseDot = ([$0, ext = '']) => {
46+
const noext = qmarksTestNoExtDot([$0]);
47+
if (!ext)
48+
return noext;
49+
ext = ext.toLowerCase();
50+
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
51+
};
52+
const qmarksTestDot = ([$0, ext = '']) => {
53+
const noext = qmarksTestNoExtDot([$0]);
54+
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
55+
};
56+
const qmarksTest = ([$0, ext = '']) => {
57+
const noext = qmarksTestNoExt([$0]);
58+
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
59+
};
60+
const qmarksTestNoExt = ([$0]) => {
61+
const len = $0.length;
62+
return (f) => f.length === len && !f.startsWith('.');
63+
};
64+
const qmarksTestNoExtDot = ([$0]) => {
65+
const len = $0.length;
66+
return (f) => f.length === len && f !== '.' && f !== '..';
67+
};
1768
/* c8 ignore start */
1869
const platform = typeof process === 'object' && process
1970
? (typeof process.env === 'object' &&
@@ -213,14 +264,53 @@ class Minimatch {
213264
// and will not contain any / characters
214265
const rawGlobParts = this.globSet.map(s => this.slashSplit(s));
215266
// consecutive globstars are an unncessary perf killer
216-
this.globParts = this.options.noglobstar
217-
? rawGlobParts
218-
: rawGlobParts.map(parts => parts.reduce((set, part) => {
219-
if (part !== '**' || set[set.length - 1] !== '**') {
267+
// also, **/*/... is equivalent to */**/..., so swap all of those
268+
// this turns a pattern like **/*/**/*/x into */*/**/x
269+
// and a pattern like **/x/**/*/y becomes **/x/*/**/y
270+
// the *later* we can push the **, the more efficient it is,
271+
// because we can avoid having to do a recursive walk until
272+
// the walked tree is as shallow as possible.
273+
// Note that this is only true up to the last pattern, though, because
274+
// a/*/** will only match a/b if b is a dir, but a/**/* will match a/b
275+
// regardless, since it's "0 or more path segments" if it's not final.
276+
if (this.options.noglobstar) {
277+
// ** is * anyway
278+
this.globParts = rawGlobParts;
279+
}
280+
else {
281+
// do this swap BEFORE the reduce, so that we can turn a string
282+
// of **/*/**/* into */*/**/** and then reduce the **'s into one
283+
for (const parts of rawGlobParts) {
284+
let swapped;
285+
do {
286+
swapped = false;
287+
for (let i = 0; i < parts.length - 1; i++) {
288+
if (parts[i] === '*' && parts[i - 1] === '**') {
289+
parts[i] = '**';
290+
parts[i - 1] = '*';
291+
swapped = true;
292+
}
293+
}
294+
} while (swapped);
295+
}
296+
this.globParts = rawGlobParts.map(parts => {
297+
parts = parts.reduce((set, part) => {
298+
const prev = set[set.length - 1];
299+
if (part === '**' && prev === '**') {
300+
return set;
301+
}
302+
if (part === '..') {
303+
if (prev && prev !== '..' && prev !== '.' && prev !== '**') {
304+
set.pop();
305+
return set;
306+
}
307+
}
220308
set.push(part);
221-
}
222-
return set;
223-
}, []));
309+
return set;
310+
}, []);
311+
return parts.length === 0 ? [''] : parts;
312+
});
313+
}
224314
this.debug(this.pattern, this.globParts);
225315
// glob --> regexps
226316
let set = this.globParts.map((s, _, __) => s.map(ss => this.parse(ss)));
@@ -458,6 +548,39 @@ class Minimatch {
458548
}
459549
if (pattern === '')
460550
return '';
551+
// far and away, the most common glob pattern parts are
552+
// *, *.*, and *.<ext> Add a fast check method for those.
553+
let m;
554+
let fastTest = null;
555+
if (isSub !== SUBPARSE) {
556+
if ((m = pattern.match(starRE))) {
557+
fastTest = options.dot ? starTestDot : starTest;
558+
}
559+
else if ((m = pattern.match(starDotExtRE))) {
560+
fastTest = (options.nocase
561+
? options.dot
562+
? starDotExtTestNocaseDot
563+
: starDotExtTestNocase
564+
: options.dot
565+
? starDotExtTestDot
566+
: starDotExtTest)(m[1]);
567+
}
568+
else if ((m = pattern.match(qmarksRE))) {
569+
fastTest = (options.nocase
570+
? options.dot
571+
? qmarksTestNocaseDot
572+
: qmarksTestNocase
573+
: options.dot
574+
? qmarksTestDot
575+
: qmarksTest)(m);
576+
}
577+
else if ((m = pattern.match(starDotStarRE))) {
578+
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
579+
}
580+
else if ((m = pattern.match(dotStarRE))) {
581+
fastTest = dotStarTest;
582+
}
583+
}
461584
let re = '';
462585
let hasMagic = false;
463586
let escaping = false;
@@ -776,7 +899,7 @@ class Minimatch {
776899
return [re, hasMagic];
777900
}
778901
// if it's nocase, and the lcase/uppercase don't match, it's magic
779-
if (options.nocase && !hasMagic) {
902+
if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
780903
hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
781904
}
782905
// skip the regexp for non-magical patterns
@@ -787,10 +910,17 @@ class Minimatch {
787910
}
788911
const flags = options.nocase ? 'i' : '';
789912
try {
790-
return Object.assign(new RegExp('^' + re + '$', flags), {
791-
_glob: pattern,
792-
_src: re,
793-
});
913+
const ext = fastTest
914+
? {
915+
_glob: pattern,
916+
_src: re,
917+
test: fastTest,
918+
}
919+
: {
920+
_glob: pattern,
921+
_src: re,
922+
};
923+
return Object.assign(new RegExp('^' + re + '$', flags), ext);
794924
/* c8 ignore start */
795925
}
796926
catch (er) {

node_modules/minimatch/dist/cjs/index.js.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

node_modules/minimatch/dist/mjs/comparator.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

node_modules/minimatch/dist/mjs/comparator.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

node_modules/minimatch/dist/mjs/comparator.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)