minimatch 3.1.2 → 9.0.4

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.
Files changed (54) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +289 -65
  3. package/dist/commonjs/assert-valid-pattern.d.ts +2 -0
  4. package/dist/commonjs/assert-valid-pattern.d.ts.map +1 -0
  5. package/dist/commonjs/assert-valid-pattern.js +14 -0
  6. package/dist/commonjs/assert-valid-pattern.js.map +1 -0
  7. package/dist/commonjs/ast.d.ts +20 -0
  8. package/dist/commonjs/ast.d.ts.map +1 -0
  9. package/dist/commonjs/ast.js +592 -0
  10. package/dist/commonjs/ast.js.map +1 -0
  11. package/dist/commonjs/brace-expressions.d.ts +8 -0
  12. package/dist/commonjs/brace-expressions.d.ts.map +1 -0
  13. package/dist/commonjs/brace-expressions.js +152 -0
  14. package/dist/commonjs/brace-expressions.js.map +1 -0
  15. package/dist/commonjs/escape.d.ts +12 -0
  16. package/dist/commonjs/escape.d.ts.map +1 -0
  17. package/dist/commonjs/escape.js +22 -0
  18. package/dist/commonjs/escape.js.map +1 -0
  19. package/dist/commonjs/index.d.ts +94 -0
  20. package/dist/commonjs/index.d.ts.map +1 -0
  21. package/dist/commonjs/index.js +1016 -0
  22. package/dist/commonjs/index.js.map +1 -0
  23. package/dist/commonjs/package.json +3 -0
  24. package/dist/commonjs/unescape.d.ts +17 -0
  25. package/dist/commonjs/unescape.d.ts.map +1 -0
  26. package/dist/commonjs/unescape.js +24 -0
  27. package/dist/commonjs/unescape.js.map +1 -0
  28. package/dist/esm/assert-valid-pattern.d.ts +2 -0
  29. package/dist/esm/assert-valid-pattern.d.ts.map +1 -0
  30. package/dist/esm/assert-valid-pattern.js +10 -0
  31. package/dist/esm/assert-valid-pattern.js.map +1 -0
  32. package/dist/esm/ast.d.ts +20 -0
  33. package/dist/esm/ast.d.ts.map +1 -0
  34. package/dist/esm/ast.js +588 -0
  35. package/dist/esm/ast.js.map +1 -0
  36. package/dist/esm/brace-expressions.d.ts +8 -0
  37. package/dist/esm/brace-expressions.d.ts.map +1 -0
  38. package/dist/esm/brace-expressions.js +148 -0
  39. package/dist/esm/brace-expressions.js.map +1 -0
  40. package/dist/esm/escape.d.ts +12 -0
  41. package/dist/esm/escape.d.ts.map +1 -0
  42. package/dist/esm/escape.js +18 -0
  43. package/dist/esm/escape.js.map +1 -0
  44. package/dist/esm/index.d.ts +94 -0
  45. package/dist/esm/index.d.ts.map +1 -0
  46. package/dist/esm/index.js +1000 -0
  47. package/dist/esm/index.js.map +1 -0
  48. package/dist/esm/package.json +3 -0
  49. package/dist/esm/unescape.d.ts +17 -0
  50. package/dist/esm/unescape.d.ts.map +1 -0
  51. package/dist/esm/unescape.js +20 -0
  52. package/dist/esm/unescape.js.map +1 -0
  53. package/package.json +62 -13
  54. package/minimatch.js +0 -947
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The ISC License
2
2
 
3
- Copyright (c) Isaac Z. Schlueter and Contributors
3
+ Copyright (c) 2011-2023 Isaac Z. Schlueter and Contributors
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  A minimal matching utility.
4
4
 
