UNPKG

lakutata

Version:

An IoC-based universal application framework.

1,704 lines (1,586 loc) 158 kB
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */ import { fileURLToPath as t } from "node:url"; import { win32 as e, posix as s } from "node:path"; import { realpathSync as i, readlinkSync as n, readdirSync as r, readdir as o, lstatSync as h } from "fs"; import * as a from "node:fs"; import { realpath as l, readlink as c, readdir as f, lstat as u } from "node:fs/promises"; import { EventEmitter as d } from "node:events"; import p from "node:stream"; import { StringDecoder as g } from "node:string_decoder"; const m = (t, e, s) => { const i = t instanceof RegExp ? w(t, s) : t; const n = e instanceof RegExp ? w(e, s) : e; const r = i !== null && n != null && y(i, n, s); return r && { start: r[0], end: r[1], pre: s.slice(0, r[0]), body: s.slice(r[0] + i.length, r[1]), post: s.slice(r[1] + n.length) }; }; const w = (t, e) => { const s = e.match(t); return s ? s[0] : null; }; const y = (t, e, s) => { let i, n, r, o = undefined, h; let a = s.indexOf(t); let l = s.indexOf(e, a + 1); let c = a; if (a >= 0 && l > 0) { if (t === e) { return [ a, l ]; } i = []; r = s.length; while (c >= 0 && !h) { if (c === a) { i.push(c); a = s.indexOf(t, c + 1); } else if (i.length === 1) { const t = i.pop(); if (t !== undefined) h = [ t, l ]; } else { n = i.pop(); if (n !== undefined && n < r) { r = n; o = l; } l = s.indexOf(e, c + 1); } c = a < l && a >= 0 ? a : l; } if (i.length && o !== undefined) { h = [ r, o ]; } } return h; }; const b = "\0SLASH" + Math.random() + "\0"; const S = "\0OPEN" + Math.random() + "\0"; const k = "\0CLOSE" + Math.random() + "\0"; const x = "\0COMMA" + Math.random() + "\0"; const v = "\0PERIOD" + Math.random() + "\0"; const E = new RegExp(b, "g"); const C = new RegExp(S, "g"); const T = new RegExp(k, "g"); const L = new RegExp(x, "g"); const A = new RegExp(v, "g"); const M = /\\\\/g; const P = /\\{/g; const F = /\\}/g; const R = /\\,/g; const O = /\\./g; function z(t) { return !isNaN(t) ? parseInt(t, 10) : t.charCodeAt(0); } function D(t) { return t.replace(M, b).replace(P, S).replace(F, k).replace(R, x).replace(O, v); } function N(t) { return t.replace(E, "\\").replace(C, "{").replace(T, "}").replace(L, ",").replace(A, "."); } function B(t) { if (!t) { return [ "" ]; } const e = []; const s = m("{", "}", t); if (!s) { return t.split(","); } const {pre: i, body: n, post: r} = s; const o = i.split(","); o[o.length - 1] += "{" + n + "}"; const h = B(r); if (r.length) { o[o.length - 1] += h.shift(); o.push.apply(o, h); } e.push.apply(e, o); return e; } function W(t) { if (!t) { return []; } if (t.slice(0, 2) === "{}") { t = "\\{\\}" + t.slice(2); } return U(D(t), true).map(N); } function I(t) { return "{" + t + "}"; } function _(t) { return /^-?0\d/.test(t); } function j(t, e) { return t <= e; } function $(t, e) { return t >= e; } function U(t, e) { const s = []; const i = m("{", "}", t); if (!i) return [ t ]; const n = i.pre; const r = i.post.length ? U(i.post, false) : [ "" ]; if (/\$$/.test(i.pre)) { for (let t = 0; t < r.length; t++) { const e = n + "{" + i.body + "}" + r[t]; s.push(e); } } else { const o = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body); const h = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body); const a = o || h; const l = i.body.indexOf(",") >= 0; if (!a && !l) { if (i.post.match(/,(?!,).*\}/)) { t = i.pre + "{" + i.body + k + i.post; return U(t); } return [ t ]; } let c; if (a) { c = i.body.split(/\.\./); } else { c = B(i.body); if (c.length === 1 && c[0] !== undefined) { c = U(c[0], false).map(I); if (c.length === 1) { return r.map(t => i.pre + c[0] + t); } } } let f; if (a && c[0] !== undefined && c[1] !== undefined) { const t = z(c[0]); const e = z(c[1]); const s = Math.max(c[0].length, c[1].length); let i = c.length === 3 && c[2] !== undefined ? Math.abs(z(c[2])) : 1; let n = j; const r = e < t; if (r) { i *= -1; n = $; } const o = c.some(_); f = []; for (let r = t; n(r, e); r += i) { let t; if (h) { t = String.fromCharCode(r); if (t === "\\") { t = ""; } } else { t = String(r); if (o) { const e = s - t.length; if (e > 0) { const s = new Array(e + 1).join("0"); if (r < 0) { t = "-" + s + t.slice(1); } else { t = s + t; } } } } f.push(t); } } else { f = []; for (let t = 0; t < c.length; t++) { f.push.apply(f, U(c[t], false)); } } for (let t = 0; t < f.length; t++) { for (let i = 0; i < r.length; i++) { const o = n + f[t] + r[i]; if (!e || a || o) { s.push(o); } } } } return s; } const G = 1024 * 64; const H = t => { if (typeof t !== "string") { throw new TypeError("invalid pattern"); } if (t.length > G) { throw new TypeError("pattern is too long"); } }; const Z = { "[:alnum:]": [ "\\p{L}\\p{Nl}\\p{Nd}", true ], "[:alpha:]": [ "\\p{L}\\p{Nl}", true ], "[:ascii:]": [ "\\x" + "00-\\x" + "7f", false ], "[:blank:]": [ "\\p{Zs}\\t", true ], "[:cntrl:]": [ "\\p{Cc}", true ], "[:digit:]": [ "\\p{Nd}", true ], "[:graph:]": [ "\\p{Z}\\p{C}", true, true ], "[:lower:]": [ "\\p{Ll}", true ], "[:print:]": [ "\\p{C}", true ], "[:punct:]": [ "\\p{P}", true ], "[:space:]": [ "\\p{Z}\\t\\r\\n\\v\\f", true ], "[:upper:]": [ "\\p{Lu}", true ], "[:word:]": [ "\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true ], "[:xdigit:]": [ "A-Fa-f0-9", false ] }; const q = t => t.replace(/[[\]\\-]/g, "\\$&"); const V = t => t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); const J = t => t.join(""); const K = (t, e) => { const s = e; if (t.charAt(s) !== "[") { throw new Error("not in a brace expression"); } const i = []; const n = []; let r = s + 1; let o = false; let h = false; let a = false; let l = false; let c = s; let f = ""; t: while (r < t.length) { const e = t.charAt(r); if ((e === "!" || e === "^") && r === s + 1) { l = true; r++; continue; } if (e === "]" && o && !a) { c = r + 1; break; } o = true; if (e === "\\") { if (!a) { a = true; r++; continue; } } if (e === "[" && !a) { for (const [e, [o, a, l]] of Object.entries(Z)) { if (t.startsWith(e, r)) { if (f) { return [ "$.", false, t.length - s, true ]; } r += e.length; if (l) n.push(o); else i.push(o); h = h || a; continue t; } } } a = false; if (f) { if (e > f) { i.push(q(f) + "-" + q(e)); } else if (e === f) { i.push(q(e)); } f = ""; r++; continue; } if (t.startsWith("-]", r + 1)) { i.push(q(e + "-")); r += 2; continue; } if (t.startsWith("-", r + 1)) { f = e; r += 2; continue; } i.push(q(e)); r++; } if (c < r) { return [ "", false, 0, false ]; } if (!i.length && !n.length) { return [ "$.", false, t.length - s, true ]; } if (n.length === 0 && i.length === 1 && /^\\?.$/.test(i[0]) && !l) { const t = i[0].length === 2 ? i[0].slice(-1) : i[0]; return [ V(t), false, c - s, false ]; } const u = "[" + (l ? "^" : "") + J(i) + "]"; const d = "[" + (l ? "" : "^") + J(n) + "]"; const p = i.length && n.length ? "(" + u + "|" + d + ")" : i.length ? u : d; return [ p, h, c - s, true ]; }; const Y = (t, {windowsPathsNoEscape: e = false, magicalBraces: s = true} = {}) => { if (s) { return e ? t.replace(/\[([^\/\\])\]/g, "$1") : t.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1"); } return e ? t.replace(/\[([^\/\\{}])\]/g, "$1") : t.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, "$1$2").replace(/\\([^\/{}])/g, "$1"); }; const X = new Set([ "!", "?", "+", "*", "@" ]); const Q = t => X.has(t); const tt = "(?!(?:^|/)\\.\\.?(?:$|/))"; const et = "(?!\\.)"; const st = new Set([ "[", "." ]); const it = new Set([ "..", "." ]); const nt = new Set("().*{}+?[]^$\\!"); const rt = t => t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); const ot = "[^/]"; const ht = ot + "*?"; const at = ot + "+?"; class AST { type; #t; #e; #s=false; #i=[]; #n; #r; #o; #h=false; #a; #l; #c=false; constructor(t, e, s = {}) { this.type = t; if (t) this.#e = true; this.#n = e; this.#t = this.#n ? this.#n.#t : this; this.#a = this.#t === this ? s : this.#t.#a; this.#o = this.#t === this ? [] : this.#t.#o; if (t === "!" && !this.#t.#h) this.#o.push(this); this.#r = this.#n ? this.#n.#i.length : 0; } get hasMagic() { if (this.#e !== undefined) return this.#e; for (const t of this.#i) { if (typeof t === "string") continue; if (t.type || t.hasMagic) return this.#e = true; } return this.#e; } toString() { if (this.#l !== undefined) return this.#l; if (!this.type) { return this.#l = this.#i.map(t => String(t)).join(""); } else { return this.#l = this.type + "(" + this.#i.map(t => String(t)).join("|") + ")"; } } #f() { if (this !== this.#t) throw new Error("should only call on root"); if (this.#h) return this; this.toString(); this.#h = true; let t; while (t = this.#o.pop()) { if (t.type !== "!") continue; let e = t; let s = e.#n; while (s) { for (let i = e.#r + 1; !s.type && i < s.#i.length; i++) { for (const e of t.#i) { if (typeof e === "string") { throw new Error("string part in extglob AST??"); } e.copyIn(s.#i[i]); } } e = s; s = e.#n; } } return this; } push(...t) { for (const e of t) { if (e === "") continue; if (typeof e !== "string" && !(e instanceof AST && e.#n === this)) { throw new Error("invalid part: " + e); } this.#i.push(e); } } toJSON() { const t = this.type === null ? this.#i.slice().map(t => typeof t === "string" ? t : t.toJSON()) : [ this.type, ...this.#i.map(t => t.toJSON()) ]; if (this.isStart() && !this.type) t.unshift([]); if (this.isEnd() && (this === this.#t || this.#t.#h && this.#n?.type === "!")) { t.push({}); } return t; } isStart() { if (this.#t === this) return true; if (!this.#n?.isStart()) return false; if (this.#r === 0) return true; const t = this.#n; for (let e = 0; e < this.#r; e++) { const s = t.#i[e]; if (!(s instanceof AST && s.type === "!")) { return false; } } return true; } isEnd() { if (this.#t === this) return true; if (this.#n?.type === "!") return true; if (!this.#n?.isEnd()) return false; if (!this.type) return this.#n?.isEnd(); const t = this.#n ? this.#n.#i.length : 0; return this.#r === t - 1; } copyIn(t) { if (typeof t === "string") this.push(t); else this.push(t.clone(this)); } clone(t) { const e = new AST(this.type, t); for (const t of this.#i) { e.copyIn(t); } return e; } static #u(t, e, s, i) { let n = false; let r = false; let o = -1; let h = false; if (e.type === null) { let a = s; let l = ""; while (a < t.length) { const s = t.charAt(a++); if (n || s === "\\") { n = !n; l += s; continue; } if (r) { if (a === o + 1) { if (s === "^" || s === "!") { h = true; } } else if (s === "]" && !(a === o + 2 && h)) { r = false; } l += s; continue; } else if (s === "[") { r = true; o = a; h = false; l += s; continue; } if (!i.noext && Q(s) && t.charAt(a) === "(") { e.push(l); l = ""; const n = new AST(s, e); a = AST.#u(t, n, a, i); e.push(n); continue; } l += s; } e.push(l); return a; } let a = s + 1; let l = new AST(null, e); const c = []; let f = ""; while (a < t.length) { const s = t.charAt(a++); if (n || s === "\\") { n = !n; f += s; continue; } if (r) { if (a === o + 1) { if (s === "^" || s === "!") { h = true; } } else if (s === "]" && !(a === o + 2 && h)) { r = false; } f += s; continue; } else if (s === "[") { r = true; o = a; h = false; f += s; continue; } if (Q(s) && t.charAt(a) === "(") { l.push(f); f = ""; const e = new AST(s, l); l.push(e); a = AST.#u(t, e, a, i); continue; } if (s === "|") { l.push(f); f = ""; c.push(l); l = new AST(null, e); continue; } if (s === ")") { if (f === "" && e.#i.length === 0) { e.#c = true; } l.push(f); f = ""; e.push(...c, l); return a; } f += s; } e.type = null; e.#e = undefined; e.#i = [ t.substring(s - 1) ]; return a; } static fromGlob(t, e = {}) { const s = new AST(null, undefined, e); AST.#u(t, s, 0, e); return s; } toMMPattern() { if (this !== this.#t) return this.#t.toMMPattern(); const t = this.toString(); const [e, s, i, n] = this.toRegExpSource(); const r = i || this.#e || this.#a.nocase && !this.#a.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase(); if (!r) { return s; } const o = (this.#a.nocase ? "i" : "") + (n ? "u" : ""); return Object.assign(new RegExp(`^${e}$`, o), { _src: e, _glob: t }); } get options() { return this.#a; } toRegExpSource(t) { const e = t ?? !!this.#a.dot; if (this.#t === this) this.#f(); if (!this.type) { const s = this.isStart() && this.isEnd() && !this.#i.some(t => typeof t !== "string"); const i = this.#i.map(e => { const [i, n, r, o] = typeof e === "string" ? AST.#d(e, this.#e, s) : e.toRegExpSource(t); this.#e = this.#e || r; this.#s = this.#s || o; return i; }).join(""); let n = ""; if (this.isStart()) { if (typeof this.#i[0] === "string") { const s = this.#i.length === 1 && it.has(this.#i[0]); if (!s) { const s = st; const r = e && s.has(i.charAt(0)) || i.startsWith("\\.") && s.has(i.charAt(2)) || i.startsWith("\\.\\.") && s.has(i.charAt(4)); const o = !e && !t && s.has(i.charAt(0)); n = r ? tt : o ? et : ""; } } } let r = ""; if (this.isEnd() && this.#t.#h && this.#n?.type === "!") { r = "(?:$|\\/)"; } const o = n + i + r; return [ o, Y(i), this.#e = !!this.#e, this.#s ]; } const s = this.type === "*" || this.type === "+"; const i = this.type === "!" ? "(?:(?!(?:" : "(?:"; let n = this.#p(e); if (this.isStart() && this.isEnd() && !n && this.type !== "!") { const t = this.toString(); this.#i = [ t ]; this.type = null; this.#e = undefined; return [ t, Y(this.toString()), false, false ]; } let r = !s || t || e || !et ? "" : this.#p(true); if (r === n) { r = ""; } if (r) { n = `(?:${n})(?:${r})*?`; } let o = ""; if (this.type === "!" && this.#c) { o = (this.isStart() && !e ? et : "") + at; } else { const s = this.type === "!" ? "))" + (this.isStart() && !e && !t ? et : "") + ht + ")" : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && r ? ")" : this.type === "*" && r ? `)?` : `)${this.type}`; o = i + n + s; } return [ o, Y(n), this.#e = !!this.#e, this.#s ]; } #p(t) { return this.#i.map(e => { if (typeof e === "string") { throw new Error("string type in extglob ast??"); } const [s, i, n, r] = e.toRegExpSource(t); this.#s = this.#s || r; return s; }).filter(t => !(this.isStart() && this.isEnd()) || !!t).join("|"); } static #d(t, e, s = false) { let i = false; let n = ""; let r = false; for (let o = 0; o < t.length; o++) { const h = t.charAt(o); if (i) { i = false; n += (nt.has(h) ? "\\" : "") + h; continue; } if (h === "\\") { if (o === t.length - 1) { n += "\\\\"; } else { i = true; } continue; } if (h === "[") { const [s, i, h, a] = K(t, o); if (h) { n += s; r = r || i; o += h - 1; e = e || a; continue; } } if (h === "*") { n += s && t === "*" ? at : ht; e = true; continue; } if (h === "?") { n += ot; e = true; continue; } n += rt(h); } return [ n, Y(t), !!e, r ]; } } const lt = (t, {windowsPathsNoEscape: e = false, magicalBraces: s = false} = {}) => { if (s) { return e ? t.replace(/[?*()[\]{}]/g, "[$&]") : t.replace(/[?*()[\]\\{}]/g, "\\$&"); } return e ? t.replace(/[?*()[\]]/g, "[$&]") : t.replace(/[?*()[\]\\]/g, "\\$&"); }; const ct = (t, e, s = {}) => { H(e); if (!s.nocomment && e.charAt(0) === "#") { return false; } return new Minimatch(e, s).match(t); }; const ft = /^\*+([^+@!?\*\[\(]*)$/; const ut = t => e => !e.startsWith(".") && e.endsWith(t); const dt = t => e => e.endsWith(t); const pt = t => { t = t.toLowerCase(); return e => !e.startsWith(".") && e.toLowerCase().endsWith(t); }; const gt = t => { t = t.toLowerCase(); return e => e.toLowerCase().endsWith(t); }; const mt = /^\*+\.\*+$/; const wt = t => !t.startsWith(".") && t.includes("."); const yt = t => t !== "." && t !== ".." && t.includes("."); const bt = /^\.\*+$/; const St = t => t !== "." && t !== ".." && t.startsWith("."); const kt = /^\*+$/; const xt = t => t.length !== 0 && !t.startsWith("."); const vt = t => t.length !== 0 && t !== "." && t !== ".."; const Et = /^\?+([^+@!?\*\[\(]*)?$/; const Ct = ([t, e = ""]) => { const s = Mt([ t ]); if (!e) return s; e = e.toLowerCase(); return t => s(t) && t.toLowerCase().endsWith(e); }; const Tt = ([t, e = ""]) => { const s = Pt([ t ]); if (!e) return s; e = e.toLowerCase(); return t => s(t) && t.toLowerCase().endsWith(e); }; const Lt = ([t, e = ""]) => { const s = Pt([ t ]); return !e ? s : t => s(t) && t.endsWith(e); }; const At = ([t, e = ""]) => { const s = Mt([ t ]); return !e ? s : t => s(t) && t.endsWith(e); }; const Mt = ([t]) => { const e = t.length; return t => t.length === e && !t.startsWith("."); }; const Pt = ([t]) => { const e = t.length; return t => t.length === e && t !== "." && t !== ".."; }; const Ft = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix"; const Rt = { win32: { sep: "\\" }, posix: { sep: "/" } }; const Ot = Ft === "win32" ? Rt.win32.sep : Rt.posix.sep; ct.sep = Ot; const zt = Symbol("globstar **"); ct.GLOBSTAR = zt; const Dt = "[^/]"; const Nt = Dt + "*?"; const Bt = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?"; const Wt = "(?:(?!(?:\\/|^)\\.).)*?"; const It = (t, e = {}) => s => ct(s, t, e); ct.filter = It; const _t = (t, e = {}) => Object.assign({}, t, e); const jt = t => { if (!t || typeof t !== "object" || !Object.keys(t).length) { return ct; } const e = ct; const s = (s, i, n = {}) => e(s, i, _t(t, n)); return Object.assign(s, { Minimatch: class Minimatch extends e.Minimatch { constructor(e, s = {}) { super(e, _t(t, s)); } static defaults(s) { return e.defaults(_t(t, s)).Minimatch; } }, AST: class AST extends e.AST { constructor(e, s, i = {}) { super(e, s, _t(t, i)); } static fromGlob(s, i = {}) { return e.AST.fromGlob(s, _t(t, i)); } }, unescape: (s, i = {}) => e.unescape(s, _t(t, i)), escape: (s, i = {}) => e.escape(s, _t(t, i)), filter: (s, i = {}) => e.filter(s, _t(t, i)), defaults: s => e.defaults(_t(t, s)), makeRe: (s, i = {}) => e.makeRe(s, _t(t, i)), braceExpand: (s, i = {}) => e.braceExpand(s, _t(t, i)), match: (s, i, n = {}) => e.match(s, i, _t(t, n)), sep: e.sep, GLOBSTAR: zt }); }; ct.defaults = jt; const $t = (t, e = {}) => { H(t); if (e.nobrace || !/\{(?:(?!\{).)*\}/.test(t)) { return [ t ]; } return W(t); }; ct.braceExpand = $t; const Ut = (t, e = {}) => new Minimatch(t, e).makeRe(); ct.makeRe = Ut; const Gt = (t, e, s = {}) => { const i = new Minimatch(e, s); t = t.filter(t => i.match(t)); if (i.options.nonull && !t.length) { t.push(e); } return t; }; ct.match = Gt; const Ht = /[?*]|[+@!]\(.*?\)|\[|\]/; const Zt = t => t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); class Minimatch { options; set; pattern; windowsPathsNoEscape; nonegate; negate; comment; empty; preserveMultipleSlashes; partial; globSet; globParts; nocase; isWindows; platform; windowsNoMagicRoot; regexp; constructor(t, e = {}) { H(t); e = e || {}; this.options = e; this.pattern = t; this.platform = e.platform || Ft; this.isWindows = this.platform === "win32"; this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === false; if (this.windowsPathsNoEscape) { this.pattern = this.pattern.replace(/\\/g, "/"); } this.preserveMultipleSlashes = !!e.preserveMultipleSlashes; this.regexp = null; this.negate = false; this.nonegate = !!e.nonegate; this.comment = false; this.empty = false; this.partial = !!e.partial; this.nocase = !!this.options.nocase; this.windowsNoMagicRoot = e.windowsNoMagicRoot !== undefined ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase); this.globSet = []; this.globParts = []; this.set = []; this.make(); } hasMagic() { if (this.options.magicalBraces && this.set.length > 1) { return true; } for (const t of this.set) { for (const e of t) { if (typeof e !== "string") return true; } } return false; } debug(...t) {} make() { const t = this.pattern; const e = this.options; if (!e.nocomment && t.charAt(0) === "#") { this.comment = true; return; } if (!t) { this.empty = true; return; } this.parseNegate(); this.globSet = [ ...new Set(this.braceExpand()) ]; if (e.debug) { this.debug = (...t) => console.error(...t); } this.debug(this.pattern, this.globSet); const s = this.globSet.map(t => this.slashSplit(t)); this.globParts = this.preprocess(s); this.debug(this.pattern, this.globParts); let i = this.globParts.map((t, e, s) => { if (this.isWindows && this.windowsNoMagicRoot) { const e = t[0] === "" && t[1] === "" && (t[2] === "?" || !Ht.test(t[2])) && !Ht.test(t[3]); const s = /^[a-z]:/i.test(t[0]); if (e) { return [ ...t.slice(0, 4), ...t.slice(4).map(t => this.parse(t)) ]; } else if (s) { return [ t[0], ...t.slice(1).map(t => this.parse(t)) ]; } } return t.map(t => this.parse(t)); }); this.debug(this.pattern, i); this.set = i.filter(t => t.indexOf(false) === -1); if (this.isWindows) { for (let t = 0; t < this.set.length; t++) { const e = this.set[t]; if (e[0] === "" && e[1] === "" && this.globParts[t][2] === "?" && typeof e[3] === "string" && /^[a-z]:$/i.test(e[3])) { e[2] = "?"; } } } this.debug(this.pattern, this.set); } preprocess(t) { if (this.options.noglobstar) { for (let e = 0; e < t.length; e++) { for (let s = 0; s < t[e].length; s++) { if (t[e][s] === "**") { t[e][s] = "*"; } } } } const {optimizationLevel: e = 1} = this.options; if (e >= 2) { t = this.firstPhasePreProcess(t); t = this.secondPhasePreProcess(t); } else if (e >= 1) { t = this.levelOneOptimize(t); } else { t = this.adjascentGlobstarOptimize(t); } return t; } adjascentGlobstarOptimize(t) { return t.map(t => { let e = -1; while (-1 !== (e = t.indexOf("**", e + 1))) { let s = e; while (t[s + 1] === "**") { s++; } if (s !== e) { t.splice(e, s - e); } } return t; }); } levelOneOptimize(t) { return t.map(t => { t = t.reduce((t, e) => { const s = t[t.length - 1]; if (e === "**" && s === "**") { return t; } if (e === "..") { if (s && s !== ".." && s !== "." && s !== "**") { t.pop(); return t; } } t.push(e); return t; }, []); return t.length === 0 ? [ "" ] : t; }); } levelTwoFileOptimize(t) { if (!Array.isArray(t)) { t = this.slashSplit(t); } let e = false; do { e = false; if (!this.preserveMultipleSlashes) { for (let s = 1; s < t.length - 1; s++) { const i = t[s]; if (s === 1 && i === "" && t[0] === "") continue; if (i === "." || i === "") { e = true; t.splice(s, 1); s--; } } if (t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "")) { e = true; t.pop(); } } let s = 0; while (-1 !== (s = t.indexOf("..", s + 1))) { const i = t[s - 1]; if (i && i !== "." && i !== ".." && i !== "**") { e = true; t.splice(s - 1, 2); s -= 2; } } } while (e); return t.length === 0 ? [ "" ] : t; } firstPhasePreProcess(t) { let e = false; do { e = false; for (let s of t) { let i = -1; while (-1 !== (i = s.indexOf("**", i + 1))) { let n = i; while (s[n + 1] === "**") { n++; } if (n > i) { s.splice(i + 1, n - i); } let r = s[i + 1]; const o = s[i + 2]; const h = s[i + 3]; if (r !== "..") continue; if (!o || o === "." || o === ".." || !h || h === "." || h === "..") { continue; } e = true; s.splice(i, 1); const a = s.slice(0); a[i] = "**"; t.push(a); i--; } if (!this.preserveMultipleSlashes) { for (let t = 1; t < s.length - 1; t++) { const i = s[t]; if (t === 1 && i === "" && s[0] === "") continue; if (i === "." || i === "") { e = true; s.splice(t, 1); t--; } } if (s[0] === "." && s.length === 2 && (s[1] === "." || s[1] === "")) { e = true; s.pop(); } } let n = 0; while (-1 !== (n = s.indexOf("..", n + 1))) { const t = s[n - 1]; if (t && t !== "." && t !== ".." && t !== "**") { e = true; const t = n === 1 && s[n + 1] === "**"; const i = t ? [ "." ] : []; s.splice(n - 1, 2, ...i); if (s.length === 0) s.push(""); n -= 2; } } } } while (e); return t; } secondPhasePreProcess(t) { for (let e = 0; e < t.length - 1; e++) { for (let s = e + 1; s < t.length; s++) { const i = this.partsMatch(t[e], t[s], !this.preserveMultipleSlashes); if (i) { t[e] = []; t[s] = i; break; } } } return t.filter(t => t.length); } partsMatch(t, e, s = false) { let i = 0; let n = 0; let r = []; let o = ""; while (i < t.length && n < e.length) { if (t[i] === e[n]) { r.push(o === "b" ? e[n] : t[i]); i++; n++; } else if (s && t[i] === "**" && e[n] === t[i + 1]) { r.push(t[i]); i++; } else if (s && e[n] === "**" && t[i] === e[n + 1]) { r.push(e[n]); n++; } else if (t[i] === "*" && e[n] && (this.options.dot || !e[n].startsWith(".")) && e[n] !== "**") { if (o === "b") return false; o = "a"; r.push(t[i]); i++; n++; } else if (e[n] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") { if (o === "a") return false; o = "b"; r.push(e[n]); i++; n++; } else { return false; } } return t.length === e.length && r; } parseNegate() { if (this.nonegate) return; const t = this.pattern; let e = false; let s = 0; for (let i = 0; i < t.length && t.charAt(i) === "!"; i++) { e = !e; s++; } if (s) this.pattern = t.slice(s); this.negate = e; } matchOne(t, e, s = false) { const i = this.options; if (this.isWindows) { const s = typeof t[0] === "string" && /^[a-z]:$/i.test(t[0]); const i = !s && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]); const n = typeof e[0] === "string" && /^[a-z]:$/i.test(e[0]); const r = !n && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] === "string" && /^[a-z]:$/i.test(e[3]); const o = i ? 3 : s ? 0 : undefined; const h = r ? 3 : n ? 0 : undefined; if (typeof o === "number" && typeof h === "number") { const [s, i] = [ t[o], e[h] ]; if (s.toLowerCase() === i.toLowerCase()) { e[h] = s; if (h > o) { e = e.slice(h); } else if (o > h) { t = t.slice(o); } } } } const {optimizationLevel: n = 1} = this.options; if (n >= 2) { t = this.levelTwoFileOptimize(t); } this.debug("matchOne", this, { file: t, pattern: e }); this.debug("matchOne", t.length, e.length); for (var r = 0, o = 0, h = t.length, a = e.length; r < h && o < a; r++, o++) { this.debug("matchOne loop"); var l = e[o]; var c = t[r]; this.debug(e, l, c); if (l === false) { return false; } if (l === zt) { this.debug("GLOBSTAR", [ e, l, c ]); var f = r; var u = o + 1; if (u === a) { this.debug("** at the end"); for (;r < h; r++) { if (t[r] === "." || t[r] === ".." || !i.dot && t[r].charAt(0) === ".") return false; } return true; } while (f < h) { var d = t[f]; this.debug("\nglobstar while", t, f, e, u, d); if (this.matchOne(t.slice(f), e.slice(u), s)) { this.debug("globstar found match!", f, h, d); return true; } else { if (d === "." || d === ".." || !i.dot && d.charAt(0) === ".") { this.debug("dot detected!", t, f, e, u); break; } this.debug("globstar swallow a segment, and continue"); f++; } } if (s) { this.debug("\n>>> no match, partial?", t, f, e, u); if (f === h) { return true; } } return false; } let n; if (typeof l === "string") { n = c === l; this.debug("string match", l, c, n); } else { n = l.test(c); this.debug("pattern match", l, c, n); } if (!n) return false; } if (r === h && o === a) { return true; } else if (r === h) { return s; } else if (o === a) { return r === h - 1 && t[r] === ""; } else { throw new Error("wtf?"); } } braceExpand() { return $t(this.pattern, this.options); } parse(t) { H(t); const e = this.options; if (t === "**") return zt; if (t === "") return ""; let s; let i = null; if (s = t.match(kt)) { i = e.dot ? vt : xt; } else if (s = t.match(ft)) { i = (e.nocase ? e.dot ? gt : pt : e.dot ? dt : ut)(s[1]); } else if (s = t.match(Et)) { i = (e.nocase ? e.dot ? Tt : Ct : e.dot ? Lt : At)(s); } else if (s = t.match(mt)) { i = e.dot ? yt : wt; } else if (s = t.match(bt)) { i = St; } const n = AST.fromGlob(t, this.options).toMMPattern(); if (i && typeof n === "object") { Reflect.defineProperty(n, "test", { value: i }); } return n; } makeRe() { if (this.regexp || this.regexp === false) return this.regexp; const t = this.set; if (!t.length) { this.regexp = false; return this.regexp; } const e = this.options; const s = e.noglobstar ? Nt : e.dot ? Bt : Wt; const i = new Set(e.nocase ? [ "i" ] : []); let n = t.map(t => { const e = t.map(t => { if (t instanceof RegExp) { for (const e of t.flags.split("")) i.add(e); } return typeof t === "string" ? Zt(t) : t === zt ? zt : t._src; }); e.forEach((t, i) => { const n = e[i + 1]; const r = e[i - 1]; if (t !== zt || r === zt) { return; } if (r === undefined) { if (n !== undefined && n !== zt) { e[i + 1] = "(?:\\/|" + s + "\\/)?" + n; } else { e[i] = s; } } else if (n === undefined) { e[i - 1] = r + "(?:\\/|\\/" + s + ")?"; } else if (n !== zt) { e[i - 1] = r + "(?:\\/|\\/" + s + "\\/)" + n; e[i + 1] = zt; } }); const n = e.filter(t => t !== zt); if (this.partial && n.length >= 1) { const t = []; for (let e = 1; e <= n.length; e++) { t.push(n.slice(0, e).join("/")); } return "(?:" + t.join("|") + ")"; } return n.join("/"); }).join("|"); const [r, o] = t.length > 1 ? [ "(?:", ")" ] : [ "", "" ]; n = "^" + r + n + o + "$"; if (this.partial) { n = "^(?:\\/|" + r + n.slice(1, -1) + o + ")$"; } if (this.negate) n = "^(?!" + n + ").+$"; try { this.regexp = new RegExp(n, [ ...i ].join("")); } catch (t) { this.regexp = false; } return this.regexp; } slashSplit(t) { if (this.preserveMultipleSlashes) { return t.split("/"); } else if (this.isWindows && /^\/\/[^\/]+/.test(t)) { return [ "", ...t.split(/\/+/) ]; } else { return t.split(/\/+/); } } match(t, e = this.partial) { this.debug("match", t, this.pattern); if (this.comment) { return false; } if (this.empty) { return t === ""; } if (t === "/" && e) { return true; } const s = this.options; if (this.isWindows) { t = t.split("\\").join("/"); } const i = this.slashSplit(t); this.debug(this.pattern, "split", i); const n = this.set; this.debug(this.pattern, "set", n); let r = i[i.length - 1]; if (!r) { for (let t = i.length - 2; !r && t >= 0; t--) { r = i[t]; } } for (let t = 0; t < n.length; t++) { const o = n[t]; let h = i; if (s.matchBase && o.length === 1) { h = [ r ]; } const a = this.matchOne(h, o, e); if (a) { if (s.flipNegate) { return true; } return !this.negate; } } if (s.flipNegate) { return false; } return this.negate; } static defaults(t) { return ct.defaults(t).Minimatch; } } ct.AST = AST; ct.Minimatch = Minimatch; ct.escape = lt; ct.unescape = Y; const qt = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date; const Vt = new Set; const Jt = typeof process === "object" && !!process ? process : {}; const Kt = (t, e, s, i) => { typeof Jt.emitWarning === "function" ? Jt.emitWarning(t, e, s, i) : console.error(`[${s}] ${e}: ${t}`); }; let Yt = globalThis.AbortController; let Xt = globalThis.AbortSignal; if (typeof Yt === "undefined") { Xt = class AbortSignal { onabort; _onabort=[]; reason; aborted=false; addEventListener(t, e) { this._onabort.push(e); } }; Yt = class AbortController { constructor() { e(); } signal=new Xt; abort(t) { if (this.signal.aborted) return; this.signal.reason = t; this.signal.aborted = true; for (const e of this.signal._onabort) { e(t); } this.signal.onabort?.(t); } }; let t = Jt.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1"; const e = () => { if (!t) return; t = false; Kt("AbortController is not defined. If using lru-cache in " + "node 14, load an AbortController polyfill from the " + "`node-abort-controller` package. A minimal polyfill is " + "provided for use by LRUCache.fetch(), but it should not be " + "relied upon in other contexts (eg, passing it to other APIs that " + "use AbortController/AbortSignal might have undesirable effects). " + "You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", e); }; } const Qt = t => !Vt.has(t); const te = t => t && t === Math.floor(t) && t > 0 && isFinite(t); const ee = t => !te(t) ? null : t <= Math.pow(2, 8) ? Uint8Array : t <= Math.pow(2, 16) ? Uint16Array : t <= Math.pow(2, 32) ? Uint32Array : t <= Number.MAX_SAFE_INTEGER ? ZeroArray : null; class ZeroArray extends Array { constructor(t) { super(t); this.fill(0); } } class Stack { heap; length; static #g=false; static create(t) { const e = ee(t); if (!e) return []; Stack.#g = true; const s = new Stack(t, e); Stack.#g = false; return s; } constructor(t, e) { if (!Stack.#g) { throw new TypeError("instantiate Stack using Stack.create(n)"); } this.heap = new e(t); this.length = 0; } push(t) { this.heap[this.length++] = t; } pop() { return this.heap[--this.length]; } } class LRUCache { #m; #w; #y; #b; #S; #k; #x; #v; get perf() { return this.#v; } ttl; ttlResolution; ttlAutopurge; updateAgeOnGet; updateAgeOnHas; allowStale; noDisposeOnSet; noUpdateTTL; maxEntrySize; sizeCalculation; noDeleteOnFetchRejection; noDeleteOnStaleGet; allowStaleOnFetchAbort; allowStaleOnFetchRejection; ignoreFetchAbort; #E; #C; #T; #L; #A; #M; #P; #F; #R; #O; #z; #D; #N; #B; #W; #I; #_; #j; static unsafeExposeInternals(t) { return { starts: t.#N, ttls: t.#B, sizes: t.#D, keyMap: t.#T, keyList: t.#L, valList: t.#A, next: t.#M, prev: t.#P, get head() { return t.#F; }, get tail() { return t.#R; }, free: t.#O, isBackgroundFetch: e => t.#$(e), backgroundFetch: (e, s, i, n) => t.#U(e, s, i, n), moveToTail: e => t.#G(e), indexes: e => t.#H(e), rindexes: e => t.#Z(e), isStale: e => t.#q(e) }; } get max() { return this.#m; } get maxSize() { return this.#w; } get calculatedSize() { return this.#C; } get size() { return this.#E; } get fetchMethod() { return this.#k; } get memoMethod() { return this.#x; } get dispose() { return this.#y; } get onInsert() { return this.#b; } get disposeAfter() { return this.#S; } constructor(t) { const {max: e = 0, ttl: s, ttlResolution: i = 1, ttlAutopurge: n, updateAgeOnGet: r, updateAgeOnHas: o, allowStale: h, dispose: a, onInsert: l, disposeAfter: c, noDisposeOnSet: f, noUpdateTTL: u, maxSize: d = 0, maxEntrySize: p = 0, sizeCalculation: g, fetchMethod: m, memoMethod: w, noDeleteOnFetchRejection: y, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: S, allowStaleOnFetchAbort: k, ignoreFetchAbort: x, perf: v} = t; if (v !== undefined) { if (typeof v?.now !== "function") { throw new TypeError("perf option must have a now() method if specified"); } } this.#v = v ?? qt; if (e !== 0 && !te(e)) { throw new TypeError("max option must be a nonnegative integer"); } const E = e ? ee(e) : Array; if (!E) { throw new Error("invalid max value: " + e); } this.#m = e; this.#w = d; this.maxEntrySize = p || this.#w; this.sizeCalculation = g; if (this.sizeCalculation) { if (!this.#w && !this.maxEntrySize) { throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize"); } if (typeof this.sizeCalculation !== "function") { throw new TypeError("sizeCalculation set to non-function"); } } if (w !== undefined && typeof w !== "function") { throw new TypeError("memoMethod must be a function if defined"); } this.#x = w; if (m !== undefined && typeof m !== "function") { throw new TypeError("fetchMethod must be a function if specified"); } this.#k = m; this.#I = !!m; this.#T = new Map; this.#L = new Array(e).fill(undefined); this.#A = new Array