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