minimatch 4.1.1 → 4.2.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.
Files changed (2) hide show
  1. package/minimatch.js +35 -6
  2. package/package.json +2 -1
package/minimatch.js CHANGED
@@ -791,13 +791,42 @@ class Minimatch {
791
791
  : twoStarNoDot
792
792
  const flags = options.nocase ? 'i' : ''
793
793
 
794
- let re = set.map(pattern =>
795
- pattern.map(p =>
796
- (p === GLOBSTAR) ? twoStar
797
- : (typeof p === 'string') ? regExpEscape(p)
794
+ // coalesce globstars and regexpify non-globstar patterns
795
+ // if it's the only item, then we just do one twoStar
796
+ // if it's the first, and there are more, prepend (\/|twoStar\/)? to next
797
+ // if it's the last, append (\/twoStar|) to previous
798
+ // if it's in the middle, append (\/|\/twoStar\/) to previous
799
+ // then filter out GLOBSTAR symbols
800
+ let re = set.map(pattern => {
801
+ pattern = pattern.map(p =>
802
+ typeof p === 'string' ? regExpEscape(p)
803
+ : p === GLOBSTAR ? GLOBSTAR
798
804
  : p._src
799
- ).join('\\\/')
800
- ).join('|')
805
+ ).reduce((set, p) => {
806
+ if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) {
807
+ set.push(p)
808
+ }
809
+ return set
810
+ }, [])
811
+ pattern.forEach((p, i) => {
812
+ if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) {
813
+ return
814
+ }
815
+ if (i === 0) {
816
+ if (pattern.length > 1) {
817
+ pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1]
818
+ } else {
819
+ pattern[i] = twoStar
820
+ }
821
+ } else if (i === pattern.length - 1) {
822
+ pattern[i-1] += '(?:\\\/|' + twoStar + ')?'
823
+ } else {
824
+ pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1]
825
+ pattern[i+1] = GLOBSTAR
826
+ }
827
+ })
828
+ return pattern.filter(p => p !== GLOBSTAR).join('/')
829
+ }).join('|')
801
830
 
802
831
  // must match entire pattern
803
832
  // 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.1",
5
+ "version": "4.2.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"