\n if (!this.preserveMultipleSlashes) {\n for (let i = 1; i < parts.length - 1; i++) {\n const p = parts[i];\n // don't squeeze out UNC patterns\n if (i === 1 && p === '' && parts[0] === '')\n continue;\n if (p === '.' || p === '') {\n didSomething = true;\n parts.splice(i, 1);\n i--;\n }\n }\n if (parts[0] === '.' &&\n parts.length === 2 &&\n (parts[1] === '.' || parts[1] === '')) {\n didSomething = true;\n parts.pop();\n }\n }\n // //../ -> /\n let dd = 0;\n while (-1 !== (dd = parts.indexOf('..', dd + 1))) {\n const p = parts[dd - 1];\n if (p && p !== '.' && p !== '..' && p !== '**') {\n didSomething = true;\n parts.splice(dd - 1, 2);\n dd -= 2;\n }\n }\n } while (didSomething);\n return parts.length === 0 ? [''] : parts;\n }\n // First phase: single-pattern processing\n // is 1 or more portions\n // is 1 or more portions\n // is any portion other than ., .., '', or **\n // is . or ''\n //\n // **/.. is *brutal* for filesystem walking performance, because\n // it effectively resets the recursive walk each time it occurs,\n // and ** cannot be reduced out by a .. pattern part like a regexp\n // or most strings (other than .., ., and '') can be.\n //\n // /**/..//
/ -> {/..//
/,/**//
/}\n // // -> /\n // //../ -> /\n // **/**/ -> **/\n //\n // **/*/ -> */**/ <== not valid because ** doesn't follow\n // this WOULD be allowed if ** did follow symlinks, or * didn't\n firstPhasePreProcess(globParts) {\n let didSomething = false;\n do {\n didSomething = false;\n // /**/..//
/ -> {/..//
/,/**//
/}\n for (let parts of globParts) {\n let gs = -1;\n while (-1 !== (gs = parts.indexOf('**', gs + 1))) {\n let gss = gs;\n while (parts[gss + 1] === '**') {\n // /**/**/ -> /**/\n gss++;\n }\n // eg, if gs is 2 and gss is 4, that means we have 3 **\n // parts, and can remove 2 of them.\n if (gss > gs) {\n parts.splice(gs + 1, gss - gs);\n }\n let next = parts[gs + 1];\n const p = parts[gs + 2];\n const p2 = parts[gs + 3];\n if (next !== '..')\n continue;\n if (!p ||\n p === '.' ||\n p === '..' ||\n !p2 ||\n p2 === '.' ||\n p2 === '..') {\n continue;\n }\n didSomething = true;\n // edit parts in place, and push the new one\n parts.splice(gs, 1);\n const other = parts.slice(0);\n other[gs] = '**';\n globParts.push(other);\n gs--;\n }\n // // -> /\n if (!this.preserveMultipleSlashes) {\n for (let i = 1; i < parts.length - 1; i++) {\n const p = parts[i];\n // don't squeeze out UNC patterns\n if (i === 1 && p === '' && parts[0] === '')\n continue;\n if (p === '.' || p === '') {\n didSomething = true;\n parts.splice(i, 1);\n i--;\n }\n }\n if (parts[0] === '.' &&\n parts.length === 2 &&\n (parts[1] === '.' || parts[1] === '')) {\n didSomething = true;\n parts.pop();\n }\n }\n // //../ -> /\n let dd = 0;\n while (-1 !== (dd = parts.indexOf('..', dd + 1))) {\n const p = parts[dd - 1];\n if (p && p !== '.' && p !== '..' && p !== '**') {\n didSomething = true;\n const needDot = dd === 1 && parts[dd + 1] === '**';\n const splin = needDot ? ['.'] : [];\n parts.splice(dd - 1, 2, ...splin);\n if (parts.length === 0)\n parts.push('');\n dd -= 2;\n }\n }\n }\n } while (didSomething);\n return globParts;\n }\n // second phase: multi-pattern dedupes\n // {/*/,//} -> /*/\n // {/,/} -> /\n // {/**/,/} -> /**/\n //\n // {/**/,/**//} -> /**/\n // ^-- not valid because ** doens't follow symlinks\n secondPhasePreProcess(globParts) {\n for (let i = 0; i < globParts.length - 1; i++) {\n for (let j = i + 1; j < globParts.length; j++) {\n const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);\n if (matched) {\n globParts[i] = [];\n globParts[j] = matched;\n break;\n }\n }\n }\n return globParts.filter(gs => gs.length);\n }\n partsMatch(a, b, emptyGSMatch = false) {\n let ai = 0;\n let bi = 0;\n let result = [];\n let which = '';\n while (ai < a.length && bi < b.length) {\n if (a[ai] === b[bi]) {\n result.push(which === 'b' ? b[bi] : a[ai]);\n ai++;\n bi++;\n }\n else if (emptyGSMatch && a[ai] === '**' && b[bi] === a[ai + 1]) {\n result.push(a[ai]);\n ai++;\n }\n else if (emptyGSMatch && b[bi] === '**' && a[ai] === b[bi + 1]) {\n result.push(b[bi]);\n bi++;\n }\n else if (a[ai] === '*' &&\n b[bi] &&\n (this.options.dot || !b[bi].startsWith('.')) &&\n b[bi] !== '**') {\n if (which === 'b')\n return false;\n which = 'a';\n result.push(a[ai]);\n ai++;\n bi++;\n }\n else if (b[bi] === '*' &&\n a[ai] &&\n (this.options.dot || !a[ai].startsWith('.')) &&\n a[ai] !== '**') {\n if (which === 'a')\n return false;\n which = 'b';\n result.push(b[bi]);\n ai++;\n bi++;\n }\n else {\n return false;\n }\n }\n // if we fall out of the loop, it means they two are identical\n // as long as their lengths match\n return a.length === b.length && result;\n }\n parseNegate() {\n if (this.nonegate)\n return;\n const pattern = this.pattern;\n let negate = false;\n let negateOffset = 0;\n for (let i = 0; i < pattern.length && pattern.charAt(i) === '!'; i++) {\n negate = !negate;\n negateOffset++;\n }\n if (negateOffset)\n this.pattern = pattern.slice(negateOffset);\n this.negate = negate;\n }\n // set partial to true to test if, for example,\n // \"/a/b\" matches the start of \"/*/b/*/d\"\n // Partial means, if you run out of file before you run\n // out of pattern, then that's fine, as long as all\n // the parts match.\n matchOne(file, pattern, partial = false) {\n const options = this.options;\n // UNC paths like //?/X:/... can match X:/... and vice versa\n // Drive letters in absolute drive or unc paths are always compared\n // case-insensitively.\n if (this.isWindows) {\n const fileDrive = typeof file[0] === 'string' && /^[a-z]:$/i.test(file[0]);\n const fileUNC = !fileDrive &&\n file[0] === '' &&\n file[1] === '' &&\n file[2] === '?' &&\n /^[a-z]:$/i.test(file[3]);\n const patternDrive = typeof pattern[0] === 'string' && /^[a-z]:$/i.test(pattern[0]);\n const patternUNC = !patternDrive &&\n pattern[0] === '' &&\n pattern[1] === '' &&\n pattern[2] === '?' &&\n typeof pattern[3] === 'string' &&\n /^[a-z]:$/i.test(pattern[3]);\n const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined;\n const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined;\n if (typeof fdi === 'number' && typeof pdi === 'number') {\n const [fd, pd] = [file[fdi], pattern[pdi]];\n if (fd.toLowerCase() === pd.toLowerCase()) {\n pattern[pdi] = fd;\n if (pdi > fdi) {\n pattern = pattern.slice(pdi);\n }\n else if (fdi > pdi) {\n file = file.slice(fdi);\n }\n }\n }\n }\n // resolve and reduce . and .. portions in the file as well.\n // dont' need to do the second phase, because it's only one string[]\n const { optimizationLevel = 1 } = this.options;\n if (optimizationLevel >= 2) {\n file = this.levelTwoFileOptimize(file);\n }\n this.debug('matchOne', this, { file, pattern });\n this.debug('matchOne', file.length, pattern.length);\n for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {\n this.debug('matchOne loop');\n var p = pattern[pi];\n var f = file[fi];\n this.debug(pattern, p, f);\n // should be impossible.\n // some invalid regexp stuff in the set.\n /* c8 ignore start */\n if (p === false) {\n return false;\n }\n /* c8 ignore stop */\n if (p === exports.GLOBSTAR) {\n this.debug('GLOBSTAR', [pattern, p, f]);\n // \"**\"\n // a/**/b/**/c would match the following:\n // a/b/x/y/z/c\n // a/x/y/z/b/c\n // a/b/x/b/x/c\n // a/b/c\n // To do this, take the rest of the pattern after\n // the **, and see if it would match the file remainder.\n // If so, return success.\n // If not, the ** \"swallows\" a segment, and try again.\n // This is recursively awful.\n //\n // a/**/b/**/c matching a/b/x/y/z/c\n // - a matches a\n // - doublestar\n // - matchOne(b/x/y/z/c, b/**/c)\n // - b matches b\n // - doublestar\n // - matchOne(x/y/z/c, c) -> no\n // - matchOne(y/z/c, c) -> no\n // - matchOne(z/c, c) -> no\n // - matchOne(c, c) yes, hit\n var fr = fi;\n var pr = pi + 1;\n if (pr === pl) {\n this.debug('** at the end');\n // a ** at the end will just swallow the rest.\n // We have found a match.\n // however, it will not swallow /.x, unless\n // options.dot is set.\n // . and .. are *never* matched by **, for explosively\n // exponential reasons.\n for (; fi < fl; fi++) {\n if (file[fi] === '.' ||\n file[fi] === '..' ||\n (!options.dot && file[fi].charAt(0) === '.'))\n return false;\n }\n return true;\n }\n // ok, let's see if we can swallow whatever we can.\n while (fr < fl) {\n var swallowee = file[fr];\n this.debug('\\nglobstar while', file, fr, pattern, pr, swallowee);\n // XXX remove this slice. Just pass the start index.\n if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {\n this.debug('globstar found match!', fr, fl, swallowee);\n // found a match.\n return true;\n }\n else {\n // can't swallow \".\" or \"..\" ever.\n // can only swallow \".foo\" when explicitly asked.\n if (swallowee === '.' ||\n swallowee === '..' ||\n (!options.dot && swallowee.charAt(0) === '.')) {\n this.debug('dot detected!', file, fr, pattern, pr);\n break;\n }\n // ** swallows a segment, and continue.\n this.debug('globstar swallow a segment, and continue');\n fr++;\n }\n }\n // no match was found.\n // However, in partial mode, we can't say this is necessarily over.\n /* c8 ignore start */\n if (partial) {\n // ran out of file\n this.debug('\\n>>> no match, partial?', file, fr, pattern, pr);\n if (fr === fl) {\n return true;\n }\n }\n /* c8 ignore stop */\n return false;\n }\n // something other than **\n // non-magic patterns just have to match exactly\n // patterns with magic have been turned into regexps.\n let hit;\n if (typeof p === 'string') {\n hit = f === p;\n this.debug('string match', p, f, hit);\n }\n else {\n hit = p.test(f);\n this.debug('pattern match', p, f, hit);\n }\n if (!hit)\n return false;\n }\n // Note: ending in / means that we'll get a final \"\"\n // at the end of the pattern. This can only match a\n // corresponding \"\" at the end of the file.\n // If the file ends in /, then it can only match a\n // a pattern that ends in /, unless the pattern just\n // doesn't have any more for it. But, a/b/ should *not*\n // match \"a/b/*\", even though \"\" matches against the\n // [^/]*? pattern, except in partial mode, where it might\n // simply not be reached yet.\n // However, a/b/ should still satisfy a/*\n // now either we fell off the end of the pattern, or we're done.\n if (fi === fl && pi === pl) {\n // ran out of pattern and filename at the same time.\n // an exact hit!\n return true;\n }\n else if (fi === fl) {\n // ran out of file, but still had pattern left.\n // this is ok if we're doing the match as part of\n // a glob fs traversal.\n return partial;\n }\n else if (pi === pl) {\n // ran out of pattern, still have file left.\n // this is only acceptable if we're on the very last\n // empty segment of a file with a trailing slash.\n // a/* should match a/b/\n return fi === fl - 1 && file[fi] === '';\n /* c8 ignore start */\n }\n else {\n // should be unreachable.\n throw new Error('wtf?');\n }\n /* c8 ignore stop */\n }\n braceExpand() {\n return (0, exports.braceExpand)(this.pattern, this.options);\n }\n parse(pattern) {\n (0, assert_valid_pattern_js_1.assertValidPattern)(pattern);\n const options = this.options;\n // shortcuts\n if (pattern === '**')\n return exports.GLOBSTAR;\n if (pattern === '')\n return '';\n // far and away, the most common glob pattern parts are\n // *, *.*, and *. Add a fast check method for those.\n let m;\n let fastTest = null;\n if ((m = pattern.match(starRE))) {\n fastTest = options.dot ? starTestDot : starTest;\n }\n else if ((m = pattern.match(starDotExtRE))) {\n fastTest = (options.nocase\n ? options.dot\n ? starDotExtTestNocaseDot\n : starDotExtTestNocase\n : options.dot\n ? starDotExtTestDot\n : starDotExtTest)(m[1]);\n }\n else if ((m = pattern.match(qmarksRE))) {\n fastTest = (options.nocase\n ? options.dot\n ? qmarksTestNocaseDot\n : qmarksTestNocase\n : options.dot\n ? qmarksTestDot\n : qmarksTest)(m);\n }\n else if ((m = pattern.match(starDotStarRE))) {\n fastTest = options.dot ? starDotStarTestDot : starDotStarTest;\n }\n else if ((m = pattern.match(dotStarRE))) {\n fastTest = dotStarTest;\n }\n const re = ast_js_1.AST.fromGlob(pattern, this.options).toMMPattern();\n if (fastTest && typeof re === 'object') {\n // Avoids overriding in frozen environments\n Reflect.defineProperty(re, 'test', { value: fastTest });\n }\n return re;\n }\n makeRe() {\n if (this.regexp || this.regexp === false)\n return this.regexp;\n // at this point, this.set is a 2d array of partial\n // pattern strings, or \"**\".\n //\n // It's better to use .match(). This function shouldn't\n // be used, really, but it's pretty convenient sometimes,\n // when you just want to work with a regex.\n const set = this.set;\n if (!set.length) {\n this.regexp = false;\n return this.regexp;\n }\n const options = this.options;\n const twoStar = options.noglobstar\n ? star\n : options.dot\n ? twoStarDot\n : twoStarNoDot;\n const flags = new Set(options.nocase ? ['i'] : []);\n // regexpify non-globstar patterns\n // if ** is only item, then we just do one twoStar\n // if ** is first, and there are more, prepend (\\/|twoStar\\/)? to next\n // if ** is last, append (\\/twoStar|) to previous\n // if ** is in the middle, append (\\/|\\/twoStar\\/) to previous\n // then filter out GLOBSTAR symbols\n let re = set\n .map(pattern => {\n const pp = pattern.map(p => {\n if (p instanceof RegExp) {\n for (const f of p.flags.split(''))\n flags.add(f);\n }\n return typeof p === 'string'\n ? regExpEscape(p)\n : p === exports.GLOBSTAR\n ? exports.GLOBSTAR\n : p._src;\n });\n pp.forEach((p, i) => {\n const next = pp[i + 1];\n const prev = pp[i - 1];\n if (p !== exports.GLOBSTAR || prev === exports.GLOBSTAR) {\n return;\n }\n if (prev === undefined) {\n if (next !== undefined && next !== exports.GLOBSTAR) {\n pp[i + 1] = '(?:\\\\/|' + twoStar + '\\\\/)?' + next;\n }\n else {\n pp[i] = twoStar;\n }\n }\n else if (next === undefined) {\n pp[i - 1] = prev + '(?:\\\\/|' + twoStar + ')?';\n }\n else if (next !== exports.GLOBSTAR) {\n pp[i - 1] = prev + '(?:\\\\/|\\\\/' + twoStar + '\\\\/)' + next;\n pp[i + 1] = exports.GLOBSTAR;\n }\n });\n return pp.filter(p => p !== exports.GLOBSTAR).join('/');\n })\n .join('|');\n // need to wrap in parens if we had more than one thing with |,\n // otherwise only the first will be anchored to ^ and the last to $\n const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', ''];\n // must match entire pattern\n // ending in a * or ** will make it less strict.\n re = '^' + open + re + close + '$';\n // can match anything, as long as it's not this.\n if (this.negate)\n re = '^(?!' + re + ').+$';\n try {\n this.regexp = new RegExp(re, [...flags].join(''));\n /* c8 ignore start */\n }\n catch (ex) {\n // should be impossible\n this.regexp = false;\n }\n /* c8 ignore stop */\n return this.regexp;\n }\n slashSplit(p) {\n // if p starts with // on windows, we preserve that\n // so that UNC paths aren't broken. Otherwise, any number of\n // / characters are coalesced into one, unless\n // preserveMultipleSlashes is set to true.\n if (this.preserveMultipleSlashes) {\n return p.split('/');\n }\n else if (this.isWindows && /^\\/\\/[^\\/]+/.test(p)) {\n // add an extra '' for the one we lose\n return ['', ...p.split(/\\/+/)];\n }\n else {\n return p.split(/\\/+/);\n }\n }\n match(f, partial = this.partial) {\n this.debug('match', f, this.pattern);\n // short-circuit in the case of busted things.\n // comments, etc.\n if (this.comment) {\n return false;\n }\n if (this.empty) {\n return f === '';\n }\n if (f === '/' && partial) {\n return true;\n }\n const options = this.options;\n // windows: need to use /, not \\\n if (this.isWindows) {\n f = f.split('\\\\').join('/');\n }\n // treat the test path as a set of pathparts.\n const ff = this.slashSplit(f);\n this.debug(this.pattern, 'split', ff);\n // just ONE of the pattern sets in this.set needs to match\n // in order for it to be valid. If negating, then just one\n // match means that we have failed.\n // Either way, return on the first hit.\n const set = this.set;\n this.debug(this.pattern, 'set', set);\n // Find the basename of the path by looking for the last non-empty segment\n let filename = ff[ff.length - 1];\n if (!filename) {\n for (let i = ff.length - 2; !filename && i >= 0; i--) {\n filename = ff[i];\n }\n }\n for (let i = 0; i < set.length; i++) {\n const pattern = set[i];\n let file = ff;\n if (options.matchBase && pattern.length === 1) {\n file = [filename];\n }\n const hit = this.matchOne(file, pattern, partial);\n if (hit) {\n if (options.flipNegate) {\n return true;\n }\n return !this.negate;\n }\n }\n // didn't get any hits. this is success if it's a negative\n // pattern, failure otherwise.\n if (options.flipNegate) {\n return false;\n }\n return this.negate;\n }\n static defaults(def) {\n return exports.minimatch.defaults(def).Minimatch;\n }\n}\nexports.Minimatch = Minimatch;\n/* c8 ignore start */\nvar ast_js_2 = require(\"./ast.js\");\nObject.defineProperty(exports, \"AST\", { enumerable: true, get: function () { return ast_js_2.AST; } });\nvar escape_js_2 = require(\"./escape.js\");\nObject.defineProperty(exports, \"escape\", { enumerable: true, get: function () { return escape_js_2.escape; } });\nvar unescape_js_2 = require(\"./unescape.js\");\nObject.defineProperty(exports, \"unescape\", { enumerable: true, get: function () { return unescape_js_2.unescape; } });\n/* c8 ignore stop */\nexports.minimatch.AST = ast_js_1.AST;\nexports.minimatch.Minimatch = Minimatch;\nexports.minimatch.escape = escape_js_1.escape;\nexports.minimatch.unescape = unescape_js_1.unescape;\n//# sourceMappingURL=index.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.unescape = void 0;\n/**\n * Un-escape a string that has been escaped with {@link escape}.\n *\n * If the {@link windowsPathsNoEscape} option is used, then square-brace\n * escapes are removed, but not backslash escapes. For example, it will turn\n * the string `'[*]'` into `*`, but it will not turn `'\\\\*'` into `'*'`,\n * becuase `\\` is a path separator in `windowsPathsNoEscape` mode.\n *\n * When `windowsPathsNoEscape` is not set, then both brace escapes and\n * backslash escapes are removed.\n *\n * Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped\n * or unescaped.\n */\nconst unescape = (s, { windowsPathsNoEscape = false, } = {}) => {\n return windowsPathsNoEscape\n ? s.replace(/\\[([^\\/\\\\])\\]/g, '$1')\n : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, '$1$2').replace(/\\\\([^\\/])/g, '$1');\n};\nexports.unescape = unescape;\n//# sourceMappingURL=unescape.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Minipass = exports.isWritable = exports.isReadable = exports.isStream = void 0;\nconst proc = typeof process === 'object' && process\n ? process\n : {\n stdout: null,\n stderr: null,\n };\nconst node_events_1 = require(\"node:events\");\nconst node_stream_1 = __importDefault(require(\"node:stream\"));\nconst node_string_decoder_1 = require(\"node:string_decoder\");\n/**\n * Return true if the argument is a Minipass stream, Node stream, or something\n * else that Minipass can interact with.\n */\nconst isStream = (s) => !!s &&\n typeof s === 'object' &&\n (s instanceof Minipass ||\n s instanceof node_stream_1.default ||\n (0, exports.isReadable)(s) ||\n (0, exports.isWritable)(s));\nexports.isStream = isStream;\n/**\n * Return true if the argument is a valid {@link Minipass.Readable}\n */\nconst isReadable = (s) => !!s &&\n typeof s === 'object' &&\n s instanceof node_events_1.EventEmitter &&\n typeof s.pipe === 'function' &&\n // node core Writable streams have a pipe() method, but it throws\n s.pipe !== node_stream_1.default.Writable.prototype.pipe;\nexports.isReadable = isReadable;\n/**\n * Return true if the argument is a valid {@link Minipass.Writable}\n */\nconst isWritable = (s) => !!s &&\n typeof s === 'object' &&\n s instanceof node_events_1.EventEmitter &&\n typeof s.write === 'function' &&\n typeof s.end === 'function';\nexports.isWritable = isWritable;\nconst EOF = Symbol('EOF');\nconst MAYBE_EMIT_END = Symbol('maybeEmitEnd');\nconst EMITTED_END = Symbol('emittedEnd');\nconst EMITTING_END = Symbol('emittingEnd');\nconst EMITTED_ERROR = Symbol('emittedError');\nconst CLOSED = Symbol('closed');\nconst READ = Symbol('read');\nconst FLUSH = Symbol('flush');\nconst FLUSHCHUNK = Symbol('flushChunk');\nconst ENCODING = Symbol('encoding');\nconst DECODER = Symbol('decoder');\nconst FLOWING = Symbol('flowing');\nconst PAUSED = Symbol('paused');\nconst RESUME = Symbol('resume');\nconst BUFFER = Symbol('buffer');\nconst PIPES = Symbol('pipes');\nconst BUFFERLENGTH = Symbol('bufferLength');\nconst BUFFERPUSH = Symbol('bufferPush');\nconst BUFFERSHIFT = Symbol('bufferShift');\nconst OBJECTMODE = Symbol('objectMode');\n// internal event when stream is destroyed\nconst DESTROYED = Symbol('destroyed');\n// internal event when stream has an error\nconst ERROR = Symbol('error');\nconst EMITDATA = Symbol('emitData');\nconst EMITEND = Symbol('emitEnd');\nconst EMITEND2 = Symbol('emitEnd2');\nconst ASYNC = Symbol('async');\nconst ABORT = Symbol('abort');\nconst ABORTED = Symbol('aborted');\nconst SIGNAL = Symbol('signal');\nconst DATALISTENERS = Symbol('dataListeners');\nconst DISCARDED = Symbol('discarded');\nconst defer = (fn) => Promise.resolve().then(fn);\nconst nodefer = (fn) => fn();\nconst isEndish = (ev) => ev === 'end' || ev === 'finish' || ev === 'prefinish';\nconst isArrayBufferLike = (b) => b instanceof ArrayBuffer ||\n (!!b &&\n typeof b === 'object' &&\n b.constructor &&\n b.constructor.name === 'ArrayBuffer' &&\n b.byteLength >= 0);\nconst isArrayBufferView = (b) => !Buffer.isBuffer(b) && ArrayBuffer.isView(b);\n/**\n * Internal class representing a pipe to a destination stream.\n *\n * @internal\n */\nclass Pipe {\n src;\n dest;\n opts;\n ondrain;\n constructor(src, dest, opts) {\n this.src = src;\n this.dest = dest;\n this.opts = opts;\n this.ondrain = () => src[RESUME]();\n this.dest.on('drain', this.ondrain);\n }\n unpipe() {\n this.dest.removeListener('drain', this.ondrain);\n }\n // only here for the prototype\n /* c8 ignore start */\n proxyErrors(_er) { }\n /* c8 ignore stop */\n end() {\n this.unpipe();\n if (this.opts.end)\n this.dest.end();\n }\n}\n/**\n * Internal class representing a pipe to a destination stream where\n * errors are proxied.\n *\n * @internal\n */\nclass PipeProxyErrors extends Pipe {\n unpipe() {\n this.src.removeListener('error', this.proxyErrors);\n super.unpipe();\n }\n constructor(src, dest, opts) {\n super(src, dest, opts);\n this.proxyErrors = er => dest.emit('error', er);\n src.on('error', this.proxyErrors);\n }\n}\nconst isObjectModeOptions = (o) => !!o.objectMode;\nconst isEncodingOptions = (o) => !o.objectMode && !!o.encoding && o.encoding !== 'buffer';\n/**\n * Main export, the Minipass class\n *\n * `RType` is the type of data emitted, defaults to Buffer\n *\n * `WType` is the type of data to be written, if RType is buffer or string,\n * then any {@link Minipass.ContiguousData} is allowed.\n *\n * `Events` is the set of event handler signatures that this object\n * will emit, see {@link Minipass.Events}\n */\nclass Minipass extends node_events_1.EventEmitter {\n [FLOWING] = false;\n [PAUSED] = false;\n [PIPES] = [];\n [BUFFER] = [];\n [OBJECTMODE];\n [ENCODING];\n [ASYNC];\n [DECODER];\n [EOF] = false;\n [EMITTED_END] = false;\n [EMITTING_END] = false;\n [CLOSED] = false;\n [EMITTED_ERROR] = null;\n [BUFFERLENGTH] = 0;\n [DESTROYED] = false;\n [SIGNAL];\n [ABORTED] = false;\n [DATALISTENERS] = 0;\n [DISCARDED] = false;\n /**\n * true if the stream can be written\n */\n writable = true;\n /**\n * true if the stream can be read\n */\n readable = true;\n /**\n * If `RType` is Buffer, then options do not need to be provided.\n * Otherwise, an options object must be provided to specify either\n * {@link Minipass.SharedOptions.objectMode} or\n * {@link Minipass.SharedOptions.encoding}, as appropriate.\n */\n constructor(...args) {\n const options = (args[0] ||\n {});\n super();\n if (options.objectMode && typeof options.encoding === 'string') {\n throw new TypeError('Encoding and objectMode may not be used together');\n }\n if (isObjectModeOptions(options)) {\n this[OBJECTMODE] = true;\n this[ENCODING] = null;\n }\n else if (isEncodingOptions(options)) {\n this[ENCODING] = options.encoding;\n this[OBJECTMODE] = false;\n }\n else {\n this[OBJECTMODE] = false;\n this[ENCODING] = null;\n }\n this[ASYNC] = !!options.async;\n this[DECODER] = this[ENCODING]\n ? new node_string_decoder_1.StringDecoder(this[ENCODING])\n : null;\n //@ts-ignore - private option for debugging and testing\n if (options && options.debugExposeBuffer === true) {\n Object.defineProperty(this, 'buffer', { get: () => this[BUFFER] });\n }\n //@ts-ignore - private option for debugging and testing\n if (options && options.debugExposePipes === true) {\n Object.defineProperty(this, 'pipes', { get: () => this[PIPES] });\n }\n const { signal } = options;\n if (signal) {\n this[SIGNAL] = signal;\n if (signal.aborted) {\n this[ABORT]();\n }\n else {\n signal.addEventListener('abort', () => this[ABORT]());\n }\n }\n }\n /**\n * The amount of data stored in the buffer waiting to be read.\n *\n * For Buffer strings, this will be the total byte length.\n * For string encoding streams, this will be the string character length,\n * according to JavaScript's `string.length` logic.\n * For objectMode streams, this is a count of the items waiting to be\n * emitted.\n */\n get bufferLength() {\n return this[BUFFERLENGTH];\n }\n /**\n * The `BufferEncoding` currently in use, or `null`\n */\n get encoding() {\n return this[ENCODING];\n }\n /**\n * @deprecated - This is a read only property\n */\n set encoding(_enc) {\n throw new Error('Encoding must be set at instantiation time');\n }\n /**\n * @deprecated - Encoding may only be set at instantiation time\n */\n setEncoding(_enc) {\n throw new Error('Encoding must be set at instantiation time');\n }\n /**\n * True if this is an objectMode stream\n */\n get objectMode() {\n return this[OBJECTMODE];\n }\n /**\n * @deprecated - This is a read-only property\n */\n set objectMode(_om) {\n throw new Error('objectMode must be set at instantiation time');\n }\n /**\n * true if this is an async stream\n */\n get ['async']() {\n return this[ASYNC];\n }\n /**\n * Set to true to make this stream async.\n *\n * Once set, it cannot be unset, as this would potentially cause incorrect\n * behavior. Ie, a sync stream can be made async, but an async stream\n * cannot be safely made sync.\n */\n set ['async'](a) {\n this[ASYNC] = this[ASYNC] || !!a;\n }\n // drop everything and get out of the flow completely\n [ABORT]() {\n this[ABORTED] = true;\n this.emit('abort', this[SIGNAL]?.reason);\n this.destroy(this[SIGNAL]?.reason);\n }\n /**\n * True if the stream has been aborted.\n */\n get aborted() {\n return this[ABORTED];\n }\n /**\n * No-op setter. Stream aborted status is set via the AbortSignal provided\n * in the constructor options.\n */\n set aborted(_) { }\n write(chunk, encoding, cb) {\n if (this[ABORTED])\n return false;\n if (this[EOF])\n throw new Error('write after end');\n if (this[DESTROYED]) {\n this.emit('error', Object.assign(new Error('Cannot call write after a stream was destroyed'), { code: 'ERR_STREAM_DESTROYED' }));\n return true;\n }\n if (typeof encoding === 'function') {\n cb = encoding;\n encoding = 'utf8';\n }\n if (!encoding)\n encoding = 'utf8';\n const fn = this[ASYNC] ? defer : nodefer;\n // convert array buffers and typed array views into buffers\n // at some point in the future, we may want to do the opposite!\n // leave strings and buffers as-is\n // anything is only allowed if in object mode, so throw\n if (!this[OBJECTMODE] && !Buffer.isBuffer(chunk)) {\n if (isArrayBufferView(chunk)) {\n //@ts-ignore - sinful unsafe type changing\n chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);\n }\n else if (isArrayBufferLike(chunk)) {\n //@ts-ignore - sinful unsafe type changing\n chunk = Buffer.from(chunk);\n }\n else if (typeof chunk !== 'string') {\n throw new Error('Non-contiguous data written to non-objectMode stream');\n }\n }\n // handle object mode up front, since it's simpler\n // this yields better performance, fewer checks later.\n if (this[OBJECTMODE]) {\n // maybe impossible?\n /* c8 ignore start */\n if (this[FLOWING] && this[BUFFERLENGTH] !== 0)\n this[FLUSH](true);\n /* c8 ignore stop */\n if (this[FLOWING])\n this.emit('data', chunk);\n else\n this[BUFFERPUSH](chunk);\n if (this[BUFFERLENGTH] !== 0)\n this.emit('readable');\n if (cb)\n fn(cb);\n return this[FLOWING];\n }\n // at this point the chunk is a buffer or string\n // don't buffer it up or send it to the decoder\n if (!chunk.length) {\n if (this[BUFFERLENGTH] !== 0)\n this.emit('readable');\n if (cb)\n fn(cb);\n return this[FLOWING];\n }\n // fast-path writing strings of same encoding to a stream with\n // an empty buffer, skipping the buffer/decoder dance\n if (typeof chunk === 'string' &&\n // unless it is a string already ready for us to use\n !(encoding === this[ENCODING] && !this[DECODER]?.lastNeed)) {\n //@ts-ignore - sinful unsafe type change\n chunk = Buffer.from(chunk, encoding);\n }\n if (Buffer.isBuffer(chunk) && this[ENCODING]) {\n //@ts-ignore - sinful unsafe type change\n chunk = this[DECODER].write(chunk);\n }\n // Note: flushing CAN potentially switch us into not-flowing mode\n if (this[FLOWING] && this[BUFFERLENGTH] !== 0)\n this[FLUSH](true);\n if (this[FLOWING])\n this.emit('data', chunk);\n else\n this[BUFFERPUSH](chunk);\n if (this[BUFFERLENGTH] !== 0)\n this.emit('readable');\n if (cb)\n fn(cb);\n return this[FLOWING];\n }\n /**\n * Low-level explicit read method.\n *\n * In objectMode, the argument is ignored, and one item is returned if\n * available.\n *\n * `n` is the number of bytes (or in the case of encoding streams,\n * characters) to consume. If `n` is not provided, then the entire buffer\n * is returned, or `null` is returned if no data is available.\n *\n * If `n` is greater that the amount of data in the internal buffer,\n * then `null` is returned.\n */\n read(n) {\n if (this[DESTROYED])\n return null;\n this[DISCARDED] = false;\n if (this[BUFFERLENGTH] === 0 ||\n n === 0 ||\n (n && n > this[BUFFERLENGTH])) {\n this[MAYBE_EMIT_END]();\n return null;\n }\n if (this[OBJECTMODE])\n n = null;\n if (this[BUFFER].length > 1 && !this[OBJECTMODE]) {\n // not object mode, so if we have an encoding, then RType is string\n // otherwise, must be Buffer\n this[BUFFER] = [\n (this[ENCODING]\n ? this[BUFFER].join('')\n : Buffer.concat(this[BUFFER], this[BUFFERLENGTH])),\n ];\n }\n const ret = this[READ](n || null, this[BUFFER][0]);\n this[MAYBE_EMIT_END]();\n return ret;\n }\n [READ](n, chunk) {\n if (this[OBJECTMODE])\n this[BUFFERSHIFT]();\n else {\n const c = chunk;\n if (n === c.length || n === null)\n this[BUFFERSHIFT]();\n else if (typeof c === 'string') {\n this[BUFFER][0] = c.slice(n);\n chunk = c.slice(0, n);\n this[BUFFERLENGTH] -= n;\n }\n else {\n this[BUFFER][0] = c.subarray(n);\n chunk = c.subarray(0, n);\n this[BUFFERLENGTH] -= n;\n }\n }\n this.emit('data', chunk);\n if (!this[BUFFER].length && !this[EOF])\n this.emit('drain');\n return chunk;\n }\n end(chunk, encoding, cb) {\n if (typeof chunk === 'function') {\n cb = chunk;\n chunk = undefined;\n }\n if (typeof encoding === 'function') {\n cb = encoding;\n encoding = 'utf8';\n }\n if (chunk !== undefined)\n this.write(chunk, encoding);\n if (cb)\n this.once('end', cb);\n this[EOF] = true;\n this.writable = false;\n // if we haven't written anything, then go ahead and emit,\n // even if we're not reading.\n // we'll re-emit if a new 'end' listener is added anyway.\n // This makes MP more suitable to write-only use cases.\n if (this[FLOWING] || !this[PAUSED])\n this[MAYBE_EMIT_END]();\n return this;\n }\n // don't let the internal resume be overwritten\n [RESUME]() {\n if (this[DESTROYED])\n return;\n if (!this[DATALISTENERS] && !this[PIPES].length) {\n this[DISCARDED] = true;\n }\n this[PAUSED] = false;\n this[FLOWING] = true;\n this.emit('resume');\n if (this[BUFFER].length)\n this[FLUSH]();\n else if (this[EOF])\n this[MAYBE_EMIT_END]();\n else\n this.emit('drain');\n }\n /**\n * Resume the stream if it is currently in a paused state\n *\n * If called when there are no pipe destinations or `data` event listeners,\n * this will place the stream in a \"discarded\" state, where all data will\n * be thrown away. The discarded state is removed if a pipe destination or\n * data handler is added, if pause() is called, or if any synchronous or\n * asynchronous iteration is started.\n */\n resume() {\n return this[RESUME]();\n }\n /**\n * Pause the stream\n */\n pause() {\n this[FLOWING] = false;\n this[PAUSED] = true;\n this[DISCARDED] = false;\n }\n /**\n * true if the stream has been forcibly destroyed\n */\n get destroyed() {\n return this[DESTROYED];\n }\n /**\n * true if the stream is currently in a flowing state, meaning that\n * any writes will be immediately emitted.\n */\n get flowing() {\n return this[FLOWING];\n }\n /**\n * true if the stream is currently in a paused state\n */\n get paused() {\n return this[PAUSED];\n }\n [BUFFERPUSH](chunk) {\n if (this[OBJECTMODE])\n this[BUFFERLENGTH] += 1;\n else\n this[BUFFERLENGTH] += chunk.length;\n this[BUFFER].push(chunk);\n }\n [BUFFERSHIFT]() {\n if (this[OBJECTMODE])\n this[BUFFERLENGTH] -= 1;\n else\n this[BUFFERLENGTH] -= this[BUFFER][0].length;\n return this[BUFFER].shift();\n }\n [FLUSH](noDrain = false) {\n do { } while (this[FLUSHCHUNK](this[BUFFERSHIFT]()) &&\n this[BUFFER].length);\n if (!noDrain && !this[BUFFER].length && !this[EOF])\n this.emit('drain');\n }\n [FLUSHCHUNK](chunk) {\n this.emit('data', chunk);\n return this[FLOWING];\n }\n /**\n * Pipe all data emitted by this stream into the destination provided.\n *\n * Triggers the flow of data.\n */\n pipe(dest, opts) {\n if (this[DESTROYED])\n return dest;\n this[DISCARDED] = false;\n const ended = this[EMITTED_END];\n opts = opts || {};\n if (dest === proc.stdout || dest === proc.stderr)\n opts.end = false;\n else\n opts.end = opts.end !== false;\n opts.proxyErrors = !!opts.proxyErrors;\n // piping an ended stream ends immediately\n if (ended) {\n if (opts.end)\n dest.end();\n }\n else {\n // \"as\" here just ignores the WType, which pipes don't care about,\n // since they're only consuming from us, and writing to the dest\n this[PIPES].push(!opts.proxyErrors\n ? new Pipe(this, dest, opts)\n : new PipeProxyErrors(this, dest, opts));\n if (this[ASYNC])\n defer(() => this[RESUME]());\n else\n this[RESUME]();\n }\n return dest;\n }\n /**\n * Fully unhook a piped destination stream.\n *\n * If the destination stream was the only consumer of this stream (ie,\n * there are no other piped destinations or `'data'` event listeners)\n * then the flow of data will stop until there is another consumer or\n * {@link Minipass#resume} is explicitly called.\n */\n unpipe(dest) {\n const p = this[PIPES].find(p => p.dest === dest);\n if (p) {\n if (this[PIPES].length === 1) {\n if (this[FLOWING] && this[DATALISTENERS] === 0) {\n this[FLOWING] = false;\n }\n this[PIPES] = [];\n }\n else\n this[PIPES].splice(this[PIPES].indexOf(p), 1);\n p.unpipe();\n }\n }\n /**\n * Alias for {@link Minipass#on}\n */\n addListener(ev, handler) {\n return this.on(ev, handler);\n }\n /**\n * Mostly identical to `EventEmitter.on`, with the following\n * behavior differences to prevent data loss and unnecessary hangs:\n *\n * - Adding a 'data' event handler will trigger the flow of data\n *\n * - Adding a 'readable' event handler when there is data waiting to be read\n * will cause 'readable' to be emitted immediately.\n *\n * - Adding an 'endish' event handler ('end', 'finish', etc.) which has\n * already passed will cause the event to be emitted immediately and all\n * handlers removed.\n *\n * - Adding an 'error' event handler after an error has been emitted will\n * cause the event to be re-emitted immediately with the error previously\n * raised.\n */\n on(ev, handler) {\n const ret = super.on(ev, handler);\n if (ev === 'data') {\n this[DISCARDED] = false;\n this[DATALISTENERS]++;\n if (!this[PIPES].length && !this[FLOWING]) {\n this[RESUME]();\n }\n }\n else if (ev === 'readable' && this[BUFFERLENGTH] !== 0) {\n super.emit('readable');\n }\n else if (isEndish(ev) && this[EMITTED_END]) {\n super.emit(ev);\n this.removeAllListeners(ev);\n }\n else if (ev === 'error' && this[EMITTED_ERROR]) {\n const h = handler;\n if (this[ASYNC])\n defer(() => h.call(this, this[EMITTED_ERROR]));\n else\n h.call(this, this[EMITTED_ERROR]);\n }\n return ret;\n }\n /**\n * Alias for {@link Minipass#off}\n */\n removeListener(ev, handler) {\n return this.off(ev, handler);\n }\n /**\n * Mostly identical to `EventEmitter.off`\n *\n * If a 'data' event handler is removed, and it was the last consumer\n * (ie, there are no pipe destinations or other 'data' event listeners),\n * then the flow of data will stop until there is another consumer or\n * {@link Minipass#resume} is explicitly called.\n */\n off(ev, handler) {\n const ret = super.off(ev, handler);\n // if we previously had listeners, and now we don't, and we don't\n // have any pipes, then stop the flow, unless it's been explicitly\n // put in a discarded flowing state via stream.resume().\n if (ev === 'data') {\n this[DATALISTENERS] = this.listeners('data').length;\n if (this[DATALISTENERS] === 0 &&\n !this[DISCARDED] &&\n !this[PIPES].length) {\n this[FLOWING] = false;\n }\n }\n return ret;\n }\n /**\n * Mostly identical to `EventEmitter.removeAllListeners`\n *\n * If all 'data' event handlers are removed, and they were the last consumer\n * (ie, there are no pipe destinations), then the flow of data will stop\n * until there is another consumer or {@link Minipass#resume} is explicitly\n * called.\n */\n removeAllListeners(ev) {\n const ret = super.removeAllListeners(ev);\n if (ev === 'data' || ev === undefined) {\n this[DATALISTENERS] = 0;\n if (!this[DISCARDED] && !this[PIPES].length) {\n this[FLOWING] = false;\n }\n }\n return ret;\n }\n /**\n * true if the 'end' event has been emitted\n */\n get emittedEnd() {\n return this[EMITTED_END];\n }\n [MAYBE_EMIT_END]() {\n if (!this[EMITTING_END] &&\n !this[EMITTED_END] &&\n !this[DESTROYED] &&\n this[BUFFER].length === 0 &&\n this[EOF]) {\n this[EMITTING_END] = true;\n this.emit('end');\n this.emit('prefinish');\n this.emit('finish');\n if (this[CLOSED])\n this.emit('close');\n this[EMITTING_END] = false;\n }\n }\n /**\n * Mostly identical to `EventEmitter.emit`, with the following\n * behavior differences to prevent data loss and unnecessary hangs:\n *\n * If the stream has been destroyed, and the event is something other\n * than 'close' or 'error', then `false` is returned and no handlers\n * are called.\n *\n * If the event is 'end', and has already been emitted, then the event\n * is ignored. If the stream is in a paused or non-flowing state, then\n * the event will be deferred until data flow resumes. If the stream is\n * async, then handlers will be called on the next tick rather than\n * immediately.\n *\n * If the event is 'close', and 'end' has not yet been emitted, then\n * the event will be deferred until after 'end' is emitted.\n *\n * If the event is 'error', and an AbortSignal was provided for the stream,\n * and there are no listeners, then the event is ignored, matching the\n * behavior of node core streams in the presense of an AbortSignal.\n *\n * If the event is 'finish' or 'prefinish', then all listeners will be\n * removed after emitting the event, to prevent double-firing.\n */\n emit(ev, ...args) {\n const data = args[0];\n // error and close are only events allowed after calling destroy()\n if (ev !== 'error' &&\n ev !== 'close' &&\n ev !== DESTROYED &&\n this[DESTROYED]) {\n return false;\n }\n else if (ev === 'data') {\n return !this[OBJECTMODE] && !data\n ? false\n : this[ASYNC]\n ? (defer(() => this[EMITDATA](data)), true)\n : this[EMITDATA](data);\n }\n else if (ev === 'end') {\n return this[EMITEND]();\n }\n else if (ev === 'close') {\n this[CLOSED] = true;\n // don't emit close before 'end' and 'finish'\n if (!this[EMITTED_END] && !this[DESTROYED])\n return false;\n const ret = super.emit('close');\n this.removeAllListeners('close');\n return ret;\n }\n else if (ev === 'error') {\n this[EMITTED_ERROR] = data;\n super.emit(ERROR, data);\n const ret = !this[SIGNAL] || this.listeners('error').length\n ? super.emit('error', data)\n : false;\n this[MAYBE_EMIT_END]();\n return ret;\n }\n else if (ev === 'resume') {\n const ret = super.emit('resume');\n this[MAYBE_EMIT_END]();\n return ret;\n }\n else if (ev === 'finish' || ev === 'prefinish') {\n const ret = super.emit(ev);\n this.removeAllListeners(ev);\n return ret;\n }\n // Some other unknown event\n const ret = super.emit(ev, ...args);\n this[MAYBE_EMIT_END]();\n return ret;\n }\n [EMITDATA](data) {\n for (const p of this[PIPES]) {\n if (p.dest.write(data) === false)\n this.pause();\n }\n const ret = this[DISCARDED] ? false : super.emit('data', data);\n this[MAYBE_EMIT_END]();\n return ret;\n }\n [EMITEND]() {\n if (this[EMITTED_END])\n return false;\n this[EMITTED_END] = true;\n this.readable = false;\n return this[ASYNC]\n ? (defer(() => this[EMITEND2]()), true)\n : this[EMITEND2]();\n }\n [EMITEND2]() {\n if (this[DECODER]) {\n const data = this[DECODER].end();\n if (data) {\n for (const p of this[PIPES]) {\n p.dest.write(data);\n }\n if (!this[DISCARDED])\n super.emit('data', data);\n }\n }\n for (const p of this[PIPES]) {\n p.end();\n }\n const ret = super.emit('end');\n this.removeAllListeners('end');\n return ret;\n }\n /**\n * Return a Promise that resolves to an array of all emitted data once\n * the stream ends.\n */\n async collect() {\n const buf = Object.assign([], {\n dataLength: 0,\n });\n if (!this[OBJECTMODE])\n buf.dataLength = 0;\n // set the promise first, in case an error is raised\n // by triggering the flow here.\n const p = this.promise();\n this.on('data', c => {\n buf.push(c);\n if (!this[OBJECTMODE])\n buf.dataLength += c.length;\n });\n await p;\n return buf;\n }\n /**\n * Return a Promise that resolves to the concatenation of all emitted data\n * once the stream ends.\n *\n * Not allowed on objectMode streams.\n */\n async concat() {\n if (this[OBJECTMODE]) {\n throw new Error('cannot concat in objectMode');\n }\n const buf = await this.collect();\n return (this[ENCODING]\n ? buf.join('')\n : Buffer.concat(buf, buf.dataLength));\n }\n /**\n * Return a void Promise that resolves once the stream ends.\n */\n async promise() {\n return new Promise((resolve, reject) => {\n this.on(DESTROYED, () => reject(new Error('stream destroyed')));\n this.on('error', er => reject(er));\n this.on('end', () => resolve());\n });\n }\n /**\n * Asynchronous `for await of` iteration.\n *\n * This will continue emitting all chunks until the stream terminates.\n */\n [Symbol.asyncIterator]() {\n // set this up front, in case the consumer doesn't call next()\n // right away.\n this[DISCARDED] = false;\n let stopped = false;\n const stop = async () => {\n this.pause();\n stopped = true;\n return { value: undefined, done: true };\n };\n const next = () => {\n if (stopped)\n return stop();\n const res = this.read();\n if (res !== null)\n return Promise.resolve({ done: false, value: res });\n if (this[EOF])\n return stop();\n let resolve;\n let reject;\n const onerr = (er) => {\n this.off('data', ondata);\n this.off('end', onend);\n this.off(DESTROYED, ondestroy);\n stop();\n reject(er);\n };\n const ondata = (value) => {\n this.off('error', onerr);\n this.off('end', onend);\n this.off(DESTROYED, ondestroy);\n this.pause();\n resolve({ value, done: !!this[EOF] });\n };\n const onend = () => {\n this.off('error', onerr);\n this.off('data', ondata);\n this.off(DESTROYED, ondestroy);\n stop();\n resolve({ done: true, value: undefined });\n };\n const ondestroy = () => onerr(new Error('stream destroyed'));\n return new Promise((res, rej) => {\n reject = rej;\n resolve = res;\n this.once(DESTROYED, ondestroy);\n this.once('error', onerr);\n this.once('end', onend);\n this.once('data', ondata);\n });\n };\n return {\n next,\n throw: stop,\n return: stop,\n [Symbol.asyncIterator]() {\n return this;\n },\n };\n }\n /**\n * Synchronous `for of` iteration.\n *\n * The iteration will terminate when the internal buffer runs out, even\n * if the stream has not yet terminated.\n */\n [Symbol.iterator]() {\n // set this up front, in case the consumer doesn't call next()\n // right away.\n this[DISCARDED] = false;\n let stopped = false;\n const stop = () => {\n this.pause();\n this.off(ERROR, stop);\n this.off(DESTROYED, stop);\n this.off('end', stop);\n stopped = true;\n return { done: true, value: undefined };\n };\n const next = () => {\n if (stopped)\n return stop();\n const value = this.read();\n return value === null ? stop() : { done: false, value };\n };\n this.once('end', stop);\n this.once(ERROR, stop);\n this.once(DESTROYED, stop);\n return {\n next,\n throw: stop,\n return: stop,\n [Symbol.iterator]() {\n return this;\n },\n };\n }\n /**\n * Destroy a stream, preventing it from being used for any further purpose.\n *\n * If the stream has a `close()` method, then it will be called on\n * destruction.\n *\n * After destruction, any attempt to write data, read data, or emit most\n * events will be ignored.\n *\n * If an error argument is provided, then it will be emitted in an\n * 'error' event.\n */\n destroy(er) {\n if (this[DESTROYED]) {\n if (er)\n this.emit('error', er);\n else\n this.emit(DESTROYED);\n return this;\n }\n this[DESTROYED] = true;\n this[DISCARDED] = true;\n // throw away all buffered data, it's never coming out\n this[BUFFER].length = 0;\n this[BUFFERLENGTH] = 0;\n const wc = this;\n if (typeof wc.close === 'function' && !this[CLOSED])\n wc.close();\n if (er)\n this.emit('error', er);\n // if no error to emit, still reject pending promises\n else\n this.emit(DESTROYED);\n return this;\n }\n /**\n * Alias for {@link isStream}\n *\n * Former export location, maintained for backwards compatibility.\n *\n * @deprecated\n */\n static get isStream() {\n return exports.isStream;\n }\n}\nexports.Minipass = Minipass;\n//# sourceMappingURL=index.js.map","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.PathScurry = exports.Path = exports.PathScurryDarwin = exports.PathScurryPosix = exports.PathScurryWin32 = exports.PathScurryBase = exports.PathPosix = exports.PathWin32 = exports.PathBase = exports.ChildrenCache = exports.ResolveCache = void 0;\nconst lru_cache_1 = require(\"lru-cache\");\nconst node_path_1 = require(\"node:path\");\nconst node_url_1 = require(\"node:url\");\nconst fs_1 = require(\"fs\");\nconst actualFS = __importStar(require(\"node:fs\"));\nconst realpathSync = fs_1.realpathSync.native;\n// TODO: test perf of fs/promises realpath vs realpathCB,\n// since the promises one uses realpath.native\nconst promises_1 = require(\"node:fs/promises\");\nconst minipass_1 = require(\"minipass\");\nconst defaultFS = {\n lstatSync: fs_1.lstatSync,\n readdir: fs_1.readdir,\n readdirSync: fs_1.readdirSync,\n readlinkSync: fs_1.readlinkSync,\n realpathSync,\n promises: {\n lstat: promises_1.lstat,\n readdir: promises_1.readdir,\n readlink: promises_1.readlink,\n realpath: promises_1.realpath,\n },\n};\n// if they just gave us require('fs') then use our default\nconst fsFromOption = (fsOption) => !fsOption || fsOption === defaultFS || fsOption === actualFS ?\n defaultFS\n : {\n ...defaultFS,\n ...fsOption,\n promises: {\n ...defaultFS.promises,\n ...(fsOption.promises || {}),\n },\n };\n// turn something like //?/c:/ into c:\\\nconst uncDriveRegexp = /^\\\\\\\\\\?\\\\([a-z]:)\\\\?$/i;\nconst uncToDrive = (rootPath) => rootPath.replace(/\\//g, '\\\\').replace(uncDriveRegexp, '$1\\\\');\n// windows paths are separated by either / or \\\nconst eitherSep = /[\\\\\\/]/;\nconst UNKNOWN = 0; // may not even exist, for all we know\nconst IFIFO = 0b0001;\nconst IFCHR = 0b0010;\nconst IFDIR = 0b0100;\nconst IFBLK = 0b0110;\nconst IFREG = 0b1000;\nconst IFLNK = 0b1010;\nconst IFSOCK = 0b1100;\nconst IFMT = 0b1111;\n// mask to unset low 4 bits\nconst IFMT_UNKNOWN = ~IFMT;\n// set after successfully calling readdir() and getting entries.\nconst READDIR_CALLED = 0b0000_0001_0000;\n// set after a successful lstat()\nconst LSTAT_CALLED = 0b0000_0010_0000;\n// set if an entry (or one of its parents) is definitely not a dir\nconst ENOTDIR = 0b0000_0100_0000;\n// set if an entry (or one of its parents) does not exist\n// (can also be set on lstat errors like EACCES or ENAMETOOLONG)\nconst ENOENT = 0b0000_1000_0000;\n// cannot have child entries -- also verify &IFMT is either IFDIR or IFLNK\n// set if we fail to readlink\nconst ENOREADLINK = 0b0001_0000_0000;\n// set if we know realpath() will fail\nconst ENOREALPATH = 0b0010_0000_0000;\nconst ENOCHILD = ENOTDIR | ENOENT | ENOREALPATH;\nconst TYPEMASK = 0b0011_1111_1111;\nconst entToType = (s) => s.isFile() ? IFREG\n : s.isDirectory() ? IFDIR\n : s.isSymbolicLink() ? IFLNK\n : s.isCharacterDevice() ? IFCHR\n : s.isBlockDevice() ? IFBLK\n : s.isSocket() ? IFSOCK\n : s.isFIFO() ? IFIFO\n : UNKNOWN;\n// normalize unicode path names\nconst normalizeCache = new Map();\nconst normalize = (s) => {\n const c = normalizeCache.get(s);\n if (c)\n return c;\n const n = s.normalize('NFKD');\n normalizeCache.set(s, n);\n return n;\n};\nconst normalizeNocaseCache = new Map();\nconst normalizeNocase = (s) => {\n const c = normalizeNocaseCache.get(s);\n if (c)\n return c;\n const n = normalize(s.toLowerCase());\n normalizeNocaseCache.set(s, n);\n return n;\n};\n/**\n * An LRUCache for storing resolved path strings or Path objects.\n * @internal\n */\nclass ResolveCache extends lru_cache_1.LRUCache {\n constructor() {\n super({ max: 256 });\n }\n}\nexports.ResolveCache = ResolveCache;\n// In order to prevent blowing out the js heap by allocating hundreds of\n// thousands of Path entries when walking extremely large trees, the \"children\"\n// in this tree are represented by storing an array of Path entries in an\n// LRUCache, indexed by the parent. At any time, Path.children() may return an\n// empty array, indicating that it doesn't know about any of its children, and\n// thus has to rebuild that cache. This is fine, it just means that we don't\n// benefit as much from having the cached entries, but huge directory walks\n// don't blow out the stack, and smaller ones are still as fast as possible.\n//\n//It does impose some complexity when building up the readdir data, because we\n//need to pass a reference to the children array that we started with.\n/**\n * an LRUCache for storing child entries.\n * @internal\n */\nclass ChildrenCache extends lru_cache_1.LRUCache {\n constructor(maxSize = 16 * 1024) {\n super({\n maxSize,\n // parent + children\n sizeCalculation: a => a.length + 1,\n });\n }\n}\nexports.ChildrenCache = ChildrenCache;\nconst setAsCwd = Symbol('PathScurry setAsCwd');\n/**\n * Path objects are sort of like a super-powered\n * {@link https://nodejs.org/docs/latest/api/fs.html#class-fsdirent fs.Dirent}\n *\n * Each one represents a single filesystem entry on disk, which may or may not\n * exist. It includes methods for reading various types of information via\n * lstat, readlink, and readdir, and caches all information to the greatest\n * degree possible.\n *\n * Note that fs operations that would normally throw will instead return an\n * \"empty\" value. This is in order to prevent excessive overhead from error\n * stack traces.\n */\nclass PathBase {\n /**\n * the basename of this path\n *\n * **Important**: *always* test the path name against any test string\n * usingthe {@link isNamed} method, and not by directly comparing this\n * string. Otherwise, unicode path strings that the system sees as identical\n * will not be properly treated as the same path, leading to incorrect\n * behavior and possible security issues.\n */\n name;\n /**\n * the Path entry corresponding to the path root.\n *\n * @internal\n */\n root;\n /**\n * All roots found within the current PathScurry family\n *\n * @internal\n */\n roots;\n /**\n * a reference to the parent path, or undefined in the case of root entries\n *\n * @internal\n */\n parent;\n /**\n * boolean indicating whether paths are compared case-insensitively\n * @internal\n */\n nocase;\n /**\n * boolean indicating that this path is the current working directory\n * of the PathScurry collection that contains it.\n */\n isCWD = false;\n // potential default fs override\n #fs;\n // Stats fields\n #dev;\n get dev() {\n return this.#dev;\n }\n #mode;\n get mode() {\n return this.#mode;\n }\n #nlink;\n get nlink() {\n return this.#nlink;\n }\n #uid;\n get uid() {\n return this.#uid;\n }\n #gid;\n get gid() {\n return this.#gid;\n }\n #rdev;\n get rdev() {\n return this.#rdev;\n }\n #blksize;\n get blksize() {\n return this.#blksize;\n }\n #ino;\n get ino() {\n return this.#ino;\n }\n #size;\n get size() {\n return this.#size;\n }\n #blocks;\n get blocks() {\n return this.#blocks;\n }\n #atimeMs;\n get atimeMs() {\n return this.#atimeMs;\n }\n #mtimeMs;\n get mtimeMs() {\n return this.#mtimeMs;\n }\n #ctimeMs;\n get ctimeMs() {\n return this.#ctimeMs;\n }\n #birthtimeMs;\n get birthtimeMs() {\n return this.#birthtimeMs;\n }\n #atime;\n get atime() {\n return this.#atime;\n }\n #mtime;\n get mtime() {\n return this.#mtime;\n }\n #ctime;\n get ctime() {\n return this.#ctime;\n }\n #birthtime;\n get birthtime() {\n return this.#birthtime;\n }\n #matchName;\n #depth;\n #fullpath;\n #fullpathPosix;\n #relative;\n #relativePosix;\n #type;\n #children;\n #linkTarget;\n #realpath;\n /**\n * This property is for compatibility with the Dirent class as of\n * Node v20, where Dirent['parentPath'] refers to the path of the\n * directory that was passed to readdir. For root entries, it's the path\n * to the entry itself.\n */\n get parentPath() {\n return (this.parent || this).fullpath();\n }\n /**\n * Deprecated alias for Dirent['parentPath'] Somewhat counterintuitively,\n * this property refers to the *parent* path, not the path object itself.\n */\n get path() {\n return this.parentPath;\n }\n /**\n * Do not create new Path objects directly. They should always be accessed\n * via the PathScurry class or other methods on the Path class.\n *\n * @internal\n */\n constructor(name, type = UNKNOWN, root, roots, nocase, children, opts) {\n this.name = name;\n this.#matchName = nocase ? normalizeNocase(name) : normalize(name);\n this.#type = type & TYPEMASK;\n this.nocase = nocase;\n this.roots = roots;\n this.root = root || this;\n this.#children = children;\n this.#fullpath = opts.fullpath;\n this.#relative = opts.relative;\n this.#relativePosix = opts.relativePosix;\n this.parent = opts.parent;\n if (this.parent) {\n this.#fs = this.parent.#fs;\n }\n else {\n this.#fs = fsFromOption(opts.fs);\n }\n }\n /**\n * Returns the depth of the Path object from its root.\n *\n * For example, a path at `/foo/bar` would have a depth of 2.\n */\n depth() {\n if (this.#depth !== undefined)\n return this.#depth;\n if (!this.parent)\n return (this.#depth = 0);\n return (this.#depth = this.parent.depth() + 1);\n }\n /**\n * @internal\n */\n childrenCache() {\n return this.#children;\n }\n /**\n * Get the Path object referenced by the string path, resolved from this Path\n */\n resolve(path) {\n if (!path) {\n return this;\n }\n const rootPath = this.getRootString(path);\n const dir = path.substring(rootPath.length);\n const dirParts = dir.split(this.splitSep);\n const result = rootPath ?\n this.getRoot(rootPath).#resolveParts(dirParts)\n : this.#resolveParts(dirParts);\n return result;\n }\n #resolveParts(dirParts) {\n let p = this;\n for (const part of dirParts) {\n p = p.child(part);\n }\n return p;\n }\n /**\n * Returns the cached children Path objects, if still available. If they\n * have fallen out of the cache, then returns an empty array, and resets the\n * READDIR_CALLED bit, so that future calls to readdir() will require an fs\n * lookup.\n *\n * @internal\n */\n children() {\n const cached = this.#children.get(this);\n if (cached) {\n return cached;\n }\n const children = Object.assign([], { provisional: 0 });\n this.#children.set(this, children);\n this.#type &= ~READDIR_CALLED;\n return children;\n }\n /**\n * Resolves a path portion and returns or creates the child Path.\n *\n * Returns `this` if pathPart is `''` or `'.'`, or `parent` if pathPart is\n * `'..'`.\n *\n * This should not be called directly. If `pathPart` contains any path\n * separators, it will lead to unsafe undefined behavior.\n *\n * Use `Path.resolve()` instead.\n *\n * @internal\n */\n child(pathPart, opts) {\n if (pathPart === '' || pathPart === '.') {\n return this;\n }\n if (pathPart === '..') {\n return this.parent || this;\n }\n // find the child\n const children = this.children();\n const name = this.nocase ? normalizeNocase(pathPart) : normalize(pathPart);\n for (const p of children) {\n if (p.#matchName === name) {\n return p;\n }\n }\n // didn't find it, create provisional child, since it might not\n // actually exist. If we know the parent isn't a dir, then\n // in fact it CAN'T exist.\n const s = this.parent ? this.sep : '';\n const fullpath = this.#fullpath ? this.#fullpath + s + pathPart : undefined;\n const pchild = this.newChild(pathPart, UNKNOWN, {\n ...opts,\n parent: this,\n fullpath,\n });\n if (!this.canReaddir()) {\n pchild.#type |= ENOENT;\n }\n // don't have to update provisional, because if we have real children,\n // then provisional is set to children.length, otherwise a lower number\n children.push(pchild);\n return pchild;\n }\n /**\n * The relative path from the cwd. If it does not share an ancestor with\n * the cwd, then this ends up being equivalent to the fullpath()\n */\n relative() {\n if (this.isCWD)\n return '';\n if (this.#relative !== undefined) {\n return this.#relative;\n }\n const name = this.name;\n const p = this.parent;\n if (!p) {\n return (this.#relative = this.name);\n }\n const pv = p.relative();\n return pv + (!pv || !p.parent ? '' : this.sep) + name;\n }\n /**\n * The relative path from the cwd, using / as the path separator.\n * If it does not share an ancestor with\n * the cwd, then this ends up being equivalent to the fullpathPosix()\n * On posix systems, this is identical to relative().\n */\n relativePosix() {\n if (this.sep === '/')\n return this.relative();\n if (this.isCWD)\n return '';\n if (this.#relativePosix !== undefined)\n return this.#relativePosix;\n const name = this.name;\n const p = this.parent;\n if (!p) {\n return (this.#relativePosix = this.fullpathPosix());\n }\n const pv = p.relativePosix();\n return pv + (!pv || !p.parent ? '' : '/') + name;\n }\n /**\n * The fully resolved path string for this Path entry\n */\n fullpath() {\n if (this.#fullpath !== undefined) {\n return this.#fullpath;\n }\n const name = this.name;\n const p = this.parent;\n if (!p) {\n return (this.#fullpath = this.name);\n }\n const pv = p.fullpath();\n const fp = pv + (!p.parent ? '' : this.sep) + name;\n return (this.#fullpath = fp);\n }\n /**\n * On platforms other than windows, this is identical to fullpath.\n *\n * On windows, this is overridden to return the forward-slash form of the\n * full UNC path.\n */\n fullpathPosix() {\n if (this.#fullpathPosix !== undefined)\n return this.#fullpathPosix;\n if (this.sep === '/')\n return (this.#fullpathPosix = this.fullpath());\n if (!this.parent) {\n const p = this.fullpath().replace(/\\\\/g, '/');\n if (/^[a-z]:\\//i.test(p)) {\n return (this.#fullpathPosix = `//?/${p}`);\n }\n else {\n return (this.#fullpathPosix = p);\n }\n }\n const p = this.parent;\n const pfpp = p.fullpathPosix();\n const fpp = pfpp + (!pfpp || !p.parent ? '' : '/') + this.name;\n return (this.#fullpathPosix = fpp);\n }\n /**\n * Is the Path of an unknown type?\n *\n * Note that we might know *something* about it if there has been a previous\n * filesystem operation, for example that it does not exist, or is not a\n * link, or whether it has child entries.\n */\n isUnknown() {\n return (this.#type & IFMT) === UNKNOWN;\n }\n isType(type) {\n return this[`is${type}`]();\n }\n getType() {\n return (this.isUnknown() ? 'Unknown'\n : this.isDirectory() ? 'Directory'\n : this.isFile() ? 'File'\n : this.isSymbolicLink() ? 'SymbolicLink'\n : this.isFIFO() ? 'FIFO'\n : this.isCharacterDevice() ? 'CharacterDevice'\n : this.isBlockDevice() ? 'BlockDevice'\n : /* c8 ignore start */ this.isSocket() ? 'Socket'\n : 'Unknown');\n /* c8 ignore stop */\n }\n /**\n * Is the Path a regular file?\n */\n isFile() {\n return (this.#type & IFMT) === IFREG;\n }\n /**\n * Is the Path a directory?\n */\n isDirectory() {\n return (this.#type & IFMT) === IFDIR;\n }\n /**\n * Is the path a character device?\n */\n isCharacterDevice() {\n return (this.#type & IFMT) === IFCHR;\n }\n /**\n * Is the path a block device?\n */\n isBlockDevice() {\n return (this.#type & IFMT) === IFBLK;\n }\n /**\n * Is the path a FIFO pipe?\n */\n isFIFO() {\n return (this.#type & IFMT) === IFIFO;\n }\n /**\n * Is the path a socket?\n */\n isSocket() {\n return (this.#type & IFMT) === IFSOCK;\n }\n /**\n * Is the path a symbolic link?\n */\n isSymbolicLink() {\n return (this.#type & IFLNK) === IFLNK;\n }\n /**\n * Return the entry if it has been subject of a successful lstat, or\n * undefined otherwise.\n *\n * Does not read the filesystem, so an undefined result *could* simply\n * mean that we haven't called lstat on it.\n */\n lstatCached() {\n return this.#type & LSTAT_CALLED ? this : undefined;\n }\n /**\n * Return the cached link target if the entry has been the subject of a\n * successful readlink, or undefined otherwise.\n *\n * Does not read the filesystem, so an undefined result *could* just mean we\n * don't have any cached data. Only use it if you are very sure that a\n * readlink() has been called at some point.\n */\n readlinkCached() {\n return this.#linkTarget;\n }\n /**\n * Returns the cached realpath target if the entry has been the subject\n * of a successful realpath, or undefined otherwise.\n *\n * Does not read the filesystem, so an undefined result *could* just mean we\n * don't have any cached data. Only use it if you are very sure that a\n * realpath() has been called at some point.\n */\n realpathCached() {\n return this.#realpath;\n }\n /**\n * Returns the cached child Path entries array if the entry has been the\n * subject of a successful readdir(), or [] otherwise.\n *\n * Does not read the filesystem, so an empty array *could* just mean we\n * don't have any cached data. Only use it if you are very sure that a\n * readdir() has been called recently enough to still be valid.\n */\n readdirCached() {\n const children = this.children();\n return children.slice(0, children.provisional);\n }\n /**\n * Return true if it's worth trying to readlink. Ie, we don't (yet) have\n * any indication that readlink will definitely fail.\n *\n * Returns false if the path is known to not be a symlink, if a previous\n * readlink failed, or if the entry does not exist.\n */\n canReadlink() {\n if (this.#linkTarget)\n return true;\n if (!this.parent)\n return false;\n // cases where it cannot possibly succeed\n const ifmt = this.#type & IFMT;\n return !((ifmt !== UNKNOWN && ifmt !== IFLNK) ||\n this.#type & ENOREADLINK ||\n this.#type & ENOENT);\n }\n /**\n * Return true if readdir has previously been successfully called on this\n * path, indicating that cachedReaddir() is likely valid.\n */\n calledReaddir() {\n return !!(this.#type & READDIR_CALLED);\n }\n /**\n * Returns true if the path is known to not exist. That is, a previous lstat\n * or readdir failed to verify its existence when that would have been\n * expected, or a parent entry was marked either enoent or enotdir.\n */\n isENOENT() {\n return !!(this.#type & ENOENT);\n }\n /**\n * Return true if the path is a match for the given path name. This handles\n * case sensitivity and unicode normalization.\n *\n * Note: even on case-sensitive systems, it is **not** safe to test the\n * equality of the `.name` property to determine whether a given pathname\n * matches, due to unicode normalization mismatches.\n *\n * Always use this method instead of testing the `path.name` property\n * directly.\n */\n isNamed(n) {\n return !this.nocase ?\n this.#matchName === normalize(n)\n : this.#matchName === normalizeNocase(n);\n }\n /**\n * Return the Path object corresponding to the target of a symbolic link.\n *\n * If the Path is not a symbolic link, or if the readlink call fails for any\n * reason, `undefined` is returned.\n *\n * Result is cached, and thus may be outdated if the filesystem is mutated.\n */\n async readlink() {\n const target = this.#linkTarget;\n if (target) {\n return target;\n }\n if (!this.canReadlink()) {\n return undefined;\n }\n /* c8 ignore start */\n // already covered by the canReadlink test, here for ts grumples\n if (!this.parent) {\n return undefined;\n }\n /* c8 ignore stop */\n try {\n const read = await this.#fs.promises.readlink(this.fullpath());\n const linkTarget = (await this.parent.realpath())?.resolve(read);\n if (linkTarget) {\n return (this.#linkTarget = linkTarget);\n }\n }\n catch (er) {\n this.#readlinkFail(er.code);\n return undefined;\n }\n }\n /**\n * Synchronous {@link PathBase.readlink}\n */\n readlinkSync() {\n const target = this.#linkTarget;\n if (target) {\n return target;\n }\n if (!this.canReadlink()) {\n return undefined;\n }\n /* c8 ignore start */\n // already covered by the canReadlink test, here for ts grumples\n if (!this.parent) {\n return undefined;\n }\n /* c8 ignore stop */\n try {\n const read = this.#fs.readlinkSync(this.fullpath());\n const linkTarget = this.parent.realpathSync()?.resolve(read);\n if (linkTarget) {\n return (this.#linkTarget = linkTarget);\n }\n }\n catch (er) {\n this.#readlinkFail(er.code);\n return undefined;\n }\n }\n #readdirSuccess(children) {\n // succeeded, mark readdir called bit\n this.#type |= READDIR_CALLED;\n // mark all remaining provisional children as ENOENT\n for (let p = children.provisional; p < children.length; p++) {\n const c = children[p];\n if (c)\n c.#markENOENT();\n }\n }\n #markENOENT() {\n // mark as UNKNOWN and ENOENT\n if (this.#type & ENOENT)\n return;\n this.#type = (this.#type | ENOENT) & IFMT_UNKNOWN;\n this.#markChildrenENOENT();\n }\n #markChildrenENOENT() {\n // all children are provisional and do not exist\n const children = this.children();\n children.provisional = 0;\n for (const p of children) {\n p.#markENOENT();\n }\n }\n #markENOREALPATH() {\n this.#type |= ENOREALPATH;\n this.#markENOTDIR();\n }\n // save the information when we know the entry is not a dir\n #markENOTDIR() {\n // entry is not a directory, so any children can't exist.\n // this *should* be impossible, since any children created\n // after it's been marked ENOTDIR should be marked ENOENT,\n // so it won't even get to this point.\n /* c8 ignore start */\n if (this.#type & ENOTDIR)\n return;\n /* c8 ignore stop */\n let t = this.#type;\n // this could happen if we stat a dir, then delete it,\n // then try to read it or one of its children.\n if ((t & IFMT) === IFDIR)\n t &= IFMT_UNKNOWN;\n this.#type = t | ENOTDIR;\n this.#markChildrenENOENT();\n }\n #readdirFail(code = '') {\n // markENOTDIR and markENOENT also set provisional=0\n if (code === 'ENOTDIR' || code === 'EPERM') {\n this.#markENOTDIR();\n }\n else if (code === 'ENOENT') {\n this.#markENOENT();\n }\n else {\n this.children().provisional = 0;\n }\n }\n #lstatFail(code = '') {\n // Windows just raises ENOENT in this case, disable for win CI\n /* c8 ignore start */\n if (code === 'ENOTDIR') {\n // already know it has a parent by this point\n const p = this.parent;\n p.#markENOTDIR();\n }\n else if (code === 'ENOENT') {\n /* c8 ignore stop */\n this.#markENOENT();\n }\n }\n #readlinkFail(code = '') {\n let ter = this.#type;\n ter |= ENOREADLINK;\n if (code === 'ENOENT')\n ter |= ENOENT;\n // windows gets a weird error when you try to readlink a file\n if (code === 'EINVAL' || code === 'UNKNOWN') {\n // exists, but not a symlink, we don't know WHAT it is, so remove\n // all IFMT bits.\n ter &= IFMT_UNKNOWN;\n }\n this.#type = ter;\n // windows just gets ENOENT in this case. We do cover the case,\n // just disabled because it's impossible on Windows CI\n /* c8 ignore start */\n if (code === 'ENOTDIR' && this.parent) {\n this.parent.#markENOTDIR();\n }\n /* c8 ignore stop */\n }\n #readdirAddChild(e, c) {\n return (this.#readdirMaybePromoteChild(e, c) ||\n this.#readdirAddNewChild(e, c));\n }\n #readdirAddNewChild(e, c) {\n // alloc new entry at head, so it's never provisional\n const type = entToType(e);\n const child = this.newChild(e.name, type, { parent: this });\n const ifmt = child.#type & IFMT;\n if (ifmt !== IFDIR && ifmt !== IFLNK && ifmt !== UNKNOWN) {\n child.#type |= ENOTDIR;\n }\n c.unshift(child);\n c.provisional++;\n return child;\n }\n #readdirMaybePromoteChild(e, c) {\n for (let p = c.provisional; p < c.length; p++) {\n const pchild = c[p];\n const name = this.nocase ? normalizeNocase(e.name) : normalize(e.name);\n if (name !== pchild.#matchName) {\n continue;\n }\n return this.#readdirPromoteChild(e, pchild, p, c);\n }\n }\n #readdirPromoteChild(e, p, index, c) {\n const v = p.name;\n // retain any other flags, but set ifmt from dirent\n p.#type = (p.#type & IFMT_UNKNOWN) | entToType(e);\n // case sensitivity fixing when we learn the true name.\n if (v !== e.name)\n p.name = e.name;\n // just advance provisional index (potentially off the list),\n // otherwise we have to splice/pop it out and re-insert at head\n if (index !== c.provisional) {\n if (index === c.length - 1)\n c.pop();\n else\n c.splice(index, 1);\n c.unshift(p);\n }\n c.provisional++;\n return p;\n }\n /**\n * Call lstat() on this Path, and update all known information that can be\n * determined.\n *\n * Note that unlike `fs.lstat()`, the returned value does not contain some\n * information, such as `mode`, `dev`, `nlink`, and `ino`. If that\n * information is required, you will need to call `fs.lstat` yourself.\n *\n * If the Path refers to a nonexistent file, or if the lstat call fails for\n * any reason, `undefined` is returned. Otherwise the updated Path object is\n * returned.\n *\n * Results are cached, and thus may be out of date if the filesystem is\n * mutated.\n */\n async lstat() {\n if ((this.#type & ENOENT) === 0) {\n try {\n this.#applyStat(await this.#fs.promises.lstat(this.fullpath()));\n return this;\n }\n catch (er) {\n this.#lstatFail(er.code);\n }\n }\n }\n /**\n * synchronous {@link PathBase.lstat}\n */\n lstatSync() {\n if ((this.#type & ENOENT) === 0) {\n try {\n this.#applyStat(this.#fs.lstatSync(this.fullpath()));\n return this;\n }\n catch (er) {\n this.#lstatFail(er.code);\n }\n }\n }\n #applyStat(st) {\n const { atime, atimeMs, birthtime, birthtimeMs, blksize, blocks, ctime, ctimeMs, dev, gid, ino, mode, mtime, mtimeMs, nlink, rdev, size, uid, } = st;\n this.#atime = atime;\n this.#atimeMs = atimeMs;\n this.#birthtime = birthtime;\n this.#birthtimeMs = birthtimeMs;\n this.#blksize = blksize;\n this.#blocks = blocks;\n this.#ctime = ctime;\n this.#ctimeMs = ctimeMs;\n this.#dev = dev;\n this.#gid = gid;\n this.#ino = ino;\n this.#mode = mode;\n this.#mtime = mtime;\n this.#mtimeMs = mtimeMs;\n this.#nlink = nlink;\n this.#rdev = rdev;\n this.#size = size;\n this.#uid = uid;\n const ifmt = entToType(st);\n // retain any other flags, but set the ifmt\n this.#type = (this.#type & IFMT_UNKNOWN) | ifmt | LSTAT_CALLED;\n if (ifmt !== UNKNOWN && ifmt !== IFDIR && ifmt !== IFLNK) {\n this.#type |= ENOTDIR;\n }\n }\n #onReaddirCB = [];\n #readdirCBInFlight = false;\n #callOnReaddirCB(children) {\n this.#readdirCBInFlight = false;\n const cbs = this.#onReaddirCB.slice();\n this.#onReaddirCB.length = 0;\n cbs.forEach(cb => cb(null, children));\n }\n /**\n * Standard node-style callback interface to get list of directory entries.\n *\n * If the Path cannot or does not contain any children, then an empty array\n * is returned.\n *\n * Results are cached, and thus may be out of date if the filesystem is\n * mutated.\n *\n * @param cb The callback called with (er, entries). Note that the `er`\n * param is somewhat extraneous, as all readdir() errors are handled and\n * simply result in an empty set of entries being returned.\n * @param allowZalgo Boolean indicating that immediately known results should\n * *not* be deferred with `queueMicrotask`. Defaults to `false`. Release\n * zalgo at your peril, the dark pony lord is devious and unforgiving.\n */\n readdirCB(cb, allowZalgo = false) {\n if (!this.canReaddir()) {\n if (allowZalgo)\n cb(null, []);\n else\n queueMicrotask(() => cb(null, []));\n return;\n }\n const children = this.children();\n if (this.calledReaddir()) {\n const c = children.slice(0, children.provisional);\n if (allowZalgo)\n cb(null, c);\n else\n queueMicrotask(() => cb(null, c));\n return;\n }\n // don't have to worry about zalgo at this point.\n this.#onReaddirCB.push(cb);\n if (this.#readdirCBInFlight) {\n return;\n }\n this.#readdirCBInFlight = true;\n // else read the directory, fill up children\n // de-provisionalize any provisional children.\n const fullpath = this.fullpath();\n this.#fs.readdir(fullpath, { withFileTypes: true }, (er, entries) => {\n if (er) {\n this.#readdirFail(er.code);\n children.provisional = 0;\n }\n else {\n // if we didn't get an error, we always get entries.\n //@ts-ignore\n for (const e of entries) {\n this.#readdirAddChild(e, children);\n }\n this.#readdirSuccess(children);\n }\n this.#callOnReaddirCB(children.slice(0, children.provisional));\n return;\n });\n }\n #asyncReaddirInFlight;\n /**\n * Return an array of known child entries.\n *\n * If the Path cannot or does not contain any children, then an empty array\n * is returned.\n *\n * Results are cached, and thus may be out of date if the filesystem is\n * mutated.\n */\n async readdir() {\n if (!this.canReaddir()) {\n return [];\n }\n const children = this.children();\n if (this.calledReaddir()) {\n return children.slice(0, children.provisional);\n }\n // else read the directory, fill up children\n // de-provisionalize any provisional children.\n const fullpath = this.fullpath();\n if (this.#asyncReaddirInFlight) {\n await this.#asyncReaddirInFlight;\n }\n else {\n /* c8 ignore start */\n let resolve = () => { };\n /* c8 ignore stop */\n this.#asyncReaddirInFlight = new Promise(res => (resolve = res));\n try {\n for (const e of await this.#fs.promises.readdir(fullpath, {\n withFileTypes: true,\n })) {\n this.#readdirAddChild(e, children);\n }\n this.#readdirSuccess(children);\n }\n catch (er) {\n this.#readdirFail(er.code);\n children.provisional = 0;\n }\n this.#asyncReaddirInFlight = undefined;\n resolve();\n }\n return children.slice(0, children.provisional);\n }\n /**\n * synchronous {@link PathBase.readdir}\n */\n readdirSync() {\n if (!this.canReaddir()) {\n return [];\n }\n const children = this.children();\n if (this.calledReaddir()) {\n return children.slice(0, children.provisional);\n }\n // else read the directory, fill up children\n // de-provisionalize any provisional children.\n const fullpath = this.fullpath();\n try {\n for (const e of this.#fs.readdirSync(fullpath, {\n withFileTypes: true,\n })) {\n this.#readdirAddChild(e, children);\n }\n this.#readdirSuccess(children);\n }\n catch (er) {\n this.#readdirFail(er.code);\n children.provisional = 0;\n }\n return children.slice(0, children.provisional);\n }\n canReaddir() {\n if (this.#type & ENOCHILD)\n return false;\n const ifmt = IFMT & this.#type;\n // we always set ENOTDIR when setting IFMT, so should be impossible\n /* c8 ignore start */\n if (!(ifmt === UNKNOWN || ifmt === IFDIR || ifmt === IFLNK)) {\n return false;\n }\n /* c8 ignore stop */\n return true;\n }\n shouldWalk(dirs, walkFilter) {\n return ((this.#type & IFDIR) === IFDIR &&\n !(this.#type & ENOCHILD) &&\n !dirs.has(this) &&\n (!walkFilter || walkFilter(this)));\n }\n /**\n * Return the Path object corresponding to path as resolved\n * by realpath(3).\n *\n * If the realpath call fails for any reason, `undefined` is returned.\n *\n * Result is cached, and thus may be outdated if the filesystem is mutated.\n * On success, returns a Path object.\n */\n async realpath() {\n if (this.#realpath)\n return this.#realpath;\n if ((ENOREALPATH | ENOREADLINK | ENOENT) & this.#type)\n return undefined;\n try {\n const rp = await this.#fs.promises.realpath(this.fullpath());\n return (this.#realpath = this.resolve(rp));\n }\n catch (_) {\n this.#markENOREALPATH();\n }\n }\n /**\n * Synchronous {@link realpath}\n */\n realpathSync() {\n if (this.#realpath)\n return this.#realpath;\n if ((ENOREALPATH | ENOREADLINK | ENOENT) & this.#type)\n return undefined;\n try {\n const rp = this.#fs.realpathSync(this.fullpath());\n return (this.#realpath = this.resolve(rp));\n }\n catch (_) {\n this.#markENOREALPATH();\n }\n }\n /**\n * Internal method to mark this Path object as the scurry cwd,\n * called by {@link PathScurry#chdir}\n *\n * @internal\n */\n [setAsCwd](oldCwd) {\n if (oldCwd === this)\n return;\n oldCwd.isCWD = false;\n this.isCWD = true;\n const changed = new Set([]);\n let rp = [];\n let p = this;\n while (p && p.parent) {\n changed.add(p);\n p.#relative = rp.join(this.sep);\n p.#relativePosix = rp.join('/');\n p = p.parent;\n rp.push('..');\n }\n // now un-memoize parents of old cwd\n p = oldCwd;\n while (p && p.parent && !changed.has(p)) {\n p.#relative = undefined;\n p.#relativePosix = undefined;\n p = p.parent;\n }\n }\n}\nexports.PathBase = PathBase;\n/**\n * Path class used on win32 systems\n *\n * Uses `'\\\\'` as the path separator for returned paths, either `'\\\\'` or `'/'`\n * as the path separator for parsing paths.\n */\nclass PathWin32 extends PathBase {\n /**\n * Separator for generating path strings.\n */\n sep = '\\\\';\n /**\n * Separator for parsing path strings.\n */\n splitSep = eitherSep;\n /**\n * Do not create new Path objects directly. They should always be accessed\n * via the PathScurry class or other methods on the Path class.\n *\n * @internal\n */\n constructor(name, type = UNKNOWN, root, roots, nocase, children, opts) {\n super(name, type, root, roots, nocase, children, opts);\n }\n /**\n * @internal\n */\n newChild(name, type = UNKNOWN, opts = {}) {\n return new PathWin32(name, type, this.root, this.roots, this.nocase, this.childrenCache(), opts);\n }\n /**\n * @internal\n */\n getRootString(path) {\n return node_path_1.win32.parse(path).root;\n }\n /**\n * @internal\n */\n getRoot(rootPath) {\n rootPath = uncToDrive(rootPath.toUpperCase());\n if (rootPath === this.root.name) {\n return this.root;\n }\n // ok, not that one, check if it matches another we know about\n for (const [compare, root] of Object.entries(this.roots)) {\n if (this.sameRoot(rootPath, compare)) {\n return (this.roots[rootPath] = root);\n }\n }\n // otherwise, have to create a new one.\n return (this.roots[rootPath] = new PathScurryWin32(rootPath, this).root);\n }\n /**\n * @internal\n */\n sameRoot(rootPath, compare = this.root.name) {\n // windows can (rarely) have case-sensitive filesystem, but\n // UNC and drive letters are always case-insensitive, and canonically\n // represented uppercase.\n rootPath = rootPath\n .toUpperCase()\n .replace(/\\//g, '\\\\')\n .replace(uncDriveRegexp, '$1\\\\');\n return rootPath === compare;\n }\n}\nexports.PathWin32 = PathWin32;\n/**\n * Path class used on all posix systems.\n *\n * Uses `'/'` as the path separator.\n */\nclass PathPosix extends PathBase {\n /**\n * separator for parsing path strings\n */\n splitSep = '/';\n /**\n * separator for generating path strings\n */\n sep = '/';\n /**\n * Do not create new Path objects directly. They should always be accessed\n * via the PathScurry class or other methods on the Path class.\n *\n * @internal\n */\n constructor(name, type = UNKNOWN, root, roots, nocase, children, opts) {\n super(name, type, root, roots, nocase, children, opts);\n }\n /**\n * @internal\n */\n getRootString(path) {\n return path.startsWith('/') ? '/' : '';\n }\n /**\n * @internal\n */\n getRoot(_rootPath) {\n return this.root;\n }\n /**\n * @internal\n */\n newChild(name, type = UNKNOWN, opts = {}) {\n return new PathPosix(name, type, this.root, this.roots, this.nocase, this.childrenCache(), opts);\n }\n}\nexports.PathPosix = PathPosix;\n/**\n * The base class for all PathScurry classes, providing the interface for path\n * resolution and filesystem operations.\n *\n * Typically, you should *not* instantiate this class directly, but rather one\n * of the platform-specific classes, or the exported {@link PathScurry} which\n * defaults to the current platform.\n */\nclass PathScurryBase {\n /**\n * The root Path entry for the current working directory of this Scurry\n */\n root;\n /**\n * The string path for the root of this Scurry's current working directory\n */\n rootPath;\n /**\n * A collection of all roots encountered, referenced by rootPath\n */\n roots;\n /**\n * The Path entry corresponding to this PathScurry's current working directory.\n */\n cwd;\n #resolveCache;\n #resolvePosixCache;\n #children;\n /**\n * Perform path comparisons case-insensitively.\n *\n * Defaults true on Darwin and Windows systems, false elsewhere.\n */\n nocase;\n #fs;\n /**\n * This class should not be instantiated directly.\n *\n * Use PathScurryWin32, PathScurryDarwin, PathScurryPosix, or PathScurry\n *\n * @internal\n */\n constructor(cwd = process.cwd(), pathImpl, sep, { nocase, childrenCacheSize = 16 * 1024, fs = defaultFS, } = {}) {\n this.#fs = fsFromOption(fs);\n if (cwd instanceof URL || cwd.startsWith('file://')) {\n cwd = (0, node_url_1.fileURLToPath)(cwd);\n }\n // resolve and split root, and then add to the store.\n // this is the only time we call path.resolve()\n const cwdPath = pathImpl.resolve(cwd);\n this.roots = Object.create(null);\n this.rootPath = this.parseRootPath(cwdPath);\n this.#resolveCache = new ResolveCache();\n this.#resolvePosixCache = new ResolveCache();\n this.#children = new ChildrenCache(childrenCacheSize);\n const split = cwdPath.substring(this.rootPath.length).split(sep);\n // resolve('/') leaves '', splits to [''], we don't want that.\n if (split.length === 1 && !split[0]) {\n split.pop();\n }\n /* c8 ignore start */\n if (nocase === undefined) {\n throw new TypeError('must provide nocase setting to PathScurryBase ctor');\n }\n /* c8 ignore stop */\n this.nocase = nocase;\n this.root = this.newRoot(this.#fs);\n this.roots[this.rootPath] = this.root;\n let prev = this.root;\n let len = split.length - 1;\n const joinSep = pathImpl.sep;\n let abs = this.rootPath;\n let sawFirst = false;\n for (const part of split) {\n const l = len--;\n prev = prev.child(part, {\n relative: new Array(l).fill('..').join(joinSep),\n relativePosix: new Array(l).fill('..').join('/'),\n fullpath: (abs += (sawFirst ? '' : joinSep) + part),\n });\n sawFirst = true;\n }\n this.cwd = prev;\n }\n /**\n * Get the depth of a provided path, string, or the cwd\n */\n depth(path = this.cwd) {\n if (typeof path === 'string') {\n path = this.cwd.resolve(path);\n }\n return path.depth();\n }\n /**\n * Return the cache of child entries. Exposed so subclasses can create\n * child Path objects in a platform-specific way.\n *\n * @internal\n */\n childrenCache() {\n return this.#children;\n }\n /**\n * Resolve one or more path strings to a resolved string\n *\n * Same interface as require('path').resolve.\n *\n * Much faster than path.resolve() when called multiple times for the same\n * path, because the resolved Path objects are cached. Much slower\n * otherwise.\n */\n resolve(...paths) {\n // first figure out the minimum number of paths we have to test\n // we always start at cwd, but any absolutes will bump the start\n let r = '';\n for (let i = paths.length - 1; i >= 0; i--) {\n const p = paths[i];\n if (!p || p === '.')\n continue;\n r = r ? `${p}/${r}` : p;\n if (this.isAbsolute(p)) {\n break;\n }\n }\n const cached = this.#resolveCache.get(r);\n if (cached !== undefined) {\n return cached;\n }\n const result = this.cwd.resolve(r).fullpath();\n this.#resolveCache.set(r, result);\n return result;\n }\n /**\n * Resolve one or more path strings to a resolved string, returning\n * the posix path. Identical to .resolve() on posix systems, but on\n * windows will return a forward-slash separated UNC path.\n *\n * Same interface as require('path').resolve.\n *\n * Much faster than path.resolve() when called multiple times for the same\n * path, because the resolved Path objects are cached. Much slower\n * otherwise.\n */\n resolvePosix(...paths) {\n // first figure out the minimum number of paths we have to test\n // we always start at cwd, but any absolutes will bump the start\n let r = '';\n for (let i = paths.length - 1; i >= 0; i--) {\n const p = paths[i];\n if (!p || p === '.')\n continue;\n r = r ? `${p}/${r}` : p;\n if (this.isAbsolute(p)) {\n break;\n }\n }\n const cached = this.#resolvePosixCache.get(r);\n if (cached !== undefined) {\n return cached;\n }\n const result = this.cwd.resolve(r).fullpathPosix();\n this.#resolvePosixCache.set(r, result);\n return result;\n }\n /**\n * find the relative path from the cwd to the supplied path string or entry\n */\n relative(entry = this.cwd) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n return entry.relative();\n }\n /**\n * find the relative path from the cwd to the supplied path string or\n * entry, using / as the path delimiter, even on Windows.\n */\n relativePosix(entry = this.cwd) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n return entry.relativePosix();\n }\n /**\n * Return the basename for the provided string or Path object\n */\n basename(entry = this.cwd) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n return entry.name;\n }\n /**\n * Return the dirname for the provided string or Path object\n */\n dirname(entry = this.cwd) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n return (entry.parent || entry).fullpath();\n }\n async readdir(entry = this.cwd, opts = {\n withFileTypes: true,\n }) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes } = opts;\n if (!entry.canReaddir()) {\n return [];\n }\n else {\n const p = await entry.readdir();\n return withFileTypes ? p : p.map(e => e.name);\n }\n }\n readdirSync(entry = this.cwd, opts = {\n withFileTypes: true,\n }) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes = true } = opts;\n if (!entry.canReaddir()) {\n return [];\n }\n else if (withFileTypes) {\n return entry.readdirSync();\n }\n else {\n return entry.readdirSync().map(e => e.name);\n }\n }\n /**\n * Call lstat() on the string or Path object, and update all known\n * information that can be determined.\n *\n * Note that unlike `fs.lstat()`, the returned value does not contain some\n * information, such as `mode`, `dev`, `nlink`, and `ino`. If that\n * information is required, you will need to call `fs.lstat` yourself.\n *\n * If the Path refers to a nonexistent file, or if the lstat call fails for\n * any reason, `undefined` is returned. Otherwise the updated Path object is\n * returned.\n *\n * Results are cached, and thus may be out of date if the filesystem is\n * mutated.\n */\n async lstat(entry = this.cwd) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n return entry.lstat();\n }\n /**\n * synchronous {@link PathScurryBase.lstat}\n */\n lstatSync(entry = this.cwd) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n return entry.lstatSync();\n }\n async readlink(entry = this.cwd, { withFileTypes } = {\n withFileTypes: false,\n }) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n withFileTypes = entry.withFileTypes;\n entry = this.cwd;\n }\n const e = await entry.readlink();\n return withFileTypes ? e : e?.fullpath();\n }\n readlinkSync(entry = this.cwd, { withFileTypes } = {\n withFileTypes: false,\n }) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n withFileTypes = entry.withFileTypes;\n entry = this.cwd;\n }\n const e = entry.readlinkSync();\n return withFileTypes ? e : e?.fullpath();\n }\n async realpath(entry = this.cwd, { withFileTypes } = {\n withFileTypes: false,\n }) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n withFileTypes = entry.withFileTypes;\n entry = this.cwd;\n }\n const e = await entry.realpath();\n return withFileTypes ? e : e?.fullpath();\n }\n realpathSync(entry = this.cwd, { withFileTypes } = {\n withFileTypes: false,\n }) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n withFileTypes = entry.withFileTypes;\n entry = this.cwd;\n }\n const e = entry.realpathSync();\n return withFileTypes ? e : e?.fullpath();\n }\n async walk(entry = this.cwd, opts = {}) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes = true, follow = false, filter, walkFilter, } = opts;\n const results = [];\n if (!filter || filter(entry)) {\n results.push(withFileTypes ? entry : entry.fullpath());\n }\n const dirs = new Set();\n const walk = (dir, cb) => {\n dirs.add(dir);\n dir.readdirCB((er, entries) => {\n /* c8 ignore start */\n if (er) {\n return cb(er);\n }\n /* c8 ignore stop */\n let len = entries.length;\n if (!len)\n return cb();\n const next = () => {\n if (--len === 0) {\n cb();\n }\n };\n for (const e of entries) {\n if (!filter || filter(e)) {\n results.push(withFileTypes ? e : e.fullpath());\n }\n if (follow && e.isSymbolicLink()) {\n e.realpath()\n .then(r => (r?.isUnknown() ? r.lstat() : r))\n .then(r => r?.shouldWalk(dirs, walkFilter) ? walk(r, next) : next());\n }\n else {\n if (e.shouldWalk(dirs, walkFilter)) {\n walk(e, next);\n }\n else {\n next();\n }\n }\n }\n }, true); // zalgooooooo\n };\n const start = entry;\n return new Promise((res, rej) => {\n walk(start, er => {\n /* c8 ignore start */\n if (er)\n return rej(er);\n /* c8 ignore stop */\n res(results);\n });\n });\n }\n walkSync(entry = this.cwd, opts = {}) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes = true, follow = false, filter, walkFilter, } = opts;\n const results = [];\n if (!filter || filter(entry)) {\n results.push(withFileTypes ? entry : entry.fullpath());\n }\n const dirs = new Set([entry]);\n for (const dir of dirs) {\n const entries = dir.readdirSync();\n for (const e of entries) {\n if (!filter || filter(e)) {\n results.push(withFileTypes ? e : e.fullpath());\n }\n let r = e;\n if (e.isSymbolicLink()) {\n if (!(follow && (r = e.realpathSync())))\n continue;\n if (r.isUnknown())\n r.lstatSync();\n }\n if (r.shouldWalk(dirs, walkFilter)) {\n dirs.add(r);\n }\n }\n }\n return results;\n }\n /**\n * Support for `for await`\n *\n * Alias for {@link PathScurryBase.iterate}\n *\n * Note: As of Node 19, this is very slow, compared to other methods of\n * walking. Consider using {@link PathScurryBase.stream} if memory overhead\n * and backpressure are concerns, or {@link PathScurryBase.walk} if not.\n */\n [Symbol.asyncIterator]() {\n return this.iterate();\n }\n iterate(entry = this.cwd, options = {}) {\n // iterating async over the stream is significantly more performant,\n // especially in the warm-cache scenario, because it buffers up directory\n // entries in the background instead of waiting for a yield for each one.\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n options = entry;\n entry = this.cwd;\n }\n return this.stream(entry, options)[Symbol.asyncIterator]();\n }\n /**\n * Iterating over a PathScurry performs a synchronous walk.\n *\n * Alias for {@link PathScurryBase.iterateSync}\n */\n [Symbol.iterator]() {\n return this.iterateSync();\n }\n *iterateSync(entry = this.cwd, opts = {}) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes = true, follow = false, filter, walkFilter, } = opts;\n if (!filter || filter(entry)) {\n yield withFileTypes ? entry : entry.fullpath();\n }\n const dirs = new Set([entry]);\n for (const dir of dirs) {\n const entries = dir.readdirSync();\n for (const e of entries) {\n if (!filter || filter(e)) {\n yield withFileTypes ? e : e.fullpath();\n }\n let r = e;\n if (e.isSymbolicLink()) {\n if (!(follow && (r = e.realpathSync())))\n continue;\n if (r.isUnknown())\n r.lstatSync();\n }\n if (r.shouldWalk(dirs, walkFilter)) {\n dirs.add(r);\n }\n }\n }\n }\n stream(entry = this.cwd, opts = {}) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes = true, follow = false, filter, walkFilter, } = opts;\n const results = new minipass_1.Minipass({ objectMode: true });\n if (!filter || filter(entry)) {\n results.write(withFileTypes ? entry : entry.fullpath());\n }\n const dirs = new Set();\n const queue = [entry];\n let processing = 0;\n const process = () => {\n let paused = false;\n while (!paused) {\n const dir = queue.shift();\n if (!dir) {\n if (processing === 0)\n results.end();\n return;\n }\n processing++;\n dirs.add(dir);\n const onReaddir = (er, entries, didRealpaths = false) => {\n /* c8 ignore start */\n if (er)\n return results.emit('error', er);\n /* c8 ignore stop */\n if (follow && !didRealpaths) {\n const promises = [];\n for (const e of entries) {\n if (e.isSymbolicLink()) {\n promises.push(e\n .realpath()\n .then((r) => r?.isUnknown() ? r.lstat() : r));\n }\n }\n if (promises.length) {\n Promise.all(promises).then(() => onReaddir(null, entries, true));\n return;\n }\n }\n for (const e of entries) {\n if (e && (!filter || filter(e))) {\n if (!results.write(withFileTypes ? e : e.fullpath())) {\n paused = true;\n }\n }\n }\n processing--;\n for (const e of entries) {\n const r = e.realpathCached() || e;\n if (r.shouldWalk(dirs, walkFilter)) {\n queue.push(r);\n }\n }\n if (paused && !results.flowing) {\n results.once('drain', process);\n }\n else if (!sync) {\n process();\n }\n };\n // zalgo containment\n let sync = true;\n dir.readdirCB(onReaddir, true);\n sync = false;\n }\n };\n process();\n return results;\n }\n streamSync(entry = this.cwd, opts = {}) {\n if (typeof entry === 'string') {\n entry = this.cwd.resolve(entry);\n }\n else if (!(entry instanceof PathBase)) {\n opts = entry;\n entry = this.cwd;\n }\n const { withFileTypes = true, follow = false, filter, walkFilter, } = opts;\n const results = new minipass_1.Minipass({ objectMode: true });\n const dirs = new Set();\n if (!filter || filter(entry)) {\n results.write(withFileTypes ? entry : entry.fullpath());\n }\n const queue = [entry];\n let processing = 0;\n const process = () => {\n let paused = false;\n while (!paused) {\n const dir = queue.shift();\n if (!dir) {\n if (processing === 0)\n results.end();\n return;\n }\n processing++;\n dirs.add(dir);\n const entries = dir.readdirSync();\n for (const e of entries) {\n if (!filter || filter(e)) {\n if (!results.write(withFileTypes ? e : e.fullpath())) {\n paused = true;\n }\n }\n }\n processing--;\n for (const e of entries) {\n let r = e;\n if (e.isSymbolicLink()) {\n if (!(follow && (r = e.realpathSync())))\n continue;\n if (r.isUnknown())\n r.lstatSync();\n }\n if (r.shouldWalk(dirs, walkFilter)) {\n queue.push(r);\n }\n }\n }\n if (paused && !results.flowing)\n results.once('drain', process);\n };\n process();\n return results;\n }\n chdir(path = this.cwd) {\n const oldCwd = this.cwd;\n this.cwd = typeof path === 'string' ? this.cwd.resolve(path) : path;\n this.cwd[setAsCwd](oldCwd);\n }\n}\nexports.PathScurryBase = PathScurryBase;\n/**\n * Windows implementation of {@link PathScurryBase}\n *\n * Defaults to case insensitve, uses `'\\\\'` to generate path strings. Uses\n * {@link PathWin32} for Path objects.\n */\nclass PathScurryWin32 extends PathScurryBase {\n /**\n * separator for generating path strings\n */\n sep = '\\\\';\n constructor(cwd = process.cwd(), opts = {}) {\n const { nocase = true } = opts;\n super(cwd, node_path_1.win32, '\\\\', { ...opts, nocase });\n this.nocase = nocase;\n for (let p = this.cwd; p; p = p.parent) {\n p.nocase = this.nocase;\n }\n }\n /**\n * @internal\n */\n parseRootPath(dir) {\n // if the path starts with a single separator, it's not a UNC, and we'll\n // just get separator as the root, and driveFromUNC will return \\\n // In that case, mount \\ on the root from the cwd.\n return node_path_1.win32.parse(dir).root.toUpperCase();\n }\n /**\n * @internal\n */\n newRoot(fs) {\n return new PathWin32(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs });\n }\n /**\n * Return true if the provided path string is an absolute path\n */\n isAbsolute(p) {\n return (p.startsWith('/') || p.startsWith('\\\\') || /^[a-z]:(\\/|\\\\)/i.test(p));\n }\n}\nexports.PathScurryWin32 = PathScurryWin32;\n/**\n * {@link PathScurryBase} implementation for all posix systems other than Darwin.\n *\n * Defaults to case-sensitive matching, uses `'/'` to generate path strings.\n *\n * Uses {@link PathPosix} for Path objects.\n */\nclass PathScurryPosix extends PathScurryBase {\n /**\n * separator for generating path strings\n */\n sep = '/';\n constructor(cwd = process.cwd(), opts = {}) {\n const { nocase = false } = opts;\n super(cwd, node_path_1.posix, '/', { ...opts, nocase });\n this.nocase = nocase;\n }\n /**\n * @internal\n */\n parseRootPath(_dir) {\n return '/';\n }\n /**\n * @internal\n */\n newRoot(fs) {\n return new PathPosix(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs });\n }\n /**\n * Return true if the provided path string is an absolute path\n */\n isAbsolute(p) {\n return p.startsWith('/');\n }\n}\nexports.PathScurryPosix = PathScurryPosix;\n/**\n * {@link PathScurryBase} implementation for Darwin (macOS) systems.\n *\n * Defaults to case-insensitive matching, uses `'/'` for generating path\n * strings.\n *\n * Uses {@link PathPosix} for Path objects.\n */\nclass PathScurryDarwin extends PathScurryPosix {\n constructor(cwd = process.cwd(), opts = {}) {\n const { nocase = true } = opts;\n super(cwd, { ...opts, nocase });\n }\n}\nexports.PathScurryDarwin = PathScurryDarwin;\n/**\n * Default {@link PathBase} implementation for the current platform.\n *\n * {@link PathWin32} on Windows systems, {@link PathPosix} on all others.\n */\nexports.Path = process.platform === 'win32' ? PathWin32 : PathPosix;\n/**\n * Default {@link PathScurryBase} implementation for the current platform.\n *\n * {@link PathScurryWin32} on Windows systems, {@link PathScurryDarwin} on\n * Darwin (macOS) systems, {@link PathScurryPosix} on all others.\n */\nexports.PathScurry = process.platform === 'win32' ? PathScurryWin32\n : process.platform === 'darwin' ? PathScurryDarwin\n : PathScurryPosix;\n//# sourceMappingURL=index.js.map","\"use strict\";\n/**\n * @module LRUCache\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.LRUCache = void 0;\nconst perf = typeof performance === 'object' &&\n performance &&\n typeof performance.now === 'function'\n ? performance\n : Date;\nconst warned = new Set();\n/* c8 ignore start */\nconst PROCESS = (typeof process === 'object' && !!process ? process : {});\n/* c8 ignore start */\nconst emitWarning = (msg, type, code, fn) => {\n typeof PROCESS.emitWarning === 'function'\n ? PROCESS.emitWarning(msg, type, code, fn)\n : console.error(`[${code}] ${type}: ${msg}`);\n};\nlet AC = globalThis.AbortController;\nlet AS = globalThis.AbortSignal;\n/* c8 ignore start */\nif (typeof AC === 'undefined') {\n //@ts-ignore\n AS = class AbortSignal {\n onabort;\n _onabort = [];\n reason;\n aborted = false;\n addEventListener(_, fn) {\n this._onabort.push(fn);\n }\n };\n //@ts-ignore\n AC = class AbortController {\n constructor() {\n warnACPolyfill();\n }\n signal = new AS();\n abort(reason) {\n if (this.signal.aborted)\n return;\n //@ts-ignore\n this.signal.reason = reason;\n //@ts-ignore\n this.signal.aborted = true;\n //@ts-ignore\n for (const fn of this.signal._onabort) {\n fn(reason);\n }\n this.signal.onabort?.(reason);\n }\n };\n let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';\n const warnACPolyfill = () => {\n if (!printACPolyfillWarning)\n return;\n printACPolyfillWarning = false;\n emitWarning('AbortController is not defined. If using lru-cache in ' +\n 'node 14, load an AbortController polyfill from the ' +\n '`node-abort-controller` package. A minimal polyfill is ' +\n 'provided for use by LRUCache.fetch(), but it should not be ' +\n 'relied upon in other contexts (eg, passing it to other APIs that ' +\n 'use AbortController/AbortSignal might have undesirable effects). ' +\n 'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.', 'NO_ABORT_CONTROLLER', 'ENOTSUP', warnACPolyfill);\n };\n}\n/* c8 ignore stop */\nconst shouldWarn = (code) => !warned.has(code);\nconst TYPE = Symbol('type');\nconst isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);\n/* c8 ignore start */\n// This is a little bit ridiculous, tbh.\n// The maximum array length is 2^32-1 or thereabouts on most JS impls.\n// And well before that point, you're caching the entire world, I mean,\n// that's ~32GB of just integers for the next/prev links, plus whatever\n// else to hold that many keys and values. Just filling the memory with\n// zeroes at init time is brutal when you get that big.\n// But why not be complete?\n// Maybe in the future, these limits will have expanded.\nconst getUintArray = (max) => !isPosInt(max)\n ? null\n : max <= Math.pow(2, 8)\n ? Uint8Array\n : max <= Math.pow(2, 16)\n ? Uint16Array\n : max <= Math.pow(2, 32)\n ? Uint32Array\n : max <= Number.MAX_SAFE_INTEGER\n ? ZeroArray\n : null;\n/* c8 ignore stop */\nclass ZeroArray extends Array {\n constructor(size) {\n super(size);\n this.fill(0);\n }\n}\nclass Stack {\n heap;\n length;\n // private constructor\n static #constructing = false;\n static create(max) {\n const HeapCls = getUintArray(max);\n if (!HeapCls)\n return [];\n Stack.#constructing = true;\n const s = new Stack(max, HeapCls);\n Stack.#constructing = false;\n return s;\n }\n constructor(max, HeapCls) {\n /* c8 ignore start */\n if (!Stack.#constructing) {\n throw new TypeError('instantiate Stack using Stack.create(n)');\n }\n /* c8 ignore stop */\n this.heap = new HeapCls(max);\n this.length = 0;\n }\n push(n) {\n this.heap[this.length++] = n;\n }\n pop() {\n return this.heap[--this.length];\n }\n}\n/**\n * Default export, the thing you're using this module to get.\n *\n * The `K` and `V` types define the key and value types, respectively. The\n * optional `FC` type defines the type of the `context` object passed to\n * `cache.fetch()` and `cache.memo()`.\n *\n * Keys and values **must not** be `null` or `undefined`.\n *\n * All properties from the options object (with the exception of `max`,\n * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are\n * added as normal public members. (The listed options are read-only getters.)\n *\n * Changing any of these will alter the defaults for subsequent method calls.\n */\nclass LRUCache {\n // options that cannot be changed without disaster\n #max;\n #maxSize;\n #dispose;\n #disposeAfter;\n #fetchMethod;\n #memoMethod;\n /**\n * {@link LRUCache.OptionsBase.ttl}\n */\n ttl;\n /**\n * {@link LRUCache.OptionsBase.ttlResolution}\n */\n ttlResolution;\n /**\n * {@link LRUCache.OptionsBase.ttlAutopurge}\n */\n ttlAutopurge;\n /**\n * {@link LRUCache.OptionsBase.updateAgeOnGet}\n */\n updateAgeOnGet;\n /**\n * {@link LRUCache.OptionsBase.updateAgeOnHas}\n */\n updateAgeOnHas;\n /**\n * {@link LRUCache.OptionsBase.allowStale}\n */\n allowStale;\n /**\n * {@link LRUCache.OptionsBase.noDisposeOnSet}\n */\n noDisposeOnSet;\n /**\n * {@link LRUCache.OptionsBase.noUpdateTTL}\n */\n noUpdateTTL;\n /**\n * {@link LRUCache.OptionsBase.maxEntrySize}\n */\n maxEntrySize;\n /**\n * {@link LRUCache.OptionsBase.sizeCalculation}\n */\n sizeCalculation;\n /**\n * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}\n */\n noDeleteOnFetchRejection;\n /**\n * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}\n */\n noDeleteOnStaleGet;\n /**\n * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}\n */\n allowStaleOnFetchAbort;\n /**\n * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}\n */\n allowStaleOnFetchRejection;\n /**\n * {@link LRUCache.OptionsBase.ignoreFetchAbort}\n */\n ignoreFetchAbort;\n // computed properties\n #size;\n #calculatedSize;\n #keyMap;\n #keyList;\n #valList;\n #next;\n #prev;\n #head;\n #tail;\n #free;\n #disposed;\n #sizes;\n #starts;\n #ttls;\n #hasDispose;\n #hasFetchMethod;\n #hasDisposeAfter;\n /**\n * Do not call this method unless you need to inspect the\n * inner workings of the cache. If anything returned by this\n * object is modified in any way, strange breakage may occur.\n *\n * These fields are private for a reason!\n *\n * @internal\n */\n static unsafeExposeInternals(c) {\n return {\n // properties\n starts: c.#starts,\n ttls: c.#ttls,\n sizes: c.#sizes,\n keyMap: c.#keyMap,\n keyList: c.#keyList,\n valList: c.#valList,\n next: c.#next,\n prev: c.#prev,\n get head() {\n return c.#head;\n },\n get tail() {\n return c.#tail;\n },\n free: c.#free,\n // methods\n isBackgroundFetch: (p) => c.#isBackgroundFetch(p),\n backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),\n moveToTail: (index) => c.#moveToTail(index),\n indexes: (options) => c.#indexes(options),\n rindexes: (options) => c.#rindexes(options),\n isStale: (index) => c.#isStale(index),\n };\n }\n // Protected read-only members\n /**\n * {@link LRUCache.OptionsBase.max} (read-only)\n */\n get max() {\n return this.#max;\n }\n /**\n * {@link LRUCache.OptionsBase.maxSize} (read-only)\n */\n get maxSize() {\n return this.#maxSize;\n }\n /**\n * The total computed size of items in the cache (read-only)\n */\n get calculatedSize() {\n return this.#calculatedSize;\n }\n /**\n * The number of items stored in the cache (read-only)\n */\n get size() {\n return this.#size;\n }\n /**\n * {@link LRUCache.OptionsBase.fetchMethod} (read-only)\n */\n get fetchMethod() {\n return this.#fetchMethod;\n }\n get memoMethod() {\n return this.#memoMethod;\n }\n /**\n * {@link LRUCache.OptionsBase.dispose} (read-only)\n */\n get dispose() {\n return this.#dispose;\n }\n /**\n * {@link LRUCache.OptionsBase.disposeAfter} (read-only)\n */\n get disposeAfter() {\n return this.#disposeAfter;\n }\n constructor(options) {\n const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, } = options;\n if (max !== 0 && !isPosInt(max)) {\n throw new TypeError('max option must be a nonnegative integer');\n }\n const UintArray = max ? getUintArray(max) : Array;\n if (!UintArray) {\n throw new Error('invalid max value: ' + max);\n }\n this.#max = max;\n this.#maxSize = maxSize;\n this.maxEntrySize = maxEntrySize || this.#maxSize;\n this.sizeCalculation = sizeCalculation;\n if (this.sizeCalculation) {\n if (!this.#maxSize && !this.maxEntrySize) {\n throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');\n }\n if (typeof this.sizeCalculation !== 'function') {\n throw new TypeError('sizeCalculation set to non-function');\n }\n }\n if (memoMethod !== undefined &&\n typeof memoMethod !== 'function') {\n throw new TypeError('memoMethod must be a function if defined');\n }\n this.#memoMethod = memoMethod;\n if (fetchMethod !== undefined &&\n typeof fetchMethod !== 'function') {\n throw new TypeError('fetchMethod must be a function if specified');\n }\n this.#fetchMethod = fetchMethod;\n this.#hasFetchMethod = !!fetchMethod;\n this.#keyMap = new Map();\n this.#keyList = new Array(max).fill(undefined);\n this.#valList = new Array(max).fill(undefined);\n this.#next = new UintArray(max);\n this.#prev = new UintArray(max);\n this.#head = 0;\n this.#tail = 0;\n this.#free = Stack.create(max);\n this.#size = 0;\n this.#calculatedSize = 0;\n if (typeof dispose === 'function') {\n this.#dispose = dispose;\n }\n if (typeof disposeAfter === 'function') {\n this.#disposeAfter = disposeAfter;\n this.#disposed = [];\n }\n else {\n this.#disposeAfter = undefined;\n this.#disposed = undefined;\n }\n this.#hasDispose = !!this.#dispose;\n this.#hasDisposeAfter = !!this.#disposeAfter;\n this.noDisposeOnSet = !!noDisposeOnSet;\n this.noUpdateTTL = !!noUpdateTTL;\n this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;\n this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;\n this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;\n this.ignoreFetchAbort = !!ignoreFetchAbort;\n // NB: maxEntrySize is set to maxSize if it's set\n if (this.maxEntrySize !== 0) {\n if (this.#maxSize !== 0) {\n if (!isPosInt(this.#maxSize)) {\n throw new TypeError('maxSize must be a positive integer if specified');\n }\n }\n if (!isPosInt(this.maxEntrySize)) {\n throw new TypeError('maxEntrySize must be a positive integer if specified');\n }\n this.#initializeSizeTracking();\n }\n this.allowStale = !!allowStale;\n this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;\n this.updateAgeOnGet = !!updateAgeOnGet;\n this.updateAgeOnHas = !!updateAgeOnHas;\n this.ttlResolution =\n isPosInt(ttlResolution) || ttlResolution === 0\n ? ttlResolution\n : 1;\n this.ttlAutopurge = !!ttlAutopurge;\n this.ttl = ttl || 0;\n if (this.ttl) {\n if (!isPosInt(this.ttl)) {\n throw new TypeError('ttl must be a positive integer if specified');\n }\n this.#initializeTTLTracking();\n }\n // do not allow completely unbounded caches\n if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {\n throw new TypeError('At least one of max, maxSize, or ttl is required');\n }\n if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {\n const code = 'LRU_CACHE_UNBOUNDED';\n if (shouldWarn(code)) {\n warned.add(code);\n const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +\n 'result in unbounded memory consumption.';\n emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);\n }\n }\n }\n /**\n * Return the number of ms left in the item's TTL. If item is not in cache,\n * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.\n */\n getRemainingTTL(key) {\n return this.#keyMap.has(key) ? Infinity : 0;\n }\n #initializeTTLTracking() {\n const ttls = new ZeroArray(this.#max);\n const starts = new ZeroArray(this.#max);\n this.#ttls = ttls;\n this.#starts = starts;\n this.#setItemTTL = (index, ttl, start = perf.now()) => {\n starts[index] = ttl !== 0 ? start : 0;\n ttls[index] = ttl;\n if (ttl !== 0 && this.ttlAutopurge) {\n const t = setTimeout(() => {\n if (this.#isStale(index)) {\n this.#delete(this.#keyList[index], 'expire');\n }\n }, ttl + 1);\n // unref() not supported on all platforms\n /* c8 ignore start */\n if (t.unref) {\n t.unref();\n }\n /* c8 ignore stop */\n }\n };\n this.#updateItemAge = index => {\n starts[index] = ttls[index] !== 0 ? perf.now() : 0;\n };\n this.#statusTTL = (status, index) => {\n if (ttls[index]) {\n const ttl = ttls[index];\n const start = starts[index];\n /* c8 ignore next */\n if (!ttl || !start)\n return;\n status.ttl = ttl;\n status.start = start;\n status.now = cachedNow || getNow();\n const age = status.now - start;\n status.remainingTTL = ttl - age;\n }\n };\n // debounce calls to perf.now() to 1s so we're not hitting\n // that costly call repeatedly.\n let cachedNow = 0;\n const getNow = () => {\n const n = perf.now();\n if (this.ttlResolution > 0) {\n cachedNow = n;\n const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);\n // not available on all platforms\n /* c8 ignore start */\n if (t.unref) {\n t.unref();\n }\n /* c8 ignore stop */\n }\n return n;\n };\n this.getRemainingTTL = key => {\n const index = this.#keyMap.get(key);\n if (index === undefined) {\n return 0;\n }\n const ttl = ttls[index];\n const start = starts[index];\n if (!ttl || !start) {\n return Infinity;\n }\n const age = (cachedNow || getNow()) - start;\n return ttl - age;\n };\n this.#isStale = index => {\n const s = starts[index];\n const t = ttls[index];\n return !!t && !!s && (cachedNow || getNow()) - s > t;\n };\n }\n // conditionally set private methods related to TTL\n #updateItemAge = () => { };\n #statusTTL = () => { };\n #setItemTTL = () => { };\n /* c8 ignore stop */\n #isStale = () => false;\n #initializeSizeTracking() {\n const sizes = new ZeroArray(this.#max);\n this.#calculatedSize = 0;\n this.#sizes = sizes;\n this.#removeItemSize = index => {\n this.#calculatedSize -= sizes[index];\n sizes[index] = 0;\n };\n this.#requireSize = (k, v, size, sizeCalculation) => {\n // provisionally accept background fetches.\n // actual value size will be checked when they return.\n if (this.#isBackgroundFetch(v)) {\n return 0;\n }\n if (!isPosInt(size)) {\n if (sizeCalculation) {\n if (typeof sizeCalculation !== 'function') {\n throw new TypeError('sizeCalculation must be a function');\n }\n size = sizeCalculation(v, k);\n if (!isPosInt(size)) {\n throw new TypeError('sizeCalculation return invalid (expect positive integer)');\n }\n }\n else {\n throw new TypeError('invalid size value (must be positive integer). ' +\n 'When maxSize or maxEntrySize is used, sizeCalculation ' +\n 'or size must be set.');\n }\n }\n return size;\n };\n this.#addItemSize = (index, size, status) => {\n sizes[index] = size;\n if (this.#maxSize) {\n const maxSize = this.#maxSize - sizes[index];\n while (this.#calculatedSize > maxSize) {\n this.#evict(true);\n }\n }\n this.#calculatedSize += sizes[index];\n if (status) {\n status.entrySize = size;\n status.totalCalculatedSize = this.#calculatedSize;\n }\n };\n }\n #removeItemSize = _i => { };\n #addItemSize = (_i, _s, _st) => { };\n #requireSize = (_k, _v, size, sizeCalculation) => {\n if (size || sizeCalculation) {\n throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');\n }\n return 0;\n };\n *#indexes({ allowStale = this.allowStale } = {}) {\n if (this.#size) {\n for (let i = this.#tail; true;) {\n if (!this.#isValidIndex(i)) {\n break;\n }\n if (allowStale || !this.#isStale(i)) {\n yield i;\n }\n if (i === this.#head) {\n break;\n }\n else {\n i = this.#prev[i];\n }\n }\n }\n }\n *#rindexes({ allowStale = this.allowStale } = {}) {\n if (this.#size) {\n for (let i = this.#head; true;) {\n if (!this.#isValidIndex(i)) {\n break;\n }\n if (allowStale || !this.#isStale(i)) {\n yield i;\n }\n if (i === this.#tail) {\n break;\n }\n else {\n i = this.#next[i];\n }\n }\n }\n }\n #isValidIndex(index) {\n return (index !== undefined &&\n this.#keyMap.get(this.#keyList[index]) === index);\n }\n /**\n * Return a generator yielding `[key, value]` pairs,\n * in order from most recently used to least recently used.\n */\n *entries() {\n for (const i of this.#indexes()) {\n if (this.#valList[i] !== undefined &&\n this.#keyList[i] !== undefined &&\n !this.#isBackgroundFetch(this.#valList[i])) {\n yield [this.#keyList[i], this.#valList[i]];\n }\n }\n }\n /**\n * Inverse order version of {@link LRUCache.entries}\n *\n * Return a generator yielding `[key, value]` pairs,\n * in order from least recently used to most recently used.\n */\n *rentries() {\n for (const i of this.#rindexes()) {\n if (this.#valList[i] !== undefined &&\n this.#keyList[i] !== undefined &&\n !this.#isBackgroundFetch(this.#valList[i])) {\n yield [this.#keyList[i], this.#valList[i]];\n }\n }\n }\n /**\n * Return a generator yielding the keys in the cache,\n * in order from most recently used to least recently used.\n */\n *keys() {\n for (const i of this.#indexes()) {\n const k = this.#keyList[i];\n if (k !== undefined &&\n !this.#isBackgroundFetch(this.#valList[i])) {\n yield k;\n }\n }\n }\n /**\n * Inverse order version of {@link LRUCache.keys}\n *\n * Return a generator yielding the keys in the cache,\n * in order from least recently used to most recently used.\n */\n *rkeys() {\n for (const i of this.#rindexes()) {\n const k = this.#keyList[i];\n if (k !== undefined &&\n !this.#isBackgroundFetch(this.#valList[i])) {\n yield k;\n }\n }\n }\n /**\n * Return a generator yielding the values in the cache,\n * in order from most recently used to least recently used.\n */\n *values() {\n for (const i of this.#indexes()) {\n const v = this.#valList[i];\n if (v !== undefined &&\n !this.#isBackgroundFetch(this.#valList[i])) {\n yield this.#valList[i];\n }\n }\n }\n /**\n * Inverse order version of {@link LRUCache.values}\n *\n * Return a generator yielding the values in the cache,\n * in order from least recently used to most recently used.\n */\n *rvalues() {\n for (const i of this.#rindexes()) {\n const v = this.#valList[i];\n if (v !== undefined &&\n !this.#isBackgroundFetch(this.#valList[i])) {\n yield this.#valList[i];\n }\n }\n }\n /**\n * Iterating over the cache itself yields the same results as\n * {@link LRUCache.entries}\n */\n [Symbol.iterator]() {\n return this.entries();\n }\n /**\n * A String value that is used in the creation of the default string\n * description of an object. Called by the built-in method\n * `Object.prototype.toString`.\n */\n [Symbol.toStringTag] = 'LRUCache';\n /**\n * Find a value for which the supplied fn method returns a truthy value,\n * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.\n */\n find(fn, getOptions = {}) {\n for (const i of this.#indexes()) {\n const v = this.#valList[i];\n const value = this.#isBackgroundFetch(v)\n ? v.__staleWhileFetching\n : v;\n if (value === undefined)\n continue;\n if (fn(value, this.#keyList[i], this)) {\n return this.get(this.#keyList[i], getOptions);\n }\n }\n }\n /**\n * Call the supplied function on each item in the cache, in order from most\n * recently used to least recently used.\n *\n * `fn` is called as `fn(value, key, cache)`.\n *\n * If `thisp` is provided, function will be called in the `this`-context of\n * the provided object, or the cache if no `thisp` object is provided.\n *\n * Does not update age or recenty of use, or iterate over stale values.\n */\n forEach(fn, thisp = this) {\n for (const i of this.#indexes()) {\n const v = this.#valList[i];\n const value = this.#isBackgroundFetch(v)\n ? v.__staleWhileFetching\n : v;\n if (value === undefined)\n continue;\n fn.call(thisp, value, this.#keyList[i], this);\n }\n }\n /**\n * The same as {@link LRUCache.forEach} but items are iterated over in\n * reverse order. (ie, less recently used items are iterated over first.)\n */\n rforEach(fn, thisp = this) {\n for (const i of this.#rindexes()) {\n const v = this.#valList[i];\n const value = this.#isBackgroundFetch(v)\n ? v.__staleWhileFetching\n : v;\n if (value === undefined)\n continue;\n fn.call(thisp, value, this.#keyList[i], this);\n }\n }\n /**\n * Delete any stale entries. Returns true if anything was removed,\n * false otherwise.\n */\n purgeStale() {\n let deleted = false;\n for (const i of this.#rindexes({ allowStale: true })) {\n if (this.#isStale(i)) {\n this.#delete(this.#keyList[i], 'expire');\n deleted = true;\n }\n }\n return deleted;\n }\n /**\n * Get the extended info about a given entry, to get its value, size, and\n * TTL info simultaneously. Returns `undefined` if the key is not present.\n *\n * Unlike {@link LRUCache#dump}, which is designed to be portable and survive\n * serialization, the `start` value is always the current timestamp, and the\n * `ttl` is a calculated remaining time to live (negative if expired).\n *\n * Always returns stale values, if their info is found in the cache, so be\n * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})\n * if relevant.\n */\n info(key) {\n const i = this.#keyMap.get(key);\n if (i === undefined)\n return undefined;\n const v = this.#valList[i];\n const value = this.#isBackgroundFetch(v)\n ? v.__staleWhileFetching\n : v;\n if (value === undefined)\n return undefined;\n const entry = { value };\n if (this.#ttls && this.#starts) {\n const ttl = this.#ttls[i];\n const start = this.#starts[i];\n if (ttl && start) {\n const remain = ttl - (perf.now() - start);\n entry.ttl = remain;\n entry.start = Date.now();\n }\n }\n if (this.#sizes) {\n entry.size = this.#sizes[i];\n }\n return entry;\n }\n /**\n * Return an array of [key, {@link LRUCache.Entry}] tuples which can be\n * passed to {@link LRLUCache#load}.\n *\n * The `start` fields are calculated relative to a portable `Date.now()`\n * timestamp, even if `performance.now()` is available.\n *\n * Stale entries are always included in the `dump`, even if\n * {@link LRUCache.OptionsBase.allowStale} is false.\n *\n * Note: this returns an actual array, not a generator, so it can be more\n * easily passed around.\n */\n dump() {\n const arr = [];\n for (const i of this.#indexes({ allowStale: true })) {\n const key = this.#keyList[i];\n const v = this.#valList[i];\n const value = this.#isBackgroundFetch(v)\n ? v.__staleWhileFetching\n : v;\n if (value === undefined || key === undefined)\n continue;\n const entry = { value };\n if (this.#ttls && this.#starts) {\n entry.ttl = this.#ttls[i];\n // always dump the start relative to a portable timestamp\n // it's ok for this to be a bit slow, it's a rare operation.\n const age = perf.now() - this.#starts[i];\n entry.start = Math.floor(Date.now() - age);\n }\n if (this.#sizes) {\n entry.size = this.#sizes[i];\n }\n arr.unshift([key, entry]);\n }\n return arr;\n }\n /**\n * Reset the cache and load in the items in entries in the order listed.\n *\n * The shape of the resulting cache may be different if the same options are\n * not used in both caches.\n *\n * The `start` fields are assumed to be calculated relative to a portable\n * `Date.now()` timestamp, even if `performance.now()` is available.\n */\n load(arr) {\n this.clear();\n for (const [key, entry] of arr) {\n if (entry.start) {\n // entry.start is a portable timestamp, but we may be using\n // node's performance.now(), so calculate the offset, so that\n // we get the intended remaining TTL, no matter how long it's\n // been on ice.\n //\n // it's ok for this to be a bit slow, it's a rare operation.\n const age = Date.now() - entry.start;\n entry.start = perf.now() - age;\n }\n this.set(key, entry.value, entry);\n }\n }\n /**\n * Add a value to the cache.\n *\n * Note: if `undefined` is specified as a value, this is an alias for\n * {@link LRUCache#delete}\n *\n * Fields on the {@link LRUCache.SetOptions} options param will override\n * their corresponding values in the constructor options for the scope\n * of this single `set()` operation.\n *\n * If `start` is provided, then that will set the effective start\n * time for the TTL calculation. Note that this must be a previous\n * value of `performance.now()` if supported, or a previous value of\n * `Date.now()` if not.\n *\n * Options object may also include `size`, which will prevent\n * calling the `sizeCalculation` function and just use the specified\n * number if it is a positive integer, and `noDisposeOnSet` which\n * will prevent calling a `dispose` function in the case of\n * overwrites.\n *\n * If the `size` (or return value of `sizeCalculation`) for a given\n * entry is greater than `maxEntrySize`, then the item will not be\n * added to the cache.\n *\n * Will update the recency of the entry.\n *\n * If the value is `undefined`, then this is an alias for\n * `cache.delete(key)`. `undefined` is never stored in the cache.\n */\n set(k, v, setOptions = {}) {\n if (v === undefined) {\n this.delete(k);\n return this;\n }\n const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;\n let { noUpdateTTL = this.noUpdateTTL } = setOptions;\n const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);\n // if the item doesn't fit, don't do anything\n // NB: maxEntrySize set to maxSize by default\n if (this.maxEntrySize && size > this.maxEntrySize) {\n if (status) {\n status.set = 'miss';\n status.maxEntrySizeExceeded = true;\n }\n // have to delete, in case something is there already.\n this.#delete(k, 'set');\n return this;\n }\n let index = this.#size === 0 ? undefined : this.#keyMap.get(k);\n if (index === undefined) {\n // addition\n index = (this.#size === 0\n ? this.#tail\n : this.#free.length !== 0\n ? this.#free.pop()\n : this.#size === this.#max\n ? this.#evict(false)\n : this.#size);\n this.#keyList[index] = k;\n this.#valList[index] = v;\n this.#keyMap.set(k, index);\n this.#next[this.#tail] = index;\n this.#prev[index] = this.#tail;\n this.#tail = index;\n this.#size++;\n this.#addItemSize(index, size, status);\n if (status)\n status.set = 'add';\n noUpdateTTL = false;\n }\n else {\n // update\n this.#moveToTail(index);\n const oldVal = this.#valList[index];\n if (v !== oldVal) {\n if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {\n oldVal.__abortController.abort(new Error('replaced'));\n const { __staleWhileFetching: s } = oldVal;\n if (s !== undefined && !noDisposeOnSet) {\n if (this.#hasDispose) {\n this.#dispose?.(s, k, 'set');\n }\n if (this.#hasDisposeAfter) {\n this.#disposed?.push([s, k, 'set']);\n }\n }\n }\n else if (!noDisposeOnSet) {\n if (this.#hasDispose) {\n this.#dispose?.(oldVal, k, 'set');\n }\n if (this.#hasDisposeAfter) {\n this.#disposed?.push([oldVal, k, 'set']);\n }\n }\n this.#removeItemSize(index);\n this.#addItemSize(index, size, status);\n this.#valList[index] = v;\n if (status) {\n status.set = 'replace';\n const oldValue = oldVal && this.#isBackgroundFetch(oldVal)\n ? oldVal.__staleWhileFetching\n : oldVal;\n if (oldValue !== undefined)\n status.oldValue = oldValue;\n }\n }\n else if (status) {\n status.set = 'update';\n }\n }\n if (ttl !== 0 && !this.#ttls) {\n this.#initializeTTLTracking();\n }\n if (this.#ttls) {\n if (!noUpdateTTL) {\n this.#setItemTTL(index, ttl, start);\n }\n if (status)\n this.#statusTTL(status, index);\n }\n if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {\n const dt = this.#disposed;\n let task;\n while ((task = dt?.shift())) {\n this.#disposeAfter?.(...task);\n }\n }\n return this;\n }\n /**\n * Evict the least recently used item, returning its value or\n * `undefined` if cache is empty.\n */\n pop() {\n try {\n while (this.#size) {\n const val = this.#valList[this.#head];\n this.#evict(true);\n if (this.#isBackgroundFetch(val)) {\n if (val.__staleWhileFetching) {\n return val.__staleWhileFetching;\n }\n }\n else if (val !== undefined) {\n return val;\n }\n }\n }\n finally {\n if (this.#hasDisposeAfter && this.#disposed) {\n const dt = this.#disposed;\n let task;\n while ((task = dt?.shift())) {\n this.#disposeAfter?.(...task);\n }\n }\n }\n }\n #evict(free) {\n const head = this.#head;\n const k = this.#keyList[head];\n const v = this.#valList[head];\n if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {\n v.__abortController.abort(new Error('evicted'));\n }\n else if (this.#hasDispose || this.#hasDisposeAfter) {\n if (this.#hasDispose) {\n this.#dispose?.(v, k, 'evict');\n }\n if (this.#hasDisposeAfter) {\n this.#disposed?.push([v, k, 'evict']);\n }\n }\n this.#removeItemSize(head);\n // if we aren't about to use the index, then null these out\n if (free) {\n this.#keyList[head] = undefined;\n this.#valList[head] = undefined;\n this.#free.push(head);\n }\n if (this.#size === 1) {\n this.#head = this.#tail = 0;\n this.#free.length = 0;\n }\n else {\n this.#head = this.#next[head];\n }\n this.#keyMap.delete(k);\n this.#size--;\n return head;\n }\n /**\n * Check if a key is in the cache, without updating the recency of use.\n * Will return false if the item is stale, even though it is technically\n * in the cache.\n *\n * Check if a key is in the cache, without updating the recency of\n * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set\n * to `true` in either the options or the constructor.\n *\n * Will return `false` if the item is stale, even though it is technically in\n * the cache. The difference can be determined (if it matters) by using a\n * `status` argument, and inspecting the `has` field.\n *\n * Will not update item age unless\n * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.\n */\n has(k, hasOptions = {}) {\n const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;\n const index = this.#keyMap.get(k);\n if (index !== undefined) {\n const v = this.#valList[index];\n if (this.#isBackgroundFetch(v) &&\n v.__staleWhileFetching === undefined) {\n return false;\n }\n if (!this.#isStale(index)) {\n if (updateAgeOnHas) {\n this.#updateItemAge(index);\n }\n if (status) {\n status.has = 'hit';\n this.#statusTTL(status, index);\n }\n return true;\n }\n else if (status) {\n status.has = 'stale';\n this.#statusTTL(status, index);\n }\n }\n else if (status) {\n status.has = 'miss';\n }\n return false;\n }\n /**\n * Like {@link LRUCache#get} but doesn't update recency or delete stale\n * items.\n *\n * Returns `undefined` if the item is stale, unless\n * {@link LRUCache.OptionsBase.allowStale} is set.\n */\n peek(k, peekOptions = {}) {\n const { allowStale = this.allowStale } = peekOptions;\n const index = this.#keyMap.get(k);\n if (index === undefined ||\n (!allowStale && this.#isStale(index))) {\n return;\n }\n const v = this.#valList[index];\n // either stale and allowed, or forcing a refresh of non-stale value\n return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;\n }\n #backgroundFetch(k, index, options, context) {\n const v = index === undefined ? undefined : this.#valList[index];\n if (this.#isBackgroundFetch(v)) {\n return v;\n }\n const ac = new AC();\n const { signal } = options;\n // when/if our AC signals, then stop listening to theirs.\n signal?.addEventListener('abort', () => ac.abort(signal.reason), {\n signal: ac.signal,\n });\n const fetchOpts = {\n signal: ac.signal,\n options,\n context,\n };\n const cb = (v, updateCache = false) => {\n const { aborted } = ac.signal;\n const ignoreAbort = options.ignoreFetchAbort && v !== undefined;\n if (options.status) {\n if (aborted && !updateCache) {\n options.status.fetchAborted = true;\n options.status.fetchError = ac.signal.reason;\n if (ignoreAbort)\n options.status.fetchAbortIgnored = true;\n }\n else {\n options.status.fetchResolved = true;\n }\n }\n if (aborted && !ignoreAbort && !updateCache) {\n return fetchFail(ac.signal.reason);\n }\n // either we didn't abort, and are still here, or we did, and ignored\n const bf = p;\n if (this.#valList[index] === p) {\n if (v === undefined) {\n if (bf.__staleWhileFetching) {\n this.#valList[index] = bf.__staleWhileFetching;\n }\n else {\n this.#delete(k, 'fetch');\n }\n }\n else {\n if (options.status)\n options.status.fetchUpdated = true;\n this.set(k, v, fetchOpts.options);\n }\n }\n return v;\n };\n const eb = (er) => {\n if (options.status) {\n options.status.fetchRejected = true;\n options.status.fetchError = er;\n }\n return fetchFail(er);\n };\n const fetchFail = (er) => {\n const { aborted } = ac.signal;\n const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;\n const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;\n const noDelete = allowStale || options.noDeleteOnFetchRejection;\n const bf = p;\n if (this.#valList[index] === p) {\n // if we allow stale on fetch rejections, then we need to ensure that\n // the stale value is not removed from the cache when the fetch fails.\n const del = !noDelete || bf.__staleWhileFetching === undefined;\n if (del) {\n this.#delete(k, 'fetch');\n }\n else if (!allowStaleAborted) {\n // still replace the *promise* with the stale value,\n // since we are done with the promise at this point.\n // leave it untouched if we're still waiting for an\n // aborted background fetch that hasn't yet returned.\n this.#valList[index] = bf.__staleWhileFetching;\n }\n }\n if (allowStale) {\n if (options.status && bf.__staleWhileFetching !== undefined) {\n options.status.returnedStale = true;\n }\n return bf.__staleWhileFetching;\n }\n else if (bf.__returned === bf) {\n throw er;\n }\n };\n const pcall = (res, rej) => {\n const fmp = this.#fetchMethod?.(k, v, fetchOpts);\n if (fmp && fmp instanceof Promise) {\n fmp.then(v => res(v === undefined ? undefined : v), rej);\n }\n // ignored, we go until we finish, regardless.\n // defer check until we are actually aborting,\n // so fetchMethod can override.\n ac.signal.addEventListener('abort', () => {\n if (!options.ignoreFetchAbort ||\n options.allowStaleOnFetchAbort) {\n res(undefined);\n // when it eventually resolves, update the cache.\n if (options.allowStaleOnFetchAbort) {\n res = v => cb(v, true);\n }\n }\n });\n };\n if (options.status)\n options.status.fetchDispatched = true;\n const p = new Promise(pcall).then(cb, eb);\n const bf = Object.assign(p, {\n __abortController: ac,\n __staleWhileFetching: v,\n __returned: undefined,\n });\n if (index === undefined) {\n // internal, don't expose status.\n this.set(k, bf, { ...fetchOpts.options, status: undefined });\n index = this.#keyMap.get(k);\n }\n else {\n this.#valList[index] = bf;\n }\n return bf;\n }\n #isBackgroundFetch(p) {\n if (!this.#hasFetchMethod)\n return false;\n const b = p;\n return (!!b &&\n b instanceof Promise &&\n b.hasOwnProperty('__staleWhileFetching') &&\n b.__abortController instanceof AC);\n }\n async fetch(k, fetchOptions = {}) {\n const { \n // get options\n allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, \n // set options\n ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL, \n // fetch exclusive options\n noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;\n if (!this.#hasFetchMethod) {\n if (status)\n status.fetch = 'get';\n return this.get(k, {\n allowStale,\n updateAgeOnGet,\n noDeleteOnStaleGet,\n status,\n });\n }\n const options = {\n allowStale,\n updateAgeOnGet,\n noDeleteOnStaleGet,\n ttl,\n noDisposeOnSet,\n size,\n sizeCalculation,\n noUpdateTTL,\n noDeleteOnFetchRejection,\n allowStaleOnFetchRejection,\n allowStaleOnFetchAbort,\n ignoreFetchAbort,\n status,\n signal,\n };\n let index = this.#keyMap.get(k);\n if (index === undefined) {\n if (status)\n status.fetch = 'miss';\n const p = this.#backgroundFetch(k, index, options, context);\n return (p.__returned = p);\n }\n else {\n // in cache, maybe already fetching\n const v = this.#valList[index];\n if (this.#isBackgroundFetch(v)) {\n const stale = allowStale && v.__staleWhileFetching !== undefined;\n if (status) {\n status.fetch = 'inflight';\n if (stale)\n status.returnedStale = true;\n }\n return stale ? v.__staleWhileFetching : (v.__returned = v);\n }\n // if we force a refresh, that means do NOT serve the cached value,\n // unless we are already in the process of refreshing the cache.\n const isStale = this.#isStale(index);\n if (!forceRefresh && !isStale) {\n if (status)\n status.fetch = 'hit';\n this.#moveToTail(index);\n if (updateAgeOnGet) {\n this.#updateItemAge(index);\n }\n if (status)\n this.#statusTTL(status, index);\n return v;\n }\n // ok, it is stale or a forced refresh, and not already fetching.\n // refresh the cache.\n const p = this.#backgroundFetch(k, index, options, context);\n const hasStale = p.__staleWhileFetching !== undefined;\n const staleVal = hasStale && allowStale;\n if (status) {\n status.fetch = isStale ? 'stale' : 'refresh';\n if (staleVal && isStale)\n status.returnedStale = true;\n }\n return staleVal ? p.__staleWhileFetching : (p.__returned = p);\n }\n }\n async forceFetch(k, fetchOptions = {}) {\n const v = await this.fetch(k, fetchOptions);\n if (v === undefined)\n throw new Error('fetch() returned undefined');\n return v;\n }\n memo(k, memoOptions = {}) {\n const memoMethod = this.#memoMethod;\n if (!memoMethod) {\n throw new Error('no memoMethod provided to constructor');\n }\n const { context, forceRefresh, ...options } = memoOptions;\n const v = this.get(k, options);\n if (!forceRefresh && v !== undefined)\n return v;\n const vv = memoMethod(k, v, {\n options,\n context,\n });\n this.set(k, vv, options);\n return vv;\n }\n /**\n * Return a value from the cache. Will update the recency of the cache\n * entry found.\n *\n * If the key is not found, get() will return `undefined`.\n */\n get(k, getOptions = {}) {\n const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;\n const index = this.#keyMap.get(k);\n if (index !== undefined) {\n const value = this.#valList[index];\n const fetching = this.#isBackgroundFetch(value);\n if (status)\n this.#statusTTL(status, index);\n if (this.#isStale(index)) {\n if (status)\n status.get = 'stale';\n // delete only if not an in-flight background fetch\n if (!fetching) {\n if (!noDeleteOnStaleGet) {\n this.#delete(k, 'expire');\n }\n if (status && allowStale)\n status.returnedStale = true;\n return allowStale ? value : undefined;\n }\n else {\n if (status &&\n allowStale &&\n value.__staleWhileFetching !== undefined) {\n status.returnedStale = true;\n }\n return allowStale ? value.__staleWhileFetching : undefined;\n }\n }\n else {\n if (status)\n status.get = 'hit';\n // if we're currently fetching it, we don't actually have it yet\n // it's not stale, which means this isn't a staleWhileRefetching.\n // If it's not stale, and fetching, AND has a __staleWhileFetching\n // value, then that means the user fetched with {forceRefresh:true},\n // so it's safe to return that value.\n if (fetching) {\n return value.__staleWhileFetching;\n }\n this.#moveToTail(index);\n if (updateAgeOnGet) {\n this.#updateItemAge(index);\n }\n return value;\n }\n }\n else if (status) {\n status.get = 'miss';\n }\n }\n #connect(p, n) {\n this.#prev[n] = p;\n this.#next[p] = n;\n }\n #moveToTail(index) {\n // if tail already, nothing to do\n // if head, move head to next[index]\n // else\n // move next[prev[index]] to next[index] (head has no prev)\n // move prev[next[index]] to prev[index]\n // prev[index] = tail\n // next[tail] = index\n // tail = index\n if (index !== this.#tail) {\n if (index === this.#head) {\n this.#head = this.#next[index];\n }\n else {\n this.#connect(this.#prev[index], this.#next[index]);\n }\n this.#connect(this.#tail, index);\n this.#tail = index;\n }\n }\n /**\n * Deletes a key out of the cache.\n *\n * Returns true if the key was deleted, false otherwise.\n */\n delete(k) {\n return this.#delete(k, 'delete');\n }\n #delete(k, reason) {\n let deleted = false;\n if (this.#size !== 0) {\n const index = this.#keyMap.get(k);\n if (index !== undefined) {\n deleted = true;\n if (this.#size === 1) {\n this.#clear(reason);\n }\n else {\n this.#removeItemSize(index);\n const v = this.#valList[index];\n if (this.#isBackgroundFetch(v)) {\n v.__abortController.abort(new Error('deleted'));\n }\n else if (this.#hasDispose || this.#hasDisposeAfter) {\n if (this.#hasDispose) {\n this.#dispose?.(v, k, reason);\n }\n if (this.#hasDisposeAfter) {\n this.#disposed?.push([v, k, reason]);\n }\n }\n this.#keyMap.delete(k);\n this.#keyList[index] = undefined;\n this.#valList[index] = undefined;\n if (index === this.#tail) {\n this.#tail = this.#prev[index];\n }\n else if (index === this.#head) {\n this.#head = this.#next[index];\n }\n else {\n const pi = this.#prev[index];\n this.#next[pi] = this.#next[index];\n const ni = this.#next[index];\n this.#prev[ni] = this.#prev[index];\n }\n this.#size--;\n this.#free.push(index);\n }\n }\n }\n if (this.#hasDisposeAfter && this.#disposed?.length) {\n const dt = this.#disposed;\n let task;\n while ((task = dt?.shift())) {\n this.#disposeAfter?.(...task);\n }\n }\n return deleted;\n }\n /**\n * Clear the cache entirely, throwing away all values.\n */\n clear() {\n return this.#clear('delete');\n }\n #clear(reason) {\n for (const index of this.#rindexes({ allowStale: true })) {\n const v = this.#valList[index];\n if (this.#isBackgroundFetch(v)) {\n v.__abortController.abort(new Error('deleted'));\n }\n else {\n const k = this.#keyList[index];\n if (this.#hasDispose) {\n this.#dispose?.(v, k, reason);\n }\n if (this.#hasDisposeAfter) {\n this.#disposed?.push([v, k, reason]);\n }\n }\n }\n this.#keyMap.clear();\n this.#valList.fill(undefined);\n this.#keyList.fill(undefined);\n if (this.#ttls && this.#starts) {\n this.#ttls.fill(0);\n this.#starts.fill(0);\n }\n if (this.#sizes) {\n this.#sizes.fill(0);\n }\n this.#head = 0;\n this.#tail = 0;\n this.#free.length = 0;\n this.#calculatedSize = 0;\n this.#size = 0;\n if (this.#hasDisposeAfter && this.#disposed) {\n const dt = this.#disposed;\n let task;\n while ((task = dt?.shift())) {\n this.#disposeAfter?.(...task);\n }\n }\n }\n}\nexports.LRUCache = LRUCache;\n//# sourceMappingURL=index.js.map","'use strict';\n\nfunction getDefaultExportFromCjs (x) {\n\treturn x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;\n}\n\nconst CRC_TABLE = new Int32Array([\n 0,\n 1996959894,\n 3993919788,\n 2567524794,\n 124634137,\n 1886057615,\n 3915621685,\n 2657392035,\n 249268274,\n 2044508324,\n 3772115230,\n 2547177864,\n 162941995,\n 2125561021,\n 3887607047,\n 2428444049,\n 498536548,\n 1789927666,\n 4089016648,\n 2227061214,\n 450548861,\n 1843258603,\n 4107580753,\n 2211677639,\n 325883990,\n 1684777152,\n 4251122042,\n 2321926636,\n 335633487,\n 1661365465,\n 4195302755,\n 2366115317,\n 997073096,\n 1281953886,\n 3579855332,\n 2724688242,\n 1006888145,\n 1258607687,\n 3524101629,\n 2768942443,\n 901097722,\n 1119000684,\n 3686517206,\n 2898065728,\n 853044451,\n 1172266101,\n 3705015759,\n 2882616665,\n 651767980,\n 1373503546,\n 3369554304,\n 3218104598,\n 565507253,\n 1454621731,\n 3485111705,\n 3099436303,\n 671266974,\n 1594198024,\n 3322730930,\n 2970347812,\n 795835527,\n 1483230225,\n 3244367275,\n 3060149565,\n 1994146192,\n 31158534,\n 2563907772,\n 4023717930,\n 1907459465,\n 112637215,\n 2680153253,\n 3904427059,\n 2013776290,\n 251722036,\n 2517215374,\n 3775830040,\n 2137656763,\n 141376813,\n 2439277719,\n 3865271297,\n 1802195444,\n 476864866,\n 2238001368,\n 4066508878,\n 1812370925,\n 453092731,\n 2181625025,\n 4111451223,\n 1706088902,\n 314042704,\n 2344532202,\n 4240017532,\n 1658658271,\n 366619977,\n 2362670323,\n 4224994405,\n 1303535960,\n 984961486,\n 2747007092,\n 3569037538,\n 1256170817,\n 1037604311,\n 2765210733,\n 3554079995,\n 1131014506,\n 879679996,\n 2909243462,\n 3663771856,\n 1141124467,\n 855842277,\n 2852801631,\n 3708648649,\n 1342533948,\n 654459306,\n 3188396048,\n 3373015174,\n 1466479909,\n 544179635,\n 3110523913,\n 3462522015,\n 1591671054,\n 702138776,\n 2966460450,\n 3352799412,\n 1504918807,\n 783551873,\n 3082640443,\n 3233442989,\n 3988292384,\n 2596254646,\n 62317068,\n 1957810842,\n 3939845945,\n 2647816111,\n 81470997,\n 1943803523,\n 3814918930,\n 2489596804,\n 225274430,\n 2053790376,\n 3826175755,\n 2466906013,\n 167816743,\n 2097651377,\n 4027552580,\n 2265490386,\n 503444072,\n 1762050814,\n 4150417245,\n 2154129355,\n 426522225,\n 1852507879,\n 4275313526,\n 2312317920,\n 282753626,\n 1742555852,\n 4189708143,\n 2394877945,\n 397917763,\n 1622183637,\n 3604390888,\n 2714866558,\n 953729732,\n 1340076626,\n 3518719985,\n 2797360999,\n 1068828381,\n 1219638859,\n 3624741850,\n 2936675148,\n 906185462,\n 1090812512,\n 3747672003,\n 2825379669,\n 829329135,\n 1181335161,\n 3412177804,\n 3160834842,\n 628085408,\n 1382605366,\n 3423369109,\n 3138078467,\n 570562233,\n 1426400815,\n 3317316542,\n 2998733608,\n 733239954,\n 1555261956,\n 3268935591,\n 3050360625,\n 752459403,\n 1541320221,\n 2607071920,\n 3965973030,\n 1969922972,\n 40735498,\n 2617837225,\n 3943577151,\n 1913087877,\n 83908371,\n 2512341634,\n 3803740692,\n 2075208622,\n 213261112,\n 2463272603,\n 3855990285,\n 2094854071,\n 198958881,\n 2262029012,\n 4057260610,\n 1759359992,\n 534414190,\n 2176718541,\n 4139329115,\n 1873836001,\n 414664567,\n 2282248934,\n 4279200368,\n 1711684554,\n 285281116,\n 2405801727,\n 4167216745,\n 1634467795,\n 376229701,\n 2685067896,\n 3608007406,\n 1308918612,\n 956543938,\n 2808555105,\n 3495958263,\n 1231636301,\n 1047427035,\n 2932959818,\n 3654703836,\n 1088359270,\n 936918e3,\n 2847714899,\n 3736837829,\n 1202900863,\n 817233897,\n 3183342108,\n 3401237130,\n 1404277552,\n 615818150,\n 3134207493,\n 3453421203,\n 1423857449,\n 601450431,\n 3009837614,\n 3294710456,\n 1567103746,\n 711928724,\n 3020668471,\n 3272380065,\n 1510334235,\n 755167117\n]);\nfunction ensureBuffer(input) {\n if (Buffer.isBuffer(input)) {\n return input;\n }\n if (typeof input === \"number\") {\n return Buffer.alloc(input);\n } else if (typeof input === \"string\") {\n return Buffer.from(input);\n } else {\n throw new Error(\"input must be buffer, number, or string, received \" + typeof input);\n }\n}\nfunction bufferizeInt(num) {\n const tmp = ensureBuffer(4);\n tmp.writeInt32BE(num, 0);\n return tmp;\n}\nfunction _crc32(buf, previous) {\n buf = ensureBuffer(buf);\n if (Buffer.isBuffer(previous)) {\n previous = previous.readUInt32BE(0);\n }\n let crc = ~~previous ^ -1;\n for (var n = 0; n < buf.length; n++) {\n crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;\n }\n return crc ^ -1;\n}\nfunction crc32() {\n return bufferizeInt(_crc32.apply(null, arguments));\n}\ncrc32.signed = function() {\n return _crc32.apply(null, arguments);\n};\ncrc32.unsigned = function() {\n return _crc32.apply(null, arguments) >>> 0;\n};\nvar bufferCrc32 = crc32;\n\nconst index = /*@__PURE__*/getDefaultExportFromCjs(bufferCrc32);\n\nmodule.exports = index;\n","(()=>{\"use strict\";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})}},e={};t.r(e),t.d(e,{XMLBuilder:()=>ut,XMLParser:()=>et,XMLValidator:()=>ft});const i=\":A-Za-z_\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD\",n=new RegExp(\"^[\"+i+\"][\"+i+\"\\\\-.\\\\d\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040]*$\");function s(t,e){const i=[];let n=e.exec(t);for(;n;){const s=[];s.startIndex=e.lastIndex-n[0].length;const r=n.length;for(let t=0;t\"!==t[o]&&\" \"!==t[o]&&\"\\t\"!==t[o]&&\"\\n\"!==t[o]&&\"\\r\"!==t[o];o++)p+=t[o];if(p=p.trim(),\"/\"===p[p.length-1]&&(p=p.substring(0,p.length-1),o--),!r(p)){let e;return e=0===p.trim().length?\"Invalid space after '<'.\":\"Tag '\"+p+\"' is an invalid name.\",x(\"InvalidTag\",e,b(t,o))}const c=f(t,o);if(!1===c)return x(\"InvalidAttr\",\"Attributes for '\"+p+\"' have open quote.\",b(t,o));let N=c.value;if(o=c.index,\"/\"===N[N.length-1]){const i=o-N.length;N=N.substring(0,N.length-1);const s=g(N,e);if(!0!==s)return x(s.err.code,s.err.msg,b(t,i+s.err.line));n=!0}else if(d){if(!c.tagClosed)return x(\"InvalidTag\",\"Closing tag '\"+p+\"' doesn't have proper closing.\",b(t,o));if(N.trim().length>0)return x(\"InvalidTag\",\"Closing tag '\"+p+\"' can't have attributes or invalid starting.\",b(t,a));if(0===i.length)return x(\"InvalidTag\",\"Closing tag '\"+p+\"' has not been opened.\",b(t,a));{const e=i.pop();if(p!==e.tagName){let i=b(t,e.tagStartPos);return x(\"InvalidTag\",\"Expected closing tag '\"+e.tagName+\"' (opened in line \"+i.line+\", col \"+i.col+\") instead of closing tag '\"+p+\"'.\",b(t,a))}0==i.length&&(s=!0)}}else{const r=g(N,e);if(!0!==r)return x(r.err.code,r.err.msg,b(t,o-N.length+r.err.line));if(!0===s)return x(\"InvalidXml\",\"Multiple possible root nodes found.\",b(t,o));-1!==e.unpairedTags.indexOf(p)||i.push({tagName:p,tagStartPos:a}),n=!0}for(o++;o0)||x(\"InvalidXml\",\"Invalid '\"+JSON.stringify(i.map((t=>t.tagName)),null,4).replace(/\\r?\\n/g,\"\")+\"' found.\",{line:1,col:1}):x(\"InvalidXml\",\"Start tag expected.\",1)}function l(t){return\" \"===t||\"\\t\"===t||\"\\n\"===t||\"\\r\"===t}function u(t,e){const i=e;for(;e5&&\"xml\"===n)return x(\"InvalidXml\",\"XML declaration allowed only at the start of the document.\",b(t,e));if(\"?\"==t[e]&&\">\"==t[e+1]){e++;break}}return e}function h(t,e){if(t.length>e+5&&\"-\"===t[e+1]&&\"-\"===t[e+2]){for(e+=3;e\"===t[e+2]){e+=2;break}}else if(t.length>e+8&&\"D\"===t[e+1]&&\"O\"===t[e+2]&&\"C\"===t[e+3]&&\"T\"===t[e+4]&&\"Y\"===t[e+5]&&\"P\"===t[e+6]&&\"E\"===t[e+7]){let i=1;for(e+=8;e\"===t[e]&&(i--,0===i))break}else if(t.length>e+9&&\"[\"===t[e+1]&&\"C\"===t[e+2]&&\"D\"===t[e+3]&&\"A\"===t[e+4]&&\"T\"===t[e+5]&&\"A\"===t[e+6]&&\"[\"===t[e+7])for(e+=8;e\"===t[e+2]){e+=2;break}return e}const d='\"',p=\"'\";function f(t,e){let i=\"\",n=\"\",s=!1;for(;e\"===t[e]&&\"\"===n){s=!0;break}i+=t[e]}return\"\"===n&&{value:i,index:e,tagClosed:s}}const c=new RegExp(\"(\\\\s*)([^\\\\s=]+)(\\\\s*=)?(\\\\s*(['\\\"])(([\\\\s\\\\S])*?)\\\\5)?\",\"g\");function g(t,e){const i=s(t,c),n={};for(let t=0;t!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1};let T;T=\"function\"!=typeof Symbol?\"@@xmlMetadata\":Symbol(\"XML Node Metadata\");class y{constructor(t){this.tagname=t,this.child=[],this[\":@\"]={}}add(t,e){\"__proto__\"===t&&(t=\"#__proto__\"),this.child.push({[t]:e})}addChild(t,e){\"__proto__\"===t.tagname&&(t.tagname=\"#__proto__\"),t[\":@\"]&&Object.keys(t[\":@\"]).length>0?this.child.push({[t.tagname]:t.child,\":@\":t[\":@\"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][T]={startIndex:e})}static getMetaDataSymbol(){return T}}class w{constructor(t){this.suppressValidationErr=!t}readDocType(t,e){const i={};if(\"O\"!==t[e+3]||\"C\"!==t[e+4]||\"T\"!==t[e+5]||\"Y\"!==t[e+6]||\"P\"!==t[e+7]||\"E\"!==t[e+8])throw new Error(\"Invalid Tag instead of DOCTYPE\");{e+=9;let n=1,s=!1,r=!1,o=\"\";for(;e