minimatch 4.1.0 → 5.0.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/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-2022 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
@@ -35,6 +35,20 @@ See:
35
35
  * `man 3 fnmatch`
36
36
  * `man 5 gitignore`
37
37
 
38
+ ## Windows
39
+
40
+ **Please only use forward-slashes in glob expressions.**
41
+
42
+ Though windows uses either `/` or `\` as its path separator, only `/`
43
+ characters are used by this glob implementation. You must use
44
+ forward-slashes **only** in glob expressions. Back-slashes in patterns
45
+ will always be interpreted as escape characters, not path separators.
46
+
47
+ Note that `\` or `/` _will_ be interpreted as path separators in paths on
48
+ Windows, and will match against `/` in glob expressions.
49
+
50
+ So just always use `/` in patterns.
51
+
38
52
  ## Minimatch Class
39
53
 
40
54
  Create a minimatch object by instantiating the `minimatch.Minimatch` class.
@@ -187,12 +201,6 @@ minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d
187
201
  minimatch('/x/y/z', '/a/**/z', { partial: true }) // false, because x !== a
188
202
  ```
189
203
 
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.
195
-
196
204
  ## Comparisons to other fnmatch/glob implementations
197
205
 
198
206
  While strict compliance with the existing standards is a worthwhile
package/minimatch.js CHANGED
@@ -17,6 +17,7 @@ const path = (() => { try { return require('path') } catch (e) {}})() || {
17
17
  minimatch.sep = path.sep
18
18
 
19
19
  const GLOBSTAR = Symbol('globstar **')
20
+ minimatch.GLOBSTAR = GLOBSTAR
20
21
  const expand = require('brace-expansion')
21
22
 
22
23
  const plTypes = {
@@ -166,11 +167,6 @@ class Minimatch {
166
167
 
167
168
  if (!options) options = {}
168
169
 
169
- // windows support: need to use /, not \
170
- if (!options.allowWindowsEscape && path.sep !== '/') {
171
- pattern = pattern.split(path.sep).join('/')
172
- }
173
-
174
170
  this.options = options
175
171
  this.set = []
176
172
  this.pattern = pattern
@@ -363,11 +359,7 @@ class Minimatch {
363
359
  // patterns with magic have been turned into regexps.
364
360
  var hit
365
361
  if (typeof p === 'string') {
366
- if (options.nocase) {
367
- hit = f.toLowerCase() === p.toLowerCase()
368
- } else {
369
- hit = f === p
370
- }
362
+ hit = f === p
371
363
  this.debug('string match', p, f, hit)
372
364
  } else {
373
365
  hit = f.match(p)
@@ -430,7 +422,7 @@ class Minimatch {
430
422
  if (pattern === '') return ''
431
423
 
432
424
  let re = ''
433
- let hasMagic = false
425
+ let hasMagic = !!options.nocase
434
426
  let escaping = false
435
427
  // ? => one single character
436
428
  const patternListStack = []
@@ -475,8 +467,16 @@ class Minimatch {
475
467
  this.debug('%s\t%s %s %j', pattern, i, re, c)
476
468
 
477
469
  // skip over any that are escaped.
478
- if (escaping && reSpecials[c]) {
479
- re += '\\' + c
470
+ if (escaping) {
471
+ /* istanbul ignore next - completely not allowed, even escaped. */
472
+ if (c === '/') {
473
+ return false
474
+ }
475
+
476
+ if (reSpecials[c]) {
477
+ re += '\\'
478
+ }
479
+ re += c
480
480
  escaping = false
481
481
  continue
482
482
  }
@@ -484,7 +484,6 @@ class Minimatch {
484
484
  switch (c) {
485
485
  /* istanbul ignore next */
486
486
  case '/': {
487
- // completely not allowed, even escaped.
488
487
  // Should already be path-split by now.
489
488
  return false
490
489
  }
@@ -567,9 +566,8 @@ class Minimatch {
567
566
  continue
568
567
 
569
568
  case '|':
570
- if (inClass || !patternListStack.length || escaping) {
569
+ if (inClass || !patternListStack.length) {
571
570
  re += '\\|'
572
- escaping = false
573
571
  continue
574
572
  }
575
573
 
@@ -600,7 +598,6 @@ class Minimatch {
600
598
  // first in the list. -- POSIX.2 2.8.3.2
601
599
  if (i === classStart + 1 || !inClass) {
602
600
  re += '\\' + c
603
- escaping = false
604
601
  continue
605
602
  }
606
603
 
@@ -635,15 +632,12 @@ class Minimatch {
635
632
  // swallow any state char that wasn't consumed
636
633
  clearStateChar()
637
634
 
638
- if (escaping) {
639
- // no need
640
- escaping = false
641
- } else if (reSpecials[c]
642
- && !(c === '^' && inClass)) {
635
+ if (reSpecials[c] && !(c === '^' && inClass)) {
643
636
  re += '\\'
644
637
  }
645
638
 
646
639
  re += c
640
+ break
647
641
 
648
642
  } // switch
649
643
  } // for
@@ -673,6 +667,7 @@ class Minimatch {
673
667
  this.debug('setting tail', re, pl)
674
668
  // maybe some even number of \, then maybe 1 \, followed by a |
675
669
  tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
670
+ /* istanbul ignore else - should already be done */
676
671
  if (!$2) {
677
672
  // the | isn't already escaped, so escape it.
678
673
  $2 = '\\'
@@ -794,13 +789,42 @@ class Minimatch {
794
789
  : twoStarNoDot
795
790
  const flags = options.nocase ? 'i' : ''
796
791
 
797
- let re = set.map(pattern =>
798
- pattern.map(p =>
799
- (p === GLOBSTAR) ? twoStar
800
- : (typeof p === 'string') ? regExpEscape(p)
792
+ // coalesce globstars and regexpify non-globstar patterns
793
+ // if it's the only item, then we just do one twoStar
794
+ // if it's the first, and there are more, prepend (\/|twoStar\/)? to next
795
+ // if it's the last, append (\/twoStar|) to previous
796
+ // if it's in the middle, append (\/|\/twoStar\/) to previous
797
+ // then filter out GLOBSTAR symbols
798
+ let re = set.map(pattern => {
799
+ pattern = pattern.map(p =>
800
+ typeof p === 'string' ? regExpEscape(p)
801
+ : p === GLOBSTAR ? GLOBSTAR
801
802
  : p._src
802
- ).join('\\\/')
803
- ).join('|')
803
+ ).reduce((set, p) => {
804
+ if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) {
805
+ set.push(p)
806
+ }
807
+ return set
808
+ }, [])
809
+ pattern.forEach((p, i) => {
810
+ if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) {
811
+ return
812
+ }
813
+ if (i === 0) {
814
+ if (pattern.length > 1) {
815
+ pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1]
816
+ } else {
817
+ pattern[i] = twoStar
818
+ }
819
+ } else if (i === pattern.length - 1) {
820
+ pattern[i-1] += '(?:\\\/|' + twoStar + ')?'
821
+ } else {
822
+ pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1]
823
+ pattern[i+1] = GLOBSTAR
824
+ }
825
+ })
826
+ return pattern.filter(p => p !== GLOBSTAR).join('/')
827
+ }).join('|')
804
828
 
805
829
  // must match entire pattern
806
830
  // ending in a * or ** will make it less strict.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
3
3
  "name": "minimatch",
4
4
  "description": "a glob matcher in javascript",
5
- "version": "4.1.0",
5
+ "version": "5.0.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/isaacs/minimatch.git"
@@ -10,6 +10,7 @@
10
10
  "main": "minimatch.js",
11
11
  "scripts": {
12
12
  "test": "tap",
13
+ "snap": "tap",
13
14
  "preversion": "npm test",
14
15
  "postversion": "npm publish",
15
16
  "prepublishOnly": "git push origin --follow-tags"
@@ -18,7 +19,7 @@
18
19
  "node": ">=10"
19
20
  },
20
21
  "dependencies": {
21
- "brace-expansion": "^1.1.7"
22
+ "brace-expansion": "^2.0.1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "tap": "^15.1.6"