1 | ;(function (require, exports, module, platform) {
|
2 |
|
3 | if (module) module.exports = minimatch
|
4 | else exports.minimatch = minimatch
|
5 |
|
6 | if (!require) {
|
7 | require = function (id) {
|
8 | switch (id) {
|
9 | case "sigmund": return function sigmund (obj) {
|
10 | return JSON.stringify(obj)
|
11 | }
|
12 | case "path": return { basename: function (f) {
|
13 | f = f.split(/[\/\\]/)
|
14 | var e = f.pop()
|
15 | if (!e) e = f.pop()
|
16 | return e
|
17 | }}
|
18 | case "lru-cache": return function LRUCache () {
|
19 |
|
20 | var cache = {}
|
21 | var cnt = 0
|
22 | this.set = function (k, v) {
|
23 | cnt ++
|
24 | if (cnt >= 100) cache = {}
|
25 | cache[k] = v
|
26 | }
|
27 | this.get = function (k) { return cache[k] }
|
28 | }
|
29 | }
|
30 | }
|
31 | }
|
32 |
|
33 | minimatch.Minimatch = Minimatch
|
34 |
|
35 | var LRU = require("lru-cache")
|
36 | , cache = minimatch.cache = new LRU({max: 100})
|
37 | , GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
|
38 | , sigmund = require("sigmund")
|
39 |
|
40 | var path = require("path")
|
41 |
|
42 |
|
43 | , qmark = "[^/]"
|
44 |
|
45 |
|
46 | , star = qmark + "*?"
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | , twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?"
|
52 |
|
53 |
|
54 |
|
55 | , twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?"
|
56 |
|
57 |
|
58 | , reSpecials = charSet("().*{}+?[]^$\\!")
|
59 |
|
60 |
|
61 | function charSet (s) {
|
62 | return s.split("").reduce(function (set, c) {
|
63 | set[c] = true
|
64 | return set
|
65 | }, {})
|
66 | }
|
67 |
|
68 |
|
69 | var slashSplit = /\/+/
|
70 |
|
71 | minimatch.filter = filter
|
72 | function filter (pattern, options) {
|
73 | options = options || {}
|
74 | return function (p, i, list) {
|
75 | return minimatch(p, pattern, options)
|
76 | }
|
77 | }
|
78 |
|
79 | function ext (a, b) {
|
80 | a = a || {}
|
81 | b = b || {}
|
82 | var t = {}
|
83 | Object.keys(b).forEach(function (k) {
|
84 | t[k] = b[k]
|
85 | })
|
86 | Object.keys(a).forEach(function (k) {
|
87 | t[k] = a[k]
|
88 | })
|
89 | return t
|
90 | }
|
91 |
|
92 | minimatch.defaults = function (def) {
|
93 | if (!def || !Object.keys(def).length) return minimatch
|
94 |
|
95 | var orig = minimatch
|
96 |
|
97 | var m = function minimatch (p, pattern, options) {
|
98 | return orig.minimatch(p, pattern, ext(def, options))
|
99 | }
|
100 |
|
101 | m.Minimatch = function Minimatch (pattern, options) {
|
102 | return new orig.Minimatch(pattern, ext(def, options))
|
103 | }
|
104 |
|
105 | return m
|
106 | }
|
107 |
|
108 | Minimatch.defaults = function (def) {
|
109 | if (!def || !Object.keys(def).length) return Minimatch
|
110 | return minimatch.defaults(def).Minimatch
|
111 | }
|
112 |
|
113 |
|
114 | function minimatch (p, pattern, options) {
|
115 | if (typeof pattern !== "string") {
|
116 | throw new TypeError("glob pattern string required")
|
117 | }
|
118 |
|
119 | if (!options) options = {}
|
120 |
|
121 |
|
122 | if (!options.nocomment && pattern.charAt(0) === "#") {
|
123 | return false
|
124 | }
|
125 |
|
126 |
|
127 | if (pattern.trim() === "") return p === ""
|
128 |
|
129 | return new Minimatch(pattern, options).match(p)
|
130 | }
|
131 |
|
132 | function Minimatch (pattern, options) {
|
133 | if (!(this instanceof Minimatch)) {
|
134 | return new Minimatch(pattern, options, cache)
|
135 | }
|
136 |
|
137 | if (typeof pattern !== "string") {
|
138 | throw new TypeError("glob pattern string required")
|
139 | }
|
140 |
|
141 | if (!options) options = {}
|
142 | pattern = pattern.trim()
|
143 |
|
144 |
|
145 |
|
146 | if (platform === "win32") {
|
147 | pattern = pattern.split("\\").join("/")
|
148 | }
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | var cacheKey = pattern + "\n" + sigmund(options)
|
154 | var cached = minimatch.cache.get(cacheKey)
|
155 | if (cached) return cached
|
156 | minimatch.cache.set(cacheKey, this)
|
157 |
|
158 | this.options = options
|
159 | this.set = []
|
160 | this.pattern = pattern
|
161 | this.regexp = null
|
162 | this.negate = false
|
163 | this.comment = false
|
164 | this.empty = false
|
165 |
|
166 |
|
167 | this.make()
|
168 | }
|
169 |
|
170 | Minimatch.prototype.debug = function() {}
|
171 |
|
172 | Minimatch.prototype.make = make
|
173 | function make () {
|
174 |
|
175 | if (this._made) return
|
176 |
|
177 | var pattern = this.pattern
|
178 | var options = this.options
|
179 |
|
180 |
|
181 | if (!options.nocomment && pattern.charAt(0) === "#") {
|
182 | this.comment = true
|
183 | return
|
184 | }
|
185 | if (!pattern) {
|
186 | this.empty = true
|
187 | return
|
188 | }
|
189 |
|
190 |
|
191 | this.parseNegate()
|
192 |
|
193 |
|
194 | var set = this.globSet = this.braceExpand()
|
195 |
|
196 | if (options.debug) this.debug = console.error
|
197 |
|
198 | this.debug(this.pattern, set)
|
199 |
|
200 | // step 3: now we have a set, so turn each one into a series of path-portion
|
201 | // matching patterns.
|
202 | // These will be regexps, except in the case of "**", which is
|
203 | // set to the GLOBSTAR object for globstar behavior,
|
204 | // and will not contain any / characters
|
205 | set = this.globParts = set.map(function (s) {
|
206 | return s.split(slashSplit)
|
207 | })
|
208 |
|
209 | this.debug(this.pattern, set)
|
210 |
|
211 | // glob --> regexps
|
212 | set = set.map(function (s, si, set) {
|
213 | return s.map(this.parse, this)
|
214 | }, this)
|
215 |
|
216 | this.debug(this.pattern, set)
|
217 |
|
218 | // filter out everything that didn't compile properly.
|
219 | set = set.filter(function (s) {
|
220 | return -1 === s.indexOf(false)
|
221 | })
|
222 |
|
223 | this.debug(this.pattern, set)
|
224 |
|
225 | this.set = set
|
226 | }
|
227 |
|
228 | Minimatch.prototype.parseNegate = parseNegate
|
229 | function parseNegate () {
|
230 | var pattern = this.pattern
|
231 | , negate = false
|
232 | , options = this.options
|
233 | , negateOffset = 0
|
234 |
|
235 | if (options.nonegate) return
|
236 |
|
237 | for ( var i = 0, l = pattern.length
|
238 | ; i < l && pattern.charAt(i) === "!"
|
239 | ; i ++) {
|
240 | negate = !negate
|
241 | negateOffset ++
|
242 | }
|
243 |
|
244 | if (negateOffset) this.pattern = pattern.substr(negateOffset)
|
245 | this.negate = negate
|
246 | }
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | minimatch.braceExpand = function (pattern, options) {
|
259 | return new Minimatch(pattern, options).braceExpand()
|
260 | }
|
261 |
|
262 | Minimatch.prototype.braceExpand = braceExpand
|
263 | function braceExpand (pattern, options) {
|
264 | options = options || this.options
|
265 | pattern = typeof pattern === "undefined"
|
266 | ? this.pattern : pattern
|
267 |
|
268 | if (typeof pattern === "undefined") {
|
269 | throw new Error("undefined pattern")
|
270 | }
|
271 |
|
272 | if (options.nobrace ||
|
273 | !pattern.match(/\{.*\}/)) {
|
274 |
|
275 | return [pattern]
|
276 | }
|
277 |
|
278 | var escaping = false
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | if (pattern.charAt(0) !== "{") {
|
298 | this.debug(pattern)
|
299 | var prefix = null
|
300 | for (var i = 0, l = pattern.length; i < l; i ++) {
|
301 | var c = pattern.charAt(i)
|
302 | this.debug(i, c)
|
303 | if (c === "\\") {
|
304 | escaping = !escaping
|
305 | } else if (c === "{" && !escaping) {
|
306 | prefix = pattern.substr(0, i)
|
307 | break
|
308 | }
|
309 | }
|
310 |
|
311 |
|
312 | if (prefix === null) {
|
313 | this.debug("no sets")
|
314 | return [pattern]
|
315 | }
|
316 |
|
317 | var tail = braceExpand.call(this, pattern.substr(i), options)
|
318 | return tail.map(function (t) {
|
319 | return prefix + t
|
320 | })
|
321 | }
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 | var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/)
|
331 | if (numset) {
|
332 | this.debug("numset", numset[1], numset[2])
|
333 | var suf = braceExpand.call(this, pattern.substr(numset[0].length), options)
|
334 | , start = +numset[1]
|
335 | , end = +numset[2]
|
336 | , inc = start > end ? -1 : 1
|
337 | , set = []
|
338 | for (var i = start; i != (end + inc); i += inc) {
|
339 |
|
340 | for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
|
341 | set.push(i + suf[ii])
|
342 | }
|
343 | }
|
344 | return set
|
345 | }
|
346 |
|
347 | // ok, walk through the set
|
348 | // We hope, somewhat optimistically, that there
|
349 | // will be a } at the end.
|
350 | // If the closing brace isn't found, then the pattern is
|
351 | // interpreted as braceExpand("\\" + pattern) so that
|
352 | // the leading \{ will be interpreted literally.
|
353 | var i = 1
|
354 | , depth = 1
|
355 | , set = []
|
356 | , member = ""
|
357 | , sawEnd = false
|
358 | , escaping = false
|
359 |
|
360 | function addMember () {
|
361 | set.push(member)
|
362 | member = ""
|
363 | }
|
364 |
|
365 | this.debug("Entering for")
|
366 | FOR: for (i = 1, l = pattern.length; i < l; i ++) {
|
367 | var c = pattern.charAt(i)
|
368 | this.debug("", i, c)
|
369 |
|
370 | if (escaping) {
|
371 | escaping = false
|
372 | member += "\\" + c
|
373 | } else {
|
374 | switch (c) {
|
375 | case "\\":
|
376 | escaping = true
|
377 | continue
|
378 |
|
379 | case "{":
|
380 | depth ++
|
381 | member += "{"
|
382 | continue
|
383 |
|
384 | case "}":
|
385 | depth --
|
386 |
|
387 | if (depth === 0) {
|
388 | addMember()
|
389 |
|
390 | i ++
|
391 | break FOR
|
392 | } else {
|
393 | member += c
|
394 | continue
|
395 | }
|
396 |
|
397 | case ",":
|
398 | if (depth === 1) {
|
399 | addMember()
|
400 | } else {
|
401 | member += c
|
402 | }
|
403 | continue
|
404 |
|
405 | default:
|
406 | member += c
|
407 | continue
|
408 | }
|
409 | }
|
410 | }
|
411 |
|
412 |
|
413 |
|
414 |
|
415 | if (depth !== 0) {
|
416 | this.debug("didn't close", pattern)
|
417 | return braceExpand.call(this, "\\" + pattern, options)
|
418 | }
|
419 |
|
420 |
|
421 | this.debug("set", set)
|
422 | this.debug("suffix", pattern.substr(i))
|
423 | var suf = braceExpand.call(this, pattern.substr(i), options)
|
424 | // ["b", "c{d,e}","{f,g}h"] ->
|
425 |
|
426 | var addBraces = set.length === 1
|
427 | this.debug("set pre-expanded", set)
|
428 | set = set.map(function (p) {
|
429 | return braceExpand.call(this, p, options)
|
430 | }, this)
|
431 | this.debug("set expanded", set)
|
432 |
|
433 |
|
434 | // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
|
435 | // ["b", "cd", "ce", "fh", "gh"]
|
436 | set = set.reduce(function (l, r) {
|
437 | return l.concat(r)
|
438 | })
|
439 |
|
440 | if (addBraces) {
|
441 | set = set.map(function (s) {
|
442 | return "{" + s + "}"
|
443 | })
|
444 | }
|
445 |
|
446 |
|
447 | var ret = []
|
448 | for (var i = 0, l = set.length; i < l; i ++) {
|
449 | for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
|
450 | ret.push(set[i] + suf[ii])
|
451 | }
|
452 | }
|
453 | return ret
|
454 | }
|
455 |
|
456 | // parse a component of the expanded set.
|
457 | // At this point, no pattern may contain "/" in it
|
458 | // so we're going to return a 2d array, where each entry is the full
|
459 | // pattern, split on '/', and then turned into a regular expression.
|
460 | // A regexp is made at the end which joins each array with an
|
461 | // escaped /, and another full one which joins each regexp with |.
|
462 | //
|
463 | // Following the lead of Bash 4.1, note that "**" only has special meaning
|
464 | // when it is the *only* thing in a path portion. Otherwise, any series
|
465 | // of * is equivalent to a single *. Globstar behavior is enabled by
|
466 | // default, and can be disabled by setting options.noglobstar.
|
467 | Minimatch.prototype.parse = parse
|
468 | var SUBPARSE = {}
|
469 | function parse (pattern, isSub) {
|
470 | var options = this.options
|
471 |
|
472 |
|
473 | if (!options.noglobstar && pattern === "**") return GLOBSTAR
|
474 | if (pattern === "") return ""
|
475 |
|
476 | var re = ""
|
477 | , hasMagic = !!options.nocase
|
478 | , escaping = false
|
479 |
|
480 | , patternListStack = []
|
481 | , plType
|
482 | , stateChar
|
483 | , inClass = false
|
484 | , reClassStart = -1
|
485 | , classStart = -1
|
486 |
|
487 |
|
488 | , patternStart = pattern.charAt(0) === "." ? ""
|
489 |
|
490 | : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))"
|
491 | : "(?!\\.)"
|
492 | , self = this
|
493 |
|
494 | function clearStateChar () {
|
495 | if (stateChar) {
|
496 |
|
497 |
|
498 | switch (stateChar) {
|
499 | case "*":
|
500 | re += star
|
501 | hasMagic = true
|
502 | break
|
503 | case "?":
|
504 | re += qmark
|
505 | hasMagic = true
|
506 | break
|
507 | default:
|
508 | re += "\\"+stateChar
|
509 | break
|
510 | }
|
511 | self.debug('clearStateChar %j %j', stateChar, re)
|
512 | stateChar = false
|
513 | }
|
514 | }
|
515 |
|
516 | for ( var i = 0, len = pattern.length, c
|
517 | ; (i < len) && (c = pattern.charAt(i))
|
518 | ; i ++ ) {
|
519 |
|
520 | this.debug("%s\t%s %s %j", pattern, i, re, c)
|
521 |
|
522 |
|
523 | if (escaping && reSpecials[c]) {
|
524 | re += "\\" + c
|
525 | escaping = false
|
526 | continue
|
527 | }
|
528 |
|
529 | SWITCH: switch (c) {
|
530 | case "/":
|
531 |
|
532 |
|
533 | return false
|
534 |
|
535 | case "\\":
|
536 | clearStateChar()
|
537 | escaping = true
|
538 | continue
|
539 |
|
540 |
|
541 |
|
542 | case "?":
|
543 | case "*":
|
544 | case "+":
|
545 | case "@":
|
546 | case "!":
|
547 | this.debug("%s\t%s %s %j <-- stateChar", pattern, i, re, c)
|
548 |
|
549 |
|
550 |
|
551 | if (inClass) {
|
552 | this.debug(' in class')
|
553 | if (c === "!" && i === classStart + 1) c = "^"
|
554 | re += c
|
555 | continue
|
556 | }
|
557 |
|
558 |
|
559 |
|
560 |
|
561 | self.debug('call clearStateChar %j', stateChar)
|
562 | clearStateChar()
|
563 | stateChar = c
|
564 |
|
565 |
|
566 |
|
567 | if (options.noext) clearStateChar()
|
568 | continue
|
569 |
|
570 | case "(":
|
571 | if (inClass) {
|
572 | re += "("
|
573 | continue
|
574 | }
|
575 |
|
576 | if (!stateChar) {
|
577 | re += "\\("
|
578 | continue
|
579 | }
|
580 |
|
581 | plType = stateChar
|
582 | patternListStack.push({ type: plType
|
583 | , start: i - 1
|
584 | , reStart: re.length })
|
585 |
|
586 | re += stateChar === "!" ? "(?:(?!" : "(?:"
|
587 | this.debug('plType %j %j', stateChar, re)
|
588 | stateChar = false
|
589 | continue
|
590 |
|
591 | case ")":
|
592 | if (inClass || !patternListStack.length) {
|
593 | re += "\\)"
|
594 | continue
|
595 | }
|
596 |
|
597 | clearStateChar()
|
598 | hasMagic = true
|
599 | re += ")"
|
600 | plType = patternListStack.pop().type
|
601 |
|
602 |
|
603 | switch (plType) {
|
604 | case "!":
|
605 | re += "[^/]*?)"
|
606 | break
|
607 | case "?":
|
608 | case "+":
|
609 | case "*": re += plType
|
610 | case "@": break
|
611 | }
|
612 | continue
|
613 |
|
614 | case "|":
|
615 | if (inClass || !patternListStack.length || escaping) {
|
616 | re += "\\|"
|
617 | escaping = false
|
618 | continue
|
619 | }
|
620 |
|
621 | clearStateChar()
|
622 | re += "|"
|
623 | continue
|
624 |
|
625 |
|
626 | case "[":
|
627 |
|
628 | clearStateChar()
|
629 |
|
630 | if (inClass) {
|
631 | re += "\\" + c
|
632 | continue
|
633 | }
|
634 |
|
635 | inClass = true
|
636 | classStart = i
|
637 | reClassStart = re.length
|
638 | re += c
|
639 | continue
|
640 |
|
641 | case "]":
|
642 |
|
643 |
|
644 |
|
645 |
|
646 | if (i === classStart + 1 || !inClass) {
|
647 | re += "\\" + c
|
648 | escaping = false
|
649 | continue
|
650 | }
|
651 |
|
652 |
|
653 | hasMagic = true
|
654 | inClass = false
|
655 | re += c
|
656 | continue
|
657 |
|
658 | default:
|
659 |
|
660 | clearStateChar()
|
661 |
|
662 | if (escaping) {
|
663 |
|
664 | escaping = false
|
665 | } else if (reSpecials[c]
|
666 | && !(c === "^" && inClass)) {
|
667 | re += "\\"
|
668 | }
|
669 |
|
670 | re += c
|
671 |
|
672 | }
|
673 | }
|
674 |
|
675 |
|
676 |
|
677 |
|
678 | if (inClass) {
|
679 |
|
680 |
|
681 |
|
682 |
|
683 | var cs = pattern.substr(classStart + 1)
|
684 | , sp = this.parse(cs, SUBPARSE)
|
685 | re = re.substr(0, reClassStart) + "\\[" + sp[0]
|
686 | hasMagic = hasMagic || sp[1]
|
687 | }
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 | var pl
|
696 | while (pl = patternListStack.pop()) {
|
697 | var tail = re.slice(pl.reStart + 3)
|
698 |
|
699 | tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
|
700 | if (!$2) {
|
701 |
|
702 | $2 = "\\"
|
703 | }
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 | return $1 + $1 + $2 + "|"
|
712 | })
|
713 |
|
714 | this.debug("tail=%j\n %s", tail, tail)
|
715 | var t = pl.type === "*" ? star
|
716 | : pl.type === "?" ? qmark
|
717 | : "\\" + pl.type
|
718 |
|
719 | hasMagic = true
|
720 | re = re.slice(0, pl.reStart)
|
721 | + t + "\\("
|
722 | + tail
|
723 | }
|
724 |
|
725 |
|
726 | clearStateChar()
|
727 | if (escaping) {
|
728 |
|
729 | re += "\\\\"
|
730 | }
|
731 |
|
732 |
|
733 |
|
734 | var addPatternStart = false
|
735 | switch (re.charAt(0)) {
|
736 | case ".":
|
737 | case "[":
|
738 | case "(": addPatternStart = true
|
739 | }
|
740 |
|
741 |
|
742 |
|
743 |
|
744 | if (re !== "" && hasMagic) re = "(?=.)" + re
|
745 |
|
746 | if (addPatternStart) re = patternStart + re
|
747 |
|
748 |
|
749 | if (isSub === SUBPARSE) {
|
750 | return [ re, hasMagic ]
|
751 | }
|
752 |
|
753 |
|
754 |
|
755 |
|
756 | if (!hasMagic) {
|
757 | return globUnescape(pattern)
|
758 | }
|
759 |
|
760 | var flags = options.nocase ? "i" : ""
|
761 | , regExp = new RegExp("^" + re + "$", flags)
|
762 |
|
763 | regExp._glob = pattern
|
764 | regExp._src = re
|
765 |
|
766 | return regExp
|
767 | }
|
768 |
|
769 | minimatch.makeRe = function (pattern, options) {
|
770 | return new Minimatch(pattern, options || {}).makeRe()
|
771 | }
|
772 |
|
773 | Minimatch.prototype.makeRe = makeRe
|
774 | function makeRe () {
|
775 | if (this.regexp || this.regexp === false) return this.regexp
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 | var set = this.set
|
784 |
|
785 | if (!set.length) return this.regexp = false
|
786 | var options = this.options
|
787 |
|
788 | var twoStar = options.noglobstar ? star
|
789 | : options.dot ? twoStarDot
|
790 | : twoStarNoDot
|
791 | , flags = options.nocase ? "i" : ""
|
792 |
|
793 | var re = set.map(function (pattern) {
|
794 | return pattern.map(function (p) {
|
795 | return (p === GLOBSTAR) ? twoStar
|
796 | : (typeof p === "string") ? regExpEscape(p)
|
797 | : p._src
|
798 | }).join("\\\/")
|
799 | }).join("|")
|
800 |
|
801 |
|
802 |
|
803 | re = "^(?:" + re + ")$"
|
804 |
|
805 |
|
806 | if (this.negate) re = "^(?!" + re + ").*$"
|
807 |
|
808 | try {
|
809 | return this.regexp = new RegExp(re, flags)
|
810 | } catch (ex) {
|
811 | return this.regexp = false
|
812 | }
|
813 | }
|
814 |
|
815 | minimatch.match = function (list, pattern, options) {
|
816 | var mm = new Minimatch(pattern, options)
|
817 | list = list.filter(function (f) {
|
818 | return mm.match(f)
|
819 | })
|
820 | if (options.nonull && !list.length) {
|
821 | list.push(pattern)
|
822 | }
|
823 | return list
|
824 | }
|
825 |
|
826 | Minimatch.prototype.match = match
|
827 | function match (f, partial) {
|
828 | this.debug("match", f, this.pattern)
|
829 |
|
830 |
|
831 | if (this.comment) return false
|
832 | if (this.empty) return f === ""
|
833 |
|
834 | if (f === "/" && partial) return true
|
835 |
|
836 | var options = this.options
|
837 |
|
838 |
|
839 |
|
840 | if (platform === "win32") {
|
841 | f = f.split("\\").join("/")
|
842 | }
|
843 |
|
844 |
|
845 | f = f.split(slashSplit)
|
846 | this.debug(this.pattern, "split", f)
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 | var set = this.set
|
854 | this.debug(this.pattern, "set", set)
|
855 |
|
856 | var splitFile = path.basename(f.join("/")).split("/")
|
857 |
|
858 | for (var i = 0, l = set.length; i < l; i ++) {
|
859 | var pattern = set[i], file = f
|
860 | if (options.matchBase && pattern.length === 1) {
|
861 | file = splitFile
|
862 | }
|
863 | var hit = this.matchOne(file, pattern, partial)
|
864 | if (hit) {
|
865 | if (options.flipNegate) return true
|
866 | return !this.negate
|
867 | }
|
868 | }
|
869 |
|
870 |
|
871 |
|
872 | if (options.flipNegate) return false
|
873 | return this.negate
|
874 | }
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 | Minimatch.prototype.matchOne = function (file, pattern, partial) {
|
882 | var options = this.options
|
883 |
|
884 | this.debug("matchOne",
|
885 | { "this": this
|
886 | , file: file
|
887 | , pattern: pattern })
|
888 |
|
889 | this.debug("matchOne", file.length, pattern.length)
|
890 |
|
891 | for ( var fi = 0
|
892 | , pi = 0
|
893 | , fl = file.length
|
894 | , pl = pattern.length
|
895 | ; (fi < fl) && (pi < pl)
|
896 | ; fi ++, pi ++ ) {
|
897 |
|
898 | this.debug("matchOne loop")
|
899 | var p = pattern[pi]
|
900 | , f = file[fi]
|
901 |
|
902 | this.debug(pattern, p, f)
|
903 |
|
904 |
|
905 |
|
906 | if (p === false) return false
|
907 |
|
908 | if (p === GLOBSTAR) {
|
909 | this.debug('GLOBSTAR', [pattern, p, f])
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 | var fr = fi
|
934 | , pr = pi + 1
|
935 | if (pr === pl) {
|
936 | this.debug('** at the end')
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 | for ( ; fi < fl; fi ++) {
|
944 | if (file[fi] === "." || file[fi] === ".." ||
|
945 | (!options.dot && file[fi].charAt(0) === ".")) return false
|
946 | }
|
947 | return true
|
948 | }
|
949 |
|
950 |
|
951 | WHILE: while (fr < fl) {
|
952 | var swallowee = file[fr]
|
953 |
|
954 | this.debug('\nglobstar while',
|
955 | file, fr, pattern, pr, swallowee)
|
956 |
|
957 |
|
958 | if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
959 | this.debug('globstar found match!', fr, fl, swallowee)
|
960 |
|
961 | return true
|
962 | } else {
|
963 |
|
964 |
|
965 | if (swallowee === "." || swallowee === ".." ||
|
966 | (!options.dot && swallowee.charAt(0) === ".")) {
|
967 | this.debug("dot detected!", file, fr, pattern, pr)
|
968 | break WHILE
|
969 | }
|
970 |
|
971 |
|
972 | this.debug('globstar swallow a segment, and continue')
|
973 | fr ++
|
974 | }
|
975 | }
|
976 |
|
977 |
|
978 |
|
979 | if (partial) {
|
980 |
|
981 | this.debug("\n>>> no match, partial?", file, fr, pattern, pr)
|
982 | if (fr === fl) return true
|
983 | }
|
984 | return false
|
985 | }
|
986 |
|
987 |
|
988 |
|
989 |
|
990 | var hit
|
991 | if (typeof p === "string") {
|
992 | if (options.nocase) {
|
993 | hit = f.toLowerCase() === p.toLowerCase()
|
994 | } else {
|
995 | hit = f === p
|
996 | }
|
997 | this.debug("string match", p, f, hit)
|
998 | } else {
|
999 | hit = f.match(p)
|
1000 | this.debug("pattern match", p, f, hit)
|
1001 | }
|
1002 |
|
1003 | if (!hit) return false
|
1004 | }
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | if (fi === fl && pi === pl) {
|
1019 |
|
1020 |
|
1021 | return true
|
1022 | } else if (fi === fl) {
|
1023 |
|
1024 |
|
1025 |
|
1026 | return partial
|
1027 | } else if (pi === pl) {
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 | var emptyFileEnd = (fi === fl - 1) && (file[fi] === "")
|
1033 | return emptyFileEnd
|
1034 | }
|
1035 |
|
1036 |
|
1037 | throw new Error("wtf?")
|
1038 | }
|
1039 |
|
1040 |
|
1041 |
|
1042 | function globUnescape (s) {
|
1043 | return s.replace(/\\(.)/g, "$1")
|
1044 | }
|
1045 |
|
1046 |
|
1047 | function regExpEscape (s) {
|
1048 | return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
|
1049 | }
|
1050 |
|
1051 | })( typeof require === "function" ? require : null,
|
1052 | this,
|
1053 | typeof module === "object" ? module : null,
|
1054 | typeof process === "object" ? process.platform : "win32"
|
1055 | )
|