Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1const minimatch = module.exports = (p, pattern, options = {}) => {2 assertValidPattern(pattern)3 4 // shortcut: comments match nothing.5 if (!options.nocomment && pattern.charAt(0) === '#') {6 return false7 }8 9 return new Minimatch(pattern, options).match(p)10}11 12module.exports = minimatch13 14const path = require('./lib/path.js')15minimatch.sep = path.sep16 17const GLOBSTAR = Symbol('globstar **')18minimatch.GLOBSTAR = GLOBSTAR19const expand = require('brace-expansion')20 21const plTypes = {22 '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},23 '?': { open: '(?:', close: ')?' },24 '+': { open: '(?:', close: ')+' },25 '*': { open: '(?:', close: ')*' },26 '@': { open: '(?:', close: ')' }27}28 29// any single thing other than /30// don't need to escape / when using new RegExp()31const qmark = '[^/]'32 33// * => any number of characters34const star = qmark + '*?'35 36// ** when dots are allowed. Anything goes, except .. and .37// not (^ or / followed by one or two dots followed by $ or /),38// followed by anything, any number of times.39const twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'40 41// not a ^ or / followed by a dot,42// followed by anything, any number of times.43const twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'44 45// "abc" -> { a:true, b:true, c:true }46const charSet = s => s.split('').reduce((set, c) => {47 set[c] = true48 return set49}, {})50 51// characters that need to be escaped in RegExp.52const reSpecials = charSet('().*{}+?[]^$\\!')53 54// characters that indicate we have to add the pattern start55const addPatternStartSet = charSet('[.(')56 57// normalizes slashes.58const slashSplit = /\/+/59 60minimatch.filter = (pattern, options = {}) =>61 (p, i, list) => minimatch(p, pattern, options)62 63const ext = (a, b = {}) => {64 const t = {}65 Object.keys(a).forEach(k => t[k] = a[k])66 Object.keys(b).forEach(k => t[k] = b[k])67 return t68}69 70minimatch.defaults = def => {71 if (!def || typeof def !== 'object' || !Object.keys(def).length) {72 return minimatch73 }74 75 const orig = minimatch76 77 const m = (p, pattern, options) => orig(p, pattern, ext(def, options))78 m.Minimatch = class Minimatch extends orig.Minimatch {79 constructor (pattern, options) {80 super(pattern, ext(def, options))81 }82 }83 m.Minimatch.defaults = options => orig.defaults(ext(def, options)).Minimatch84 m.filter = (pattern, options) => orig.filter(pattern, ext(def, options))85 m.defaults = options => orig.defaults(ext(def, options))86 m.makeRe = (pattern, options) => orig.makeRe(pattern, ext(def, options))87 m.braceExpand = (pattern, options) => orig.braceExpand(pattern, ext(def, options))88 m.match = (list, pattern, options) => orig.match(list, pattern, ext(def, options))89 90 return m91}92 93 94 95 96 97// Brace expansion:98// a{b,c}d -> abd acd99// a{b,}c -> abc ac100// a{0..3}d -> a0d a1d a2d a3d101// a{b,c{d,e}f}g -> abg acdfg acefg102// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg103//104// Invalid sets are not expanded.105// a{2..}b -> a{2..}b106// a{b}c -> a{b}c107minimatch.braceExpand = (pattern, options) => braceExpand(pattern, options)108 109const braceExpand = (pattern, options = {}) => {110 assertValidPattern(pattern)111 112 // Thanks to Yeting Li <https://github.com/yetingli> for113 // improving this regexp to avoid a ReDOS vulnerability.114 if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {115 // shortcut. no need to expand.116 return [pattern]117 }118 119 return expand(pattern)120}121 122const MAX_PATTERN_LENGTH = 1024 * 64123const assertValidPattern = pattern => {124 if (typeof pattern !== 'string') {125 throw new TypeError('invalid pattern')126 }127 128 if (pattern.length > MAX_PATTERN_LENGTH) {129 throw new TypeError('pattern is too long')130 }131}132 133// parse a component of the expanded set.134// At this point, no pattern may contain "/" in it135// so we're going to return a 2d array, where each entry is the full136// pattern, split on '/', and then turned into a regular expression.137// A regexp is made at the end which joins each array with an138// escaped /, and another full one which joins each regexp with |.139//140// Following the lead of Bash 4.1, note that "**" only has special meaning141// when it is the *only* thing in a path portion. Otherwise, any series142// of * is equivalent to a single *. Globstar behavior is enabled by143// default, and can be disabled by setting options.noglobstar.144const SUBPARSE = Symbol('subparse')145 146minimatch.makeRe = (pattern, options) =>147 new Minimatch(pattern, options || {}).makeRe()148 149minimatch.match = (list, pattern, options = {}) => {150 const mm = new Minimatch(pattern, options)151 list = list.filter(f => mm.match(f))152 if (mm.options.nonull && !list.length) {153 list.push(pattern)154 }155 return list156}157 158// replace stuff like \* with *159const globUnescape = s => s.replace(/\\(.)/g, '$1')160const charUnescape = s => s.replace(/\\([^-\]])/g, '$1')161const regExpEscape = s => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')162const braExpEscape = s => s.replace(/[[\]\\]/g, '\\$&')163 164class Minimatch {165 constructor (pattern, options) {166 assertValidPattern(pattern)167 168 if (!options) options = {}169 170 this.options = options171 this.maxGlobstarRecursion = options.maxGlobstarRecursion !== undefined172 ? options.maxGlobstarRecursion : 200173 this.set = []174 this.pattern = pattern175 this.windowsPathsNoEscape = !!options.windowsPathsNoEscape ||176 options.allowWindowsEscape === false177 if (this.windowsPathsNoEscape) {178 this.pattern = this.pattern.replace(/\\/g, '/')179 }180 this.regexp = null181 this.negate = false182 this.comment = false183 this.empty = false184 this.partial = !!options.partial185 186 // make the set of regexps etc.187 this.make()188 }189 190 debug () {}191 192 make () {193 const pattern = this.pattern194 const options = this.options195 196 // empty patterns and comments match nothing.197 if (!options.nocomment && pattern.charAt(0) === '#') {198 this.comment = true199 return200 }201 if (!pattern) {202 this.empty = true203 return204 }205 206 // step 1: figure out negation, etc.207 this.parseNegate()208 209 // step 2: expand braces210 let set = this.globSet = this.braceExpand()211 212 if (options.debug) this.debug = (...args) => console.error(...args)213 214 this.debug(this.pattern, set)215 216 // step 3: now we have a set, so turn each one into a series of path-portion217 // matching patterns.218 // These will be regexps, except in the case of "**", which is219 // set to the GLOBSTAR object for globstar behavior,220 // and will not contain any / characters221 set = this.globParts = set.map(s => s.split(slashSplit))222 223 this.debug(this.pattern, set)224 225 // glob --> regexps226 set = set.map((s, si, set) => s.map(this.parse, this))227 228 this.debug(this.pattern, set)229 230 // filter out everything that didn't compile properly.231 set = set.filter(s => s.indexOf(false) === -1)232 233 this.debug(this.pattern, set)234 235 this.set = set236 }237 238 parseNegate () {239 if (this.options.nonegate) return240 241 const pattern = this.pattern242 let negate = false243 let negateOffset = 0244 245 for (let i = 0; i < pattern.length && pattern.charAt(i) === '!'; i++) {246 negate = !negate247 negateOffset++248 }249 250 if (negateOffset) this.pattern = pattern.slice(negateOffset)251 this.negate = negate252 }253 254 // set partial to true to test if, for example,255 // "/a/b" matches the start of "/*/b/*/d"256 // Partial means, if you run out of file before you run257 // out of pattern, then that's fine, as long as all258 // the parts match.259 matchOne (file, pattern, partial) {260 if (pattern.indexOf(GLOBSTAR) !== -1) {261 return this._matchGlobstar(file, pattern, partial, 0, 0)262 }263 return this._matchOne(file, pattern, partial, 0, 0)264 }265 266 _matchGlobstar (file, pattern, partial, fileIndex, patternIndex) {267 // find first globstar from patternIndex268 let firstgs = -1269 for (let i = patternIndex; i < pattern.length; i++) {270 if (pattern[i] === GLOBSTAR) { firstgs = i; break }271 }272 273 // find last globstar274 let lastgs = -1275 for (let i = pattern.length - 1; i >= 0; i--) {276 if (pattern[i] === GLOBSTAR) { lastgs = i; break }277 }278 279 const head = pattern.slice(patternIndex, firstgs)280 const body = partial ? pattern.slice(firstgs + 1) : pattern.slice(firstgs + 1, lastgs)281 const tail = partial ? [] : pattern.slice(lastgs + 1)282 283 // check the head284 if (head.length) {285 const fileHead = file.slice(fileIndex, fileIndex + head.length)286 if (!this._matchOne(fileHead, head, partial, 0, 0)) {287 return false288 }289 fileIndex += head.length290 }291 292 // check the tail293 let fileTailMatch = 0294 if (tail.length) {295 if (tail.length + fileIndex > file.length) return false296 297 const tailStart = file.length - tail.length298 if (this._matchOne(file, tail, partial, tailStart, 0)) {299 fileTailMatch = tail.length300 } else {301 // affordance for stuff like a/**/* matching a/b/302 if (file[file.length - 1] !== '' ||303 fileIndex + tail.length === file.length) {304 return false305 }306 if (!this._matchOne(file, tail, partial, tailStart - 1, 0)) {307 return false308 }309 fileTailMatch = tail.length + 1310 }311 }312 313 // if body is empty (single ** between head and tail)314 if (!body.length) {315 let sawSome = !!fileTailMatch316 for (let i = fileIndex; i < file.length - fileTailMatch; i++) {317 const f = String(file[i])318 sawSome = true319 if (f === '.' || f === '..' ||320 (!this.options.dot && f.charAt(0) === '.')) {321 return false322 }323 }324 return partial || sawSome325 }326 327 // split body into segments at each GLOBSTAR328 const bodySegments = [[[], 0]]329 let currentBody = bodySegments[0]330 let nonGsParts = 0331 const nonGsPartsSums = [0]332 for (const b of body) {333 if (b === GLOBSTAR) {334 nonGsPartsSums.push(nonGsParts)335 currentBody = [[], 0]336 bodySegments.push(currentBody)337 } else {338 currentBody[0].push(b)339 nonGsParts++340 }341 }342 343 let idx = bodySegments.length - 1344 const fileLength = file.length - fileTailMatch345 for (const b of bodySegments) {346 b[1] = fileLength - (nonGsPartsSums[idx--] + b[0].length)347 }348 349 return !!this._matchGlobStarBodySections(350 file, bodySegments, fileIndex, 0, partial, 0, !!fileTailMatch351 )352 }353 354 // return false for "nope, not matching"355 // return null for "not matching, cannot keep trying"356 _matchGlobStarBodySections (357 file, bodySegments, fileIndex, bodyIndex, partial, globStarDepth, sawTail358 ) {359 const bs = bodySegments[bodyIndex]360 if (!bs) {361 // just make sure there are no bad dots362 for (let i = fileIndex; i < file.length; i++) {363 sawTail = true364 const f = file[i]365 if (f === '.' || f === '..' ||366 (!this.options.dot && f.charAt(0) === '.')) {367 return false368 }369 }370 return sawTail371 }372 373 const [body, after] = bs374 while (fileIndex <= after) {375 const m = this._matchOne(376 file.slice(0, fileIndex + body.length),377 body,378 partial,379 fileIndex,380 0381 )382 // if limit exceeded, no match. intentional false negative,383 // acceptable break in correctness for security.384 if (m && globStarDepth < this.maxGlobstarRecursion) {385 const sub = this._matchGlobStarBodySections(386 file, bodySegments,387 fileIndex + body.length, bodyIndex + 1,388 partial, globStarDepth + 1, sawTail389 )390 if (sub !== false) {391 return sub392 }393 }394 const f = file[fileIndex]395 if (f === '.' || f === '..' ||396 (!this.options.dot && f.charAt(0) === '.')) {397 return false398 }399 fileIndex++400 }401 return partial || null402 }403 404 _matchOne (file, pattern, partial, fileIndex, patternIndex) {405 let fi, pi, fl, pl406 for (407 fi = fileIndex, pi = patternIndex, fl = file.length, pl = pattern.length408 ; (fi < fl) && (pi < pl)409 ; fi++, pi++410 ) {411 this.debug('matchOne loop')412 const p = pattern[pi]413 const f = file[fi]414 415 this.debug(pattern, p, f)416 417 // should be impossible.418 // some invalid regexp stuff in the set.419 /* istanbul ignore if */420 if (p === false || p === GLOBSTAR) return false421 422 // something other than **423 // non-magic patterns just have to match exactly424 // patterns with magic have been turned into regexps.425 let hit426 if (typeof p === 'string') {427 hit = f === p428 this.debug('string match', p, f, hit)429 } else {430 hit = f.match(p)431 this.debug('pattern match', p, f, hit)432 }433 434 if (!hit) return false435 }436 437 // now either we fell off the end of the pattern, or we're done.438 if (fi === fl && pi === pl) {439 // ran out of pattern and filename at the same time.440 // an exact hit!441 return true442 } else if (fi === fl) {443 // ran out of file, but still had pattern left.444 // this is ok if we're doing the match as part of445 // a glob fs traversal.446 return partial447 } else /* istanbul ignore else */ if (pi === pl) {448 // ran out of pattern, still have file left.449 // this is only acceptable if we're on the very last450 // empty segment of a file with a trailing slash.451 // a/* should match a/b/452 return (fi === fl - 1) && (file[fi] === '')453 }454 455 // should be unreachable.456 /* istanbul ignore next */457 throw new Error('wtf?')458 }459 460 braceExpand () {461 return braceExpand(this.pattern, this.options)462 }463 464 parse (pattern, isSub) {465 assertValidPattern(pattern)466 467 const options = this.options468 469 // shortcuts470 if (pattern === '**') {471 if (!options.noglobstar)472 return GLOBSTAR473 else474 pattern = '*'475 }476 if (pattern === '') return ''477 478 let re = ''479 let hasMagic = false480 let escaping = false481 // ? => one single character482 const patternListStack = []483 const negativeLists = []484 let stateChar485 let inClass = false486 let reClassStart = -1487 let classStart = -1488 let cs489 let pl490 let sp491 // . and .. never match anything that doesn't start with .,492 // even when options.dot is set. However, if the pattern493 // starts with ., then traversal patterns can match.494 let dotTravAllowed = pattern.charAt(0) === '.'495 let dotFileAllowed = options.dot || dotTravAllowed496 const patternStart = () =>497 dotTravAllowed498 ? ''499 : dotFileAllowed500 ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'501 : '(?!\\.)'502 const subPatternStart = (p) =>503 p.charAt(0) === '.'504 ? ''505 : options.dot506 ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'507 : '(?!\\.)'508 509 510 const clearStateChar = () => {511 if (stateChar) {512 // we had some state-tracking character513 // that wasn't consumed by this pass.514 switch (stateChar) {515 case '*':516 re += star517 hasMagic = true518 break519 case '?':520 re += qmark521 hasMagic = true522 break523 default:524 re += '\\' + stateChar525 break526 }527 this.debug('clearStateChar %j %j', stateChar, re)528 stateChar = false529 }530 }531 532 for (let i = 0, c; (i < pattern.length) && (c = pattern.charAt(i)); i++) {533 this.debug('%s\t%s %s %j', pattern, i, re, c)534 535 // skip over any that are escaped.536 if (escaping) {537 /* istanbul ignore next - completely not allowed, even escaped. */538 if (c === '/') {539 return false540 }541 542 if (reSpecials[c]) {543 re += '\\'544 }545 re += c546 escaping = false547 continue548 }549 550 switch (c) {551 /* istanbul ignore next */552 case '/': {553 // Should already be path-split by now.554 return false555 }556 557 case '\\':558 if (inClass && pattern.charAt(i + 1) === '-') {559 re += c560 continue561 }562 563 clearStateChar()564 escaping = true565 continue566 567 // the various stateChar values568 // for the "extglob" stuff.569 case '?':570 case '*':571 case '+':572 case '@':573 case '!':574 this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)575 576 // all of those are literals inside a class, except that577 // the glob [!a] means [^a] in regexp578 if (inClass) {579 this.debug(' in class')580 if (c === '!' && i === classStart + 1) c = '^'581 re += c582 continue583 }584 585 // coalesce consecutive non-globstar * characters586 if (c === '*' && stateChar === '*') continue587 588 // if we already have a stateChar, then it means589 // that there was something like ** or +? in there.590 // Handle the stateChar, then proceed with this one.591 this.debug('call clearStateChar %j', stateChar)592 clearStateChar()593 stateChar = c594 // if extglob is disabled, then +(asdf|foo) isn't a thing.595 // just clear the statechar *now*, rather than even diving into596 // the patternList stuff.597 if (options.noext) clearStateChar()598 continue599 600 case '(': {601 if (inClass) {602 re += '('603 continue604 }605 606 if (!stateChar) {607 re += '\\('608 continue609 }610 611 const plEntry = {612 type: stateChar,613 start: i - 1,614 reStart: re.length,615 open: plTypes[stateChar].open,616 close: plTypes[stateChar].close,617 }618 this.debug(this.pattern, '\t', plEntry)619 patternListStack.push(plEntry)620 // negation is (?:(?!(?:js)(?:<rest>))[^/]*)621 re += plEntry.open622 // next entry starts with a dot maybe?623 if (plEntry.start === 0 && plEntry.type !== '!') {624 dotTravAllowed = true625 re += subPatternStart(pattern.slice(i + 1))626 }627 this.debug('plType %j %j', stateChar, re)628 stateChar = false629 continue630 }631 632 case ')': {633 const plEntry = patternListStack[patternListStack.length - 1]634 if (inClass || !plEntry) {635 re += '\\)'636 continue637 }638 patternListStack.pop()639 640 // closing an extglob641 clearStateChar()642 hasMagic = true643 pl = plEntry644 // negation is (?:(?!js)[^/]*)645 // The others are (?:<pattern>)<type>646 re += pl.close647 if (pl.type === '!') {648 negativeLists.push(Object.assign(pl, { reEnd: re.length }))649 }650 continue651 }652 653 case '|': {654 const plEntry = patternListStack[patternListStack.length - 1]655 if (inClass || !plEntry) {656 re += '\\|'657 continue658 }659 660 clearStateChar()661 re += '|'662 // next subpattern can start with a dot?663 if (plEntry.start === 0 && plEntry.type !== '!') {664 dotTravAllowed = true665 re += subPatternStart(pattern.slice(i + 1))666 }667 continue668 }669 670 // these are mostly the same in regexp and glob671 case '[':672 // swallow any state-tracking char before the [673 clearStateChar()674 675 if (inClass) {676 re += '\\' + c677 continue678 }679 680 inClass = true681 classStart = i682 reClassStart = re.length683 re += c684 continue685 686 case ']':687 // a right bracket shall lose its special688 // meaning and represent itself in689 // a bracket expression if it occurs690 // first in the list. -- POSIX.2 2.8.3.2691 if (i === classStart + 1 || !inClass) {692 re += '\\' + c693 continue694 }695 696 // split where the last [ was, make sure we don't have697 // an invalid re. if so, re-walk the contents of the698 // would-be class to re-translate any characters that699 // were passed through as-is700 // TODO: It would probably be faster to determine this701 // without a try/catch and a new RegExp, but it's tricky702 // to do safely. For now, this is safe and works.703 cs = pattern.substring(classStart + 1, i)704 try {705 RegExp('[' + braExpEscape(charUnescape(cs)) + ']')706 // looks good, finish up the class.707 re += c708 } catch (er) {709 // out of order ranges in JS are errors, but in glob syntax,710 // they're just a range that matches nothing.711 re = re.substring(0, reClassStart) + '(?:$.)' // match nothing ever712 }713 hasMagic = true714 inClass = false715 continue716 717 default:718 // swallow any state char that wasn't consumed719 clearStateChar()720 721 if (reSpecials[c] && !(c === '^' && inClass)) {722 re += '\\'723 }724 725 re += c726 break727 728 } // switch729 } // for730 731 // handle the case where we left a class open.732 // "[abc" is valid, equivalent to "\[abc"733 if (inClass) {734 // split where the last [ was, and escape it735 // this is a huge pita. We now have to re-walk736 // the contents of the would-be class to re-translate737 // any characters that were passed through as-is738 cs = pattern.slice(classStart + 1)739 sp = this.parse(cs, SUBPARSE)740 re = re.substring(0, reClassStart) + '\\[' + sp[0]741 hasMagic = hasMagic || sp[1]742 }743 744 // handle the case where we had a +( thing at the *end*745 // of the pattern.746 // each pattern list stack adds 3 chars, and we need to go through747 // and escape any | chars that were passed through as-is for the regexp.748 // Go through and escape them, taking care not to double-escape any749 // | chars that were already escaped.750 for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {751 let tail752 tail = re.slice(pl.reStart + pl.open.length)753 this.debug('setting tail', re, pl)754 // maybe some even number of \, then maybe 1 \, followed by a |755 tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {756 /* istanbul ignore else - should already be done */757 if (!$2) {758 // the | isn't already escaped, so escape it.759 $2 = '\\'760 }761 762 // need to escape all those slashes *again*, without escaping the763 // one that we need for escaping the | character. As it works out,764 // escaping an even number of slashes can be done by simply repeating765 // it exactly after itself. That's why this trick works.766 //767 // I am sorry that you have to see this.768 return $1 + $1 + $2 + '|'769 })770 771 this.debug('tail=%j\n %s', tail, tail, pl, re)772 const t = pl.type === '*' ? star773 : pl.type === '?' ? qmark774 : '\\' + pl.type775 776 hasMagic = true777 re = re.slice(0, pl.reStart) + t + '\\(' + tail778 }779 780 // handle trailing things that only matter at the very end.781 clearStateChar()782 if (escaping) {783 // trailing \\784 re += '\\\\'785 }786 787 // only need to apply the nodot start if the re starts with788 // something that could conceivably capture a dot789 const addPatternStart = addPatternStartSet[re.charAt(0)]790 791 // Hack to work around lack of negative lookbehind in JS792 // A pattern like: *.!(x).!(y|z) needs to ensure that a name793 // like 'a.xyz.yz' doesn't match. So, the first negative794 // lookahead, has to look ALL the way ahead, to the end of795 // the pattern.796 for (let n = negativeLists.length - 1; n > -1; n--) {797 const nl = negativeLists[n]798 799 const nlBefore = re.slice(0, nl.reStart)800 const nlFirst = re.slice(nl.reStart, nl.reEnd - 8)801 let nlAfter = re.slice(nl.reEnd)802 const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter803 804 // Handle nested stuff like *(*.js|!(*.json)), where open parens805 // mean that we should *not* include the ) in the bit that is considered806 // "after" the negated section.807 const closeParensBefore = nlBefore.split(')').length808 const openParensBefore = nlBefore.split('(').length - closeParensBefore809 let cleanAfter = nlAfter810 for (let i = 0; i < openParensBefore; i++) {811 cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')812 }813 nlAfter = cleanAfter814 815 const dollar = nlAfter === '' && isSub !== SUBPARSE ? '(?:$|\\/)' : ''816 817 re = nlBefore + nlFirst + nlAfter + dollar + nlLast818 }819 820 // if the re is not "" at this point, then we need to make sure821 // it doesn't match against an empty path part.822 // Otherwise a/* will match a/, which it should not.823 if (re !== '' && hasMagic) {824 re = '(?=.)' + re825 }826 827 if (addPatternStart) {828 re = patternStart() + re829 }830 831 // parsing just a piece of a larger pattern.832 if (isSub === SUBPARSE) {833 return [re, hasMagic]834 }835 836 // if it's nocase, and the lcase/uppercase don't match, it's magic837 if (options.nocase && !hasMagic) {838 hasMagic = pattern.toUpperCase() !== pattern.toLowerCase()839 }840 841 // skip the regexp for non-magical patterns842 // unescape anything in it, though, so that it'll be843 // an exact match against a file etc.844 if (!hasMagic) {845 return globUnescape(pattern)846 }847 848 const flags = options.nocase ? 'i' : ''849 try {850 return Object.assign(new RegExp('^' + re + '$', flags), {851 _glob: pattern,852 _src: re,853 })854 } catch (er) /* istanbul ignore next - should be impossible */ {855 // If it was an invalid regular expression, then it can't match856 // anything. This trick looks for a character after the end of857 // the string, which is of course impossible, except in multi-line858 // mode, but it's not a /m regex.859 return new RegExp('$.')860 }861 }862 863 makeRe () {864 if (this.regexp || this.regexp === false) return this.regexp865 866 // at this point, this.set is a 2d array of partial867 // pattern strings, or "**".868 //869 // It's better to use .match(). This function shouldn't870 // be used, really, but it's pretty convenient sometimes,871 // when you just want to work with a regex.872 const set = this.set873 874 if (!set.length) {875 this.regexp = false876 return this.regexp877 }878 const options = this.options879 880 const twoStar = options.noglobstar ? star881 : options.dot ? twoStarDot882 : twoStarNoDot883 const flags = options.nocase ? 'i' : ''884 885 // coalesce globstars and regexpify non-globstar patterns886 // if it's the only item, then we just do one twoStar887 // if it's the first, and there are more, prepend (\/|twoStar\/)? to next888 // if it's the last, append (\/twoStar|) to previous889 // if it's in the middle, append (\/|\/twoStar\/) to previous890 // then filter out GLOBSTAR symbols891 let re = set.map(pattern => {892 pattern = pattern.map(p =>893 typeof p === 'string' ? regExpEscape(p)894 : p === GLOBSTAR ? GLOBSTAR895 : p._src896 ).reduce((set, p) => {897 if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) {898 set.push(p)899 }900 return set901 }, [])902 pattern.forEach((p, i) => {903 if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) {904 return905 }906 if (i === 0) {907 if (pattern.length > 1) {908 pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1]909 } else {910 pattern[i] = twoStar911 }912 } else if (i === pattern.length - 1) {913 pattern[i-1] += '(?:\\\/|' + twoStar + ')?'914 } else {915 pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1]916 pattern[i+1] = GLOBSTAR917 }918 })919 return pattern.filter(p => p !== GLOBSTAR).join('/')920 }).join('|')921 922 // must match entire pattern923 // ending in a * or ** will make it less strict.924 re = '^(?:' + re + ')$'925 926 // can match anything, as long as it's not this.927 if (this.negate) re = '^(?!' + re + ').*$'928 929 try {930 this.regexp = new RegExp(re, flags)931 } catch (ex) /* istanbul ignore next - should be impossible */ {932 this.regexp = false933 }934 return this.regexp935 }936 937 match (f, partial = this.partial) {938 this.debug('match', f, this.pattern)939 // short-circuit in the case of busted things.940 // comments, etc.941 if (this.comment) return false942 if (this.empty) return f === ''943 944 if (f === '/' && partial) return true945 946 const options = this.options947 948 // windows: need to use /, not \949 if (path.sep !== '/') {950 f = f.split(path.sep).join('/')951 }952 953 // treat the test path as a set of pathparts.954 f = f.split(slashSplit)955 this.debug(this.pattern, 'split', f)956 957 // just ONE of the pattern sets in this.set needs to match958 // in order for it to be valid. If negating, then just one959 // match means that we have failed.960 // Either way, return on the first hit.961 962 const set = this.set963 this.debug(this.pattern, 'set', set)964 965 // Find the basename of the path by looking for the last non-empty segment966 let filename967 for (let i = f.length - 1; i >= 0; i--) {968 filename = f[i]969 if (filename) break970 }971 972 for (let i = 0; i < set.length; i++) {973 const pattern = set[i]974 let file = f975 if (options.matchBase && pattern.length === 1) {976 file = [filename]977 }978 const hit = this.matchOne(file, pattern, partial)979 if (hit) {980 if (options.flipNegate) return true981 return !this.negate982 }983 }984 985 // didn't get any hits. this is success if it's a negative986 // pattern, failure otherwise.987 if (options.flipNegate) return false988 return this.negate989 }990 991 static defaults (def) {992 return minimatch.defaults(def).Minimatch993 }994}995 996minimatch.Minimatch = Minimatch997 