minimatch 7.4.4 → 8.0.1

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.
@@ -1,3 +1,4 @@
1
+ import { AST } from './ast.js';
1
2
  export interface MinimatchOptions {
2
3
  nobrace?: boolean;
3
4
  nocomment?: boolean;
@@ -29,6 +30,7 @@ export declare const minimatch: {
29
30
  braceExpand: (pattern: string, options?: MinimatchOptions) => string[];
30
31
  makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
31
32
  match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
33
+ AST: typeof AST;
32
34
  Minimatch: typeof Minimatch;
33
35
  escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;
34
36
  unescape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;
@@ -46,9 +48,8 @@ export type MMRegExp = RegExp & {
46
48
  _src?: string;
47
49
  _glob?: string;
48
50
  };
49
- type SubparseReturn = [string, boolean];
50
- type ParseReturnFiltered = string | MMRegExp | typeof GLOBSTAR;
51
- type ParseReturn = ParseReturnFiltered | false;
51
+ export type ParseReturnFiltered = string | MMRegExp | typeof GLOBSTAR;
52
+ export type ParseReturn = ParseReturnFiltered | false;
52
53
  export declare class Minimatch {
53
54
  options: MinimatchOptions;
54
55
  set: ParseReturnFiltered[][];
@@ -81,12 +82,13 @@ export declare class Minimatch {
81
82
  parseNegate(): void;
82
83
  matchOne(file: string[], pattern: ParseReturn[], partial?: boolean): boolean;
83
84
  braceExpand(): string[];
84
- parse(pattern: string): ParseReturn | SubparseReturn;
85
+ parse(pattern: string): ParseReturn;
85
86
  makeRe(): false | MMRegExp;
86
87
  slashSplit(p: string): string[];
87
88
  match(f: string, partial?: boolean): boolean;
88
89
  static defaults(def: MinimatchOptions): typeof Minimatch;
89
90
  }
91
+ export { AST } from './ast.js';
90
92
  export { escape } from './escape.js';
91
93
  export { unescape } from './unescape.js';
92
94
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,EACL,KAAK,GACL,SAAS,GACT,QAAQ,GACR,SAAS,GACT,OAAO,GACP,OAAO,GACP,SAAS,GACT,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,CAAA;IACZ,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,eAAO,MAAM,SAAS;QACjB,MAAM,WACA,MAAM,YACN,gBAAgB;;;sBAgIf,MAAM,YAAW,gBAAgB,SACvC,MAAM;oBAOkB,gBAAgB,KAAG,gBAAgB;2BA6DtD,MAAM,YACN,gBAAgB;sBAwCK,MAAM,YAAW,gBAAgB;kBAKzD,MAAM,EAAE,WACL,MAAM,YACN,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AAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA"}
package/dist/mjs/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import expand from 'brace-expansion';
2
- import { parseClass } from './brace-expressions.js';
2
+ import { assertValidPattern } from './assert-valid-pattern.js';
3
+ import { AST } from './ast.js';
3
4
  import { escape } from './escape.js';
4
5
  import { unescape } from './unescape.js';
5
6
  export const minimatch = (p, pattern, options = {}) => {
@@ -78,13 +79,6 @@ export const sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep
78
79
  minimatch.sep = sep;
79
80
  export const GLOBSTAR = Symbol('globstar **');
80
81
  minimatch.GLOBSTAR = GLOBSTAR;
81
- const plTypes = {
82
- '!': { open: '(?:(?!(?:', close: '))[^/]*?)' },
83
- '?': { open: '(?:', close: ')?' },
84
- '+': { open: '(?:', close: ')+' },
85
- '*': { open: '(?:', close: ')*' },
86
- '@': { open: '(?:', close: ')' },
87
- };
88
82
  // any single thing other than /
89
83
  // don't need to escape / when using new RegExp()
90
84
  const qmark = '[^/]';
@@ -97,15 +91,6 @@ const twoStarDot = '(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?';
97
91
  // not a ^ or / followed by a dot,
98
92
  // followed by anything, any number of times.
99
93
  const twoStarNoDot = '(?:(?!(?:\\/|^)\\.).)*?';
100
- // "abc" -> { a:true, b:true, c:true }
101
- const charSet = (s) => s.split('').reduce((set, c) => {
102
- set[c] = true;
103
- return set;
104
- }, {});
105
- // characters that need to be escaped in RegExp.
106
- const reSpecials = charSet('().*{}+?[]^$\\!');
107
- // characters that indicate we have to add the pattern start
108
- const addPatternStartSet = charSet('[.(');
109
94
  export const filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
110
95
  minimatch.filter = filter;
111
96
  const ext = (a, b = {}) => Object.assign({}, a, b);
@@ -124,6 +109,16 @@ export const defaults = (def) => {
124
109
  return orig.defaults(ext(def, options)).Minimatch;
125
110
  }
126
111
  },
112
+ AST: class AST extends orig.AST {
113
+ /* c8 ignore start */
114
+ constructor(type, parent, options = {}) {
115
+ super(type, parent, ext(def, options));
116
+ }
117
+ /* c8 ignore stop */
118
+ static fromGlob(pattern, options = {}) {
119
+ return orig.AST.fromGlob(pattern, ext(def, options));
120
+ }
121
+ },
127
122
  unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
128
123
  escape: (s, options = {}) => orig.escape(s, ext(def, options)),
129
124
  filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
@@ -157,15 +152,6 @@ export const braceExpand = (pattern, options = {}) => {
157
152
  return expand(pattern);
158
153
  };
159
154
  minimatch.braceExpand = braceExpand;
160
- const MAX_PATTERN_LENGTH = 1024 * 64;
161
- const assertValidPattern = (pattern) => {
162
- if (typeof pattern !== 'string') {
163
- throw new TypeError('invalid pattern');
164
- }
165
- if (pattern.length > MAX_PATTERN_LENGTH) {
166
- throw new TypeError('pattern is too long');
167
- }
168
- };
169
155
  // parse a component of the expanded set.
170
156
  // At this point, no pattern may contain "/" in it
171
157
  // so we're going to return a 2d array, where each entry is the full
@@ -189,7 +175,6 @@ export const match = (list, pattern, options = {}) => {
189
175
  };
190
176
  minimatch.match = match;
191
177
  // replace stuff like \* with *
192
- const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
193
178
  const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
194
179
  const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
195
180
  export class Minimatch {
@@ -840,293 +825,8 @@ export class Minimatch {
840
825
  else if ((m = pattern.match(dotStarRE))) {
841
826
  fastTest = dotStarTest;
842
827
  }
843
- let re = '';
844
- let hasMagic = false;
845
- let escaping = false;
846
- // ? => one single character
847
- const patternListStack = [];
848
- const negativeLists = [];
849
- let stateChar = false;
850
- let uflag = false;
851
- let pl;
852
- // . and .. never match anything that doesn't start with .,
853
- // even when options.dot is set. However, if the pattern
854
- // starts with ., then traversal patterns can match.
855
- let dotTravAllowed = pattern.charAt(0) === '.';
856
- let dotFileAllowed = options.dot || dotTravAllowed;
857
- const patternStart = () => dotTravAllowed
858
- ? ''
859
- : dotFileAllowed
860
- ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
861
- : '(?!\\.)';
862
- const subPatternStart = (p) => p.charAt(0) === '.'
863
- ? ''
864
- : options.dot
865
- ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
866
- : '(?!\\.)';
867
- const clearStateChar = () => {
868
- if (stateChar) {
869
- // we had some state-tracking character
870
- // that wasn't consumed by this pass.
871
- switch (stateChar) {
872
- case '*':
873
- re += star;
874
- hasMagic = true;
875
- break;
876
- case '?':
877
- re += qmark;
878
- hasMagic = true;
879
- break;
880
- default:
881
- re += '\\' + stateChar;
882
- break;
883
- }
884
- this.debug('clearStateChar %j %j', stateChar, re);
885
- stateChar = false;
886
- }
887
- };
888
- for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
889
- this.debug('%s\t%s %s %j', pattern, i, re, c);
890
- // skip over any that are escaped.
891
- if (escaping) {
892
- // completely not allowed, even escaped.
893
- // should be impossible.
894
- /* c8 ignore start */
895
- if (c === '/') {
896
- return false;
897
- }
898
- /* c8 ignore stop */
899
- if (reSpecials[c]) {
900
- re += '\\';
901
- }
902
- re += c;
903
- escaping = false;
904
- continue;
905
- }
906
- switch (c) {
907
- // Should already be path-split by now.
908
- /* c8 ignore start */
909
- case '/': {
910
- return false;
911
- }
912
- /* c8 ignore stop */
913
- case '\\':
914
- clearStateChar();
915
- escaping = true;
916
- continue;
917
- // the various stateChar values
918
- // for the "extglob" stuff.
919
- case '?':
920
- case '*':
921
- case '+':
922
- case '@':
923
- case '!':
924
- this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
925
- // if we already have a stateChar, then it means
926
- // that there was something like ** or +? in there.
927
- // Handle the stateChar, then proceed with this one.
928
- this.debug('call clearStateChar %j', stateChar);
929
- clearStateChar();
930
- stateChar = c;
931
- // if extglob is disabled, then +(asdf|foo) isn't a thing.
932
- // just clear the statechar *now*, rather than even diving into
933
- // the patternList stuff.
934
- if (options.noext)
935
- clearStateChar();
936
- continue;
937
- case '(': {
938
- if (!stateChar) {
939
- re += '\\(';
940
- continue;
941
- }
942
- const plEntry = {
943
- type: stateChar,
944
- start: i - 1,
945
- reStart: re.length,
946
- open: plTypes[stateChar].open,
947
- close: plTypes[stateChar].close,
948
- };
949
- this.debug(this.pattern, '\t', plEntry);
950
- patternListStack.push(plEntry);
951
- // negation is (?:(?!(?:js)(?:<rest>))[^/]*)
952
- re += plEntry.open;
953
- // next entry starts with a dot maybe?
954
- if (plEntry.start === 0 && plEntry.type !== '!') {
955
- dotTravAllowed = true;
956
- re += subPatternStart(pattern.slice(i + 1));
957
- }
958
- this.debug('plType %j %j', stateChar, re);
959
- stateChar = false;
960
- continue;
961
- }
962
- case ')': {
963
- const plEntry = patternListStack[patternListStack.length - 1];
964
- if (!plEntry) {
965
- re += '\\)';
966
- continue;
967
- }
968
- patternListStack.pop();
969
- // closing an extglob
970
- clearStateChar();
971
- hasMagic = true;
972
- pl = plEntry;
973
- // negation is (?:(?!js)[^/]*)
974
- // The others are (?:<pattern>)<type>
975
- re += pl.close;
976
- if (pl.type === '!') {
977
- negativeLists.push(Object.assign(pl, { reEnd: re.length }));
978
- }
979
- continue;
980
- }
981
- case '|': {
982
- const plEntry = patternListStack[patternListStack.length - 1];
983
- if (!plEntry) {
984
- re += '\\|';
985
- continue;
986
- }
987
- clearStateChar();
988
- re += '|';
989
- // next subpattern can start with a dot?
990
- if (plEntry.start === 0 && plEntry.type !== '!') {
991
- dotTravAllowed = true;
992
- re += subPatternStart(pattern.slice(i + 1));
993
- }
994
- continue;
995
- }
996
- // these are mostly the same in regexp and glob
997
- case '[':
998
- // swallow any state-tracking char before the [
999
- clearStateChar();
1000
- const [src, needUflag, consumed, magic] = parseClass(pattern, i);
1001
- if (consumed) {
1002
- re += src;
1003
- uflag = uflag || needUflag;
1004
- i += consumed - 1;
1005
- hasMagic = hasMagic || magic;
1006
- }
1007
- else {
1008
- re += '\\[';
1009
- }
1010
- continue;
1011
- case ']':
1012
- re += '\\' + c;
1013
- continue;
1014
- default:
1015
- // swallow any state char that wasn't consumed
1016
- clearStateChar();
1017
- re += regExpEscape(c);
1018
- break;
1019
- } // switch
1020
- } // for
1021
- // handle the case where we had a +( thing at the *end*
1022
- // of the pattern.
1023
- // each pattern list stack adds 3 chars, and we need to go through
1024
- // and escape any | chars that were passed through as-is for the regexp.
1025
- // Go through and escape them, taking care not to double-escape any
1026
- // | chars that were already escaped.
1027
- for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
1028
- let tail;
1029
- tail = re.slice(pl.reStart + pl.open.length);
1030
- this.debug(this.pattern, 'setting tail', re, pl);
1031
- // maybe some even number of \, then maybe 1 \, followed by a |
1032
- tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
1033
- if (!$2) {
1034
- // the | isn't already escaped, so escape it.
1035
- $2 = '\\';
1036
- // should already be done
1037
- /* c8 ignore start */
1038
- }
1039
- /* c8 ignore stop */
1040
- // need to escape all those slashes *again*, without escaping the
1041
- // one that we need for escaping the | character. As it works out,
1042
- // escaping an even number of slashes can be done by simply repeating
1043
- // it exactly after itself. That's why this trick works.
1044
- //
1045
- // I am sorry that you have to see this.
1046
- return $1 + $1 + $2 + '|';
1047
- });
1048
- this.debug('tail=%j\n %s', tail, tail, pl, re);
1049
- const t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
1050
- hasMagic = true;
1051
- re = re.slice(0, pl.reStart) + t + '\\(' + tail;
1052
- }
1053
- // handle trailing things that only matter at the very end.
1054
- clearStateChar();
1055
- if (escaping) {
1056
- // trailing \\
1057
- re += '\\\\';
1058
- }
1059
- // only need to apply the nodot start if the re starts with
1060
- // something that could conceivably capture a dot
1061
- const addPatternStart = addPatternStartSet[re.charAt(0)];
1062
- // Hack to work around lack of negative lookbehind in JS
1063
- // A pattern like: *.!(x).!(y|z) needs to ensure that a name
1064
- // like 'a.xyz.yz' doesn't match. So, the first negative
1065
- // lookahead, has to look ALL the way ahead, to the end of
1066
- // the pattern.
1067
- for (let n = negativeLists.length - 1; n > -1; n--) {
1068
- const nl = negativeLists[n];
1069
- const nlBefore = re.slice(0, nl.reStart);
1070
- const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
1071
- let nlAfter = re.slice(nl.reEnd);
1072
- const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
1073
- // Handle nested stuff like *(*.js|!(*.json)), where open parens
1074
- // mean that we should *not* include the ) in the bit that is considered
1075
- // "after" the negated section.
1076
- const closeParensBefore = nlBefore.split(')').length;
1077
- const openParensBefore = nlBefore.split('(').length - closeParensBefore;
1078
- let cleanAfter = nlAfter;
1079
- for (let i = 0; i < openParensBefore; i++) {
1080
- cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
1081
- }
1082
- nlAfter = cleanAfter;
1083
- const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
1084
- re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
1085
- }
1086
- // if the re is not "" at this point, then we need to make sure
1087
- // it doesn't match against an empty path part.
1088
- // Otherwise a/* will match a/, which it should not.
1089
- if (re !== '' && hasMagic) {
1090
- re = '(?=.)' + re;
1091
- }
1092
- if (addPatternStart) {
1093
- re = patternStart() + re;
1094
- }
1095
- // if it's nocase, and the lcase/uppercase don't match, it's magic
1096
- if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
1097
- hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
1098
- }
1099
- // skip the regexp for non-magical patterns
1100
- // unescape anything in it, though, so that it'll be
1101
- // an exact match against a file etc.
1102
- if (!hasMagic) {
1103
- return globUnescape(re);
1104
- }
1105
- const flags = (options.nocase ? 'i' : '') + (uflag ? 'u' : '');
1106
- try {
1107
- const ext = fastTest
1108
- ? {
1109
- _glob: pattern,
1110
- _src: re,
1111
- test: fastTest,
1112
- }
1113
- : {
1114
- _glob: pattern,
1115
- _src: re,
1116
- };
1117
- return Object.assign(new RegExp('^' + re + '$', flags), ext);
1118
- /* c8 ignore start */
1119
- }
1120
- catch (er) {
1121
- // should be impossible
1122
- // If it was an invalid regular expression, then it can't match
1123
- // anything. This trick looks for a character after the end of
1124
- // the string, which is of course impossible, except in multi-line
1125
- // mode, but it's not a /m regex.
1126
- this.debug('invalid regexp', er);
1127
- return new RegExp('$.');
1128
- }
1129
- /* c8 ignore stop */
828
+ const re = AST.fromGlob(pattern, this.options).toMMPattern();
829
+ return fastTest ? Object.assign(re, { test: fastTest }) : re;
1130
830
  }
