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