Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Feb 14, 2023
1 parent 9b4b366 commit 678c6bf
Show file tree
Hide file tree
Showing 16 changed files with 299 additions and 108 deletions.
10 changes: 0 additions & 10 deletions node_modules/minimatch/dist/cjs/comparator.d.ts

This file was deleted.

23 changes: 0 additions & 23 deletions node_modules/minimatch/dist/cjs/comparator.js

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/minimatch/dist/cjs/comparator.js.map

This file was deleted.

15 changes: 3 additions & 12 deletions node_modules/minimatch/dist/cjs/index-cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ declare const _default: {
filter: (pattern: string, options?: import("./index.js").MinimatchOptions) => (p: string) => boolean;
defaults: (def: import("./index.js").MinimatchOptions) => any;
braceExpand: (pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | (RegExp & {
_src?: string | undefined;
_glob?: string | undefined;
});
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
Minimatch: typeof import("./index.js").Minimatch;
} & {
Expand All @@ -19,10 +16,7 @@ declare const _default: {
filter: (pattern: string, options?: import("./index.js").MinimatchOptions) => (p: string) => boolean;
defaults: (def: import("./index.js").MinimatchOptions) => any;
braceExpand: (pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | (RegExp & {
_src?: string | undefined;
_glob?: string | undefined;
});
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
Minimatch: typeof import("./index.js").Minimatch;
};
Expand All @@ -33,10 +27,7 @@ declare const _default: {
filter: (pattern: string, options?: import("./index.js").MinimatchOptions) => (p: string) => boolean;
defaults: (def: import("./index.js").MinimatchOptions) => any;
braceExpand: (pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | (RegExp & {
_src?: string | undefined;
_glob?: string | undefined;
});
makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
Minimatch: typeof import("./index.js").Minimatch;
};
Expand Down
3 changes: 2 additions & 1 deletion node_modules/minimatch/dist/cjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface MinimatchOptions {
partial?: boolean;
dot?: boolean;
nocase?: boolean;
nocaseMagicOnly?: boolean;
matchBase?: boolean;
flipNegate?: boolean;
preserveMultipleSlashes?: boolean;
Expand All @@ -35,7 +36,7 @@ export declare const braceExpand: (pattern: string, options?: MinimatchOptions)
declare const SUBPARSE: unique symbol;
export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
type MMRegExp = RegExp & {
export type MMRegExp = RegExp & {
_src?: string;
_glob?: string;
};
Expand Down
154 changes: 142 additions & 12 deletions node_modules/minimatch/dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,57 @@ const minimatch = (p, pattern, options = {}) => {
};
exports.minimatch = minimatch;
exports.default = exports.minimatch;
// Optimized checking for the most common glob patterns.
const starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
const starDotExtTest = (ext) => (f) => !f.startsWith('.') && f.endsWith(ext);
const starDotExtTestDot = (ext) => (f) => f.endsWith(ext);
const starDotExtTestNocase = (ext) => {
ext = ext.toLowerCase();
return (f) => !f.startsWith('.') && f.toLowerCase().endsWith(ext);
};
const starDotExtTestNocaseDot = (ext) => {
ext = ext.toLowerCase();
return (f) => f.toLowerCase().endsWith(ext);
};
const starDotStarRE = /^\*+\.\*+$/;
const starDotStarTest = (f) => !f.startsWith('.') && f.includes('.');
const starDotStarTestDot = (f) => f !== '.' && f !== '..' && f.includes('.');
const dotStarRE = /^\.\*+$/;
const dotStarTest = (f) => f !== '.' && f !== '..' && f.startsWith('.');
const starRE = /^\*+$/;
const starTest = (f) => f.length !== 0 && !f.startsWith('.');
const starTestDot = (f) => f.length !== 0 && f !== '.' && f !== '..';
const qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
const qmarksTestNocase = ([$0, ext = '']) => {
const noext = qmarksTestNoExt([$0]);
if (!ext)
return noext;
ext = ext.toLowerCase();
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
};
const qmarksTestNocaseDot = ([$0, ext = '']) => {
const noext = qmarksTestNoExtDot([$0]);
if (!ext)
return noext;
ext = ext.toLowerCase();
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
};
const qmarksTestDot = ([$0, ext = '']) => {
const noext = qmarksTestNoExtDot([$0]);
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
};
const qmarksTest = ([$0, ext = '']) => {
const noext = qmarksTestNoExt([$0]);
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
};
const qmarksTestNoExt = ([$0]) => {
const len = $0.length;
return (f) => f.length === len && !f.startsWith('.');
};
const qmarksTestNoExtDot = ([$0]) => {
const len = $0.length;
return (f) => f.length === len && f !== '.' && f !== '..';
};
/* c8 ignore start */
const platform = typeof process === 'object' && process
? (typeof process.env === 'object' &&
Expand Down Expand Up @@ -213,14 +264,53 @@ class Minimatch {
// and will not contain any / characters
const rawGlobParts = this.globSet.map(s => this.slashSplit(s));
// consecutive globstars are an unncessary perf killer
this.globParts = this.options.noglobstar
? rawGlobParts
: rawGlobParts.map(parts => parts.reduce((set, part) => {
if (part !== '**' || set[set.length - 1] !== '**') {
// also, **/*/... is equivalent to */**/..., so swap all of those
// this turns a pattern like **/*/**/*/x into */*/**/x
// and a pattern like **/x/**/*/y becomes **/x/*/**/y
// the *later* we can push the **, the more efficient it is,
// because we can avoid having to do a recursive walk until
// the walked tree is as shallow as possible.
// Note that this is only true up to the last pattern, though, because
// a/*/** will only match a/b if b is a dir, but a/**/* will match a/b
// regardless, since it's "0 or more path segments" if it's not final.
if (this.options.noglobstar) {
// ** is * anyway
this.globParts = rawGlobParts;
}
else {
// do this swap BEFORE the reduce, so that we can turn a string
// of **/*/**/* into */*/**/** and then reduce the **'s into one
for (const parts of rawGlobParts) {
let swapped;
do {
swapped = false;
for (let i = 0; i < parts.length - 1; i++) {
if (parts[i] === '*' && parts[i - 1] === '**') {
parts[i] = '**';
parts[i - 1] = '*';
swapped = true;
}
}
} while (swapped);
}
this.globParts = rawGlobParts.map(parts => {
parts = parts.reduce((set, part) => {
const prev = set[set.length - 1];
if (part === '**' && prev === '**') {
return set;
}
if (part === '..') {
if (prev && prev !== '..' && prev !== '.' && prev !== '**') {
set.pop();
return set;
}
}
set.push(part);
}
return set;
}, []));
return set;
}, []);
return parts.length === 0 ? [''] : parts;
});
}
this.debug(this.pattern, this.globParts);
// glob --> regexps
let set = this.globParts.map((s, _, __) => s.map(ss => this.parse(ss)));
Expand Down Expand Up @@ -458,6 +548,39 @@ class Minimatch {
}
if (pattern === '')
return '';
// far and away, the most common glob pattern parts are
// *, *.*, and *.<ext> Add a fast check method for those.
let m;
let fastTest = null;
if (isSub !== SUBPARSE) {
if ((m = pattern.match(starRE))) {
fastTest = options.dot ? starTestDot : starTest;
}
else if ((m = pattern.match(starDotExtRE))) {
fastTest = (options.nocase
? options.dot
? starDotExtTestNocaseDot
: starDotExtTestNocase
: options.dot
? starDotExtTestDot
: starDotExtTest)(m[1]);
}
else if ((m = pattern.match(qmarksRE))) {
fastTest = (options.nocase
? options.dot
? qmarksTestNocaseDot
: qmarksTestNocase
: options.dot
? qmarksTestDot
: qmarksTest)(m);
}
else if ((m = pattern.match(starDotStarRE))) {
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
}
else if ((m = pattern.match(dotStarRE))) {
fastTest = dotStarTest;
}
}
let re = '';
let hasMagic = false;
let escaping = false;
Expand Down Expand Up @@ -776,7 +899,7 @@ class Minimatch {
return [re, hasMagic];
}
// if it's nocase, and the lcase/uppercase don't match, it's magic
if (options.nocase && !hasMagic) {
if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
}
// skip the regexp for non-magical patterns
Expand All @@ -787,10 +910,17 @@ class Minimatch {
}
const flags = options.nocase ? 'i' : '';
try {
return Object.assign(new RegExp('^' + re + '$', flags), {
_glob: pattern,
_src: re,
});
const ext = fastTest
? {
_glob: pattern,
_src: re,
test: fastTest,
}
: {
_glob: pattern,
_src: re,
};
return Object.assign(new RegExp('^' + re + '$', flags), ext);
/* c8 ignore start */
}
catch (er) {
Expand Down
2 changes: 1 addition & 1 deletion node_modules/minimatch/dist/cjs/index.js.map

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions node_modules/minimatch/dist/mjs/comparator.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/minimatch/dist/mjs/comparator.js

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/minimatch/dist/mjs/comparator.js.map

This file was deleted.

3 changes: 2 additions & 1 deletion node_modules/minimatch/dist/mjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface MinimatchOptions {
partial?: boolean;
dot?: boolean;
nocase?: boolean;
nocaseMagicOnly?: boolean;
matchBase?: boolean;
flipNegate?: boolean;
preserveMultipleSlashes?: boolean;
Expand All @@ -35,7 +36,7 @@ export declare const braceExpand: (pattern: string, options?: MinimatchOptions)
declare const SUBPARSE: unique symbol;
export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
type MMRegExp = RegExp & {
export type MMRegExp = RegExp & {
_src?: string;
_glob?: string;
};
Expand Down
Loading

0 comments on commit 678c6bf

Please sign in to comment.