minimatch 7.2.0 → 7.4.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/README.md CHANGED
@@ -32,11 +32,20 @@ Supports these glob features:
32
32
  - Brace Expansion
33
33
  - Extended glob matching
34
34
  - "Globstar" `**` matching
35
+ - [Posix character
36
+ classes](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html),
37
+ like `[[:alpha:]]`, supporting the full range of Unicode
38
+ characters. For example, `[[:alpha:]]` will match against
39
+ `'é'`, though `[a-zA-Z]` will not. Collating symbol and set
40
+ matching is not supported, so `[[=e=]]` will _not_ match `'é'`
41
+ and `[[.ch.]]` will not match `'ch'` in locales where `ch` is
42
+ considered a single character.
35
43
 
36
44
  See:
37
45
 
38
46
  - `man sh`
39
- - `man bash`
47
+ - `man bash` [Pattern
48
+ Matching](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html)
40
49
  - `man 3 fnmatch`
41
50
  - `man 5 gitignore`
42
51
 
@@ -113,7 +122,7 @@ var mm = new Minimatch(pattern, options)
113
122
 
114
123
  ### Methods
115
124
 
116
- - `makeRe` Generate the `regexp` member if necessary, and return it.
125
+ - `makeRe()` Generate the `regexp` member if necessary, and return it.
117
126
  Will return `false` if the pattern is invalid.
118
127
  - `match(fname)` Return true if the filename matches the pattern, or
119
128
  false otherwise.
@@ -121,6 +130,21 @@ var mm = new Minimatch(pattern, options)
121
130
  filename, and match it against a single row in the `regExpSet`. This
122
131
  method is mainly for internal use, but is exposed so that it can be
123
132
  used by a glob-walker that needs to avoid excessive filesystem calls.
133
+ - `hasMagic()` Returns true if the parsed pattern contains any
134
+ magic characters. Returns false if all comparator parts are
135
+ string literals. If the `magicalBraces` option is set on the
136
+ constructor, then it will consider brace expansions which are
137
+ not otherwise magical to be magic. If not set, then a pattern
138
+ like `a{b,c}d` will return `false`, because neither `abd` nor
139
+ `acd` contain any special glob characters.
140
+
141
+ This does **not** mean that the pattern string can be used as a
142
+ literal filename, as it may contain magic glob characters that
143
+ are escaped. For example, the pattern `\\*` or `[*]` would not
144
+ be considered to have magic, as the matching portion parses to
145
+ the literal string `'*'` and would match a path named `'*'`,
146
+ not `'\\*'` or `'[*]'`. The `minimatch.unescape()` method may
147
+ be used to remove escape characters.
124
148
 
125
149
  All other methods are internal, and will be called as necessary.
126
150
 
@@ -141,6 +165,34 @@ supplied argument, suitable for use with `Array.filter`. Example:
141
165
  var javascripts = fileList.filter(minimatch.filter('*.js', { matchBase: true }))