5
- [![Build Status](https://travis-ci.org/isaacs/minimatch.svg?branch=master)](http://travis-ci.org/isaacs/minimatch)
6
-
7
-
8
5
  This is the matching library used internally by npm.
9
6
 
10
7
  It works by converting glob expressions into JavaScript `RegExp`
@@ -12,101 +9,193 @@ objects.
12
9
 
13
10
  ## Usage
14
11
 
15
- ```javascript
16
- var minimatch = require("minimatch")
17
-
18
- minimatch("bar.foo", "*.foo") // true!
19
- minimatch("bar.foo", "*.bar") // false!
20
- minimatch("bar.foo", "*.+(bar|foo)", { debug: true }) // true, and noisy!
12
+ ```js
13
+ // hybrid module, load with require() or import
14
+ import { minimatch } from 'minimatch'
15
+ // or:
16
+ const { minimatch } = require('minimatch')
17
+
18
+ minimatch('bar.foo', '*.foo') // true!
19
+ minimatch('bar.foo', '*.bar') // false!
20
+ minimatch('bar.foo', '*.+(bar|foo)', { debug: true }) // true, and noisy!
21
21
  ```
22
22
 
23
23
  ## Features
24
24
 
25
25
  Supports these glob features:
26
26
 
27
- * Brace Expansion
28
- * Extended glob matching
29
- * "Globstar" `**` matching
27
+ - Brace Expansion
28
+ - Extended glob matching
29
+ - "Globstar" `**` matching
30
+ - [Posix character
31
+ classes](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html),
32
+ like `[[:alpha:]]`, supporting the full range of Unicode
33
+ characters. For example, `[[:alpha:]]` will match against
34
+ `'é'`, though `[a-zA-Z]` will not. Collating symbol and set
35
+ matching is not supported, so `[[=e=]]` will _not_ match `'é'`
36
+ and `[[.ch.]]` will not match `'ch'` in locales where `ch` is
37
+ considered a single character.
30
38
 
31
39
  See:
32
40
 
33
- * `man sh`
34
- * `man bash`
35
- * `man 3 fnmatch`
36
- * `man 5 gitignore`
41
+ - `man sh`
42
+ - `man bash` [Pattern
43
+ Matching](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html)
44
+ - `man 3 fnmatch`
45
+ - `man 5 gitignore`
46
+
47
+ ## Windows
48
+
49
+ **Please only use forward-slashes in glob expressions.**
50
+
51
+ Though windows uses either `/` or `\` as its path separator, only `/`
52
+ characters are used by this glob implementation. You must use
53
+ forward-slashes **only** in glob expressions. Back-slashes in patterns
54
+ will always be interpreted as escape characters, not path separators.
55
+
56
+ Note that `\` or `/` _will_ be interpreted as path separators in paths on
57
+ Windows, and will match against `/` in glob expressions.
58
+
59
+ So just always use `/` in patterns.
60
+
61
+ ### UNC Paths
62
+
63
+ On Windows, UNC paths like `//?/c:/...` or
64
+ `//ComputerName/Share/...` are handled specially.
65
+
66
+ - Patterns starting with a double-slash followed by some
67
+ non-slash characters will preserve their double-slash. As a
68
+ result, a pattern like `//*` will match `//x`, but not `/x`.
69
+ - Patterns staring with `//?/<drive letter>:` will _not_ treat
70
+ the `?` as a wildcard character. Instead, it will be treated
71
+ as a normal string.
72
+ - Patterns starting with `//?/<drive letter>:/...` will match
73
+ file paths starting with `<drive letter>:/...`, and vice versa,
74
+ as if the `//?/` was not present. This behavior only is
75
+ present when the drive letters are a case-insensitive match to
76
+ one another. The remaining portions of the path/pattern are
77
+ compared case sensitively, unless `nocase:true` is set.
78
+
79
+ Note that specifying a UNC path using `\` characters as path
80
+ separators is always allowed in the file path argument, but only
81
+ allowed in the pattern argument when `windowsPathsNoEscape: true`
82
+ is set in the options.
37
83
 
38
84
  ## Minimatch Class
39
85
 
40
86
  Create a minimatch object by instantiating the `minimatch.Minimatch` class.
41
87
 
42
88
  ```javascript
43
- var Minimatch = require("minimatch").Minimatch
89
+ var Minimatch = require('minimatch').Minimatch
44
90
  var mm = new Minimatch(pattern, options)
45
91
  ```
46
92
 
47
93
  ### Properties
48
94
 
49
- * `pattern` The original pattern the minimatch object represents.
50
- * `options` The options supplied to the constructor.
51
- * `set` A 2-dimensional array of regexp or string expressions.
95
+ - `pattern` The original pattern the minimatch object represents.
96
+ - `options` The options supplied to the constructor.
97
+ - `set` A 2-dimensional array of regexp or string expressions.
52
98
  Each row in the
53
- array corresponds to a brace-expanded pattern. Each item in the row
54
- corresponds to a single path-part. For example, the pattern
99
+ array corresponds to a brace-expanded pattern. Each item in the row
100
+ corresponds to a single path-part. For example, the pattern
55
101
  `{a,b/c}/d` would expand to a set of patterns like:
56
102
 
57
103
  [ [ a, d ]
58
104
  , [ b, c, d ] ]
59
105
 
60
- If a portion of the pattern doesn't have any "magic" in it
61
- (that is, it's something like `"foo"` rather than `fo*o?`), then it
62
- will be left as a string rather than converted to a regular
63
- expression.
106
+ If a portion of the pattern doesn't have any "magic" in it
107
+ (that is, it's something like `"foo"` rather than `fo*o?`), then it
108
+ will be left as a string rather than converted to a regular
109
+ expression.
64
110
 
65
- * `regexp` Created by the `makeRe` method. A single regular expression
66
- expressing the entire pattern. This is useful in cases where you wish
111
+ - `regexp` Created by the `makeRe` method. A single regular expression
112
+ expressing the entire pattern. This is useful in cases where you wish
67
113
  to use the pattern somewhat like `fnmatch(3)` with `FNM_PATH` enabled.
68
- * `negate` True if the pattern is negated.
69
- * `comment` True if the pattern is a comment.
70
- * `empty` True if the pattern is `""`.
114
+ - `negate` True if the pattern is negated.
115
+ - `comment` True if the pattern is a comment.
116
+ - `empty` True if the pattern is `""`.
71
117
 
72
118
  ### Methods
73
119
 
74
- * `makeRe` Generate the `regexp` member if necessary, and return it.
120
+ - `makeRe()` Generate the `regexp` member if necessary, and return it.
75
121
  Will return `false` if the pattern is invalid.
76
- * `match(fname)` Return true if the filename matches the pattern, or
122
+ - `match(fname)` Return true if the filename matches the pattern, or
77
123
  false otherwise.
78
- * `matchOne(fileArray, patternArray, partial)` Take a `/`-split
79
- filename, and match it against a single row in the `regExpSet`. This
124
+ - `matchOne(fileArray, patternArray, partial)` Take a `/`-split
125
+ filename, and match it against a single row in the `regExpSet`. This
80
126
  method is mainly for internal use, but is exposed so that it can be
81
127
  used by a glob-walker that needs to avoid excessive filesystem calls.
128
+ - `hasMagic()` Returns true if the parsed pattern contains any
129
+ magic characters. Returns false if all comparator parts are
130
+ string literals. If the `magicalBraces` option is set on the
131
+ constructor, then it will consider brace expansions which are
132
+ not otherwise magical to be magic. If not set, then a pattern
133
+ like `a{b,c}d` will return `false`, because neither `abd` nor
134
+ `acd` contain any special glob characters.
135
+
136
+ This does **not** mean that the pattern string can be used as a
137
+ literal filename, as it may contain magic glob characters that
138
+ are escaped. For example, the pattern `\\*` or `[*]` would not
139
+ be considered to have magic, as the matching portion parses to
140
+ the literal string `'*'` and would match a path named `'*'`,
141
+ not `'\\*'` or `'[*]'`. The `minimatch.unescape()` method may
142
+ be used to remove escape characters.
82
143
 
83
144
  All other methods are internal, and will be called as necessary.
84
145
 
85
146
  ### minimatch(path, pattern, options)
86
147
 
87
- Main export. Tests a path against the pattern using the options.
148
+ Main export. Tests a path against the pattern using the options.
88
149
 
89
150
  ```javascript
90
- var isJS = minimatch(file, "*.js", { matchBase: true })
151
+ var isJS = minimatch(file, '*.js', { matchBase: true })
91
152
  ```
92
153
 
93
154
  ### minimatch.filter(pattern, options)
94
155
 
95
156
  Returns a function that tests its
96
- supplied argument, suitable for use with `Array.filter`. Example:
157
+ supplied argument, suitable for use with `Array.filter`. Example:
97
158
 
98
159
  ```javascript
99
- var javascripts = fileList.filter(minimatch.filter("*.js", {matchBase: true}))
160
+ var javascripts = fileList.filter(minimatch.filter('*.js', { matchBase: true }))
100
161
  ```
101
162
 
163
+ ### minimatch.escape(pattern, options = {})
164
+
165
+ Escape all magic characters in a glob pattern, so that it will
166
+ only ever match literal strings
167
+
168
+ If the `windowsPathsNoEscape` option is used, then characters are
169
+ escaped by wrapping in `[]`, because a magic character wrapped in
170
+ a character class can only be satisfied by that exact character.
171
+
172
+ Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot
173
+ be escaped or unescaped.
174
+
175
+ ### minimatch.unescape(pattern, options = {})
176
+
177
+ Un-escape a glob string that may contain some escaped characters.
178
+
179
+ If the `windowsPathsNoEscape` option is used, then square-brace
180
+ escapes are removed, but not backslash escapes. For example, it
181
+ will turn the string `'[*]'` into `*`, but it will not turn
182
+ `'\\*'` into `'*'`, because `\` is a path separator in
183
+ `windowsPathsNoEscape` mode.
184
+
185
+ When `windowsPathsNoEscape` is not set, then both brace escapes
186
+ and backslash escapes are removed.
187
+
188
+ Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot
189
+ be escaped or unescaped.
190
+
102
191
  ### minimatch.match(list, pattern, options)
103
192
 
104
193
  Match against the list of
105
- files, in the style of fnmatch or glob. If nothing is matched, and
194
+ files, in the style of fnmatch or glob. If nothing is matched, and
106
195
  options.nonull is set, then return a list containing the pattern itself.
107
196
 
108
197
  ```javascript
109
- var javascripts = minimatch.match(fileList, "*.js", {matchBase: true}))
198
+ var javascripts = minimatch.match(fileList, '*.js', { matchBase: true })
110
199
  ```
111
200
 
112
201
  ### minimatch.makeRe(pattern, options)
@@ -145,16 +234,36 @@ Disable "extglob" style patterns like `+(a|b)`.
145
234
 
146
235
  Perform a case-insensitive match.
147
236
 
237
+ ### nocaseMagicOnly
238
+
239
+ When used with `{nocase: true}`, create regular expressions that
240
+ are case-insensitive, but leave string match portions untouched.
241
+ Has no effect when used without `{nocase: true}`
242
+
243
+ Useful when some other form of case-insensitive matching is used,
244
+ or if the original string representation is useful in some other
245
+ way.
246
+
148
247
  ### nonull
149
248
 
150
249
  When a match is not found by `minimatch.match`, return a list containing
151
- the pattern itself if this option is set. When not set, an empty list
250
+ the pattern itself if this option is set. When not set, an empty list
152
251
  is returned if there are no matches.
153
252
 
253
+ ### magicalBraces
254
+
255
+ This only affects the results of the `Minimatch.hasMagic` method.
256
+
257
+ If the pattern contains brace expansions, such as `a{b,c}d`, but
258
+ no other magic characters, then the `Minimatch.hasMagic()` method
259
+ will return `false` by default. When this option set, it will
260
+ return `true` for brace expansion as well as other magic glob
261
+ characters.
262
+
154
263
  ### matchBase
155
264
 
156
265
  If set, then patterns without slashes will be matched
157
- against the basename of the path if it contains slashes. For example,
266
+ against the basename of the path if it contains slashes. For example,
158
267
  `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
159
268
 
160
269
  ### nocomment
@@ -173,58 +282,173 @@ Returns from negate expressions the same as if they were not negated.
173
282
 
174
283
  ### partial
175
284
 
176
- Compare a partial path to a pattern. As long as the parts of the path that
285
+ Compare a partial path to a pattern. As long as the parts of the path that
177
286
  are present are not contradicted by the pattern, it will be treated as a
178
- match. This is useful in applications where you're walking through a
287
+ match. This is useful in applications where you're walking through a
179
288
  folder structure, and don't yet have the full path, but want to ensure that
180
289
  you do not walk down paths that can never be a match.
181
290
 
182
291
  For example,
183
292
 
184
293
  ```js
185
- minimatch('/a/b', '/a/*/c/d', { partial: true }) // true, might be /a/b/c/d
186
- minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d
294
+ minimatch('/a/b', '/a/*/c/d', { partial: true }) // true, might be /a/b/c/d
295
+ minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d
187
296
  minimatch('/x/y/z', '/a/**/z', { partial: true }) // false, because x !== a
188
297
  ```
189
298
 
190
- ### allowWindowsEscape
191
-
192
- Windows path separator `\` is by default converted to `/`, which
193
- prohibits the usage of `\` as a escape character. This flag skips that
194
- behavior and allows using the escape character.
299
+ ### windowsPathsNoEscape
300
+
301
+ Use `\\` as a path separator _only_, and _never_ as an escape
302
+ character. If set, all `\\` characters are replaced with `/` in
303
+ the pattern. Note that this makes it **impossible** to match
304
+ against paths containing literal glob pattern characters, but
305
+ allows matching with patterns constructed using `path.join()` and
306
+ `path.resolve()` on Windows platforms, mimicking the (buggy!)
307
+ behavior of earlier versions on Windows. Please use with
308
+ caution, and be mindful of [the caveat about Windows
309
+ paths](#windows).
310
+
311
+ For legacy reasons, this is also set if
312
+ `options.allowWindowsEscape` is set to the exact value `false`.
313
+
314
+ ### windowsNoMagicRoot
315
+
316
+ When a pattern starts with a UNC path or drive letter, and in
317
+ `nocase:true` mode, do not convert the root portions of the
318
+ pattern into a case-insensitive regular expression, and instead
319
+ leave them as strings.
320
+
321
+ This is the default when the platform is `win32` and
322
+ `nocase:true` is set.
323
+
324
+ ### preserveMultipleSlashes
325
+
326
+ By default, multiple `/` characters (other than the leading `//`
327
+ in a UNC path, see "UNC Paths" above) are treated as a single
328
+ `/`.
329
+
330
+ That is, a pattern like `a///b` will match the file path `a/b`.
331
+
332
+ Set `preserveMultipleSlashes: true` to suppress this behavior.
333
+
334
+ ### optimizationLevel
335
+
336
+ A number indicating the level of optimization that should be done
337
+ to the pattern prior to parsing and using it for matches.
338
+
339
+ Globstar parts `**` are always converted to `*` when `noglobstar`
340
+ is set, and multiple adjascent `**` parts are converted into a
341
+ single `**` (ie, `a/**/**/b` will be treated as `a/**/b`, as this
342
+ is equivalent in all cases).
343
+
344
+ - `0` - Make no further changes. In this mode, `.` and `..` are
345
+ maintained in the pattern, meaning that they must also appear
346
+ in the same position in the test path string. Eg, a pattern
347
+ like `a/*/../c` will match the string `a/b/../c` but not the
348
+ string `a/c`.
349
+ - `1` - (default) Remove cases where a double-dot `..` follows a
350
+ pattern portion that is not `**`, `.`, `..`, or empty `''`. For
351
+ example, the pattern `./a/b/../*` is converted to `./a/*`, and
352
+ so it will match the path string `./a/c`, but not the path
353
+ string `./a/b/../c`. Dots and empty path portions in the
354
+ pattern are preserved.
355
+ - `2` (or higher) - Much more aggressive optimizations, suitable
356
+ for use with file-walking cases:
357
+
358
+ - Remove cases where a double-dot `..` follows a pattern
359
+ portion that is not `**`, `.`, or empty `''`. Remove empty
360
+ and `.` portions of the pattern, where safe to do so (ie,
361
+ anywhere other than the last position, the first position, or
362
+ the second position in a pattern starting with `/`, as this
363
+ may indicate a UNC path on Windows).
364
+ - Convert patterns containing `<pre>/**/../<p>/<rest>` into the
365
+ equivalent `<pre>/{..,**}/<p>/<rest>`, where `<p>` is a
366
+ a pattern portion other than `.`, `..`, `**`, or empty
367
+ `''`.
368
+ - Dedupe patterns where a `**` portion is present in one and
369
+ omitted in another, and it is not the final path portion, and
370
+ they are otherwise equivalent. So `{a/**/b,a/b}` becomes
371
+ `a/**/b`, because `**` matches against an empty path portion.
372
+ - Dedupe patterns where a `*` portion is present in one, and a
373
+ non-dot pattern other than `**`, `.`, `..`, or `''` is in the
374
+ same position in the other. So `a/{*,x}/b` becomes `a/*/b`,
375
+ because `*` can match against `x`.
376
+
377
+ While these optimizations improve the performance of
378
+ file-walking use cases such as [glob](http://npm.im/glob) (ie,
379
+ the reason this module exists), there are cases where it will
380
+ fail to match a literal string that would have been matched in
381
+ optimization level 1 or 0.
382
+
383
+ Specifically, while the `Minimatch.match()` method will
384
+ optimize the file path string in the same ways, resulting in
385
+ the same matches, it will fail when tested with the regular
386
+ expression provided by `Minimatch.makeRe()`, unless the path
387
+ string is first processed with
388
+ `minimatch.levelTwoFileOptimize()` or similar.
389
+
390
+ ### platform
391
+
392
+ When set to `win32`, this will trigger all windows-specific
393
+ behaviors (special handling for UNC paths, and treating `\` as
394
+ separators in file paths for comparison.)
395
+
396
+ Defaults to the value of `process.platform`.
195
397
 
196
398
  ## Comparisons to other fnmatch/glob implementations
197
399
 
198
- While strict compliance with the existing standards is a worthwhile
199
- goal, some discrepancies exist between minimatch and other
200
- implementations, and are intentional.
400
+ While strict compliance with the existing standards is a
401
+ worthwhile goal, some discrepancies exist between minimatch and
402
+ other implementations. Some are intentional, and some are
403
+ unavoidable.
201
404
 
202
- If the pattern starts with a `!` character, then it is negated. Set the
405
+ If the pattern starts with a `!` character, then it is negated. Set the
203
406
  `nonegate` flag to suppress this behavior, and treat leading `!`
204
- characters normally. This is perhaps relevant if you wish to start the
205
- pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
407
+ characters normally. This is perhaps relevant if you wish to start the
408
+ pattern with a negative extglob pattern like `!(a|B)`. Multiple `!`
206
409
  characters at the start of a pattern will negate the pattern multiple
207
410
  times.
208
411
 
209
412
  If a pattern starts with `#`, then it is treated as a comment, and
210
- will not match anything. Use `\#` to match a literal `#` at the
413
+ will not match anything. Use `\#` to match a literal `#` at the
211
414
  start of a line, or set the `nocomment` flag to suppress this behavior.
212
415
 
213
416
  The double-star character `**` is supported by default, unless the
214
- `noglobstar` flag is set. This is supported in the manner of bsdglob
417
+ `noglobstar` flag is set. This is supported in the manner of bsdglob
215
418
  and bash 4.1, where `**` only has special significance if it is the only
216
- thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
419
+ thing in a path part. That is, `a/**/b` will match `a/x/y/b`, but
217
420
  `a/**b` will not.
218
421
 
219
422
  If an escaped pattern has no matches, and the `nonull` flag is set,
220
423
  then minimatch.match returns the pattern as-provided, rather than
221
- interpreting the character escapes. For example,
424
+ interpreting the character escapes. For example,
222
425
  `minimatch.match([], "\\*a\\?")` will return `"\\*a\\?"` rather than
223
- `"*a?"`. This is akin to setting the `nullglob` option in bash, except
426
+ `"*a?"`. This is akin to setting the `nullglob` option in bash, except
224
427
  that it does not resolve escaped pattern characters.
225
428
 
226
429
  If brace expansion is not disabled, then it is performed before any
227
- other interpretation of the glob pattern. Thus, a pattern like
430
+ other interpretation of the glob pattern. Thus, a pattern like
228
431
  `+(a|{b),c)}`, which would not be valid in bash or zsh, is expanded
229
432
  **first** into the set of `+(a|b)` and `+(a|c)`, and those patterns are
230
- checked for validity. Since those two are valid, matching proceeds.
433
+ checked for validity. Since those two are valid, matching proceeds.
434
+
435
+ Negated extglob patterns are handled as closely as possible to
436
+ Bash semantics, but there are some cases with negative extglobs
437
+ which are exceedingly difficult to express in a JavaScript
438
+ regular expression. In particular the negated pattern
439
+ `<start>!(<pattern>*|)*` will in bash match anything that does
440
+ not start with `<start><pattern>`. However,
441
+ `<start>!(<pattern>*)*` _will_ match paths starting with
442
+ `<start><pattern>`, because the empty string can match against
443
+ the negated portion. In this library, `<start>!(<pattern>*|)*`
444
+ will _not_ match any pattern starting with `<start>`, due to a
445
+ difference in precisely which patterns are considered "greedy" in
446
+ Regular Expressions vs bash path expansion. This may be fixable,
447
+ but not without incurring some complexity and performance costs,
448
+ and the trade-off seems to not be worth pursuing.
449
+
450
+ Note that `fnmatch(3)` in libc is an extremely naive string comparison
451
+ matcher, which does not do anything special for slashes. This library is
452
+ designed to be used in glob searching and file walkers, and so it does do
453
+ special things with `/`. Thus, `foo*` will not match `foo/bar` in this
454
+ library, even though it would in `fnmatch(3)`.
@@ -0,0 +1,2 @@
1
+ export declare const assertValidPattern: (pattern: any) => void;
2
+ //# sourceMappingURL=assert-valid-pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-valid-pattern.d.ts","sourceRoot":"","sources":["../../src/assert-valid-pattern.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAUlD,CAAA"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertValidPattern = void 0;
4
+ const MAX_PATTERN_LENGTH = 1024 * 64;
5
+ const assertValidPattern = (pattern) => {
6
+ if (typeof pattern !== 'string') {
7
+ throw new TypeError('invalid pattern');
8
+ }
9
+ if (pattern.length > MAX_PATTERN_LENGTH) {
10
+ throw new TypeError('pattern is too long');
11
+ }
12
+ };
13
+ exports.assertValidPattern = assertValidPattern;
14
+ //# sourceMappingURL=assert-valid-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-valid-pattern.js","sourceRoot":"","sources":["../../src/assert-valid-pattern.ts"],"names":[],"mappings":";;;AAAA,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAA;AAC7B,MAAM,kBAAkB,GAA2B,CACxD,OAAY,EACe,EAAE;IAC7B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,MAAM,IAAI,SAAS,CAAC,iBAAiB,CAAC,CAAA;KACvC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,kBAAkB,EAAE;QACvC,MAAM,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAA;KAC3C;AACH,CAAC,CAAA;AAVY,QAAA,kBAAkB,sBAU9B","sourcesContent":["const MAX_PATTERN_LENGTH = 1024 * 64\nexport const assertValidPattern: (pattern: any) => void = (\n pattern: any\n): asserts pattern is string => {\n if (typeof pattern !== 'string') {\n throw new TypeError('invalid pattern')\n }\n\n if (pattern.length > MAX_PATTERN_LENGTH) {\n throw new TypeError('pattern is too long')\n }\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { MinimatchOptions, MMRegExp } from './index.js';
2
+ export type ExtglobType = '!' | '?' | '+' | '*' | '@';
3
+ export declare class AST {
4
+ #private;
5
+ type: ExtglobType | null;
6
+ constructor(type: ExtglobType | null, parent?: AST, options?: MinimatchOptions);
7
+ get hasMagic(): boolean | undefined;
8
+ toString(): string;
9
+ push(...parts: (string | AST)[]): void;
10
+ toJSON(): any[];
11
+ isStart(): boolean;
12
+ isEnd(): boolean;
13
+ copyIn(part: AST | string): void;
14
+ clone(parent: AST): AST;
15
+ static fromGlob(pattern: string, options?: MinimatchOptions): AST;
16
+ toMMPattern(): MMRegExp | string;
17
+ get options(): MinimatchOptions;
18
+ toRegExpSource(allowDot?: boolean): [re: string, body: string, hasMagic: boolean, uflag: boolean];
19
+ }
20
+ //# sourceMappingURL=ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAwCvD,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAkCrD,qBAAa,GAAG;;IACd,IAAI,EAAE,WAAW,GAAG,IAAI,CAAA;gBAiBtB,IAAI,EAAE,WAAW,GAAG,IAAI,EACxB,MAAM,CAAC,EAAE,GAAG,EACZ,OAAO,GAAE,gBAAqB;IAahC,IAAI,QAAQ,IAAI,OAAO,GAAG,SAAS,CAUlC;IAGD,QAAQ,IAAI,MAAM;IA+ClB,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE;IAY/B,MAAM;IAgBN,OAAO,IAAI,OAAO;IAgBlB,KAAK,IAAI,OAAO;IAYhB,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;IAKzB,KAAK,CAAC,MAAM,EAAE,GAAG;IAsIjB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB;IAQ/D,WAAW,IAAI,QAAQ,GAAG,MAAM;IA2BhC,IAAI,OAAO,qBAEV;IAuED,cAAc,CACZ,QAAQ,CAAC,EAAE,OAAO,GACjB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;CAiMjE"}