browser.js 31 KB

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