minimatch 2.0.9 → 3.0.3

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  A minimal matching utility.
4
4
 
5
- [![Build Status](https://secure.travis-ci.org/isaacs/minimatch.png)](http://travis-ci.org/isaacs/minimatch)
5
+ [![Build Status](https://secure.travis-ci.org/isaacs/minimatch.svg)](http://travis-ci.org/isaacs/minimatch)
6
6
 
7
7
 
8
8
  This is the matching library used internally by npm.
@@ -37,7 +37,7 @@ See:
37
37
 
38
38
  ## Minimatch Class
39
39
 
40
- Create a minimatch object by instanting the `minimatch.Minimatch` class.
40
+ Create a minimatch object by instantiating the `minimatch.Minimatch` class.
41
41
 
42
42
  ```javascript
43
43
  var Minimatch = require("minimatch").Minimatch
@@ -82,13 +82,6 @@ var mm = new Minimatch(pattern, options)
82
82
 
83
83
  All other methods are internal, and will be called as necessary.
84
84
 
85
- ## Functions
86
-
87
- The top-level exported function has a `cache` property, which is an LRU
88
- cache set to store 100 items. So, calling these methods repeatedly
89
- with the same pattern and options will use the same Minimatch object,
90
- saving the cost of parsing it multiple times.
91
-
92
85
  ### minimatch(path, pattern, options)
93
86
 
94
87
  Main export. Tests a path against the pattern using the options.
package/minimatch.js CHANGED
@@ -9,6 +9,14 @@ try {
9
9
  var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
10
10
  var expand = require('brace-expansion')
11
11
 
12
+ var plTypes = {
13
+ '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
14
+ '?': { open: '(?:', close: ')?' },
15
+ '+': { open: '(?:', close: ')+' },
16
+ '*': { open: '(?:', close: ')*' },
17
+ '@': { open: '(?:', close: ')' }
18
+ }
19
+
12
20
  // any single thing other than /
13
21
  // don't need to escape / when using new RegExp()
14
22
  var qmark = '[^/]'
@@ -235,7 +243,7 @@ function braceExpand (pattern, options) {
235
243
  ? this.pattern : pattern
236
244
 
237
245
  if (typeof pattern === 'undefined') {
238
- throw new Error('undefined pattern')
246
+ throw new TypeError('undefined pattern')
239
247
  }
240
248
 
241
249
  if (options.nobrace ||
@@ -261,6 +269,10 @@ function braceExpand (pattern, options) {
261
269
  Minimatch.prototype.parse = parse
262
270
  var SUBPARSE = {}
263
271
  function parse (pattern, isSub) {
272
+ if (pattern.length > 1024 * 64) {
273
+ throw new TypeError('pattern is too long')
274
+ }
275
+
264
276
  var options = this.options
265
277
 
266
278
  // shortcuts
@@ -273,7 +285,6 @@ function parse (pattern, isSub) {
273
285
  // ? => one single character
274
286
  var patternListStack = []
275
287
  var negativeLists = []
276
- var plType
277
288
  var stateChar
278
289
  var inClass = false
279
290
  var reClassStart = -1
@@ -372,11 +383,12 @@ function parse (pattern, isSub) {
372
383
  continue
373
384
  }
374
385
 
375
- plType = stateChar
376
386
  patternListStack.push({
377
- type: plType,
387
+ type: stateChar,
378
388
  start: i - 1,
379
- reStart: re.length
389
+ reStart: re.length,
390
+ open: plTypes[stateChar].open,
391
+ close: plTypes[stateChar].close
380
392
  })
381
393
  // negation is (?:(?!js)[^/]*)
382
394
  re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
@@ -392,24 +404,14 @@ function parse (pattern, isSub) {
392
404
 
393
405
  clearStateChar()
394
406
  hasMagic = true
395
- re += ')'
396
407
  var pl = patternListStack.pop()
397
- plType = pl.type
398
408
  // negation is (?:(?!js)[^/]*)
399
409
  // The others are (?:<pattern>)<type>
400
- switch (plType) {
401
- case '!':
402
- negativeLists.push(pl)
403
- re += ')[^/]*?)'
404
- pl.reEnd = re.length
405
- break
406
- case '?':
407
- case '+':
408
- case '*':
409
- re += plType
410
- break
411
- case '@': break // the default anyway
410
+ re += pl.close
411
+ if (pl.type === '!') {
412
+ negativeLists.push(pl)
412
413
  }
414
+ pl.reEnd = re.length
413
415
  continue
414
416
 
415
417
  case '|':
@@ -516,9 +518,10 @@ function parse (pattern, isSub) {
516
518
  // Go through and escape them, taking care not to double-escape any
517
519
  // | chars that were already escaped.
518
520
  for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
519
- var tail = re.slice(pl.reStart + 3)
521
+ var tail = re.slice(pl.reStart + pl.open.length)
522
+ this.debug('setting tail', re, pl)
520
523
  // maybe some even number of \, then maybe 1 \, followed by a |
521
- tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
524
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
522
525
  if (!$2) {
523
526
  // the | isn't already escaped, so escape it.
524
527
  $2 = '\\'
@@ -533,7 +536,7 @@ function parse (pattern, isSub) {
533
536
  return $1 + $1 + $2 + '|'
534
537
  })
535
538
 
536
- this.debug('tail=%j\n %s', tail, tail)
539
+ this.debug('tail=%j\n %s', tail, tail, pl, re)
537
540
  var t = pl.type === '*' ? star
538
541
  : pl.type === '?' ? qmark
539
542
  : '\\' + pl.type
@@ -570,11 +573,24 @@ function parse (pattern, isSub) {
570
573
  var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
571
574
  var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
572
575
  var nlAfter = re.slice(nl.reEnd)
576
+
577
+ nlLast += nlAfter
578
+
579
+ // Handle nested stuff like *(*.js|!(*.json)), where open parens
580
+ // mean that we should *not* include the ) in the bit that is considered
581
+ // "after" the negated section.
582
+ var openParensBefore = nlBefore.split('(').length - 1
583
+ var cleanAfter = nlAfter
584
+ for (i = 0; i < openParensBefore; i++) {
585
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
586
+ }
587
+ nlAfter = cleanAfter
588
+
573
589
  var dollar = ''
574
590
  if (nlAfter === '' && isSub !== SUBPARSE) {
575
591
  dollar = '$'
576
592
  }
577
- var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast + nlAfter
593
+ var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
578
594
  re = newRe
579
595
  }
580
596
 
@@ -602,7 +618,15 @@ function parse (pattern, isSub) {
602
618
  }
603
619
 
604
620
  var flags = options.nocase ? 'i' : ''
605
- var regExp = new RegExp('^' + re + '$', flags)
621
+ try {
622
+ var regExp = new RegExp('^' + re + '$', flags)
623
+ } catch (er) {
624
+ // If it was an invalid regular expression, then it can't match
625
+ // anything. This trick looks for a character after the end of
626
+ // the string, which is of course impossible, except in multi-line
627
+ // mode, but it's not a /m regex.
628
+ return new RegExp('$.')
629
+ }
606
630
 
607
631
  regExp._glob = pattern
608
632
  regExp._src = re
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": "2.0.9",
5
+ "version": "3.0.3",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/isaacs/minimatch.git"
@@ -10,8 +10,7 @@
10
10
  "main": "minimatch.js",
11
11
  "scripts": {
12
12
  "posttest": "standard minimatch.js test/*.js",
13
- "test": "tap test/*.js",
14
- "prepublish": "browserify -o browser.js -e minimatch.js -s minimatch --bare"
13
+ "test": "tap test/*.js"
15
14
  },
16
15
  "engines": {
17
16
  "node": "*"
@@ -20,13 +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": "^1.2.0"
23
+ "tap": "^5.6.0"
26
24
  },
27
25
  "license": "ISC",
28
26
  "files": [
29
- "minimatch.js",
30
- "browser.js"
27
+ "minimatch.js"
31
28
  ]
32
29
  }
package/browser.js DELETED
@@ -1,1146 +0,0 @@
1
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.minimatch = f()}})(function(){var define,module,exports;return (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 negativeLists = []
277
- var plType
278
- var stateChar
279
- var inClass = false
280
- var reClassStart = -1
281
- var classStart = -1
282
- // . and .. never match anything that doesn't start with .,
283
- // even when options.dot is set.
284
- var patternStart = pattern.charAt(0) === '.' ? '' // anything
285
- // not (start or / followed by . or .. followed by / or end)
286
- : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
287
- : '(?!\\.)'
288
- var self = this
289
-
290
- function clearStateChar () {
291
- if (stateChar) {
292
- // we had some state-tracking character
293
- // that wasn't consumed by this pass.
294
- switch (stateChar) {
295
- case '*':
296
- re += star
297
- hasMagic = true
298
- break
299
- case '?':
300
- re += qmark
301
- hasMagic = true
302
- break
303
- default:
304
- re += '\\' + stateChar
305
- break
306
- }
307
- self.debug('clearStateChar %j %j', stateChar, re)
308
- stateChar = false
309
- }
310
- }
311
-
312
- for (var i = 0, len = pattern.length, c
313
- ; (i < len) && (c = pattern.charAt(i))
314
- ; i++) {
315
- this.debug('%s\t%s %s %j', pattern, i, re, c)
316
-
317
- // skip over any that are escaped.
318
- if (escaping && reSpecials[c]) {
319
- re += '\\' + c
320
- escaping = false
321
- continue
322
- }
323
-
324
- switch (c) {
325
- case '/':
326
- // completely not allowed, even escaped.
327
- // Should already be path-split by now.
328
- return false
329
-
330
- case '\\':
331
- clearStateChar()
332
- escaping = true
333
- continue
334
-
335
- // the various stateChar values
336
- // for the "extglob" stuff.
337
- case '?':
338
- case '*':
339
- case '+':
340
- case '@':
341
- case '!':
342
- this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
343
-
344
- // all of those are literals inside a class, except that
345
- // the glob [!a] means [^a] in regexp
346
- if (inClass) {
347
- this.debug(' in class')
348
- if (c === '!' && i === classStart + 1) c = '^'
349
- re += c
350
- continue
351
- }
352
-
353
- // if we already have a stateChar, then it means
354
- // that there was something like ** or +? in there.
355
- // Handle the stateChar, then proceed with this one.
356
- self.debug('call clearStateChar %j', stateChar)
357
- clearStateChar()
358
- stateChar = c
359
- // if extglob is disabled, then +(asdf|foo) isn't a thing.
360
- // just clear the statechar *now*, rather than even diving into
361
- // the patternList stuff.
362
- if (options.noext) clearStateChar()
363
- continue
364
-
365
- case '(':
366
- if (inClass) {
367
- re += '('
368
- continue
369
- }
370
-
371
- if (!stateChar) {
372
- re += '\\('
373
- continue
374
- }
375
-
376
- plType = stateChar
377
- patternListStack.push({
378
- type: plType,
379
- start: i - 1,
380
- reStart: re.length
381
- })
382
- // negation is (?:(?!js)[^/]*)
383
- re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
384
- this.debug('plType %j %j', stateChar, re)
385
- stateChar = false
386
- continue
387
-
388
- case ')':
389
- if (inClass || !patternListStack.length) {
390
- re += '\\)'
391
- continue
392
- }
393
-
394
- clearStateChar()
395
- hasMagic = true
396
- re += ')'
397
- var pl = patternListStack.pop()
398
- plType = pl.type
399
- // negation is (?:(?!js)[^/]*)
400
- // The others are (?:<pattern>)<type>
401
- switch (plType) {
402
- case '!':
403
- negativeLists.push(pl)
404
- re += ')[^/]*?)'
405
- pl.reEnd = re.length
406
- break
407
- case '?':
408
- case '+':
409
- case '*':
410
- re += plType
411
- break
412
- case '@': break // the default anyway
413
- }
414
- continue
415
-
416
- case '|':
417
- if (inClass || !patternListStack.length || escaping) {
418
- re += '\\|'
419
- escaping = false
420
- continue
421
- }
422
-
423
- clearStateChar()
424
- re += '|'
425
- continue
426
-
427
- // these are mostly the same in regexp and glob
428
- case '[':
429
- // swallow any state-tracking char before the [
430
- clearStateChar()
431
-
432
- if (inClass) {
433
- re += '\\' + c
434
- continue
435
- }
436
-
437
- inClass = true
438
- classStart = i
439
- reClassStart = re.length
440
- re += c
441
- continue
442
-
443
- case ']':
444
- // a right bracket shall lose its special
445
- // meaning and represent itself in
446
- // a bracket expression if it occurs
447
- // first in the list. -- POSIX.2 2.8.3.2
448
- if (i === classStart + 1 || !inClass) {
449
- re += '\\' + c
450
- escaping = false
451
- continue
452
- }
453
-
454
- // handle the case where we left a class open.
455
- // "[z-a]" is valid, equivalent to "\[z-a\]"
456
- if (inClass) {
457
- // split where the last [ was, make sure we don't have
458
- // an invalid re. if so, re-walk the contents of the
459
- // would-be class to re-translate any characters that
460
- // were passed through as-is
461
- // TODO: It would probably be faster to determine this
462
- // without a try/catch and a new RegExp, but it's tricky
463
- // to do safely. For now, this is safe and works.
464
- var cs = pattern.substring(classStart + 1, i)
465
- try {
466
- RegExp('[' + cs + ']')
467
- } catch (er) {
468
- // not a valid class!
469
- var sp = this.parse(cs, SUBPARSE)
470
- re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
471
- hasMagic = hasMagic || sp[1]
472
- inClass = false
473
- continue
474
- }
475
- }
476
-
477
- // finish up the class.
478
- hasMagic = true
479
- inClass = false
480
- re += c
481
- continue
482
-
483
- default:
484
- // swallow any state char that wasn't consumed
485
- clearStateChar()
486
-
487
- if (escaping) {
488
- // no need
489
- escaping = false
490
- } else if (reSpecials[c]
491
- && !(c === '^' && inClass)) {
492
- re += '\\'
493
- }
494
-
495
- re += c
496
-
497
- } // switch
498
- } // for
499
-
500
- // handle the case where we left a class open.
501
- // "[abc" is valid, equivalent to "\[abc"
502
- if (inClass) {
503
- // split where the last [ was, and escape it
504
- // this is a huge pita. We now have to re-walk
505
- // the contents of the would-be class to re-translate
506
- // any characters that were passed through as-is
507
- cs = pattern.substr(classStart + 1)
508
- sp = this.parse(cs, SUBPARSE)
509
- re = re.substr(0, reClassStart) + '\\[' + sp[0]
510
- hasMagic = hasMagic || sp[1]
511
- }
512
-
513
- // handle the case where we had a +( thing at the *end*
514
- // of the pattern.
515
- // each pattern list stack adds 3 chars, and we need to go through
516
- // and escape any | chars that were passed through as-is for the regexp.
517
- // Go through and escape them, taking care not to double-escape any
518
- // | chars that were already escaped.
519
- for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
520
- var tail = re.slice(pl.reStart + 3)
521
- // maybe some even number of \, then maybe 1 \, followed by a |
522
- tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
523
- if (!$2) {
524
- // the | isn't already escaped, so escape it.
525
- $2 = '\\'
526
- }
527
-
528
- // need to escape all those slashes *again*, without escaping the
529
- // one that we need for escaping the | character. As it works out,
530
- // escaping an even number of slashes can be done by simply repeating
531
- // it exactly after itself. That's why this trick works.
532
- //
533
- // I am sorry that you have to see this.
534
- return $1 + $1 + $2 + '|'
535
- })
536
-
537
- this.debug('tail=%j\n %s', tail, tail)
538
- var t = pl.type === '*' ? star
539
- : pl.type === '?' ? qmark
540
- : '\\' + pl.type
541
-
542
- hasMagic = true
543
- re = re.slice(0, pl.reStart) + t + '\\(' + tail
544
- }
545
-
546
- // handle trailing things that only matter at the very end.
547
- clearStateChar()
548
- if (escaping) {
549
- // trailing \\
550
- re += '\\\\'
551
- }
552
-
553
- // only need to apply the nodot start if the re starts with
554
- // something that could conceivably capture a dot
555
- var addPatternStart = false
556
- switch (re.charAt(0)) {
557
- case '.':
558
- case '[':
559
- case '(': addPatternStart = true
560
- }
561
-
562
- // Hack to work around lack of negative lookbehind in JS
563
- // A pattern like: *.!(x).!(y|z) needs to ensure that a name
564
- // like 'a.xyz.yz' doesn't match. So, the first negative
565
- // lookahead, has to look ALL the way ahead, to the end of
566
- // the pattern.
567
- for (var n = negativeLists.length - 1; n > -1; n--) {
568
- var nl = negativeLists[n]
569
-
570
- var nlBefore = re.slice(0, nl.reStart)
571
- var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
572
- var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
573
- var nlAfter = re.slice(nl.reEnd)
574
- var dollar = ''
575
- if (nlAfter === '' && isSub !== SUBPARSE) {
576
- dollar = '$'
577
- }
578
- var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast + nlAfter
579
- re = newRe
580
- }
581
-
582
- // if the re is not "" at this point, then we need to make sure
583
- // it doesn't match against an empty path part.
584
- // Otherwise a/* will match a/, which it should not.
585
- if (re !== '' && hasMagic) {
586
- re = '(?=.)' + re
587
- }
588
-
589
- if (addPatternStart) {
590
- re = patternStart + re
591
- }
592
-
593
- // parsing just a piece of a larger pattern.
594
- if (isSub === SUBPARSE) {
595
- return [re, hasMagic]
596
- }
597
-
598
- // skip the regexp for non-magical patterns
599
- // unescape anything in it, though, so that it'll be
600
- // an exact match against a file etc.
601
- if (!hasMagic) {
602
- return globUnescape(pattern)
603
- }
604
-
605
- var flags = options.nocase ? 'i' : ''
606
- var regExp = new RegExp('^' + re + '$', flags)
607
-
608
- regExp._glob = pattern
609
- regExp._src = re
610
-
611
- return regExp
612
- }
613
-
614
- minimatch.makeRe = function (pattern, options) {
615
- return new Minimatch(pattern, options || {}).makeRe()
616
- }
617
-
618
- Minimatch.prototype.makeRe = makeRe
619
- function makeRe () {
620
- if (this.regexp || this.regexp === false) return this.regexp
621
-
622
- // at this point, this.set is a 2d array of partial
623
- // pattern strings, or "**".
624
- //
625
- // It's better to use .match(). This function shouldn't
626
- // be used, really, but it's pretty convenient sometimes,
627
- // when you just want to work with a regex.
628
- var set = this.set
629
-
630
- if (!set.length) {
631
- this.regexp = false
632
- return this.regexp
633
- }
634
- var options = this.options
635
-
636
- var twoStar = options.noglobstar ? star
637
- : options.dot ? twoStarDot
638
- : twoStarNoDot
639
- var flags = options.nocase ? 'i' : ''
640
-
641
- var re = set.map(function (pattern) {
642
- return pattern.map(function (p) {
643
- return (p === GLOBSTAR) ? twoStar
644
- : (typeof p === 'string') ? regExpEscape(p)
645
- : p._src
646
- }).join('\\\/')
647
- }).join('|')
648
-
649
- // must match entire pattern
650
- // ending in a * or ** will make it less strict.
651
- re = '^(?:' + re + ')$'
652
-
653
- // can match anything, as long as it's not this.
654
- if (this.negate) re = '^(?!' + re + ').*$'
655
-
656
- try {
657
- this.regexp = new RegExp(re, flags)
658
- } catch (ex) {
659
- this.regexp = false
660
- }
661
- return this.regexp
662
- }
663
-
664
- minimatch.match = function (list, pattern, options) {
665
- options = options || {}
666
- var mm = new Minimatch(pattern, options)
667
- list = list.filter(function (f) {
668
- return mm.match(f)
669
- })
670
- if (mm.options.nonull && !list.length) {
671
- list.push(pattern)
672
- }
673
- return list
674
- }
675
-
676
- Minimatch.prototype.match = match
677
- function match (f, partial) {
678
- this.debug('match', f, this.pattern)
679
- // short-circuit in the case of busted things.
680
- // comments, etc.
681
- if (this.comment) return false
682
- if (this.empty) return f === ''
683
-
684
- if (f === '/' && partial) return true
685
-
686
- var options = this.options
687
-
688
- // windows: need to use /, not \
689
- if (path.sep !== '/') {
690
- f = f.split(path.sep).join('/')
691
- }
692
-
693
- // treat the test path as a set of pathparts.
694
- f = f.split(slashSplit)
695
- this.debug(this.pattern, 'split', f)
696
-
697
- // just ONE of the pattern sets in this.set needs to match
698
- // in order for it to be valid. If negating, then just one
699
- // match means that we have failed.
700
- // Either way, return on the first hit.
701
-
702
- var set = this.set
703
- this.debug(this.pattern, 'set', set)
704
-
705
- // Find the basename of the path by looking for the last non-empty segment
706
- var filename
707
- var i
708
- for (i = f.length - 1; i >= 0; i--) {
709
- filename = f[i]
710
- if (filename) break
711
- }
712
-
713
- for (i = 0; i < set.length; i++) {
714
- var pattern = set[i]
715
- var file = f
716
- if (options.matchBase && pattern.length === 1) {
717
- file = [filename]
718
- }
719
- var hit = this.matchOne(file, pattern, partial)
720
- if (hit) {
721
- if (options.flipNegate) return true
722
- return !this.negate
723
- }
724
- }
725
-
726
- // didn't get any hits. this is success if it's a negative
727
- // pattern, failure otherwise.
728
- if (options.flipNegate) return false
729
- return this.negate
730
- }
731
-
732
- // set partial to true to test if, for example,
733
- // "/a/b" matches the start of "/*/b/*/d"
734
- // Partial means, if you run out of file before you run
735
- // out of pattern, then that's fine, as long as all
736
- // the parts match.
737
- Minimatch.prototype.matchOne = function (file, pattern, partial) {
738
- var options = this.options
739
-
740
- this.debug('matchOne',
741
- { 'this': this, file: file, pattern: pattern })
742
-
743
- this.debug('matchOne', file.length, pattern.length)
744
-
745
- for (var fi = 0,
746
- pi = 0,
747
- fl = file.length,
748
- pl = pattern.length
749
- ; (fi < fl) && (pi < pl)
750
- ; fi++, pi++) {
751
- this.debug('matchOne loop')
752
- var p = pattern[pi]
753
- var f = file[fi]
754
-
755
- this.debug(pattern, p, f)
756
-
757
- // should be impossible.
758
- // some invalid regexp stuff in the set.
759
- if (p === false) return false
760
-
761
- if (p === GLOBSTAR) {
762
- this.debug('GLOBSTAR', [pattern, p, f])
763
-
764
- // "**"
765
- // a/**/b/**/c would match the following:
766
- // a/b/x/y/z/c
767
- // a/x/y/z/b/c
768
- // a/b/x/b/x/c
769
- // a/b/c
770
- // To do this, take the rest of the pattern after
771
- // the **, and see if it would match the file remainder.
772
- // If so, return success.
773
- // If not, the ** "swallows" a segment, and try again.
774
- // This is recursively awful.
775
- //
776
- // a/**/b/**/c matching a/b/x/y/z/c
777
- // - a matches a
778
- // - doublestar
779
- // - matchOne(b/x/y/z/c, b/**/c)
780
- // - b matches b
781
- // - doublestar
782
- // - matchOne(x/y/z/c, c) -> no
783
- // - matchOne(y/z/c, c) -> no
784
- // - matchOne(z/c, c) -> no
785
- // - matchOne(c, c) yes, hit
786
- var fr = fi
787
- var pr = pi + 1
788
- if (pr === pl) {
789
- this.debug('** at the end')
790
- // a ** at the end will just swallow the rest.
791
- // We have found a match.
792
- // however, it will not swallow /.x, unless
793
- // options.dot is set.
794
- // . and .. are *never* matched by **, for explosively
795
- // exponential reasons.
796
- for (; fi < fl; fi++) {
797
- if (file[fi] === '.' || file[fi] === '..' ||
798
- (!options.dot && file[fi].charAt(0) === '.')) return false
799
- }
800
- return true
801
- }
802
-
803
- // ok, let's see if we can swallow whatever we can.
804
- while (fr < fl) {
805
- var swallowee = file[fr]
806
-
807
- this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
808
-
809
- // XXX remove this slice. Just pass the start index.
810
- if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
811
- this.debug('globstar found match!', fr, fl, swallowee)
812
- // found a match.
813
- return true
814
- } else {
815
- // can't swallow "." or ".." ever.
816
- // can only swallow ".foo" when explicitly asked.
817
- if (swallowee === '.' || swallowee === '..' ||
818
- (!options.dot && swallowee.charAt(0) === '.')) {
819
- this.debug('dot detected!', file, fr, pattern, pr)
820
- break
821
- }
822
-
823
- // ** swallows a segment, and continue.
824
- this.debug('globstar swallow a segment, and continue')
825
- fr++
826
- }
827
- }
828
-
829
- // no match was found.
830
- // However, in partial mode, we can't say this is necessarily over.
831
- // If there's more *pattern* left, then
832
- if (partial) {
833
- // ran out of file
834
- this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
835
- if (fr === fl) return true
836
- }
837
- return false
838
- }
839
-
840
- // something other than **
841
- // non-magic patterns just have to match exactly
842
- // patterns with magic have been turned into regexps.
843
- var hit
844
- if (typeof p === 'string') {
845
- if (options.nocase) {
846
- hit = f.toLowerCase() === p.toLowerCase()
847
- } else {
848
- hit = f === p
849
- }
850
- this.debug('string match', p, f, hit)
851
- } else {
852
- hit = f.match(p)
853
- this.debug('pattern match', p, f, hit)
854
- }
855
-
856
- if (!hit) return false
857
- }
858
-
859
- // Note: ending in / means that we'll get a final ""
860
- // at the end of the pattern. This can only match a
861
- // corresponding "" at the end of the file.
862
- // If the file ends in /, then it can only match a
863
- // a pattern that ends in /, unless the pattern just
864
- // doesn't have any more for it. But, a/b/ should *not*
865
- // match "a/b/*", even though "" matches against the
866
- // [^/]*? pattern, except in partial mode, where it might
867
- // simply not be reached yet.
868
- // However, a/b/ should still satisfy a/*
869
-
870
- // now either we fell off the end of the pattern, or we're done.
871
- if (fi === fl && pi === pl) {
872
- // ran out of pattern and filename at the same time.
873
- // an exact hit!
874
- return true
875
- } else if (fi === fl) {
876
- // ran out of file, but still had pattern left.
877
- // this is ok if we're doing the match as part of
878
- // a glob fs traversal.
879
- return partial
880
- } else if (pi === pl) {
881
- // ran out of pattern, still have file left.
882
- // this is only acceptable if we're on the very last
883
- // empty segment of a file with a trailing slash.
884
- // a/* should match a/b/
885
- var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
886
- return emptyFileEnd
887
- }
888
-
889
- // should be unreachable.
890
- throw new Error('wtf?')
891
- }
892
-
893
- // replace stuff like \* with *
894
- function globUnescape (s) {
895
- return s.replace(/\\(.)/g, '$1')
896
- }
897
-
898
- function regExpEscape (s) {
899
- return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
900
- }
901
-
902
- },{"brace-expansion":2,"path":undefined}],2:[function(require,module,exports){
903
- var concatMap = require('concat-map');
904
- var balanced = require('balanced-match');
905
-
906
- module.exports = expandTop;
907
-
908
- var escSlash = '\0SLASH'+Math.random()+'\0';
909
- var escOpen = '\0OPEN'+Math.random()+'\0';
910
- var escClose = '\0CLOSE'+Math.random()+'\0';
911
- var escComma = '\0COMMA'+Math.random()+'\0';
912
- var escPeriod = '\0PERIOD'+Math.random()+'\0';
913
-
914
- function numeric(str) {
915
- return parseInt(str, 10) == str
916
- ? parseInt(str, 10)
917
- : str.charCodeAt(0);
918
- }
919
-
920
- function escapeBraces(str) {
921
- return str.split('\\\\').join(escSlash)
922
- .split('\\{').join(escOpen)
923
- .split('\\}').join(escClose)
924
- .split('\\,').join(escComma)
925
- .split('\\.').join(escPeriod);
926
- }
927
-
928
- function unescapeBraces(str) {
929
- return str.split(escSlash).join('\\')
930
- .split(escOpen).join('{')
931
- .split(escClose).join('}')
932
- .split(escComma).join(',')
933
- .split(escPeriod).join('.');
934
- }
935
-
936
-
937
- // Basically just str.split(","), but handling cases
938
- // where we have nested braced sections, which should be
939
- // treated as individual members, like {a,{b,c},d}
940
- function parseCommaParts(str) {
941
- if (!str)
942
- return [''];
943
-
944
- var parts = [];
945
- var m = balanced('{', '}', str);
946
-
947
- if (!m)
948
- return str.split(',');
949
-
950
- var pre = m.pre;
951
- var body = m.body;
952
- var post = m.post;
953
- var p = pre.split(',');
954
-
955
- p[p.length-1] += '{' + body + '}';
956
- var postParts = parseCommaParts(post);
957
- if (post.length) {
958
- p[p.length-1] += postParts.shift();
959
- p.push.apply(p, postParts);
960
- }
961
-
962
- parts.push.apply(parts, p);
963
-
964
- return parts;
965
- }
966
-
967
- function expandTop(str) {
968
- if (!str)
969
- return [];
970
-
971
- var expansions = expand(escapeBraces(str));
972
- return expansions.filter(identity).map(unescapeBraces);
973
- }
974
-
975
- function identity(e) {
976
- return e;
977
- }
978
-
979
- function embrace(str) {
980
- return '{' + str + '}';
981
- }
982
- function isPadded(el) {
983
- return /^-?0\d/.test(el);
984
- }
985
-
986
- function lte(i, y) {
987
- return i <= y;
988
- }
989
- function gte(i, y) {
990
- return i >= y;
991
- }
992
-
993
- function expand(str) {
994
- var expansions = [];
995
-
996
- var m = balanced('{', '}', str);
997
- if (!m || /\$$/.test(m.pre)) return [str];
998
-
999
- var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
1000
- var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
1001
- var isSequence = isNumericSequence || isAlphaSequence;
1002
- var isOptions = /^(.*,)+(.+)?$/.test(m.body);
1003
- if (!isSequence && !isOptions) {
1004
- // {a},b}
1005
- if (m.post.match(/,.*}/)) {
1006
- str = m.pre + '{' + m.body + escClose + m.post;
1007
- return expand(str);
1008
- }
1009
- return [str];
1010
- }
1011
-
1012
- var n;
1013
- if (isSequence) {
1014
- n = m.body.split(/\.\./);
1015
- } else {
1016
- n = parseCommaParts(m.body);
1017
- if (n.length === 1) {
1018
- // x{{a,b}}y ==> x{a}y x{b}y
1019
- n = expand(n[0]).map(embrace);
1020
- if (n.length === 1) {
1021
- var post = m.post.length
1022
- ? expand(m.post)
1023
- : [''];
1024
- return post.map(function(p) {
1025
- return m.pre + n[0] + p;
1026
- });
1027
- }
1028
- }
1029
- }
1030
-
1031
- // at this point, n is the parts, and we know it's not a comma set
1032
- // with a single entry.
1033
-
1034
- // no need to expand pre, since it is guaranteed to be free of brace-sets
1035
- var pre = m.pre;
1036
- var post = m.post.length
1037
- ? expand(m.post)
1038
- : [''];
1039
-
1040
- var N;
1041
-
1042
- if (isSequence) {
1043
- var x = numeric(n[0]);
1044
- var y = numeric(n[1]);
1045
- var width = Math.max(n[0].length, n[1].length)
1046
- var incr = n.length == 3
1047
- ? Math.abs(numeric(n[2]))
1048
- : 1;
1049
- var test = lte;
1050
- var reverse = y < x;
1051
- if (reverse) {
1052
- incr *= -1;
1053
- test = gte;
1054
- }
1055
- var pad = n.some(isPadded);
1056
-
1057
- N = [];
1058
-
1059
- for (var i = x; test(i, y); i += incr) {
1060
- var c;
1061
- if (isAlphaSequence) {
1062
- c = String.fromCharCode(i);
1063
- if (c === '\\')
1064
- c = '';
1065
- } else {
1066
- c = String(i);
1067
- if (pad) {
1068
- var need = width - c.length;
1069
- if (need > 0) {
1070
- var z = new Array(need + 1).join('0');
1071
- if (i < 0)
1072
- c = '-' + z + c.slice(1);
1073
- else
1074
- c = z + c;
1075
- }
1076
- }
1077
- }
1078
- N.push(c);
1079
- }
1080
- } else {
1081
- N = concatMap(n, function(el) { return expand(el) });
1082
- }
1083
-
1084
- for (var j = 0; j < N.length; j++) {
1085
- for (var k = 0; k < post.length; k++) {
1086
- expansions.push([pre, N[j], post[k]].join(''))
1087
- }
1088
- }
1089
-
1090
- return expansions;
1091
- }
1092
-
1093
-
1094
- },{"balanced-match":3,"concat-map":4}],3:[function(require,module,exports){
1095
- module.exports = balanced;
1096
- function balanced(a, b, str) {
1097
- var bal = 0;
1098
- var m = {};
1099
- var ended = false;
1100
-
1101
- for (var i = 0; i < str.length; i++) {
1102
- if (a == str.substr(i, a.length)) {
1103
- if (!('start' in m)) m.start = i;
1104
- bal++;
1105
- }
1106
- else if (b == str.substr(i, b.length) && 'start' in m) {
1107
- ended = true;
1108
- bal--;
1109
- if (!bal) {
1110
- m.end = i;
1111
- m.pre = str.substr(0, m.start);
1112
- m.body = (m.end - m.start > 1)
1113
- ? str.substring(m.start + a.length, m.end)
1114
- : '';
1115
- m.post = str.slice(m.end + b.length);
1116
- return m;
1117
- }
1118
- }
1119
- }
1120
-
1121
- // if we opened more than we closed, find the one we closed
1122
- if (bal && ended) {
1123
- var start = m.start + a.length;
1124
- m = balanced(a, b, str.substr(start));
1125
- if (m) {
1126
- m.start += start;
1127
- m.end += start;
1128
- m.pre = str.slice(0, start) + m.pre;
1129
- }
1130
- return m;
1131
- }
1132
- }
1133
-
1134
- },{}],4:[function(require,module,exports){
1135
- module.exports = function (xs, fn) {
1136
- var res = [];
1137
- for (var i = 0; i < xs.length; i++) {
1138
- var x = fn(xs[i], i);
1139
- if (Array.isArray(x)) res.push.apply(res, x);
1140
- else res.push(x);
1141
- }
1142
- return res;
1143
- };
1144
-
1145
- },{}]},{},[1])(1)
1146
- });