minimatch 2.0.7 → 3.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 +12 -20
- package/minimatch.js +52 -7
- package/package.json +6 -12
- package/browser.js +0 -1113
package/LICENSE
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
All rights reserved.
|
|
1
|
+
The ISC License
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
obtaining a copy of this software and associated documentation
|
|
6
|
-
files (the "Software"), to deal in the Software without
|
|
7
|
-
restriction, including without limitation the rights to use,
|
|
8
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the
|
|
10
|
-
Software is furnished to do so, subject to the following
|
|
11
|
-
conditions:
|
|
3
|
+
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
12
4
|
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
15
8
|
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
15
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/minimatch.js
CHANGED
|
@@ -272,6 +272,7 @@ function parse (pattern, isSub) {
|
|
|
272
272
|
var escaping = false
|
|
273
273
|
// ? => one single character
|
|
274
274
|
var patternListStack = []
|
|
275
|
+
var negativeLists = []
|
|
275
276
|
var plType
|
|
276
277
|
var stateChar
|
|
277
278
|
var inClass = false
|
|
@@ -372,9 +373,13 @@ function parse (pattern, isSub) {
|
|
|
372
373
|
}
|
|
373
374
|
|
|
374
375
|
plType = stateChar
|
|
375
|
-
patternListStack.push({
|
|
376
|
+
patternListStack.push({
|
|
377
|
+
type: plType,
|
|
378
|
+
start: i - 1,
|
|
379
|
+
reStart: re.length
|
|
380
|
+
})
|
|
376
381
|
// negation is (?:(?!js)[^/]*)
|
|
377
|
-
re += stateChar === '!' ? '(?:(?!' : '(?:'
|
|
382
|
+
re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
|
|
378
383
|
this.debug('plType %j %j', stateChar, re)
|
|
379
384
|
stateChar = false
|
|
380
385
|
continue
|
|
@@ -388,12 +393,15 @@ function parse (pattern, isSub) {
|
|
|
388
393
|
clearStateChar()
|
|
389
394
|
hasMagic = true
|
|
390
395
|
re += ')'
|
|
391
|
-
|
|
396
|
+
var pl = patternListStack.pop()
|
|
397
|
+
plType = pl.type
|
|
392
398
|
// negation is (?:(?!js)[^/]*)
|
|
393
399
|
// The others are (?:<pattern>)<type>
|
|
394
400
|
switch (plType) {
|
|
395
401
|
case '!':
|
|
396
|
-
|
|
402
|
+
negativeLists.push(pl)
|
|
403
|
+
re += ')[^/]*?)'
|
|
404
|
+
pl.reEnd = re.length
|
|
397
405
|
break
|
|
398
406
|
case '?':
|
|
399
407
|
case '+':
|
|
@@ -507,7 +515,7 @@ function parse (pattern, isSub) {
|
|
|
507
515
|
// and escape any | chars that were passed through as-is for the regexp.
|
|
508
516
|
// Go through and escape them, taking care not to double-escape any
|
|
509
517
|
// | chars that were already escaped.
|
|
510
|
-
for (
|
|
518
|
+
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
|
|
511
519
|
var tail = re.slice(pl.reStart + 3)
|
|
512
520
|
// maybe some even number of \, then maybe 1 \, followed by a |
|
|
513
521
|
tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
|
|
@@ -550,12 +558,49 @@ function parse (pattern, isSub) {
|
|
|
550
558
|
case '(': addPatternStart = true
|
|
551
559
|
}
|
|
552
560
|
|
|
561
|
+
// Hack to work around lack of negative lookbehind in JS
|
|
562
|
+
// A pattern like: *.!(x).!(y|z) needs to ensure that a name
|
|
563
|
+
// like 'a.xyz.yz' doesn't match. So, the first negative
|
|
564
|
+
// lookahead, has to look ALL the way ahead, to the end of
|
|
565
|
+
// the pattern.
|
|
566
|
+
for (var n = negativeLists.length - 1; n > -1; n--) {
|
|
567
|
+
var nl = negativeLists[n]
|
|
568
|
+
|
|
569
|
+
var nlBefore = re.slice(0, nl.reStart)
|
|
570
|
+
var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
|
|
571
|
+
var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
|
|
572
|
+
var nlAfter = re.slice(nl.reEnd)
|
|
573
|
+
|
|
574
|
+
nlLast += nlAfter
|
|
575
|
+
|
|
576
|
+
// Handle nested stuff like *(*.js|!(*.json)), where open parens
|
|
577
|
+
// mean that we should *not* include the ) in the bit that is considered
|
|
578
|
+
// "after" the negated section.
|
|
579
|
+
var openParensBefore = nlBefore.split('(').length - 1
|
|
580
|
+
var cleanAfter = nlAfter
|
|
581
|
+
for (i = 0; i < openParensBefore; i++) {
|
|
582
|
+
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
|
|
583
|
+
}
|
|
584
|
+
nlAfter = cleanAfter
|
|
585
|
+
|
|
586
|
+
var dollar = ''
|
|
587
|
+
if (nlAfter === '' && isSub !== SUBPARSE) {
|
|
588
|
+
dollar = '$'
|
|
589
|
+
}
|
|
590
|
+
var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
|
|
591
|
+
re = newRe
|
|
592
|
+
}
|
|
593
|
+
|
|
553
594
|
// if the re is not "" at this point, then we need to make sure
|
|
554
595
|
// it doesn't match against an empty path part.
|
|
555
596
|
// Otherwise a/* will match a/, which it should not.
|
|
556
|
-
if (re !== '' && hasMagic)
|
|
597
|
+
if (re !== '' && hasMagic) {
|
|
598
|
+
re = '(?=.)' + re
|
|
599
|
+
}
|
|
557
600
|
|
|
558
|
-
if (addPatternStart)
|
|
601
|
+
if (addPatternStart) {
|
|
602
|
+
re = patternStart + re
|
|
603
|
+
}
|
|
559
604
|
|
|
560
605
|
// parsing just a piece of a larger pattern.
|
|
561
606
|
if (isSub === SUBPARSE) {
|
package/package.json
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
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": "
|
|
5
|
+
"version": "3.0.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git://github.com/isaacs/minimatch.git"
|
|
9
9
|
},
|
|
10
10
|
"main": "minimatch.js",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"test": "tap test/*.js"
|
|
14
|
-
"prepublish": "browserify -o browser.js -e minimatch.js --bare"
|
|
12
|
+
"posttest": "standard minimatch.js test/*.js",
|
|
13
|
+
"test": "tap test/*.js"
|
|
15
14
|
},
|
|
16
15
|
"engines": {
|
|
17
16
|
"node": "*"
|
|
@@ -20,16 +19,11 @@
|
|
|
20
19
|
"brace-expansion": "^1.0.0"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
|
-
"browserify": "^9.0.3",
|
|
24
22
|
"standard": "^3.7.2",
|
|
25
|
-
"tap": ""
|
|
26
|
-
},
|
|
27
|
-
"license": {
|
|
28
|
-
"type": "MIT",
|
|
29
|
-
"url": "http://github.com/isaacs/minimatch/raw/master/LICENSE"
|
|
23
|
+
"tap": "^1.2.0"
|
|
30
24
|
},
|
|
25
|
+
"license": "ISC",
|
|
31
26
|
"files": [
|
|
32
|
-
"minimatch.js"
|
|
33
|
-
"browser.js"
|
|
27
|
+
"minimatch.js"
|
|
34
28
|
]
|
|
35
29
|
}
|
package/browser.js
DELETED
|
@@ -1,1113 +0,0 @@
|
|
|
1
|
-
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
2
|
-
module.exports = minimatch
|
|
3
|
-
minimatch.Minimatch = Minimatch
|
|
4
|
-
|
|
5
|
-
var path = { sep: '/' }
|
|
6
|
-
try {
|
|
7
|
-
path = require('path')
|
|
8
|
-
} catch (er) {}
|
|
9
|
-
|
|
10
|
-
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
|
|
11
|
-
var expand = require('brace-expansion')
|
|
12
|
-
|
|
13
|
-
// any single thing other than /
|
|
14
|
-
// don't need to escape / when using new RegExp()
|
|
15
|
-
var qmark = '[^/]'
|
|
16
|
-
|
|
17
|
-
// * => any number of characters
|
|
18
|
-
var star = qmark + '*?'
|
|
19
|
-
|
|
20
|
-
// ** when dots are allowed. Anything goes, except .. and .
|
|
21
|
-
// not (^ or / followed by one or two dots followed by $ or /),
|
|
22
|
-
// followed by anything, any number of times.
|
|
23
|
-
var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
|
|
24
|
-
|
|
25
|
-
// not a ^ or / followed by a dot,
|
|
26
|
-
// followed by anything, any number of times.
|
|
27
|
-
var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
|
|
28
|
-
|
|
29
|
-
// characters that need to be escaped in RegExp.
|
|
30
|
-
var reSpecials = charSet('().*{}+?[]^$\\!')
|
|
31
|
-
|
|
32
|
-
// "abc" -> { a:true, b:true, c:true }
|
|
33
|
-
function charSet (s) {
|
|
34
|
-
return s.split('').reduce(function (set, c) {
|
|
35
|
-
set[c] = true
|
|
36
|
-
return set
|
|
37
|
-
}, {})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// normalizes slashes.
|
|
41
|
-
var slashSplit = /\/+/
|
|
42
|
-
|
|
43
|
-
minimatch.filter = filter
|
|
44
|
-
function filter (pattern, options) {
|
|
45
|
-
options = options || {}
|
|
46
|
-
return function (p, i, list) {
|
|
47
|
-
return minimatch(p, pattern, options)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function ext (a, b) {
|
|
52
|
-
a = a || {}
|
|
53
|
-
b = b || {}
|
|
54
|
-
var t = {}
|
|
55
|
-
Object.keys(b).forEach(function (k) {
|
|
56
|
-
t[k] = b[k]
|
|
57
|
-
})
|
|
58
|
-
Object.keys(a).forEach(function (k) {
|
|
59
|
-
t[k] = a[k]
|
|
60
|
-
})
|
|
61
|
-
return t
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
minimatch.defaults = function (def) {
|
|
65
|
-
if (!def || !Object.keys(def).length) return minimatch
|
|
66
|
-
|
|
67
|
-
var orig = minimatch
|
|
68
|
-
|
|
69
|
-
var m = function minimatch (p, pattern, options) {
|
|
70
|
-
return orig.minimatch(p, pattern, ext(def, options))
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
m.Minimatch = function Minimatch (pattern, options) {
|
|
74
|
-
return new orig.Minimatch(pattern, ext(def, options))
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return m
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
Minimatch.defaults = function (def) {
|
|
81
|
-
if (!def || !Object.keys(def).length) return Minimatch
|
|
82
|
-
return minimatch.defaults(def).Minimatch
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function minimatch (p, pattern, options) {
|
|
86
|
-
if (typeof pattern !== 'string') {
|
|
87
|
-
throw new TypeError('glob pattern string required')
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!options) options = {}
|
|
91
|
-
|
|
92
|
-
// shortcut: comments match nothing.
|
|
93
|
-
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// "" only matches ""
|
|
98
|
-
if (pattern.trim() === '') return p === ''
|
|
99
|
-
|
|
100
|
-
return new Minimatch(pattern, options).match(p)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function Minimatch (pattern, options) {
|
|
104
|
-
if (!(this instanceof Minimatch)) {
|
|
105
|
-
return new Minimatch(pattern, options)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (typeof pattern !== 'string') {
|
|
109
|
-
throw new TypeError('glob pattern string required')
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!options) options = {}
|
|
113
|
-
pattern = pattern.trim()
|
|
114
|
-
|
|
115
|
-
// windows support: need to use /, not \
|
|
116
|
-
if (path.sep !== '/') {
|
|
117
|
-
pattern = pattern.split(path.sep).join('/')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.options = options
|
|
121
|
-
this.set = []
|
|
122
|
-
this.pattern = pattern
|
|
123
|
-
this.regexp = null
|
|
124
|
-
this.negate = false
|
|
125
|
-
this.comment = false
|
|
126
|
-
this.empty = false
|
|
127
|
-
|
|
128
|
-
// make the set of regexps etc.
|
|
129
|
-
this.make()
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
Minimatch.prototype.debug = function () {}
|
|
133
|
-
|
|
134
|
-
Minimatch.prototype.make = make
|
|
135
|
-
function make () {
|
|
136
|
-
// don't do it more than once.
|
|
137
|
-
if (this._made) return
|
|
138
|
-
|
|
139
|
-
var pattern = this.pattern
|
|
140
|
-
var options = this.options
|
|
141
|
-
|
|
142
|
-
// empty patterns and comments match nothing.
|
|
143
|
-
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
144
|
-
this.comment = true
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
if (!pattern) {
|
|
148
|
-
this.empty = true
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// step 1: figure out negation, etc.
|
|
153
|
-
this.parseNegate()
|
|
154
|
-
|
|
155
|
-
// step 2: expand braces
|
|
156
|
-
var set = this.globSet = this.braceExpand()
|
|
157
|
-
|
|
158
|
-
if (options.debug) this.debug = console.error
|
|
159
|
-
|
|
160
|
-
this.debug(this.pattern, set)
|
|
161
|
-
|
|
162
|
-
// step 3: now we have a set, so turn each one into a series of path-portion
|
|
163
|
-
// matching patterns.
|
|
164
|
-
// These will be regexps, except in the case of "**", which is
|
|
165
|
-
// set to the GLOBSTAR object for globstar behavior,
|
|
166
|
-
// and will not contain any / characters
|
|
167
|
-
set = this.globParts = set.map(function (s) {
|
|
168
|
-
return s.split(slashSplit)
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
this.debug(this.pattern, set)
|
|
172
|
-
|
|
173
|
-
// glob --> regexps
|
|
174
|
-
set = set.map(function (s, si, set) {
|
|
175
|
-
return s.map(this.parse, this)
|
|
176
|
-
}, this)
|
|
177
|
-
|
|
178
|
-
this.debug(this.pattern, set)
|
|
179
|
-
|
|
180
|
-
// filter out everything that didn't compile properly.
|
|
181
|
-
set = set.filter(function (s) {
|
|
182
|
-
return s.indexOf(false) === -1
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
this.debug(this.pattern, set)
|
|
186
|
-
|
|
187
|
-
this.set = set
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
Minimatch.prototype.parseNegate = parseNegate
|
|
191
|
-
function parseNegate () {
|
|
192
|
-
var pattern = this.pattern
|
|
193
|
-
var negate = false
|
|
194
|
-
var options = this.options
|
|
195
|
-
var negateOffset = 0
|
|
196
|
-
|
|
197
|
-
if (options.nonegate) return
|
|
198
|
-
|
|
199
|
-
for (var i = 0, l = pattern.length
|
|
200
|
-
; i < l && pattern.charAt(i) === '!'
|
|
201
|
-
; i++) {
|
|
202
|
-
negate = !negate
|
|
203
|
-
negateOffset++
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (negateOffset) this.pattern = pattern.substr(negateOffset)
|
|
207
|
-
this.negate = negate
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Brace expansion:
|
|
211
|
-
// a{b,c}d -> abd acd
|
|
212
|
-
// a{b,}c -> abc ac
|
|
213
|
-
// a{0..3}d -> a0d a1d a2d a3d
|
|
214
|
-
// a{b,c{d,e}f}g -> abg acdfg acefg
|
|
215
|
-
// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
|
|
216
|
-
//
|
|
217
|
-
// Invalid sets are not expanded.
|
|
218
|
-
// a{2..}b -> a{2..}b
|
|
219
|
-
// a{b}c -> a{b}c
|
|
220
|
-
minimatch.braceExpand = function (pattern, options) {
|
|
221
|
-
return braceExpand(pattern, options)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
Minimatch.prototype.braceExpand = braceExpand
|
|
225
|
-
|
|
226
|
-
function braceExpand (pattern, options) {
|
|
227
|
-
if (!options) {
|
|
228
|
-
if (this instanceof Minimatch) {
|
|
229
|
-
options = this.options
|
|
230
|
-
} else {
|
|
231
|
-
options = {}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
pattern = typeof pattern === 'undefined'
|
|
236
|
-
? this.pattern : pattern
|
|
237
|
-
|
|
238
|
-
if (typeof pattern === 'undefined') {
|
|
239
|
-
throw new Error('undefined pattern')
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (options.nobrace ||
|
|
243
|
-
!pattern.match(/\{.*\}/)) {
|
|
244
|
-
// shortcut. no need to expand.
|
|
245
|
-
return [pattern]
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return expand(pattern)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// parse a component of the expanded set.
|
|
252
|
-
// At this point, no pattern may contain "/" in it
|
|
253
|
-
// so we're going to return a 2d array, where each entry is the full
|
|
254
|
-
// pattern, split on '/', and then turned into a regular expression.
|
|
255
|
-
// A regexp is made at the end which joins each array with an
|
|
256
|
-
// escaped /, and another full one which joins each regexp with |.
|
|
257
|
-
//
|
|
258
|
-
// Following the lead of Bash 4.1, note that "**" only has special meaning
|
|
259
|
-
// when it is the *only* thing in a path portion. Otherwise, any series
|
|
260
|
-
// of * is equivalent to a single *. Globstar behavior is enabled by
|
|
261
|
-
// default, and can be disabled by setting options.noglobstar.
|
|
262
|
-
Minimatch.prototype.parse = parse
|
|
263
|
-
var SUBPARSE = {}
|
|
264
|
-
function parse (pattern, isSub) {
|
|
265
|
-
var options = this.options
|
|
266
|
-
|
|
267
|
-
// shortcuts
|
|
268
|
-
if (!options.noglobstar && pattern === '**') return GLOBSTAR
|
|
269
|
-
if (pattern === '') return ''
|
|
270
|
-
|
|
271
|
-
var re = ''
|
|
272
|
-
var hasMagic = !!options.nocase
|
|
273
|
-
var escaping = false
|
|
274
|
-
// ? => one single character
|
|
275
|
-
var patternListStack = []
|
|
276
|
-
var plType
|
|
277
|
-
var stateChar
|
|
278
|
-
var inClass = false
|
|
279
|
-
var reClassStart = -1
|
|
280
|
-
var classStart = -1
|
|
281
|
-
// . and .. never match anything that doesn't start with .,
|
|
282
|
-
// even when options.dot is set.
|
|
283
|
-
var patternStart = pattern.charAt(0) === '.' ? '' // anything
|
|
284
|
-
// not (start or / followed by . or .. followed by / or end)
|
|
285
|
-
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
|
|
286
|
-
: '(?!\\.)'
|
|
287
|
-
var self = this
|
|
288
|
-
|
|
289
|
-
function clearStateChar () {
|
|
290
|
-
if (stateChar) {
|
|
291
|
-
// we had some state-tracking character
|
|
292
|
-
// that wasn't consumed by this pass.
|
|
293
|
-
switch (stateChar) {
|
|
294
|
-
case '*':
|
|
295
|
-
re += star
|
|
296
|
-
hasMagic = true
|
|
297
|
-
break
|
|
298
|
-
case '?':
|
|
299
|
-
re += qmark
|
|
300
|
-
hasMagic = true
|
|
301
|
-
break
|
|
302
|
-
default:
|
|
303
|
-
re += '\\' + stateChar
|
|
304
|
-
break
|
|
305
|
-
}
|
|
306
|
-
self.debug('clearStateChar %j %j', stateChar, re)
|
|
307
|
-
stateChar = false
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
for (var i = 0, len = pattern.length, c
|
|
312
|
-
; (i < len) && (c = pattern.charAt(i))
|
|
313
|
-
; i++) {
|
|
314
|
-
this.debug('%s\t%s %s %j', pattern, i, re, c)
|
|
315
|
-
|
|
316
|
-
// skip over any that are escaped.
|
|
317
|
-
if (escaping && reSpecials[c]) {
|
|
318
|
-
re += '\\' + c
|
|
319
|
-
escaping = false
|
|
320
|
-
continue
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
switch (c) {
|
|
324
|
-
case '/':
|
|
325
|
-
// completely not allowed, even escaped.
|
|
326
|
-
// Should already be path-split by now.
|
|
327
|
-
return false
|
|
328
|
-
|
|
329
|
-
case '\\':
|
|
330
|
-
clearStateChar()
|
|
331
|
-
escaping = true
|
|
332
|
-
continue
|
|
333
|
-
|
|
334
|
-
// the various stateChar values
|
|
335
|
-
// for the "extglob" stuff.
|
|
336
|
-
case '?':
|
|
337
|
-
case '*':
|
|
338
|
-
case '+':
|
|
339
|
-
case '@':
|
|
340
|
-
case '!':
|
|
341
|
-
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
|
|
342
|
-
|
|
343
|
-
// all of those are literals inside a class, except that
|
|
344
|
-
// the glob [!a] means [^a] in regexp
|
|
345
|
-
if (inClass) {
|
|
346
|
-
this.debug(' in class')
|
|
347
|
-
if (c === '!' && i === classStart + 1) c = '^'
|
|
348
|
-
re += c
|
|
349
|
-
continue
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// if we already have a stateChar, then it means
|
|
353
|
-
// that there was something like ** or +? in there.
|
|
354
|
-
// Handle the stateChar, then proceed with this one.
|
|
355
|
-
self.debug('call clearStateChar %j', stateChar)
|
|
356
|
-
clearStateChar()
|
|
357
|
-
stateChar = c
|
|
358
|
-
// if extglob is disabled, then +(asdf|foo) isn't a thing.
|
|
359
|
-
// just clear the statechar *now*, rather than even diving into
|
|
360
|
-
// the patternList stuff.
|
|
361
|
-
if (options.noext) clearStateChar()
|
|
362
|
-
continue
|
|
363
|
-
|
|
364
|
-
case '(':
|
|
365
|
-
if (inClass) {
|
|
366
|
-
re += '('
|
|
367
|
-
continue
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (!stateChar) {
|
|
371
|
-
re += '\\('
|
|
372
|
-
continue
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
plType = stateChar
|
|
376
|
-
patternListStack.push({ type: plType, start: i - 1, reStart: re.length })
|
|
377
|
-
// negation is (?:(?!js)[^/]*)
|
|
378
|
-
re += stateChar === '!' ? '(?:(?!' : '(?:'
|
|
379
|
-
this.debug('plType %j %j', stateChar, re)
|
|
380
|
-
stateChar = false
|
|
381
|
-
continue
|
|
382
|
-
|
|
383
|
-
case ')':
|
|
384
|
-
if (inClass || !patternListStack.length) {
|
|
385
|
-
re += '\\)'
|
|
386
|
-
continue
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
clearStateChar()
|
|
390
|
-
hasMagic = true
|
|
391
|
-
re += ')'
|
|
392
|
-
plType = patternListStack.pop().type
|
|
393
|
-
// negation is (?:(?!js)[^/]*)
|
|
394
|
-
// The others are (?:<pattern>)<type>
|
|
395
|
-
switch (plType) {
|
|
396
|
-
case '!':
|
|
397
|
-
re += '[^/]*?)'
|
|
398
|
-
break
|
|
399
|
-
case '?':
|
|
400
|
-
case '+':
|
|
401
|
-
case '*':
|
|
402
|
-
re += plType
|
|
403
|
-
break
|
|
404
|
-
case '@': break // the default anyway
|
|
405
|
-
}
|
|
406
|
-
continue
|
|
407
|
-
|
|
408
|
-
case '|':
|
|
409
|
-
if (inClass || !patternListStack.length || escaping) {
|
|
410
|
-
re += '\\|'
|
|
411
|
-
escaping = false
|
|
412
|
-
continue
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
clearStateChar()
|
|
416
|
-
re += '|'
|
|
417
|
-
continue
|
|
418
|
-
|
|
419
|
-
// these are mostly the same in regexp and glob
|
|
420
|
-
case '[':
|
|
421
|
-
// swallow any state-tracking char before the [
|
|
422
|
-
clearStateChar()
|
|
423
|
-
|
|
424
|
-
if (inClass) {
|
|
425
|
-
re += '\\' + c
|
|
426
|
-
continue
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
inClass = true
|
|
430
|
-
classStart = i
|
|
431
|
-
reClassStart = re.length
|
|
432
|
-
re += c
|
|
433
|
-
continue
|
|
434
|
-
|
|
435
|
-
case ']':
|
|
436
|
-
// a right bracket shall lose its special
|
|
437
|
-
// meaning and represent itself in
|
|
438
|
-
// a bracket expression if it occurs
|
|
439
|
-
// first in the list. -- POSIX.2 2.8.3.2
|
|
440
|
-
if (i === classStart + 1 || !inClass) {
|
|
441
|
-
re += '\\' + c
|
|
442
|
-
escaping = false
|
|
443
|
-
continue
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// handle the case where we left a class open.
|
|
447
|
-
// "[z-a]" is valid, equivalent to "\[z-a\]"
|
|
448
|
-
if (inClass) {
|
|
449
|
-
// split where the last [ was, make sure we don't have
|
|
450
|
-
// an invalid re. if so, re-walk the contents of the
|
|
451
|
-
// would-be class to re-translate any characters that
|
|
452
|
-
// were passed through as-is
|
|
453
|
-
// TODO: It would probably be faster to determine this
|
|
454
|
-
// without a try/catch and a new RegExp, but it's tricky
|
|
455
|
-
// to do safely. For now, this is safe and works.
|
|
456
|
-
var cs = pattern.substring(classStart + 1, i)
|
|
457
|
-
try {
|
|
458
|
-
RegExp('[' + cs + ']')
|
|
459
|
-
} catch (er) {
|
|
460
|
-
// not a valid class!
|
|
461
|
-
var sp = this.parse(cs, SUBPARSE)
|
|
462
|
-
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
|
|
463
|
-
hasMagic = hasMagic || sp[1]
|
|
464
|
-
inClass = false
|
|
465
|
-
continue
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// finish up the class.
|
|
470
|
-
hasMagic = true
|
|
471
|
-
inClass = false
|
|
472
|
-
re += c
|
|
473
|
-
continue
|
|
474
|
-
|
|
475
|
-
default:
|
|
476
|
-
// swallow any state char that wasn't consumed
|
|
477
|
-
clearStateChar()
|
|
478
|
-
|
|
479
|
-
if (escaping) {
|
|
480
|
-
// no need
|
|
481
|
-
escaping = false
|
|
482
|
-
} else if (reSpecials[c]
|
|
483
|
-
&& !(c === '^' && inClass)) {
|
|
484
|
-
re += '\\'
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
re += c
|
|
488
|
-
|
|
489
|
-
} // switch
|
|
490
|
-
} // for
|
|
491
|
-
|
|
492
|
-
// handle the case where we left a class open.
|
|
493
|
-
// "[abc" is valid, equivalent to "\[abc"
|
|
494
|
-
if (inClass) {
|
|
495
|
-
// split where the last [ was, and escape it
|
|
496
|
-
// this is a huge pita. We now have to re-walk
|
|
497
|
-
// the contents of the would-be class to re-translate
|
|
498
|
-
// any characters that were passed through as-is
|
|
499
|
-
cs = pattern.substr(classStart + 1)
|
|
500
|
-
sp = this.parse(cs, SUBPARSE)
|
|
501
|
-
re = re.substr(0, reClassStart) + '\\[' + sp[0]
|
|
502
|
-
hasMagic = hasMagic || sp[1]
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// handle the case where we had a +( thing at the *end*
|
|
506
|
-
// of the pattern.
|
|
507
|
-
// each pattern list stack adds 3 chars, and we need to go through
|
|
508
|
-
// and escape any | chars that were passed through as-is for the regexp.
|
|
509
|
-
// Go through and escape them, taking care not to double-escape any
|
|
510
|
-
// | chars that were already escaped.
|
|
511
|
-
for (var pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
|
|
512
|
-
var tail = re.slice(pl.reStart + 3)
|
|
513
|
-
// maybe some even number of \, then maybe 1 \, followed by a |
|
|
514
|
-
tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
|
|
515
|
-
if (!$2) {
|
|
516
|
-
// the | isn't already escaped, so escape it.
|
|
517
|
-
$2 = '\\'
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// need to escape all those slashes *again*, without escaping the
|
|
521
|
-
// one that we need for escaping the | character. As it works out,
|
|
522
|
-
// escaping an even number of slashes can be done by simply repeating
|
|
523
|
-
// it exactly after itself. That's why this trick works.
|
|
524
|
-
//
|
|
525
|
-
// I am sorry that you have to see this.
|
|
526
|
-
return $1 + $1 + $2 + '|'
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
this.debug('tail=%j\n %s', tail, tail)
|
|
530
|
-
var t = pl.type === '*' ? star
|
|
531
|
-
: pl.type === '?' ? qmark
|
|
532
|
-
: '\\' + pl.type
|
|
533
|
-
|
|
534
|
-
hasMagic = true
|
|
535
|
-
re = re.slice(0, pl.reStart) + t + '\\(' + tail
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// handle trailing things that only matter at the very end.
|
|
539
|
-
clearStateChar()
|
|
540
|
-
if (escaping) {
|
|
541
|
-
// trailing \\
|
|
542
|
-
re += '\\\\'
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// only need to apply the nodot start if the re starts with
|
|
546
|
-
// something that could conceivably capture a dot
|
|
547
|
-
var addPatternStart = false
|
|
548
|
-
switch (re.charAt(0)) {
|
|
549
|
-
case '.':
|
|
550
|
-
case '[':
|
|
551
|
-
case '(': addPatternStart = true
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// if the re is not "" at this point, then we need to make sure
|
|
555
|
-
// it doesn't match against an empty path part.
|
|
556
|
-
// Otherwise a/* will match a/, which it should not.
|
|
557
|
-
if (re !== '' && hasMagic) re = '(?=.)' + re
|
|
558
|
-
|
|
559
|
-
if (addPatternStart) re = patternStart + re
|
|
560
|
-
|
|
561
|
-
// parsing just a piece of a larger pattern.
|
|
562
|
-
if (isSub === SUBPARSE) {
|
|
563
|
-
return [re, hasMagic]
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// skip the regexp for non-magical patterns
|
|
567
|
-
// unescape anything in it, though, so that it'll be
|
|
568
|
-
// an exact match against a file etc.
|
|
569
|
-
if (!hasMagic) {
|
|
570
|
-
return globUnescape(pattern)
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
var flags = options.nocase ? 'i' : ''
|
|
574
|
-
var regExp = new RegExp('^' + re + '$', flags)
|
|
575
|
-
|
|
576
|
-
regExp._glob = pattern
|
|
577
|
-
regExp._src = re
|
|
578
|
-
|
|
579
|
-
return regExp
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
minimatch.makeRe = function (pattern, options) {
|
|
583
|
-
return new Minimatch(pattern, options || {}).makeRe()
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
Minimatch.prototype.makeRe = makeRe
|
|
587
|
-
function makeRe () {
|
|
588
|
-
if (this.regexp || this.regexp === false) return this.regexp
|
|
589
|
-
|
|
590
|
-
// at this point, this.set is a 2d array of partial
|
|
591
|
-
// pattern strings, or "**".
|
|
592
|
-
//
|
|
593
|
-
// It's better to use .match(). This function shouldn't
|
|
594
|
-
// be used, really, but it's pretty convenient sometimes,
|
|
595
|
-
// when you just want to work with a regex.
|
|
596
|
-
var set = this.set
|
|
597
|
-
|
|
598
|
-
if (!set.length) {
|
|
599
|
-
this.regexp = false
|
|
600
|
-
return this.regexp
|
|
601
|
-
}
|
|
602
|
-
var options = this.options
|
|
603
|
-
|
|
604
|
-
var twoStar = options.noglobstar ? star
|
|
605
|
-
: options.dot ? twoStarDot
|
|
606
|
-
: twoStarNoDot
|
|
607
|
-
var flags = options.nocase ? 'i' : ''
|
|
608
|
-
|
|
609
|
-
var re = set.map(function (pattern) {
|
|
610
|
-
return pattern.map(function (p) {
|
|
611
|
-
return (p === GLOBSTAR) ? twoStar
|
|
612
|
-
: (typeof p === 'string') ? regExpEscape(p)
|
|
613
|
-
: p._src
|
|
614
|
-
}).join('\\\/')
|
|
615
|
-
}).join('|')
|
|
616
|
-
|
|
617
|
-
// must match entire pattern
|
|
618
|
-
// ending in a * or ** will make it less strict.
|
|
619
|
-
re = '^(?:' + re + ')$'
|
|
620
|
-
|
|
621
|
-
// can match anything, as long as it's not this.
|
|
622
|
-
if (this.negate) re = '^(?!' + re + ').*$'
|
|
623
|
-
|
|
624
|
-
try {
|
|
625
|
-
this.regexp = new RegExp(re, flags)
|
|
626
|
-
} catch (ex) {
|
|
627
|
-
this.regexp = false
|
|
628
|
-
}
|
|
629
|
-
return this.regexp
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
minimatch.match = function (list, pattern, options) {
|
|
633
|
-
options = options || {}
|
|
634
|
-
var mm = new Minimatch(pattern, options)
|
|
635
|
-
list = list.filter(function (f) {
|
|
636
|
-
return mm.match(f)
|
|
637
|
-
})
|
|
638
|
-
if (mm.options.nonull && !list.length) {
|
|
639
|
-
list.push(pattern)
|
|
640
|
-
}
|
|
641
|
-
return list
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
Minimatch.prototype.match = match
|
|
645
|
-
function match (f, partial) {
|
|
646
|
-
this.debug('match', f, this.pattern)
|
|
647
|
-
// short-circuit in the case of busted things.
|
|
648
|
-
// comments, etc.
|
|
649
|
-
if (this.comment) return false
|
|
650
|
-
if (this.empty) return f === ''
|
|
651
|
-
|
|
652
|
-
if (f === '/' && partial) return true
|
|
653
|
-
|
|
654
|
-
var options = this.options
|
|
655
|
-
|
|
656
|
-
// windows: need to use /, not \
|
|
657
|
-
if (path.sep !== '/') {
|
|
658
|
-
f = f.split(path.sep).join('/')
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
// treat the test path as a set of pathparts.
|
|
662
|
-
f = f.split(slashSplit)
|
|
663
|
-
this.debug(this.pattern, 'split', f)
|
|
664
|
-
|
|
665
|
-
// just ONE of the pattern sets in this.set needs to match
|
|
666
|
-
// in order for it to be valid. If negating, then just one
|
|
667
|
-
// match means that we have failed.
|
|
668
|
-
// Either way, return on the first hit.
|
|
669
|
-
|
|
670
|
-
var set = this.set
|
|
671
|
-
this.debug(this.pattern, 'set', set)
|
|
672
|
-
|
|
673
|
-
// Find the basename of the path by looking for the last non-empty segment
|
|
674
|
-
var filename
|
|
675
|
-
var i
|
|
676
|
-
for (i = f.length - 1; i >= 0; i--) {
|
|
677
|
-
filename = f[i]
|
|
678
|
-
if (filename) break
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
for (i = 0; i < set.length; i++) {
|
|
682
|
-
var pattern = set[i]
|
|
683
|
-
var file = f
|
|
684
|
-
if (options.matchBase && pattern.length === 1) {
|
|
685
|
-
file = [filename]
|
|
686
|
-
}
|
|
687
|
-
var hit = this.matchOne(file, pattern, partial)
|
|
688
|
-
if (hit) {
|
|
689
|
-
if (options.flipNegate) return true
|
|
690
|
-
return !this.negate
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// didn't get any hits. this is success if it's a negative
|
|
695
|
-
// pattern, failure otherwise.
|
|
696
|
-
if (options.flipNegate) return false
|
|
697
|
-
return this.negate
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
// set partial to true to test if, for example,
|
|
701
|
-
// "/a/b" matches the start of "/*/b/*/d"
|
|
702
|
-
// Partial means, if you run out of file before you run
|
|
703
|
-
// out of pattern, then that's fine, as long as all
|
|
704
|
-
// the parts match.
|
|
705
|
-
Minimatch.prototype.matchOne = function (file, pattern, partial) {
|
|
706
|
-
var options = this.options
|
|
707
|
-
|
|
708
|
-
this.debug('matchOne',
|
|
709
|
-
{ 'this': this, file: file, pattern: pattern })
|
|
710
|
-
|
|
711
|
-
this.debug('matchOne', file.length, pattern.length)
|
|
712
|
-
|
|
713
|
-
for (var fi = 0,
|
|
714
|
-
pi = 0,
|
|
715
|
-
fl = file.length,
|
|
716
|
-
pl = pattern.length
|
|
717
|
-
; (fi < fl) && (pi < pl)
|
|
718
|
-
; fi++, pi++) {
|
|
719
|
-
this.debug('matchOne loop')
|
|
720
|
-
var p = pattern[pi]
|
|
721
|
-
var f = file[fi]
|
|
722
|
-
|
|
723
|
-
this.debug(pattern, p, f)
|
|
724
|
-
|
|
725
|
-
// should be impossible.
|
|
726
|
-
// some invalid regexp stuff in the set.
|
|
727
|
-
if (p === false) return false
|
|
728
|
-
|
|
729
|
-
if (p === GLOBSTAR) {
|
|
730
|
-
this.debug('GLOBSTAR', [pattern, p, f])
|
|
731
|
-
|
|
732
|
-
// "**"
|
|
733
|
-
// a/**/b/**/c would match the following:
|
|
734
|
-
// a/b/x/y/z/c
|
|
735
|
-
// a/x/y/z/b/c
|
|
736
|
-
// a/b/x/b/x/c
|
|
737
|
-
// a/b/c
|
|
738
|
-
// To do this, take the rest of the pattern after
|
|
739
|
-
// the **, and see if it would match the file remainder.
|
|
740
|
-
// If so, return success.
|
|
741
|
-
// If not, the ** "swallows" a segment, and try again.
|
|
742
|
-
// This is recursively awful.
|
|
743
|
-
//
|
|
744
|
-
// a/**/b/**/c matching a/b/x/y/z/c
|
|
745
|
-
// - a matches a
|
|
746
|
-
// - doublestar
|
|
747
|
-
// - matchOne(b/x/y/z/c, b/**/c)
|
|
748
|
-
// - b matches b
|
|
749
|
-
// - doublestar
|
|
750
|
-
// - matchOne(x/y/z/c, c) -> no
|
|
751
|
-
// - matchOne(y/z/c, c) -> no
|
|
752
|
-
// - matchOne(z/c, c) -> no
|
|
753
|
-
// - matchOne(c, c) yes, hit
|
|
754
|
-
var fr = fi
|
|
755
|
-
var pr = pi + 1
|
|
756
|
-
if (pr === pl) {
|
|
757
|
-
this.debug('** at the end')
|
|
758
|
-
// a ** at the end will just swallow the rest.
|
|
759
|
-
// We have found a match.
|
|
760
|
-
// however, it will not swallow /.x, unless
|
|
761
|
-
// options.dot is set.
|
|
762
|
-
// . and .. are *never* matched by **, for explosively
|
|
763
|
-
// exponential reasons.
|
|
764
|
-
for (; fi < fl; fi++) {
|
|
765
|
-
if (file[fi] === '.' || file[fi] === '..' ||
|
|
766
|
-
(!options.dot && file[fi].charAt(0) === '.')) return false
|
|
767
|
-
}
|
|
768
|
-
return true
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
// ok, let's see if we can swallow whatever we can.
|
|
772
|
-
while (fr < fl) {
|
|
773
|
-
var swallowee = file[fr]
|
|
774
|
-
|
|
775
|
-
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
|
|
776
|
-
|
|
777
|
-
// XXX remove this slice. Just pass the start index.
|
|
778
|
-
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
779
|
-
this.debug('globstar found match!', fr, fl, swallowee)
|
|
780
|
-
// found a match.
|
|
781
|
-
return true
|
|
782
|
-
} else {
|
|
783
|
-
// can't swallow "." or ".." ever.
|
|
784
|
-
// can only swallow ".foo" when explicitly asked.
|
|
785
|
-
if (swallowee === '.' || swallowee === '..' ||
|
|
786
|
-
(!options.dot && swallowee.charAt(0) === '.')) {
|
|
787
|
-
this.debug('dot detected!', file, fr, pattern, pr)
|
|
788
|
-
break
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
// ** swallows a segment, and continue.
|
|
792
|
-
this.debug('globstar swallow a segment, and continue')
|
|
793
|
-
fr++
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// no match was found.
|
|
798
|
-
// However, in partial mode, we can't say this is necessarily over.
|
|
799
|
-
// If there's more *pattern* left, then
|
|
800
|
-
if (partial) {
|
|
801
|
-
// ran out of file
|
|
802
|
-
this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
|
|
803
|
-
if (fr === fl) return true
|
|
804
|
-
}
|
|
805
|
-
return false
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// something other than **
|
|
809
|
-
// non-magic patterns just have to match exactly
|
|
810
|
-
// patterns with magic have been turned into regexps.
|
|
811
|
-
var hit
|
|
812
|
-
if (typeof p === 'string') {
|
|
813
|
-
if (options.nocase) {
|
|
814
|
-
hit = f.toLowerCase() === p.toLowerCase()
|
|
815
|
-
} else {
|
|
816
|
-
hit = f === p
|
|
817
|
-
}
|
|
818
|
-
this.debug('string match', p, f, hit)
|
|
819
|
-
} else {
|
|
820
|
-
hit = f.match(p)
|
|
821
|
-
this.debug('pattern match', p, f, hit)
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
if (!hit) return false
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
// Note: ending in / means that we'll get a final ""
|
|
828
|
-
// at the end of the pattern. This can only match a
|
|
829
|
-
// corresponding "" at the end of the file.
|
|
830
|
-
// If the file ends in /, then it can only match a
|
|
831
|
-
// a pattern that ends in /, unless the pattern just
|
|
832
|
-
// doesn't have any more for it. But, a/b/ should *not*
|
|
833
|
-
// match "a/b/*", even though "" matches against the
|
|
834
|
-
// [^/]*? pattern, except in partial mode, where it might
|
|
835
|
-
// simply not be reached yet.
|
|
836
|
-
// However, a/b/ should still satisfy a/*
|
|
837
|
-
|
|
838
|
-
// now either we fell off the end of the pattern, or we're done.
|
|
839
|
-
if (fi === fl && pi === pl) {
|
|
840
|
-
// ran out of pattern and filename at the same time.
|
|
841
|
-
// an exact hit!
|
|
842
|
-
return true
|
|
843
|
-
} else if (fi === fl) {
|
|
844
|
-
// ran out of file, but still had pattern left.
|
|
845
|
-
// this is ok if we're doing the match as part of
|
|
846
|
-
// a glob fs traversal.
|
|
847
|
-
return partial
|
|
848
|
-
} else if (pi === pl) {
|
|
849
|
-
// ran out of pattern, still have file left.
|
|
850
|
-
// this is only acceptable if we're on the very last
|
|
851
|
-
// empty segment of a file with a trailing slash.
|
|
852
|
-
// a/* should match a/b/
|
|
853
|
-
var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
|
|
854
|
-
return emptyFileEnd
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
// should be unreachable.
|
|
858
|
-
throw new Error('wtf?')
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// replace stuff like \* with *
|
|
862
|
-
function globUnescape (s) {
|
|
863
|
-
return s.replace(/\\(.)/g, '$1')
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
function regExpEscape (s) {
|
|
867
|
-
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
},{"brace-expansion":2,"path":undefined}],2:[function(require,module,exports){
|
|
871
|
-
var concatMap = require('concat-map');
|
|
872
|
-
var balanced = require('balanced-match');
|
|
873
|
-
|
|
874
|
-
module.exports = expandTop;
|
|
875
|
-
|
|
876
|
-
var escSlash = '\0SLASH'+Math.random()+'\0';
|
|
877
|
-
var escOpen = '\0OPEN'+Math.random()+'\0';
|
|
878
|
-
var escClose = '\0CLOSE'+Math.random()+'\0';
|
|
879
|
-
var escComma = '\0COMMA'+Math.random()+'\0';
|
|
880
|
-
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
|
881
|
-
|
|
882
|
-
function numeric(str) {
|
|
883
|
-
return parseInt(str, 10) == str
|
|
884
|
-
? parseInt(str, 10)
|
|
885
|
-
: str.charCodeAt(0);
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
function escapeBraces(str) {
|
|
889
|
-
return str.split('\\\\').join(escSlash)
|
|
890
|
-
.split('\\{').join(escOpen)
|
|
891
|
-
.split('\\}').join(escClose)
|
|
892
|
-
.split('\\,').join(escComma)
|
|
893
|
-
.split('\\.').join(escPeriod);
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
function unescapeBraces(str) {
|
|
897
|
-
return str.split(escSlash).join('\\')
|
|
898
|
-
.split(escOpen).join('{')
|
|
899
|
-
.split(escClose).join('}')
|
|
900
|
-
.split(escComma).join(',')
|
|
901
|
-
.split(escPeriod).join('.');
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
// Basically just str.split(","), but handling cases
|
|
906
|
-
// where we have nested braced sections, which should be
|
|
907
|
-
// treated as individual members, like {a,{b,c},d}
|
|
908
|
-
function parseCommaParts(str) {
|
|
909
|
-
if (!str)
|
|
910
|
-
return [''];
|
|
911
|
-
|
|
912
|
-
var parts = [];
|
|
913
|
-
var m = balanced('{', '}', str);
|
|
914
|
-
|
|
915
|
-
if (!m)
|
|
916
|
-
return str.split(',');
|
|
917
|
-
|
|
918
|
-
var pre = m.pre;
|
|
919
|
-
var body = m.body;
|
|
920
|
-
var post = m.post;
|
|
921
|
-
var p = pre.split(',');
|
|
922
|
-
|
|
923
|
-
p[p.length-1] += '{' + body + '}';
|
|
924
|
-
var postParts = parseCommaParts(post);
|
|
925
|
-
if (post.length) {
|
|
926
|
-
p[p.length-1] += postParts.shift();
|
|
927
|
-
p.push.apply(p, postParts);
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
parts.push.apply(parts, p);
|
|
931
|
-
|
|
932
|
-
return parts;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
function expandTop(str) {
|
|
936
|
-
if (!str)
|
|
937
|
-
return [];
|
|
938
|
-
|
|
939
|
-
var expansions = expand(escapeBraces(str));
|
|
940
|
-
return expansions.filter(identity).map(unescapeBraces);
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
function identity(e) {
|
|
944
|
-
return e;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
function embrace(str) {
|
|
948
|
-
return '{' + str + '}';
|
|
949
|
-
}
|
|
950
|
-
function isPadded(el) {
|
|
951
|
-
return /^-?0\d/.test(el);
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
function lte(i, y) {
|
|
955
|
-
return i <= y;
|
|
956
|
-
}
|
|
957
|
-
function gte(i, y) {
|
|
958
|
-
return i >= y;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
function expand(str) {
|
|
962
|
-
var expansions = [];
|
|
963
|
-
|
|
964
|
-
var m = balanced('{', '}', str);
|
|
965
|
-
if (!m || /\$$/.test(m.pre)) return [str];
|
|
966
|
-
|
|
967
|
-
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
968
|
-
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
969
|
-
var isSequence = isNumericSequence || isAlphaSequence;
|
|
970
|
-
var isOptions = /^(.*,)+(.+)?$/.test(m.body);
|
|
971
|
-
if (!isSequence && !isOptions) {
|
|
972
|
-
// {a},b}
|
|
973
|
-
if (m.post.match(/,.*}/)) {
|
|
974
|
-
str = m.pre + '{' + m.body + escClose + m.post;
|
|
975
|
-
return expand(str);
|
|
976
|
-
}
|
|
977
|
-
return [str];
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
var n;
|
|
981
|
-
if (isSequence) {
|
|
982
|
-
n = m.body.split(/\.\./);
|
|
983
|
-
} else {
|
|
984
|
-
n = parseCommaParts(m.body);
|
|
985
|
-
if (n.length === 1) {
|
|
986
|
-
// x{{a,b}}y ==> x{a}y x{b}y
|
|
987
|
-
n = expand(n[0]).map(embrace);
|
|
988
|
-
if (n.length === 1) {
|
|
989
|
-
var post = m.post.length
|
|
990
|
-
? expand(m.post)
|
|
991
|
-
: [''];
|
|
992
|
-
return post.map(function(p) {
|
|
993
|
-
return m.pre + n[0] + p;
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
// at this point, n is the parts, and we know it's not a comma set
|
|
1000
|
-
// with a single entry.
|
|
1001
|
-
|
|
1002
|
-
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
1003
|
-
var pre = m.pre;
|
|
1004
|
-
var post = m.post.length
|
|
1005
|
-
? expand(m.post)
|
|
1006
|
-
: [''];
|
|
1007
|
-
|
|
1008
|
-
var N;
|
|
1009
|
-
|
|
1010
|
-
if (isSequence) {
|
|
1011
|
-
var x = numeric(n[0]);
|
|
1012
|
-
var y = numeric(n[1]);
|
|
1013
|
-
var width = Math.max(n[0].length, n[1].length)
|
|
1014
|
-
var incr = n.length == 3
|
|
1015
|
-
? Math.abs(numeric(n[2]))
|
|
1016
|
-
: 1;
|
|
1017
|
-
var test = lte;
|
|
1018
|
-
var reverse = y < x;
|
|
1019
|
-
if (reverse) {
|
|
1020
|
-
incr *= -1;
|
|
1021
|
-
test = gte;
|
|
1022
|
-
}
|
|
1023
|
-
var pad = n.some(isPadded);
|
|
1024
|
-
|
|
1025
|
-
N = [];
|
|
1026
|
-
|
|
1027
|
-
for (var i = x; test(i, y); i += incr) {
|
|
1028
|
-
var c;
|
|
1029
|
-
if (isAlphaSequence) {
|
|
1030
|
-
c = String.fromCharCode(i);
|
|
1031
|
-
if (c === '\\')
|
|
1032
|
-
c = '';
|
|
1033
|
-
} else {
|
|
1034
|
-
c = String(i);
|
|
1035
|
-
if (pad) {
|
|
1036
|
-
var need = width - c.length;
|
|
1037
|
-
if (need > 0) {
|
|
1038
|
-
var z = new Array(need + 1).join('0');
|
|
1039
|
-
if (i < 0)
|
|
1040
|
-
c = '-' + z + c.slice(1);
|
|
1041
|
-
else
|
|
1042
|
-
c = z + c;
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
N.push(c);
|
|
1047
|
-
}
|
|
1048
|
-
} else {
|
|
1049
|
-
N = concatMap(n, function(el) { return expand(el) });
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
for (var j = 0; j < N.length; j++) {
|
|
1053
|
-
for (var k = 0; k < post.length; k++) {
|
|
1054
|
-
expansions.push([pre, N[j], post[k]].join(''))
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
return expansions;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
},{"balanced-match":3,"concat-map":4}],3:[function(require,module,exports){
|
|
1063
|
-
module.exports = balanced;
|
|
1064
|
-
function balanced(a, b, str) {
|
|
1065
|
-
var bal = 0;
|
|
1066
|
-
var m = {};
|
|
1067
|
-
var ended = false;
|
|
1068
|
-
|
|
1069
|
-
for (var i = 0; i < str.length; i++) {
|
|
1070
|
-
if (a == str.substr(i, a.length)) {
|
|
1071
|
-
if (!('start' in m)) m.start = i;
|
|
1072
|
-
bal++;
|
|
1073
|
-
}
|
|
1074
|
-
else if (b == str.substr(i, b.length) && 'start' in m) {
|
|
1075
|
-
ended = true;
|
|
1076
|
-
bal--;
|
|
1077
|
-
if (!bal) {
|
|
1078
|
-
m.end = i;
|
|
1079
|
-
m.pre = str.substr(0, m.start);
|
|
1080
|
-
m.body = (m.end - m.start > 1)
|
|
1081
|
-
? str.substring(m.start + a.length, m.end)
|
|
1082
|
-
: '';
|
|
1083
|
-
m.post = str.slice(m.end + b.length);
|
|
1084
|
-
return m;
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
// if we opened more than we closed, find the one we closed
|
|
1090
|
-
if (bal && ended) {
|
|
1091
|
-
var start = m.start + a.length;
|
|
1092
|
-
m = balanced(a, b, str.substr(start));
|
|
1093
|
-
if (m) {
|
|
1094
|
-
m.start += start;
|
|
1095
|
-
m.end += start;
|
|
1096
|
-
m.pre = str.slice(0, start) + m.pre;
|
|
1097
|
-
}
|
|
1098
|
-
return m;
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
},{}],4:[function(require,module,exports){
|
|
1103
|
-
module.exports = function (xs, fn) {
|
|
1104
|
-
var res = [];
|
|
1105
|
-
for (var i = 0; i < xs.length; i++) {
|
|
1106
|
-
var x = fn(xs[i], i);
|
|
1107
|
-
if (Array.isArray(x)) res.push.apply(res, x);
|
|
1108
|
-
else res.push(x);
|
|
1109
|
-
}
|
|
1110
|
-
return res;
|
|
1111
|
-
};
|
|
1112
|
-
|
|
1113
|
-
},{}]},{},[1]);
|