142
166
  ```
143
167
 
168
+ ### minimatch.escape(pattern, options = {})
169
+
170
+ Escape all magic characters in a glob pattern, so that it will
171
+ only ever match literal strings
172
+
173
+ If the `windowsPathsNoEscape` option is used, then characters are
174
+ escaped by wrapping in `[]`, because a magic character wrapped in
175
+ a character class can only be satisfied by that exact character.
176
+
177
+ Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot
178
+ be escaped or unescaped.
179
+
180
+ ### minimatch.unescape(pattern, options = {})
181
+
182
+ Un-escape a glob string that may contain some escaped characters.
183
+
184
+ If the `windowsPathsNoEscape` option is used, then square-brace
185
+ escapes are removed, but not backslash escapes. For example, it
186
+ will turn the string `'[*]'` into `*`, but it will not turn
187
+ `'\\*'` into `'*'`, becuase `\` is a path separator in
188
+ `windowsPathsNoEscape` mode.
189
+
190
+ When `windowsPathsNoEscape` is not set, then both brace escapes
191
+ and backslash escapes are removed.
192
+
193
+ Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot
194
+ be escaped or unescaped.
195
+
144
196
  ### minimatch.match(list, pattern, options)
145
197
 
146
198
  Match against the list of
@@ -203,6 +255,16 @@ When a match is not found by `minimatch.match`, return a list containing
203
255
  the pattern itself if this option is set. When not set, an empty list
204
256
  is returned if there are no matches.
205
257
 
258
+ ### magicalBraces
259
+
260
+ This only affects the results of the `Minimatch.hasMagic` method.
261
+
262
+ If the pattern contains brace expansions, such as `a{b,c}d`, but
263
+ no other magic characters, then the `Minipass.hasMagic()` method
264
+ will return `false` by default. When this option set, it will
265
+ return `true` for brace expansion as well as other magic glob
266
+ characters.
267
+
206
268
  ### matchBase
207
269
 
208
270
  If set, then patterns without slashes will be matched
@@ -0,0 +1,7 @@
1
+ export type ParseClassResult = [
2
+ src: string,
3
+ uFlag: boolean,
4
+ consumed: number,
5
+ hasMagic: boolean
6
+ ];
7
+ export declare const parseClass: (glob: string, position: number) => ParseClassResult;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ // translate the various posix character classes into unicode properties
3
+ // this works across all unicode locales
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.parseClass = void 0;
6
+ // { <posix class>: [<translation>, /u flag required, negated]
7
+ const posixClasses = {
8
+ '[:alnum:]': ['\\p{L}\\p{Nl}\\p{Nd}', true],
9
+ '[:alpha:]': ['\\p{L}\\p{Nl}', true],
10
+ '[:ascii:]': ['\\x' + '00-\\x' + '7f', false],
11
+ '[:blank:]': ['\\p{Zs}\\t', true],
12
+ '[:cntrl:]': ['\\p{Cc}', true],
13
+ '[:digit:]': ['\\p{Nd}', true],
14
+ '[:graph:]': ['\\p{Z}\\p{C}', true, true],
15
+ '[:lower:]': ['\\p{Ll}', true],
16
+ '[:print:]': ['\\p{C}', true],
17
+ '[:punct:]': ['\\p{P}', true],
18
+ '[:space:]': ['\\p{Z}\\t\\r\\n\\v\\f', true],
19
+ '[:upper:]': ['\\p{Lu}', true],
20
+ '[:word:]': ['\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}', true],
21
+ '[:xdigit:]': ['A-Fa-f0-9', false],
22
+ };
23
+ // only need to escape a few things inside of brace expressions
24
+ // escapes: [ \ ] -
25
+ const braceEscape = (s) => s.replace(/[[\]\\-]/g, '\\$&');
26
+ // escape all regexp magic characters
27
+ const regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
28
+ // everything has already been escaped, we just have to join
29
+ const rangesToString = (ranges) => ranges.join('');
30
+ // takes a glob string at a posix brace expression, and returns
31
+ // an equivalent regular expression source, and boolean indicating
32
+ // whether the /u flag needs to be applied, and the number of chars
33
+ // consumed to parse the character class.
34
+ // This also removes out of order ranges, and returns ($.) if the
35
+ // entire class just no good.
36
+ const parseClass = (glob, position) => {
37
+ const pos = position;
38
+ /* c8 ignore start */
39
+ if (glob.charAt(pos) !== '[') {
40
+ throw new Error('not in a brace expression');
41
+ }
42
+ /* c8 ignore stop */
43
+ const ranges = [];
44
+ const negs = [];
45
+ let i = pos + 1;
46
+ let sawStart = false;
47
+ let uflag = false;
48
+ let escaping = false;
49
+ let negate = false;
50
+ let endPos = pos;
51
+ let rangeStart = '';
52
+ WHILE: while (i < glob.length) {
53
+ const c = glob.charAt(i);
54
+ if ((c === '!' || c === '^') && i === pos + 1) {
55
+ negate = true;
56
+ i++;
57
+ continue;
58
+ }
59
+ if (c === ']' && sawStart && !escaping) {
60
+ endPos = i + 1;
61
+ break;
62
+ }
63
+ sawStart = true;
64
+ if (c === '\\') {
65
+ if (!escaping) {
66
+ escaping = true;
67
+ i++;
68
+ continue;
69
+ }
70
+ // escaped \ char, fall through and treat like normal char
71
+ }
72
+ if (c === '[' && !escaping) {
73
+ // either a posix class, a collation equivalent, or just a [
74
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
75
+ if (glob.startsWith(cls, i)) {
76
+ // invalid, [a-[] is fine, but not [a-[:alpha]]
77
+ if (rangeStart) {
78
+ return ['$.', false, glob.length - pos, true];
79
+ }
80
+ i += cls.length;
81
+ if (neg)
82
+ negs.push(unip);
83
+ else
84
+ ranges.push(unip);
85
+ uflag = uflag || u;
86
+ continue WHILE;
87
+ }
88
+ }
89
+ }
90
+ // now it's just a normal character, effectively
91
+ escaping = false;
92
+ if (rangeStart) {
93
+ // throw this range away if it's not valid, but others
94
+ // can still match.
95
+ if (c > rangeStart) {
96
+ ranges.push(braceEscape(rangeStart) + '-' + braceEscape(c));
97
+ }
98
+ else if (c === rangeStart) {
99
+ ranges.push(braceEscape(c));
100
+ }
101
+ rangeStart = '';
102
+ i++;
103
+ continue;
104
+ }
105
+ // now might be the start of a range.
106
+ // can be either c-d or c-] or c<more...>] or c] at this point
107
+ if (glob.startsWith('-]', i + 1)) {
108
+ ranges.push(braceEscape(c + '-'));
109
+ i += 2;
110
+ continue;
111
+ }
112
+ if (glob.startsWith('-', i + 1)) {
113
+ rangeStart = c;
114
+ i += 2;
115
+ continue;
116
+ }
117
+ // not the start of a range, just a single character
118
+ ranges.push(braceEscape(c));
119
+ i++;
120
+ }
121
+ if (endPos < i) {
122
+ // didn't see the end of the class, not a valid class,
123
+ // but might still be valid as a literal match.
124
+ return ['', false, 0, false];
125
+ }
126
+ // if we got no ranges and no negates, then we have a range that
127
+ // cannot possibly match anything, and that poisons the whole glob
128
+ if (!ranges.length && !negs.length) {
129
+ return ['$.', false, glob.length - pos, true];
130
+ }
131
+ // if we got one positive range, and it's a single character, then that's
132
+ // not actually a magic pattern, it's just that one literal character.
133
+ // we should not treat that as "magic", we should just return the literal
134
+ // character. [_] is a perfectly valid way to escape glob magic chars.
135
+ if (negs.length === 0 &&
136
+ ranges.length === 1 &&
137
+ /^\\?.$/.test(ranges[0]) &&
138
+ !negate) {
139
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
140
+ return [regexpEscape(r), false, endPos - pos, false];
141
+ }
142
+ const sranges = '[' + (negate ? '^' : '') + rangesToString(ranges) + ']';
143
+ const snegs = '[' + (negate ? '' : '^') + rangesToString(negs) + ']';
144
+ const comb = ranges.length && negs.length
145
+ ? '(' + sranges + '|' + snegs + ')'
146
+ : ranges.length
147
+ ? sranges
148
+ : snegs;
149
+ return [comb, uflag, endPos - pos, true];
150
+ };
151
+ exports.parseClass = parseClass;
152
+ //# sourceMappingURL=brace-expressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brace-expressions.js","sourceRoot":"","sources":["../../src/brace-expressions.ts"],"names":[],"mappings":";AAAA,wEAAwE;AACxE,wCAAwC;;;AAExC,8DAA8D;A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,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,GAAG,CAAA;IACxE,MAAM,KAAK,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;IACpE,MAAM,IAAI,GACR,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;QAC1B,CAAC,CAAC,GAAG,GAAG,OAAO,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG;QACnC,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,KAAK,CAAA;IAEX,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAA;AAC1C,CAAC,CAAA;AAhIY,QAAA,UAAU,cAgItB"}
@@ -0,0 +1,11 @@
1
+ import { MinimatchOptions } from './index.js';
2
+ /**
3
+ * Escape all magic characters in a glob pattern.
4
+ *
5
+ * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
6
+ * option is used, then characters are escaped by wrapping in `[]`, because
7
+ * a magic character wrapped in a character class can only be satisfied by
8
+ * that exact character. In this mode, `\` is _not_ escaped, because it is
9
+ * not interpreted as a magic character, but instead as a path separator.
10
+ */
11
+ export declare const escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, 'windowsPathsNoEscape'>) => string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escape = void 0;
4
+ /**
5
+ * Escape all magic characters in a glob pattern.
6
+ *
7
+ * If the {@link windowsPathsNoEscape | GlobOptions.windowsPathsNoEscape}
8
+ * option is used, then characters are escaped by wrapping in `[]`, because
9
+ * a magic character wrapped in a character class can only be satisfied by
10
+ * that exact character. In this mode, `\` is _not_ escaped, because it is
11
+ * not interpreted as a magic character, but instead as a path separator.
12
+ */
13
+ const escape = (s, { windowsPathsNoEscape = false, } = {}) => {
14
+ // don't need to escape +@! because we escape the parens
15
+ // that make those magic, and escaping ! as [!] isn't valid,
16
+ // because [!]] is a valid glob class meaning not ']'.
17
+ return windowsPathsNoEscape
18
+ ? s.replace(/[?*()[\]]/g, '[$&]')
19
+ : s.replace(/[?*()[\]\\]/g, '\\$&');
20
+ };
21
+ exports.escape = escape;
22
+ //# sourceMappingURL=escape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/escape.ts"],"names":[],"mappings":";;;AACA;;;;;;;;GAQG;AACI,MAAM,MAAM,GAAG,CACpB,CAAS,EACT,EACE,oBAAoB,GAAG,KAAK,MACsB,EAAE,EACtD,EAAE;IACF,wDAAwD;IACxD,4DAA4D;IAC5D,sDAAsD;IACtD,OAAO,oBAAoB;QACzB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;QACjC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;AACvC,CAAC,CAAA;AAZY,QAAA,MAAM,UAYlB"}
@@ -8,6 +8,8 @@ declare const _default: {
8
8
  makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
9
9
  match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
10
10
  Minimatch: typeof import("./index.js").Minimatch;
11
+ escape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;
12
+ unescape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;
11
13
  } & {
12
14
  default: {
13
15
  (p: string, pattern: string, options?: import("./index.js").MinimatchOptions): boolean;
@@ -19,6 +21,8 @@ declare const _default: {
19
21
  makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
20
22
  match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
21
23
  Minimatch: typeof import("./index.js").Minimatch;
24
+ escape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;
25
+ unescape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;
22
26
  };
23
27
  minimatch: {
24
28
  (p: string, pattern: string, options?: import("./index.js").MinimatchOptions): boolean;
@@ -30,6 +34,8 @@ declare const _default: {
30
34
  makeRe: (pattern: string, options?: import("./index.js").MinimatchOptions) => false | import("./index.js").MMRegExp;
31
35
  match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
32
36
  Minimatch: typeof import("./index.js").Minimatch;
37
+ escape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;
38
+ unescape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;
33
39
  };
34
40
  };
35
41
  export = _default;
@@ -12,6 +12,7 @@ export interface MinimatchOptions {
12
12
  dot?: boolean;
13
13
  nocase?: boolean;
14
14
  nocaseMagicOnly?: boolean;
15
+ magicalBraces?: boolean;
15
16
  matchBase?: boolean;
16
17
  flipNegate?: boolean;
17
18
  preserveMultipleSlashes?: boolean;
@@ -29,6 +30,8 @@ export declare const minimatch: {
29
30
  makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
30
31
  match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
31
32
  Minimatch: typeof Minimatch;
33
+ escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;
34
+ unescape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;
32
35
  };
33
36
  export default minimatch;
34
37
  type Sep = '\\' | '/';
@@ -37,7 +40,6 @@ export declare const GLOBSTAR: unique symbol;
37
40
  export declare const filter: (pattern: string, options?: MinimatchOptions) => (p: string) => boolean;
38
41
  export declare const defaults: (def: MinimatchOptions) => typeof minimatch;
39
42
  export declare const braceExpand: (pattern: string, options?: MinimatchOptions) => string[];
40
- declare const SUBPARSE: unique symbol;
41
43
  export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
42
44
  export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
43
45
  export type MMRegExp = RegExp & {
@@ -66,6 +68,7 @@ export declare class Minimatch {
66
68
  windowsNoMagicRoot: boolean;
67
69
  regexp: false | null | MMRegExp;
68
70
  constructor(pattern: string, options?: MinimatchOptions);
71
+ hasMagic(): boolean;
69
72
  debug(..._: any[]): void;
70
73
  make(): void;
71
74
  preprocess(globParts: string[][]): string[][];
@@ -78,9 +81,11 @@ export declare class Minimatch {
78
81
  parseNegate(): void;
79
82
  matchOne(file: string[], pattern: ParseReturn[], partial?: boolean): boolean;
80
83
  braceExpand(): string[];
81
- parse(pattern: string, isSub?: typeof SUBPARSE): ParseReturn | SubparseReturn;
84
+ parse(pattern: string): ParseReturn | SubparseReturn;
82
85
  makeRe(): false | MMRegExp;
83
86
  slashSplit(p: string): string[];
84
87
  match(f: string, partial?: boolean): boolean;
85
88
  static defaults(def: MinimatchOptions): typeof Minimatch;
86
89
  }
90
+ export { escape } from './escape.js';
91
+ export { unescape } from './unescape.js';