1131
831
  makeRe() {
1132
832
  if (this.regexp || this.regexp === false)
@@ -1148,7 +848,7 @@ export class Minimatch {
1148
848
  : options.dot
1149
849
  ? twoStarDot
1150
850
  : twoStarNoDot;
1151
- const flags = options.nocase ? 'i' : '';
851
+ const flags = new Set(options.nocase ? ['i'] : []);
1152
852
  // regexpify non-globstar patterns
1153
853
  // if ** is only item, then we just do one twoStar
1154
854
  // if ** is first, and there are more, prepend (\/|twoStar\/)? to next
@@ -1157,11 +857,17 @@ export class Minimatch {
1157
857
  // then filter out GLOBSTAR symbols
1158
858
  let re = set
1159
859
  .map(pattern => {
1160
- const pp = pattern.map(p => typeof p === 'string'
1161
- ? regExpEscape(p)
1162
- : p === GLOBSTAR
1163
- ? GLOBSTAR
1164
- : p._src);
860
+ const pp = pattern.map(p => {
861
+ if (p instanceof RegExp) {
862
+ for (const f of p.flags.split(''))
863
+ flags.add(f);
864
+ }
865
+ return typeof p === 'string'
866
+ ? regExpEscape(p)
867
+ : p === GLOBSTAR
868
+ ? GLOBSTAR
869
+ : p._src;
870
+ });
1165
871
  pp.forEach((p, i) => {
1166
872
  const next = pp[i + 1];
1167
873
  const prev = pp[i - 1];
@@ -1187,14 +893,17 @@ export class Minimatch {
1187
893
  return pp.filter(p => p !== GLOBSTAR).join('/');
1188
894
  })
1189
895
  .join('|');
896
+ // need to wrap in parens if we had more than one thing with |,
897
+ // otherwise only the first will be anchored to ^ and the last to $
898
+ const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', ''];
1190
899
  // must match entire pattern
1191
900
  // ending in a * or ** will make it less strict.
1192
- re = '^(?:' + re + ')$';
901
+ re = '^' + open + re + close + '$';
1193
902
  // can match anything, as long as it's not this.
1194
903
  if (this.negate)
1195
- re = '^(?!' + re + ').*$';
904
+ re = '^(?!' + re + ').+$';
1196
905
  try {
1197
- this.regexp = new RegExp(re, flags);
906
+ this.regexp = new RegExp(re, [...flags].join(''));
1198
907
  /* c8 ignore start */
1199
908
  }
1200
909
  catch (ex) {
@@ -1280,9 +989,11 @@ export class Minimatch {
1280
989
  }
1281
990
  }
1282
991
  /* c8 ignore start */
992
+ export { AST } from './ast.js';
1283
993
  export { escape } from './escape.js';
1284
994
  export { unescape } from './unescape.js';
1285
995
  /* c8 ignore stop */
996
+ minimatch.AST = AST;
1286
997
  minimatch.Minimatch = Minimatch;
1287
998
  minimatch.escape = escape;
1288
999
  minimatch.unescape = unescape;