+842
| #!/usr/bin/env node | ||
| import path from 'node:path'; | ||
| import N$1 from 'tty'; | ||
| import poof from './index.mjs'; | ||
| import 'node:fs/promises'; | ||
| import 'node:os'; | ||
| import 'node:child_process'; | ||
| import 'node:url'; | ||
| import 'node:timers/promises'; | ||
| const V$2 = "known-flag", k$2 = "unknown-flag", C$1 = "argument", { stringify: h } = JSON, O$1 = /\B([A-Z])/g, v$1 = (t) => t.replace(O$1, "-$1").toLowerCase(), { hasOwnProperty: D$1 } = Object.prototype, w$2 = (t, n) => D$1.call(t, n), L$2 = (t) => Array.isArray(t), b$2 = (t) => typeof t == "function" ? [t, false] : L$2(t) ? [t[0], true] : b$2(t.type), d$2 = (t, n) => t === Boolean ? n !== "false" : n, m$1 = (t, n) => typeof n == "boolean" ? n : t === Number && n === "" ? Number.NaN : t(n), R$2 = /[\s.:=]/, B = (t) => { | ||
| const n = `Flag name ${h(t)}`; | ||
| if (t.length === 0) throw new Error(`${n} cannot be empty`); | ||
| if (t.length === 1) throw new Error(`${n} must be longer than a character`); | ||
| const r = t.match(R$2); | ||
| if (r) throw new Error(`${n} cannot contain ${h(r?.[0])}`); | ||
| }, K$1 = (t) => { | ||
| const n = {}, r = (e, o) => { | ||
| if (w$2(n, e)) throw new Error(`Duplicate flags named ${h(e)}`); | ||
| n[e] = o; | ||
| }; | ||
| for (const e in t) { | ||
| if (!w$2(t, e)) continue; | ||
| B(e); | ||
| const o = t[e], s = [[], ...b$2(o), o]; | ||
| r(e, s); | ||
| const i = v$1(e); | ||
| if (e !== i && r(i, s), "alias" in o && typeof o.alias == "string") { | ||
| const { alias: a } = o, l = `Flag alias ${h(a)} for flag ${h(e)}`; | ||
| if (a.length === 0) throw new Error(`${l} cannot be empty`); | ||
| if (a.length > 1) throw new Error(`${l} must be a single character`); | ||
| r(a, s); | ||
| } | ||
| } | ||
| return n; | ||
| }, _$2 = (t, n) => { | ||
| const r = {}; | ||
| for (const e in t) { | ||
| if (!w$2(t, e)) continue; | ||
| const [o, , s, i] = n[e]; | ||
| if (o.length === 0 && "default" in i) { | ||
| let { default: a } = i; | ||
| typeof a == "function" && (a = a()), r[e] = a; | ||
| } else r[e] = s ? o : o.pop(); | ||
| } | ||
| return r; | ||
| }, F$1 = "--", G$1 = /[.:=]/, T$2 = /^-{1,2}\w/, N = (t) => { | ||
| if (!T$2.test(t)) return; | ||
| const n = !t.startsWith(F$1); | ||
| let r = t.slice(n ? 1 : 2), e; | ||
| const o = r.match(G$1); | ||
| if (o) { | ||
| const { index: s } = o; | ||
| e = r.slice(s + 1), r = r.slice(0, s); | ||
| } | ||
| return [r, e, n]; | ||
| }, $$1 = (t, { onFlag: n, onArgument: r }) => { | ||
| let e; | ||
| const o = (s, i) => { | ||
| if (typeof e != "function") return true; | ||
| e(s, i), e = void 0; | ||
| }; | ||
| for (let s = 0; s < t.length; s += 1) { | ||
| const i = t[s]; | ||
| if (i === F$1) { | ||
| o(); | ||
| const l = t.slice(s + 1); | ||
| r?.(l, [s], true); | ||
| break; | ||
| } | ||
| const a = N(i); | ||
| if (a) { | ||
| if (o(), !n) continue; | ||
| const [l, f, g] = a; | ||
| if (g) for (let c = 0; c < l.length; c += 1) { | ||
| o(); | ||
| const u = c === l.length - 1; | ||
| e = n(l[c], u ? f : void 0, [s, c + 1, u]); | ||
| } | ||
| else e = n(l, f, [s]); | ||
| } else o(i, [s]) && r?.([i], [s]); | ||
| } | ||
| o(); | ||
| }, E = (t, n) => { | ||
| for (const [r, e, o] of n.reverse()) { | ||
| if (e) { | ||
| const s = t[r]; | ||
| let i = s.slice(0, e); | ||
| if (o || (i += s.slice(e + 1)), i !== "-") { | ||
| t[r] = i; | ||
| continue; | ||
| } | ||
| } | ||
| t.splice(r, 1); | ||
| } | ||
| }, U$2 = (t, n = process.argv.slice(2), { ignore: r } = {}) => { | ||
| const e = [], o = K$1(t), s = {}, i = []; | ||
| return i[F$1] = [], $$1(n, { onFlag(a, l, f) { | ||
| const g = w$2(o, a); | ||
| if (!r?.(g ? V$2 : k$2, a, l)) { | ||
| if (g) { | ||
| const [c, u] = o[a], y = d$2(u, l), p = (P, A) => { | ||
| e.push(f), A && e.push(A), c.push(m$1(u, P || "")); | ||
| }; | ||
| return y === void 0 ? p : p(y); | ||
| } | ||
| w$2(s, a) || (s[a] = []), s[a].push(l === void 0 ? true : l), e.push(f); | ||
| } | ||
| }, onArgument(a, l, f) { | ||
| r?.(C$1, n[l[0]]) || (i.push(...a), f ? (i[F$1] = a, n.splice(l[0])) : e.push(l)); | ||
| } }), E(n, e), { flags: _$2(t, o), unknownFlags: s, _: i }; | ||
| }; | ||
| var DD = Object.create; | ||
| var m = Object.defineProperty, uD = Object.defineProperties, FD = Object.getOwnPropertyDescriptor, CD = Object.getOwnPropertyDescriptors, tD = Object.getOwnPropertyNames, I$1 = Object.getOwnPropertySymbols, ED = Object.getPrototypeOf, L$1 = Object.prototype.hasOwnProperty, eD = Object.prototype.propertyIsEnumerable; | ||
| var W$1 = (D, F, u) => F in D ? m(D, F, { enumerable: true, configurable: true, writable: true, value: u }) : D[F] = u, p = (D, F) => { | ||
| for (var u in F || (F = {})) L$1.call(F, u) && W$1(D, u, F[u]); | ||
| if (I$1) for (var u of I$1(F)) eD.call(F, u) && W$1(D, u, F[u]); | ||
| return D; | ||
| }, c = (D, F) => uD(D, CD(F)), nD = (D) => m(D, "__esModule", { value: true }); | ||
| var rD = (D, F) => () => (D && (F = D(D = 0)), F); | ||
| var iD = (D, F) => () => (F || D((F = { exports: {} }).exports, F), F.exports); | ||
| var oD = (D, F, u, C) => { | ||
| if (F && typeof F == "object" || typeof F == "function") for (let t of tD(F)) !L$1.call(D, t) && (t !== "default") && m(D, t, { get: () => F[t], enumerable: !(C = FD(F, t)) || C.enumerable }); | ||
| return D; | ||
| }, BD = (D, F) => oD(nD(m(D != null ? DD(ED(D)) : {}, "default", { value: D, enumerable: true })), D); | ||
| var i = rD(() => { | ||
| }); | ||
| var $ = iD((LD, N) => { | ||
| i(); | ||
| N.exports = function() { | ||
| return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g; | ||
| }; | ||
| }); | ||
| i(); | ||
| i(); | ||
| i(); | ||
| var v = (D) => { | ||
| var u, C, t; | ||
| let F = (u = process.stdout.columns) != null ? u : Number.POSITIVE_INFINITY; | ||
| return typeof D == "function" && (D = D(F)), D || (D = {}), Array.isArray(D) ? { columns: D, stdoutColumns: F } : { columns: (C = D.columns) != null ? C : [], stdoutColumns: (t = D.stdoutColumns) != null ? t : F }; | ||
| }; | ||
| i(); | ||
| i(); | ||
| i(); | ||
| i(); | ||
| i(); | ||
| function w$1({ onlyFirst: D = false } = {}) { | ||
| let F = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|"); | ||
| return new RegExp(F, D ? void 0 : "g"); | ||
| } | ||
| function d$1(D) { | ||
| if (typeof D != "string") throw new TypeError(`Expected a \`string\`, got \`${typeof D}\``); | ||
| return D.replace(w$1(), ""); | ||
| } | ||
| i(); | ||
| function y$1(D) { | ||
| return Number.isInteger(D) ? D >= 4352 && (D <= 4447 || D === 9001 || D === 9002 || 11904 <= D && D <= 12871 && D !== 12351 || 12880 <= D && D <= 19903 || 19968 <= D && D <= 42182 || 43360 <= D && D <= 43388 || 44032 <= D && D <= 55203 || 63744 <= D && D <= 64255 || 65040 <= D && D <= 65049 || 65072 <= D && D <= 65131 || 65281 <= D && D <= 65376 || 65504 <= D && D <= 65510 || 110592 <= D && D <= 110593 || 127488 <= D && D <= 127569 || 131072 <= D && D <= 262141) : false; | ||
| } | ||
| var j = BD($()); | ||
| function g(D) { | ||
| if (typeof D != "string" || D.length === 0 || (D = d$1(D), D.length === 0)) return 0; | ||
| D = D.replace((0, j.default)(), " "); | ||
| let F = 0; | ||
| for (let u = 0; u < D.length; u++) { | ||
| let C = D.codePointAt(u); | ||
| C <= 31 || C >= 127 && C <= 159 || C >= 768 && C <= 879 || (C > 65535 && u++, F += y$1(C) ? 2 : 1); | ||
| } | ||
| return F; | ||
| } | ||
| var b$1 = (D) => Math.max(...D.split(` | ||
| `).map(g)); | ||
| var k$1 = (D) => { | ||
| let F = []; | ||
| for (let u of D) { | ||
| let { length: C } = u, t = C - F.length; | ||
| for (let E = 0; E < t; E += 1) F.push(0); | ||
| for (let E = 0; E < C; E += 1) { | ||
| let e = b$1(u[E]); | ||
| e > F[E] && (F[E] = e); | ||
| } | ||
| } | ||
| return F; | ||
| }; | ||
| i(); | ||
| var _$1 = /^\d+%$/, z$1 = { width: "auto", align: "left", contentWidth: 0, paddingLeft: 0, paddingRight: 0, paddingTop: 0, paddingBottom: 0, horizontalPadding: 0, paddingLeftString: "", paddingRightString: "" }, sD = (D, F) => { | ||
| var C; | ||
| let u = []; | ||
| for (let t = 0; t < D.length; t += 1) { | ||
| let E = (C = F[t]) != null ? C : "auto"; | ||
| if (typeof E == "number" || E === "auto" || E === "content-width" || typeof E == "string" && _$1.test(E)) { | ||
| u.push(c(p({}, z$1), { width: E, contentWidth: D[t] })); | ||
| continue; | ||
| } | ||
| if (E && typeof E == "object") { | ||
| let e = c(p(p({}, z$1), E), { contentWidth: D[t] }); | ||
| e.horizontalPadding = e.paddingLeft + e.paddingRight, u.push(e); | ||
| continue; | ||
| } | ||
| throw new Error(`Invalid column width: ${JSON.stringify(E)}`); | ||
| } | ||
| return u; | ||
| }; | ||
| function aD(D, F) { | ||
| for (let u of D) { | ||
| let { width: C } = u; | ||
| if (C === "content-width" && (u.width = u.contentWidth), C === "auto") { | ||
| let n = Math.min(20, u.contentWidth); | ||
| u.width = n, u.autoOverflow = u.contentWidth - n; | ||
| } | ||
| if (typeof C == "string" && _$1.test(C)) { | ||
| let n = Number.parseFloat(C.slice(0, -1)) / 100; | ||
| u.width = Math.floor(F * n) - (u.paddingLeft + u.paddingRight); | ||
| } | ||
| let { horizontalPadding: t } = u, E = 1, e = E + t; | ||
| if (e >= F) { | ||
| let n = e - F, o = Math.ceil(u.paddingLeft / t * n), B = n - o; | ||
| u.paddingLeft -= o, u.paddingRight -= B, u.horizontalPadding = u.paddingLeft + u.paddingRight; | ||
| } | ||
| u.paddingLeftString = u.paddingLeft ? " ".repeat(u.paddingLeft) : "", u.paddingRightString = u.paddingRight ? " ".repeat(u.paddingRight) : ""; | ||
| let r = F - u.horizontalPadding; | ||
| u.width = Math.max(Math.min(u.width, r), E); | ||
| } | ||
| } | ||
| var G = () => Object.assign([], { columns: 0 }); | ||
| function lD(D, F) { | ||
| let u = [G()], [C] = u; | ||
| for (let t of D) { | ||
| let E = t.width + t.horizontalPadding; | ||
| C.columns + E > F && (C = G(), u.push(C)), C.push(t), C.columns += E; | ||
| } | ||
| for (let t of u) { | ||
| let E = t.reduce((s, l) => s + l.width + l.horizontalPadding, 0), e = F - E; | ||
| if (e === 0) continue; | ||
| let r = t.filter((s) => "autoOverflow" in s), n = r.filter((s) => s.autoOverflow > 0), o = n.reduce((s, l) => s + l.autoOverflow, 0), B = Math.min(o, e); | ||
| for (let s of n) { | ||
| let l = Math.floor(s.autoOverflow / o * B); | ||
| s.width += l, e -= l; | ||
| } | ||
| let a = Math.floor(e / r.length); | ||
| for (let s = 0; s < r.length; s += 1) { | ||
| let l = r[s]; | ||
| s === r.length - 1 ? l.width += e : l.width += a, e -= a; | ||
| } | ||
| } | ||
| return u; | ||
| } | ||
| function Z$1(D, F, u) { | ||
| let C = sD(u, F); | ||
| return aD(C, D), lD(C, D); | ||
| } | ||
| i(); | ||
| i(); | ||
| i(); | ||
| var O = 10, U$1 = (D = 0) => (F) => `\x1B[${F + D}m`, V$1 = (D = 0) => (F) => `\x1B[${38 + D};5;${F}m`, Y = (D = 0) => (F, u, C) => `\x1B[${38 + D};2;${F};${u};${C}m`; | ||
| function AD() { | ||
| let D = /* @__PURE__ */ new Map(), F = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } }; | ||
| F.color.gray = F.color.blackBright, F.bgColor.bgGray = F.bgColor.bgBlackBright, F.color.grey = F.color.blackBright, F.bgColor.bgGrey = F.bgColor.bgBlackBright; | ||
| for (let [u, C] of Object.entries(F)) { | ||
| for (let [t, E] of Object.entries(C)) F[t] = { open: `\x1B[${E[0]}m`, close: `\x1B[${E[1]}m` }, C[t] = F[t], D.set(E[0], E[1]); | ||
| Object.defineProperty(F, u, { value: C, enumerable: false }); | ||
| } | ||
| return Object.defineProperty(F, "codes", { value: D, enumerable: false }), F.color.close = "\x1B[39m", F.bgColor.close = "\x1B[49m", F.color.ansi = U$1(), F.color.ansi256 = V$1(), F.color.ansi16m = Y(), F.bgColor.ansi = U$1(O), F.bgColor.ansi256 = V$1(O), F.bgColor.ansi16m = Y(O), Object.defineProperties(F, { rgbToAnsi256: { value: (u, C, t) => u === C && C === t ? u < 8 ? 16 : u > 248 ? 231 : Math.round((u - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u / 255 * 5) + 6 * Math.round(C / 255 * 5) + Math.round(t / 255 * 5), enumerable: false }, hexToRgb: { value: (u) => { | ||
| let C = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(u.toString(16)); | ||
| if (!C) return [0, 0, 0]; | ||
| let { colorString: t } = C.groups; | ||
| t.length === 3 && (t = t.split("").map((e) => e + e).join("")); | ||
| let E = Number.parseInt(t, 16); | ||
| return [E >> 16 & 255, E >> 8 & 255, E & 255]; | ||
| }, enumerable: false }, hexToAnsi256: { value: (u) => F.rgbToAnsi256(...F.hexToRgb(u)), enumerable: false }, ansi256ToAnsi: { value: (u) => { | ||
| if (u < 8) return 30 + u; | ||
| if (u < 16) return 90 + (u - 8); | ||
| let C, t, E; | ||
| if (u >= 232) C = ((u - 232) * 10 + 8) / 255, t = C, E = C; | ||
| else { | ||
| u -= 16; | ||
| let n = u % 36; | ||
| C = Math.floor(u / 36) / 5, t = Math.floor(n / 6) / 5, E = n % 6 / 5; | ||
| } | ||
| let e = Math.max(C, t, E) * 2; | ||
| if (e === 0) return 30; | ||
| let r = 30 + (Math.round(E) << 2 | Math.round(t) << 1 | Math.round(C)); | ||
| return e === 2 && (r += 60), r; | ||
| }, enumerable: false }, rgbToAnsi: { value: (u, C, t) => F.ansi256ToAnsi(F.rgbToAnsi256(u, C, t)), enumerable: false }, hexToAnsi: { value: (u) => F.ansi256ToAnsi(F.hexToAnsi256(u)), enumerable: false } }), F; | ||
| } | ||
| var fD = AD(), K = fD; | ||
| var x$1 = /* @__PURE__ */ new Set(["\x1B", "\x9B"]), gD = 39, R$1 = "\x07", q$1 = "[", pD = "]", H$1 = "m", M$1 = `${pD}8;;`, J$1 = (D) => `${x$1.values().next().value}${q$1}${D}${H$1}`, Q = (D) => `${x$1.values().next().value}${M$1}${D}${R$1}`, hD = (D) => D.split(" ").map((F) => g(F)), S = (D, F, u) => { | ||
| let C = [...F], t = false, E = false, e = g(d$1(D[D.length - 1])); | ||
| for (let [r, n] of C.entries()) { | ||
| let o = g(n); | ||
| if (e + o <= u ? D[D.length - 1] += n : (D.push(n), e = 0), x$1.has(n) && (t = true, E = C.slice(r + 1).join("").startsWith(M$1)), t) { | ||
| E ? n === R$1 && (t = false, E = false) : n === H$1 && (t = false); | ||
| continue; | ||
| } | ||
| e += o, e === u && r < C.length - 1 && (D.push(""), e = 0); | ||
| } | ||
| !e && D[D.length - 1].length > 0 && D.length > 1 && (D[D.length - 2] += D.pop()); | ||
| }, cD = (D) => { | ||
| let F = D.split(" "), u = F.length; | ||
| for (; u > 0 && !(g(F[u - 1]) > 0); ) u--; | ||
| return u === F.length ? D : F.slice(0, u).join(" ") + F.slice(u).join(""); | ||
| }, dD = (D, F, u = {}) => { | ||
| if (u.trim !== false && D.trim() === "") return ""; | ||
| let C = "", t, E, e = hD(D), r = [""]; | ||
| for (let [o, B] of D.split(" ").entries()) { | ||
| u.trim !== false && (r[r.length - 1] = r[r.length - 1].trimStart()); | ||
| let a = g(r[r.length - 1]); | ||
| if (o !== 0 && (a >= F && (u.wordWrap === false || u.trim === false) && (r.push(""), a = 0), (a > 0 || u.trim === false) && (r[r.length - 1] += " ", a++)), u.hard && e[o] > F) { | ||
| let s = F - a, l = 1 + Math.floor((e[o] - s - 1) / F); | ||
| Math.floor((e[o] - 1) / F) < l && r.push(""), S(r, B, F); | ||
| continue; | ||
| } | ||
| if (a + e[o] > F && a > 0 && e[o] > 0) { | ||
| if (u.wordWrap === false && a < F) { | ||
| S(r, B, F); | ||
| continue; | ||
| } | ||
| r.push(""); | ||
| } | ||
| if (a + e[o] > F && u.wordWrap === false) { | ||
| S(r, B, F); | ||
| continue; | ||
| } | ||
| r[r.length - 1] += B; | ||
| } | ||
| u.trim !== false && (r = r.map((o) => cD(o))); | ||
| let n = [...r.join(` | ||
| `)]; | ||
| for (let [o, B] of n.entries()) { | ||
| if (C += B, x$1.has(B)) { | ||
| let { groups: s } = new RegExp(`(?:\\${q$1}(?<code>\\d+)m|\\${M$1}(?<uri>.*)${R$1})`).exec(n.slice(o).join("")) || { groups: {} }; | ||
| if (s.code !== void 0) { | ||
| let l = Number.parseFloat(s.code); | ||
| t = l === gD ? void 0 : l; | ||
| } else s.uri !== void 0 && (E = s.uri.length === 0 ? void 0 : s.uri); | ||
| } | ||
| let a = K.codes.get(Number(t)); | ||
| n[o + 1] === ` | ||
| ` ? (E && (C += Q("")), t && a && (C += J$1(a))) : B === ` | ||
| ` && (t && a && (C += J$1(t)), E && (C += Q(E))); | ||
| } | ||
| return C; | ||
| }; | ||
| function T$1(D, F, u) { | ||
| return String(D).normalize().replace(/\r\n/g, ` | ||
| `).split(` | ||
| `).map((C) => dD(C, F, u)).join(` | ||
| `); | ||
| } | ||
| var X = (D) => Array.from({ length: D }).fill(""); | ||
| function P$1(D, F) { | ||
| let u = [], C = 0; | ||
| for (let t of D) { | ||
| let E = 0, e = t.map((n) => { | ||
| var a; | ||
| let o = (a = F[C]) != null ? a : ""; | ||
| C += 1, n.preprocess && (o = n.preprocess(o)), b$1(o) > n.width && (o = T$1(o, n.width, { hard: true })); | ||
| let B = o.split(` | ||
| `); | ||
| if (n.postprocess) { | ||
| let { postprocess: s } = n; | ||
| B = B.map((l, h) => s.call(n, l, h)); | ||
| } | ||
| return n.paddingTop && B.unshift(...X(n.paddingTop)), n.paddingBottom && B.push(...X(n.paddingBottom)), B.length > E && (E = B.length), c(p({}, n), { lines: B }); | ||
| }), r = []; | ||
| for (let n = 0; n < E; n += 1) { | ||
| let o = e.map((B) => { | ||
| var h; | ||
| let a = (h = B.lines[n]) != null ? h : "", s = Number.isFinite(B.width) ? " ".repeat(B.width - g(a)) : "", l = B.paddingLeftString; | ||
| return B.align === "right" && (l += s), l += a, B.align === "left" && (l += s), l + B.paddingRightString; | ||
| }).join(""); | ||
| r.push(o); | ||
| } | ||
| u.push(r.join(` | ||
| `)); | ||
| } | ||
| return u.join(` | ||
| `); | ||
| } | ||
| function mD(D, F) { | ||
| if (!D || D.length === 0) return ""; | ||
| let u = k$1(D), C = u.length; | ||
| if (C === 0) return ""; | ||
| let { stdoutColumns: t, columns: E } = v(F); | ||
| if (E.length > C) throw new Error(`${E.length} columns defined, but only ${C} columns found`); | ||
| let e = Z$1(t, E, u); | ||
| return D.map((r) => P$1(e, r)).join(` | ||
| `); | ||
| } | ||
| i(); | ||
| var bD = ["<", ">", "=", ">=", "<="]; | ||
| function xD(D) { | ||
| if (!bD.includes(D)) throw new TypeError(`Invalid breakpoint operator: ${D}`); | ||
| } | ||
| function wD(D) { | ||
| let F = Object.keys(D).map((u) => { | ||
| let [C, t] = u.split(" "); | ||
| xD(C); | ||
| let E = Number.parseInt(t, 10); | ||
| if (Number.isNaN(E)) throw new TypeError(`Invalid breakpoint value: ${t}`); | ||
| let e = D[u]; | ||
| return { operator: C, breakpoint: E, value: e }; | ||
| }).sort((u, C) => C.breakpoint - u.breakpoint); | ||
| return (u) => { | ||
| var C; | ||
| return (C = F.find(({ operator: t, breakpoint: E }) => t === "=" && u === E || t === ">" && u > E || t === "<" && u < E || t === ">=" && u >= E || t === "<=" && u <= E)) == null ? void 0 : C.value; | ||
| }; | ||
| } | ||
| const P = (t) => t.replace(/[\W_]([a-z\d])?/gi, (e, r) => r ? r.toUpperCase() : ""), q = (t) => t.replace(/\B([A-Z])/g, "-$1").toLowerCase(), I = { "> 80": [{ width: "content-width", paddingLeft: 2, paddingRight: 8 }, { width: "auto" }], "> 40": [{ width: "auto", paddingLeft: 2, paddingRight: 8, preprocess: (t) => t.trim() }, { width: "100%", paddingLeft: 2, paddingBottom: 1 }], "> 0": { stdoutColumns: 1e3, columns: [{ width: "content-width", paddingLeft: 2, paddingRight: 8 }, { width: "content-width" }] } }; | ||
| function D(t) { | ||
| let e = false; | ||
| return { type: "table", data: { tableData: Object.keys(t).sort((a, i) => a.localeCompare(i)).map((a) => { | ||
| const i = t[a], s = "alias" in i; | ||
| return s && (e = true), { name: a, flag: i, flagFormatted: `--${q(a)}`, aliasesEnabled: e, aliasFormatted: s ? `-${i.alias}` : void 0 }; | ||
| }).map((a) => (a.aliasesEnabled = e, [{ type: "flagName", data: a }, { type: "flagDescription", data: a }])), tableBreakpoints: I } }; | ||
| } | ||
| const A = (t) => !t || (t.version ?? (t.help ? t.help.version : void 0)), C = (t) => { | ||
| const e = "parent" in t && t.parent?.name; | ||
| return (e ? `${e} ` : "") + t.name; | ||
| }; | ||
| function R(t) { | ||
| const e = []; | ||
| t.name && e.push(C(t)); | ||
| const r = A(t) ?? ("parent" in t && A(t.parent)); | ||
| if (r && e.push(`v${r}`), e.length !== 0) return { id: "name", type: "text", data: `${e.join(" ")} | ||
| ` }; | ||
| } | ||
| function L(t) { | ||
| const { help: e } = t; | ||
| if (!(!e || !e.description)) return { id: "description", type: "text", data: `${e.description} | ||
| ` }; | ||
| } | ||
| function T(t) { | ||
| const e = t.help || {}; | ||
| if ("usage" in e) return e.usage ? { id: "usage", type: "section", data: { title: "Usage:", body: Array.isArray(e.usage) ? e.usage.join(` | ||
| `) : e.usage } } : void 0; | ||
| if (t.name) { | ||
| const r = [], n = [C(t)]; | ||
| if (t.flags && Object.keys(t.flags).length > 0 && n.push("[flags...]"), t.parameters && t.parameters.length > 0) { | ||
| const { parameters: a } = t, i = a.indexOf("--"), s = i > -1 && a.slice(i + 1).some((o) => o.startsWith("<")); | ||
| n.push(a.map((o) => o !== "--" ? o : s ? "--" : "[--]").join(" ")); | ||
| } | ||
| if (n.length > 1 && r.push(n.join(" ")), "commands" in t && t.commands?.length && r.push(`${t.name} <command>`), r.length > 0) return { id: "usage", type: "section", data: { title: "Usage:", body: r.join(` | ||
| `) } }; | ||
| } | ||
| } | ||
| function _(t) { | ||
| return !("commands" in t) || !t.commands?.length ? void 0 : { id: "commands", type: "section", data: { title: "Commands:", body: { type: "table", data: { tableData: t.commands.map((n) => [n.options.name, n.options.help ? n.options.help.description : ""]), tableOptions: [{ width: "content-width", paddingLeft: 2, paddingRight: 8 }] } }, indentBody: 0 } }; | ||
| } | ||
| function k(t) { | ||
| if (!(!t.flags || Object.keys(t.flags).length === 0)) return { id: "flags", type: "section", data: { title: "Flags:", body: D(t.flags), indentBody: 0 } }; | ||
| } | ||
| function F(t) { | ||
| const { help: e } = t; | ||
| if (!e || !e.examples || e.examples.length === 0) return; | ||
| let { examples: r } = e; | ||
| if (Array.isArray(r) && (r = r.join(` | ||
| `)), r) return { id: "examples", type: "section", data: { title: "Examples:", body: r } }; | ||
| } | ||
| function H(t) { | ||
| if (!("alias" in t) || !t.alias) return; | ||
| const { alias: e } = t; | ||
| return { id: "aliases", type: "section", data: { title: "Aliases:", body: Array.isArray(e) ? e.join(", ") : e } }; | ||
| } | ||
| const U = (t) => [R, L, T, _, k, F, H].map((e) => e(t)).filter(Boolean), V = N$1.WriteStream.prototype.hasColors(); | ||
| class J { | ||
| text(e) { | ||
| return e; | ||
| } | ||
| bold(e) { | ||
| return V ? `\x1B[1m${e}\x1B[22m` : e.toLocaleUpperCase(); | ||
| } | ||
| indentText({ text: e, spaces: r }) { | ||
| return e.replace(/^/gm, " ".repeat(r)); | ||
| } | ||
| heading(e) { | ||
| return this.bold(e); | ||
| } | ||
| section({ title: e, body: r, indentBody: n = 2 }) { | ||
| return `${(e ? `${this.heading(e)} | ||
| ` : "") + (r ? this.indentText({ text: this.render(r), spaces: n }) : "")} | ||
| `; | ||
| } | ||
| table({ tableData: e, tableOptions: r, tableBreakpoints: n }) { | ||
| return mD(e.map((a) => a.map((i) => this.render(i))), n ? wD(n) : r); | ||
| } | ||
| flagParameter(e) { | ||
| return e === Boolean ? "" : e === String ? "<string>" : e === Number ? "<number>" : Array.isArray(e) ? this.flagParameter(e[0]) : "<value>"; | ||
| } | ||
| flagOperator(e) { | ||
| return " "; | ||
| } | ||
| flagName(e) { | ||
| const { flag: r, flagFormatted: n, aliasesEnabled: a, aliasFormatted: i } = e; | ||
| let s = ""; | ||
| if (i ? s += `${i}, ` : a && (s += " "), s += n, "placeholder" in r && typeof r.placeholder == "string") s += `${this.flagOperator(e)}${r.placeholder}`; | ||
| else { | ||
| const o = this.flagParameter("type" in r ? r.type : r); | ||
| o && (s += `${this.flagOperator(e)}${o}`); | ||
| } | ||
| return s; | ||
| } | ||
| flagDefault(e) { | ||
| return JSON.stringify(e); | ||
| } | ||
| flagDescription({ flag: e }) { | ||
| let r = "description" in e ? e.description ?? "" : ""; | ||
| if ("default" in e) { | ||
| let { default: n } = e; | ||
| typeof n == "function" && (n = n()), n && (r += ` (default: ${this.flagDefault(n)})`); | ||
| } | ||
| return r; | ||
| } | ||
| render(e) { | ||
| if (typeof e == "string") return e; | ||
| if (Array.isArray(e)) return e.map((r) => this.render(r)).join(` | ||
| `); | ||
| if ("type" in e && this[e.type]) { | ||
| const r = this[e.type]; | ||
| if (typeof r == "function") return r.call(this, e.data); | ||
| } | ||
| throw new Error(`Invalid node type: ${JSON.stringify(e)}`); | ||
| } | ||
| } | ||
| const y = (t) => t.length > 0 && !t.includes(" "), { stringify: d } = JSON, M = /[|\\{}()[\]^$+*?.]/; | ||
| function w(t) { | ||
| const e = []; | ||
| let r, n; | ||
| for (const a of t) { | ||
| if (n) throw new Error(`Invalid parameter: Spread parameter ${d(n)} must be last`); | ||
| const i = a[0], s = a[a.length - 1]; | ||
| let o; | ||
| if (i === "<" && s === ">" && (o = true, r)) throw new Error(`Invalid parameter: Required parameter ${d(a)} cannot come after optional parameter ${d(r)}`); | ||
| if (i === "[" && s === "]" && (o = false, r = a), o === void 0) throw new Error(`Invalid parameter: ${d(a)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`); | ||
| let l = a.slice(1, -1); | ||
| const f = l.slice(-3) === "..."; | ||
| f && (n = a, l = l.slice(0, -3)); | ||
| const p = l.match(M); | ||
| if (p) throw new Error(`Invalid parameter: ${d(a)}. Invalid character found ${d(p[0])}`); | ||
| e.push({ name: l, required: o, spread: f }); | ||
| } | ||
| return e; | ||
| } | ||
| function b(t, e, r, n) { | ||
| for (let a = 0; a < e.length; a += 1) { | ||
| const { name: i, required: s, spread: o } = e[a], l = P(i); | ||
| if (l in t) throw new Error(`Invalid parameter: ${d(i)} is used more than once.`); | ||
| const f = o ? r.slice(a) : r[a]; | ||
| if (o && (a = e.length), s && (!f || o && f.length === 0)) return console.error(`Error: Missing required parameter ${d(i)} | ||
| `), n(), process.exit(1); | ||
| t[l] = f; | ||
| } | ||
| } | ||
| function W(t) { | ||
| return t === void 0 || t !== false; | ||
| } | ||
| function x(t, e, r, n) { | ||
| const a = { ...e.flags }, i = e.version; | ||
| i && (a.version = { type: Boolean, description: "Show version" }); | ||
| const { help: s } = e, o = W(s); | ||
| o && !("help" in a) && (a.help = { type: Boolean, alias: "h", description: "Show help" }); | ||
| const l = U$2(a, n, { ignore: e.ignoreArgv }), f = () => { | ||
| console.log(e.version); | ||
| }; | ||
| if (i && l.flags.version === true) return f(), process.exit(0); | ||
| const p = new J(), O = o && s?.render ? s.render : (c) => p.render(c), u = (c) => { | ||
| const m = U({ ...e, ...c ? { help: c } : {}, flags: a }); | ||
| console.log(O(m, p)); | ||
| }; | ||
| if (o && l.flags.help === true) return u(), process.exit(0); | ||
| if (e.parameters) { | ||
| let { parameters: c } = e, m = l._; | ||
| const g = c.indexOf("--"), v = c.slice(g + 1), h = /* @__PURE__ */ Object.create(null); | ||
| if (g > -1 && v.length > 0) { | ||
| c = c.slice(0, g); | ||
| const E = l._["--"]; | ||
| m = m.slice(0, -E.length || void 0), b(h, w(c), m, u), b(h, w(v), E, u); | ||
| } else b(h, w(c), m, u); | ||
| Object.assign(l._, h); | ||
| } | ||
| const $ = { ...l, showVersion: f, showHelp: u }; | ||
| return typeof r == "function" && r($), { command: t, ...$ }; | ||
| } | ||
| function z(t, e) { | ||
| const r = /* @__PURE__ */ new Map(); | ||
| for (const n of e) { | ||
| const a = [n.options.name], { alias: i } = n.options; | ||
| i && (Array.isArray(i) ? a.push(...i) : a.push(i)); | ||
| for (const s of a) { | ||
| if (r.has(s)) throw new Error(`Duplicate command name found: ${d(s)}`); | ||
| r.set(s, n); | ||
| } | ||
| } | ||
| return r.get(t); | ||
| } | ||
| function Z(t, e, r = process.argv.slice(2)) { | ||
| if (!t) throw new Error("Options is required"); | ||
| if ("name" in t && (!t.name || !y(t.name))) throw new Error(`Invalid script name: ${d(t.name)}`); | ||
| const n = r[0]; | ||
| if (t.commands && n && y(n)) { | ||
| const a = z(n, t.commands); | ||
| if (a) return x(a.options.name, { ...a.options, parent: t }, a.callback, r.slice(1)); | ||
| } | ||
| return x(void 0, t, e, r); | ||
| } | ||
| const peq = new Uint32Array(65536); | ||
| const myers_32 = (a, b) => { | ||
| const n = a.length; | ||
| const m = b.length; | ||
| const lst = 1 << n - 1; | ||
| let pv = -1; | ||
| let mv = 0; | ||
| let sc = n; | ||
| let i = n; | ||
| while (i--) { | ||
| peq[a.charCodeAt(i)] |= 1 << i; | ||
| } | ||
| for (i = 0; i < m; i++) { | ||
| let eq = peq[b.charCodeAt(i)]; | ||
| const xv = eq | mv; | ||
| eq |= (eq & pv) + pv ^ pv; | ||
| mv |= ~(eq | pv); | ||
| pv &= eq; | ||
| if (mv & lst) { | ||
| sc++; | ||
| } | ||
| if (pv & lst) { | ||
| sc--; | ||
| } | ||
| mv = mv << 1 | 1; | ||
| pv = pv << 1 | ~(xv | mv); | ||
| mv &= xv; | ||
| } | ||
| i = n; | ||
| while (i--) { | ||
| peq[a.charCodeAt(i)] = 0; | ||
| } | ||
| return sc; | ||
| }; | ||
| const myers_x = (b, a) => { | ||
| const n = a.length; | ||
| const m = b.length; | ||
| const mhc = []; | ||
| const phc = []; | ||
| const hsize = Math.ceil(n / 32); | ||
| const vsize = Math.ceil(m / 32); | ||
| for (let i = 0; i < hsize; i++) { | ||
| phc[i] = -1; | ||
| mhc[i] = 0; | ||
| } | ||
| let j = 0; | ||
| for (; j < vsize - 1; j++) { | ||
| let mv2 = 0; | ||
| let pv2 = -1; | ||
| const start2 = j * 32; | ||
| const vlen2 = Math.min(32, m) + start2; | ||
| for (let k = start2; k < vlen2; k++) { | ||
| peq[b.charCodeAt(k)] |= 1 << k; | ||
| } | ||
| for (let i = 0; i < n; i++) { | ||
| const eq = peq[a.charCodeAt(i)]; | ||
| const pb = phc[i / 32 | 0] >>> i & 1; | ||
| const mb = mhc[i / 32 | 0] >>> i & 1; | ||
| const xv = eq | mv2; | ||
| const xh = ((eq | mb) & pv2) + pv2 ^ pv2 | eq | mb; | ||
| let ph = mv2 | ~(xh | pv2); | ||
| let mh = pv2 & xh; | ||
| if (ph >>> 31 ^ pb) { | ||
| phc[i / 32 | 0] ^= 1 << i; | ||
| } | ||
| if (mh >>> 31 ^ mb) { | ||
| mhc[i / 32 | 0] ^= 1 << i; | ||
| } | ||
| ph = ph << 1 | pb; | ||
| mh = mh << 1 | mb; | ||
| pv2 = mh | ~(xv | ph); | ||
| mv2 = ph & xv; | ||
| } | ||
| for (let k = start2; k < vlen2; k++) { | ||
| peq[b.charCodeAt(k)] = 0; | ||
| } | ||
| } | ||
| let mv = 0; | ||
| let pv = -1; | ||
| const start = j * 32; | ||
| const vlen = Math.min(32, m - start) + start; | ||
| for (let k = start; k < vlen; k++) { | ||
| peq[b.charCodeAt(k)] |= 1 << k; | ||
| } | ||
| let score = m; | ||
| for (let i = 0; i < n; i++) { | ||
| const eq = peq[a.charCodeAt(i)]; | ||
| const pb = phc[i / 32 | 0] >>> i & 1; | ||
| const mb = mhc[i / 32 | 0] >>> i & 1; | ||
| const xv = eq | mv; | ||
| const xh = ((eq | mb) & pv) + pv ^ pv | eq | mb; | ||
| let ph = mv | ~(xh | pv); | ||
| let mh = pv & xh; | ||
| score += ph >>> m - 1 & 1; | ||
| score -= mh >>> m - 1 & 1; | ||
| if (ph >>> 31 ^ pb) { | ||
| phc[i / 32 | 0] ^= 1 << i; | ||
| } | ||
| if (mh >>> 31 ^ mb) { | ||
| mhc[i / 32 | 0] ^= 1 << i; | ||
| } | ||
| ph = ph << 1 | pb; | ||
| mh = mh << 1 | mb; | ||
| pv = mh | ~(xv | ph); | ||
| mv = ph & xv; | ||
| } | ||
| for (let k = start; k < vlen; k++) { | ||
| peq[b.charCodeAt(k)] = 0; | ||
| } | ||
| return score; | ||
| }; | ||
| const distance = (a, b) => { | ||
| if (a.length < b.length) { | ||
| const tmp = b; | ||
| b = a; | ||
| a = tmp; | ||
| } | ||
| if (b.length === 0) { | ||
| return a.length; | ||
| } | ||
| if (a.length <= 32) { | ||
| return myers_32(a, b); | ||
| } | ||
| return myers_x(a, b); | ||
| }; | ||
| const closest = (str, arr) => { | ||
| let min_distance = Infinity; | ||
| let min_index = 0; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| const dist = distance(str, arr[i]); | ||
| if (dist < min_distance) { | ||
| min_distance = dist; | ||
| min_index = i; | ||
| } | ||
| } | ||
| return arr[min_index]; | ||
| }; | ||
| var name = "poof"; | ||
| var version = "3.0.0"; | ||
| var description = "Fast, non-blocking rm -rf alternative. Deletes files instantly while cleanup runs in the background."; | ||
| var packageJson = { | ||
| name: name, | ||
| version: version, | ||
| description: description}; | ||
| const knownFlags = ["dry", "verbose", "dangerous", "version", "help"]; | ||
| const findClosestFlag = (unknown) => { | ||
| const match = closest(unknown, knownFlags); | ||
| return distance(unknown, match) <= 2 ? match : void 0; | ||
| }; | ||
| const friendlyMessages = { | ||
| EBUSY: "Resource busy or locked", | ||
| EPERM: "Operation not permitted", | ||
| ENOENT: "File not found" | ||
| }; | ||
| const formatError = ({ error }) => { | ||
| const { code, message } = error; | ||
| if (code && code in friendlyMessages) { | ||
| return friendlyMessages[code]; | ||
| } | ||
| return message; | ||
| }; | ||
| const argv = Z({ | ||
| name: packageJson.name, | ||
| version: packageJson.version, | ||
| description: packageJson.description, | ||
| parameters: ["[globs...]"], | ||
| flags: { | ||
| dry: { | ||
| type: Boolean, | ||
| alias: "d", | ||
| description: "Simulate the deletion" | ||
| }, | ||
| verbose: { | ||
| type: Boolean, | ||
| alias: "v", | ||
| description: "Log removed files" | ||
| }, | ||
| dangerous: { | ||
| type: Boolean, | ||
| description: "Allow deleting paths outside current directory" | ||
| } | ||
| } | ||
| }); | ||
| const unknownFlags = Object.keys(argv.unknownFlags); | ||
| if (unknownFlags.length > 0) { | ||
| for (const flag of unknownFlags) { | ||
| const closestMatch = findClosestFlag(flag); | ||
| const suggestion = closestMatch ? ` (Did you mean --${closestMatch}?)` : ""; | ||
| console.error(`Unknown flag: --${flag}.${suggestion}`); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| (async () => { | ||
| const { globs } = argv._; | ||
| if (globs.length === 0) { | ||
| argv.showHelp(); | ||
| return; | ||
| } | ||
| const cwd = process.cwd(); | ||
| const { deleted, errors } = await poof(globs, { | ||
| dry: argv.flags.dry, | ||
| dangerous: argv.flags.dangerous | ||
| }); | ||
| if (deleted.length === 0 && errors.length === 0) { | ||
| console.warn("No matches found"); | ||
| } | ||
| if (argv.flags.dry) { | ||
| console.log("Dry run (no files deleted)"); | ||
| if (deleted.length > 0) { | ||
| console.log("Would delete:"); | ||
| for (const file of deleted) { | ||
| console.log(` - ${path.relative(cwd, file)}`); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
| if (argv.flags.verbose) { | ||
| for (const file of deleted) { | ||
| console.log(`Removed: ${path.relative(cwd, file)}`); | ||
| } | ||
| } | ||
| if (errors.length > 0) { | ||
| console.error("Errors:"); | ||
| for (const error of errors) { | ||
| const displayPath = path.isAbsolute(error.path) ? path.relative(cwd, error.path) : error.path; | ||
| console.error(` - ${displayPath}: ${formatError(error)}`); | ||
| } | ||
| process.exit(1); | ||
| } | ||
| })().catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); |
+1854
| #!/usr/bin/env node | ||
| import fs from 'node:fs/promises'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { spawn } from 'node:child_process'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { setTimeout } from 'node:timers/promises'; | ||
| const isEnabled = (namespace) => (process.env.DEBUG ?? "").split(",").some((pattern) => { | ||
| const trimmed = pattern.trim(); | ||
| if (trimmed.endsWith("*")) { | ||
| return namespace.startsWith(trimmed.slice(0, -1)); | ||
| } | ||
| return namespace === trimmed; | ||
| }); | ||
| const noop = (..._args) => { | ||
| }; | ||
| const createDebug = (namespace) => { | ||
| if (!isEnabled(namespace)) { | ||
| return noop; | ||
| } | ||
| return (...args) => { | ||
| console.error(`${(/* @__PURE__ */ new Date()).toISOString()} ${namespace}`, ...args); | ||
| }; | ||
| }; | ||
| function getDefaultExportFromCjs (x) { | ||
| return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
| } | ||
| var utils = {}; | ||
| var constants; | ||
| var hasRequiredConstants; | ||
| function requireConstants () { | ||
| if (hasRequiredConstants) return constants; | ||
| hasRequiredConstants = 1; | ||
| const WIN_SLASH = "\\\\/"; | ||
| const WIN_NO_SLASH = `[^${WIN_SLASH}]`; | ||
| const DOT_LITERAL = "\\."; | ||
| const PLUS_LITERAL = "\\+"; | ||
| const QMARK_LITERAL = "\\?"; | ||
| const SLASH_LITERAL = "\\/"; | ||
| const ONE_CHAR = "(?=.)"; | ||
| const QMARK = "[^/]"; | ||
| const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`; | ||
| const START_ANCHOR = `(?:^|${SLASH_LITERAL})`; | ||
| const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`; | ||
| const NO_DOT = `(?!${DOT_LITERAL})`; | ||
| const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`; | ||
| const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`; | ||
| const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`; | ||
| const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`; | ||
| const STAR = `${QMARK}*?`; | ||
| const SEP = "/"; | ||
| const POSIX_CHARS = { | ||
| DOT_LITERAL, | ||
| PLUS_LITERAL, | ||
| QMARK_LITERAL, | ||
| SLASH_LITERAL, | ||
| ONE_CHAR, | ||
| QMARK, | ||
| END_ANCHOR, | ||
| DOTS_SLASH, | ||
| NO_DOT, | ||
| NO_DOTS, | ||
| NO_DOT_SLASH, | ||
| NO_DOTS_SLASH, | ||
| QMARK_NO_DOT, | ||
| STAR, | ||
| START_ANCHOR, | ||
| SEP | ||
| }; | ||
| const WINDOWS_CHARS = { | ||
| ...POSIX_CHARS, | ||
| SLASH_LITERAL: `[${WIN_SLASH}]`, | ||
| QMARK: WIN_NO_SLASH, | ||
| STAR: `${WIN_NO_SLASH}*?`, | ||
| DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`, | ||
| NO_DOT: `(?!${DOT_LITERAL})`, | ||
| NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`, | ||
| NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`, | ||
| NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`, | ||
| QMARK_NO_DOT: `[^.${WIN_SLASH}]`, | ||
| START_ANCHOR: `(?:^|[${WIN_SLASH}])`, | ||
| END_ANCHOR: `(?:[${WIN_SLASH}]|$)`, | ||
| SEP: "\\" | ||
| }; | ||
| const POSIX_REGEX_SOURCE = { | ||
| alnum: "a-zA-Z0-9", | ||
| alpha: "a-zA-Z", | ||
| ascii: "\\x00-\\x7F", | ||
| blank: " \\t", | ||
| cntrl: "\\x00-\\x1F\\x7F", | ||
| digit: "0-9", | ||
| graph: "\\x21-\\x7E", | ||
| lower: "a-z", | ||
| print: "\\x20-\\x7E ", | ||
| punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~", | ||
| space: " \\t\\r\\n\\v\\f", | ||
| upper: "A-Z", | ||
| word: "A-Za-z0-9_", | ||
| xdigit: "A-Fa-f0-9" | ||
| }; | ||
| constants = { | ||
| MAX_LENGTH: 1024 * 64, | ||
| POSIX_REGEX_SOURCE, | ||
| // regular expressions | ||
| REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g, | ||
| REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/, | ||
| REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/, | ||
| REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g, | ||
| REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g, | ||
| REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g, | ||
| // Replace globs with equivalent patterns to reduce parsing time. | ||
| REPLACEMENTS: { | ||
| __proto__: null, | ||
| "***": "*", | ||
| "**/**": "**", | ||
| "**/**/**": "**" | ||
| }, | ||
| // Digits | ||
| CHAR_0: 48, | ||
| /* 0 */ | ||
| CHAR_9: 57, | ||
| /* 9 */ | ||
| // Alphabet chars. | ||
| CHAR_UPPERCASE_A: 65, | ||
| /* A */ | ||
| CHAR_LOWERCASE_A: 97, | ||
| /* a */ | ||
| CHAR_UPPERCASE_Z: 90, | ||
| /* Z */ | ||
| CHAR_LOWERCASE_Z: 122, | ||
| /* z */ | ||
| CHAR_LEFT_PARENTHESES: 40, | ||
| /* ( */ | ||
| CHAR_RIGHT_PARENTHESES: 41, | ||
| /* ) */ | ||
| CHAR_ASTERISK: 42, | ||
| /* * */ | ||
| // Non-alphabetic chars. | ||
| CHAR_AMPERSAND: 38, | ||
| /* & */ | ||
| CHAR_AT: 64, | ||
| /* @ */ | ||
| CHAR_BACKWARD_SLASH: 92, | ||
| /* \ */ | ||
| CHAR_CARRIAGE_RETURN: 13, | ||
| /* \r */ | ||
| CHAR_CIRCUMFLEX_ACCENT: 94, | ||
| /* ^ */ | ||
| CHAR_COLON: 58, | ||
| /* : */ | ||
| CHAR_COMMA: 44, | ||
| /* , */ | ||
| CHAR_DOT: 46, | ||
| /* . */ | ||
| CHAR_DOUBLE_QUOTE: 34, | ||
| /* " */ | ||
| CHAR_EQUAL: 61, | ||
| /* = */ | ||
| CHAR_EXCLAMATION_MARK: 33, | ||
| /* ! */ | ||
| CHAR_FORM_FEED: 12, | ||
| /* \f */ | ||
| CHAR_FORWARD_SLASH: 47, | ||
| /* / */ | ||
| CHAR_GRAVE_ACCENT: 96, | ||
| /* ` */ | ||
| CHAR_HASH: 35, | ||
| /* # */ | ||
| CHAR_HYPHEN_MINUS: 45, | ||
| /* - */ | ||
| CHAR_LEFT_ANGLE_BRACKET: 60, | ||
| /* < */ | ||
| CHAR_LEFT_CURLY_BRACE: 123, | ||
| /* { */ | ||
| CHAR_LEFT_SQUARE_BRACKET: 91, | ||
| /* [ */ | ||
| CHAR_LINE_FEED: 10, | ||
| /* \n */ | ||
| CHAR_NO_BREAK_SPACE: 160, | ||
| /* \u00A0 */ | ||
| CHAR_PERCENT: 37, | ||
| /* % */ | ||
| CHAR_PLUS: 43, | ||
| /* + */ | ||
| CHAR_QUESTION_MARK: 63, | ||
| /* ? */ | ||
| CHAR_RIGHT_ANGLE_BRACKET: 62, | ||
| /* > */ | ||
| CHAR_RIGHT_CURLY_BRACE: 125, | ||
| /* } */ | ||
| CHAR_RIGHT_SQUARE_BRACKET: 93, | ||
| /* ] */ | ||
| CHAR_SEMICOLON: 59, | ||
| /* ; */ | ||
| CHAR_SINGLE_QUOTE: 39, | ||
| /* ' */ | ||
| CHAR_SPACE: 32, | ||
| /* */ | ||
| CHAR_TAB: 9, | ||
| /* \t */ | ||
| CHAR_UNDERSCORE: 95, | ||
| /* _ */ | ||
| CHAR_VERTICAL_LINE: 124, | ||
| /* | */ | ||
| CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, | ||
| /* \uFEFF */ | ||
| /** | ||
| * Create EXTGLOB_CHARS | ||
| */ | ||
| extglobChars(chars) { | ||
| return { | ||
| "!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` }, | ||
| "?": { type: "qmark", open: "(?:", close: ")?" }, | ||
| "+": { type: "plus", open: "(?:", close: ")+" }, | ||
| "*": { type: "star", open: "(?:", close: ")*" }, | ||
| "@": { type: "at", open: "(?:", close: ")" } | ||
| }; | ||
| }, | ||
| /** | ||
| * Create GLOB_CHARS | ||
| */ | ||
| globChars(win32) { | ||
| return win32 === true ? WINDOWS_CHARS : POSIX_CHARS; | ||
| } | ||
| }; | ||
| return constants; | ||
| } | ||
| var hasRequiredUtils; | ||
| function requireUtils () { | ||
| if (hasRequiredUtils) return utils; | ||
| hasRequiredUtils = 1; | ||
| (function (exports$1) { | ||
| const { | ||
| REGEX_BACKSLASH, | ||
| REGEX_REMOVE_BACKSLASH, | ||
| REGEX_SPECIAL_CHARS, | ||
| REGEX_SPECIAL_CHARS_GLOBAL | ||
| } = /*@__PURE__*/ requireConstants(); | ||
| exports$1.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val); | ||
| exports$1.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str); | ||
| exports$1.isRegexChar = (str) => str.length === 1 && exports$1.hasRegexChars(str); | ||
| exports$1.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1"); | ||
| exports$1.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/"); | ||
| exports$1.isWindows = () => { | ||
| if (typeof navigator !== "undefined" && navigator.platform) { | ||
| const platform = navigator.platform.toLowerCase(); | ||
| return platform === "win32" || platform === "windows"; | ||
| } | ||
| if (typeof process !== "undefined" && process.platform) { | ||
| return process.platform === "win32"; | ||
| } | ||
| return false; | ||
| }; | ||
| exports$1.removeBackslashes = (str) => { | ||
| return str.replace(REGEX_REMOVE_BACKSLASH, (match) => { | ||
| return match === "\\" ? "" : match; | ||
| }); | ||
| }; | ||
| exports$1.escapeLast = (input, char, lastIdx) => { | ||
| const idx = input.lastIndexOf(char, lastIdx); | ||
| if (idx === -1) return input; | ||
| if (input[idx - 1] === "\\") return exports$1.escapeLast(input, char, idx - 1); | ||
| return `${input.slice(0, idx)}\\${input.slice(idx)}`; | ||
| }; | ||
| exports$1.removePrefix = (input, state = {}) => { | ||
| let output = input; | ||
| if (output.startsWith("./")) { | ||
| output = output.slice(2); | ||
| state.prefix = "./"; | ||
| } | ||
| return output; | ||
| }; | ||
| exports$1.wrapOutput = (input, state = {}, options = {}) => { | ||
| const prepend = options.contains ? "" : "^"; | ||
| const append = options.contains ? "" : "$"; | ||
| let output = `${prepend}(?:${input})${append}`; | ||
| if (state.negated === true) { | ||
| output = `(?:^(?!${output}).*$)`; | ||
| } | ||
| return output; | ||
| }; | ||
| exports$1.basename = (path, { windows } = {}) => { | ||
| const segs = path.split(windows ? /[\\/]/ : "/"); | ||
| const last = segs[segs.length - 1]; | ||
| if (last === "") { | ||
| return segs[segs.length - 2]; | ||
| } | ||
| return last; | ||
| }; | ||
| } (utils)); | ||
| return utils; | ||
| } | ||
| var scan_1; | ||
| var hasRequiredScan; | ||
| function requireScan () { | ||
| if (hasRequiredScan) return scan_1; | ||
| hasRequiredScan = 1; | ||
| const utils = /*@__PURE__*/ requireUtils(); | ||
| const { | ||
| CHAR_ASTERISK, | ||
| /* * */ | ||
| CHAR_AT, | ||
| /* @ */ | ||
| CHAR_BACKWARD_SLASH, | ||
| /* \ */ | ||
| CHAR_COMMA, | ||
| /* , */ | ||
| CHAR_DOT, | ||
| /* . */ | ||
| CHAR_EXCLAMATION_MARK, | ||
| /* ! */ | ||
| CHAR_FORWARD_SLASH, | ||
| /* / */ | ||
| CHAR_LEFT_CURLY_BRACE, | ||
| /* { */ | ||
| CHAR_LEFT_PARENTHESES, | ||
| /* ( */ | ||
| CHAR_LEFT_SQUARE_BRACKET, | ||
| /* [ */ | ||
| CHAR_PLUS, | ||
| /* + */ | ||
| CHAR_QUESTION_MARK, | ||
| /* ? */ | ||
| CHAR_RIGHT_CURLY_BRACE, | ||
| /* } */ | ||
| CHAR_RIGHT_PARENTHESES, | ||
| /* ) */ | ||
| CHAR_RIGHT_SQUARE_BRACKET | ||
| /* ] */ | ||
| } = /*@__PURE__*/ requireConstants(); | ||
| const isPathSeparator = (code) => { | ||
| return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH; | ||
| }; | ||
| const depth = (token) => { | ||
| if (token.isPrefix !== true) { | ||
| token.depth = token.isGlobstar ? Infinity : 1; | ||
| } | ||
| }; | ||
| const scan = (input, options) => { | ||
| const opts = options || {}; | ||
| const length = input.length - 1; | ||
| const scanToEnd = opts.parts === true || opts.scanToEnd === true; | ||
| const slashes = []; | ||
| const tokens = []; | ||
| const parts = []; | ||
| let str = input; | ||
| let index = -1; | ||
| let start = 0; | ||
| let lastIndex = 0; | ||
| let isBrace = false; | ||
| let isBracket = false; | ||
| let isGlob = false; | ||
| let isExtglob = false; | ||
| let isGlobstar = false; | ||
| let braceEscaped = false; | ||
| let backslashes = false; | ||
| let negated = false; | ||
| let negatedExtglob = false; | ||
| let finished = false; | ||
| let braces = 0; | ||
| let prev; | ||
| let code; | ||
| let token = { value: "", depth: 0, isGlob: false }; | ||
| const eos = () => index >= length; | ||
| const peek = () => str.charCodeAt(index + 1); | ||
| const advance = () => { | ||
| prev = code; | ||
| return str.charCodeAt(++index); | ||
| }; | ||
| while (index < length) { | ||
| code = advance(); | ||
| let next; | ||
| if (code === CHAR_BACKWARD_SLASH) { | ||
| backslashes = token.backslashes = true; | ||
| code = advance(); | ||
| if (code === CHAR_LEFT_CURLY_BRACE) { | ||
| braceEscaped = true; | ||
| } | ||
| continue; | ||
| } | ||
| if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) { | ||
| braces++; | ||
| while (eos() !== true && (code = advance())) { | ||
| if (code === CHAR_BACKWARD_SLASH) { | ||
| backslashes = token.backslashes = true; | ||
| advance(); | ||
| continue; | ||
| } | ||
| if (code === CHAR_LEFT_CURLY_BRACE) { | ||
| braces++; | ||
| continue; | ||
| } | ||
| if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) { | ||
| isBrace = token.isBrace = true; | ||
| isGlob = token.isGlob = true; | ||
| finished = true; | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (braceEscaped !== true && code === CHAR_COMMA) { | ||
| isBrace = token.isBrace = true; | ||
| isGlob = token.isGlob = true; | ||
| finished = true; | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (code === CHAR_RIGHT_CURLY_BRACE) { | ||
| braces--; | ||
| if (braces === 0) { | ||
| braceEscaped = false; | ||
| isBrace = token.isBrace = true; | ||
| finished = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (code === CHAR_FORWARD_SLASH) { | ||
| slashes.push(index); | ||
| tokens.push(token); | ||
| token = { value: "", depth: 0, isGlob: false }; | ||
| if (finished === true) continue; | ||
| if (prev === CHAR_DOT && index === start + 1) { | ||
| start += 2; | ||
| continue; | ||
| } | ||
| lastIndex = index + 1; | ||
| continue; | ||
| } | ||
| if (opts.noext !== true) { | ||
| const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK; | ||
| if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) { | ||
| isGlob = token.isGlob = true; | ||
| isExtglob = token.isExtglob = true; | ||
| finished = true; | ||
| if (code === CHAR_EXCLAMATION_MARK && index === start) { | ||
| negatedExtglob = true; | ||
| } | ||
| if (scanToEnd === true) { | ||
| while (eos() !== true && (code = advance())) { | ||
| if (code === CHAR_BACKWARD_SLASH) { | ||
| backslashes = token.backslashes = true; | ||
| code = advance(); | ||
| continue; | ||
| } | ||
| if (code === CHAR_RIGHT_PARENTHESES) { | ||
| isGlob = token.isGlob = true; | ||
| finished = true; | ||
| break; | ||
| } | ||
| } | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| if (code === CHAR_ASTERISK) { | ||
| if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true; | ||
| isGlob = token.isGlob = true; | ||
| finished = true; | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (code === CHAR_QUESTION_MARK) { | ||
| isGlob = token.isGlob = true; | ||
| finished = true; | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (code === CHAR_LEFT_SQUARE_BRACKET) { | ||
| while (eos() !== true && (next = advance())) { | ||
| if (next === CHAR_BACKWARD_SLASH) { | ||
| backslashes = token.backslashes = true; | ||
| advance(); | ||
| continue; | ||
| } | ||
| if (next === CHAR_RIGHT_SQUARE_BRACKET) { | ||
| isBracket = token.isBracket = true; | ||
| isGlob = token.isGlob = true; | ||
| finished = true; | ||
| break; | ||
| } | ||
| } | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) { | ||
| negated = token.negated = true; | ||
| start++; | ||
| continue; | ||
| } | ||
| if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) { | ||
| isGlob = token.isGlob = true; | ||
| if (scanToEnd === true) { | ||
| while (eos() !== true && (code = advance())) { | ||
| if (code === CHAR_LEFT_PARENTHESES) { | ||
| backslashes = token.backslashes = true; | ||
| code = advance(); | ||
| continue; | ||
| } | ||
| if (code === CHAR_RIGHT_PARENTHESES) { | ||
| finished = true; | ||
| break; | ||
| } | ||
| } | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| if (isGlob === true) { | ||
| finished = true; | ||
| if (scanToEnd === true) { | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| if (opts.noext === true) { | ||
| isExtglob = false; | ||
| isGlob = false; | ||
| } | ||
| let base = str; | ||
| let prefix = ""; | ||
| let glob = ""; | ||
| if (start > 0) { | ||
| prefix = str.slice(0, start); | ||
| str = str.slice(start); | ||
| lastIndex -= start; | ||
| } | ||
| if (base && isGlob === true && lastIndex > 0) { | ||
| base = str.slice(0, lastIndex); | ||
| glob = str.slice(lastIndex); | ||
| } else if (isGlob === true) { | ||
| base = ""; | ||
| glob = str; | ||
| } else { | ||
| base = str; | ||
| } | ||
| if (base && base !== "" && base !== "/" && base !== str) { | ||
| if (isPathSeparator(base.charCodeAt(base.length - 1))) { | ||
| base = base.slice(0, -1); | ||
| } | ||
| } | ||
| if (opts.unescape === true) { | ||
| if (glob) glob = utils.removeBackslashes(glob); | ||
| if (base && backslashes === true) { | ||
| base = utils.removeBackslashes(base); | ||
| } | ||
| } | ||
| const state = { | ||
| prefix, | ||
| input, | ||
| start, | ||
| base, | ||
| glob, | ||
| isBrace, | ||
| isBracket, | ||
| isGlob, | ||
| isExtglob, | ||
| isGlobstar, | ||
| negated, | ||
| negatedExtglob | ||
| }; | ||
| if (opts.tokens === true) { | ||
| state.maxDepth = 0; | ||
| if (!isPathSeparator(code)) { | ||
| tokens.push(token); | ||
| } | ||
| state.tokens = tokens; | ||
| } | ||
| if (opts.parts === true || opts.tokens === true) { | ||
| let prevIndex; | ||
| for (let idx = 0; idx < slashes.length; idx++) { | ||
| const n = prevIndex ? prevIndex + 1 : start; | ||
| const i = slashes[idx]; | ||
| const value = input.slice(n, i); | ||
| if (opts.tokens) { | ||
| if (idx === 0 && start !== 0) { | ||
| tokens[idx].isPrefix = true; | ||
| tokens[idx].value = prefix; | ||
| } else { | ||
| tokens[idx].value = value; | ||
| } | ||
| depth(tokens[idx]); | ||
| state.maxDepth += tokens[idx].depth; | ||
| } | ||
| if (idx !== 0 || value !== "") { | ||
| parts.push(value); | ||
| } | ||
| prevIndex = i; | ||
| } | ||
| if (prevIndex && prevIndex + 1 < input.length) { | ||
| const value = input.slice(prevIndex + 1); | ||
| parts.push(value); | ||
| if (opts.tokens) { | ||
| tokens[tokens.length - 1].value = value; | ||
| depth(tokens[tokens.length - 1]); | ||
| state.maxDepth += tokens[tokens.length - 1].depth; | ||
| } | ||
| } | ||
| state.slashes = slashes; | ||
| state.parts = parts; | ||
| } | ||
| return state; | ||
| }; | ||
| scan_1 = scan; | ||
| return scan_1; | ||
| } | ||
| var parse_1; | ||
| var hasRequiredParse; | ||
| function requireParse () { | ||
| if (hasRequiredParse) return parse_1; | ||
| hasRequiredParse = 1; | ||
| const constants = /*@__PURE__*/ requireConstants(); | ||
| const utils = /*@__PURE__*/ requireUtils(); | ||
| const { | ||
| MAX_LENGTH, | ||
| POSIX_REGEX_SOURCE, | ||
| REGEX_NON_SPECIAL_CHARS, | ||
| REGEX_SPECIAL_CHARS_BACKREF, | ||
| REPLACEMENTS | ||
| } = constants; | ||
| const expandRange = (args, options) => { | ||
| if (typeof options.expandRange === "function") { | ||
| return options.expandRange(...args, options); | ||
| } | ||
| args.sort(); | ||
| const value = `[${args.join("-")}]`; | ||
| try { | ||
| new RegExp(value); | ||
| } catch (ex) { | ||
| return args.map((v) => utils.escapeRegex(v)).join(".."); | ||
| } | ||
| return value; | ||
| }; | ||
| const syntaxError = (type, char) => { | ||
| return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`; | ||
| }; | ||
| const parse = (input, options) => { | ||
| if (typeof input !== "string") { | ||
| throw new TypeError("Expected a string"); | ||
| } | ||
| input = REPLACEMENTS[input] || input; | ||
| const opts = { ...options }; | ||
| const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH; | ||
| let len = input.length; | ||
| if (len > max) { | ||
| throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`); | ||
| } | ||
| const bos = { type: "bos", value: "", output: opts.prepend || "" }; | ||
| const tokens = [bos]; | ||
| const capture = opts.capture ? "" : "?:"; | ||
| const PLATFORM_CHARS = constants.globChars(opts.windows); | ||
| const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS); | ||
| const { | ||
| DOT_LITERAL, | ||
| PLUS_LITERAL, | ||
| SLASH_LITERAL, | ||
| ONE_CHAR, | ||
| DOTS_SLASH, | ||
| NO_DOT, | ||
| NO_DOT_SLASH, | ||
| NO_DOTS_SLASH, | ||
| QMARK, | ||
| QMARK_NO_DOT, | ||
| STAR, | ||
| START_ANCHOR | ||
| } = PLATFORM_CHARS; | ||
| const globstar = (opts2) => { | ||
| return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`; | ||
| }; | ||
| const nodot = opts.dot ? "" : NO_DOT; | ||
| const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT; | ||
| let star = opts.bash === true ? globstar(opts) : STAR; | ||
| if (opts.capture) { | ||
| star = `(${star})`; | ||
| } | ||
| if (typeof opts.noext === "boolean") { | ||
| opts.noextglob = opts.noext; | ||
| } | ||
| const state = { | ||
| input, | ||
| index: -1, | ||
| start: 0, | ||
| dot: opts.dot === true, | ||
| consumed: "", | ||
| output: "", | ||
| prefix: "", | ||
| backtrack: false, | ||
| negated: false, | ||
| brackets: 0, | ||
| braces: 0, | ||
| parens: 0, | ||
| quotes: 0, | ||
| globstar: false, | ||
| tokens | ||
| }; | ||
| input = utils.removePrefix(input, state); | ||
| len = input.length; | ||
| const extglobs = []; | ||
| const braces = []; | ||
| const stack = []; | ||
| let prev = bos; | ||
| let value; | ||
| const eos = () => state.index === len - 1; | ||
| const peek = state.peek = (n = 1) => input[state.index + n]; | ||
| const advance = state.advance = () => input[++state.index] || ""; | ||
| const remaining = () => input.slice(state.index + 1); | ||
| const consume = (value2 = "", num = 0) => { | ||
| state.consumed += value2; | ||
| state.index += num; | ||
| }; | ||
| const append = (token) => { | ||
| state.output += token.output != null ? token.output : token.value; | ||
| consume(token.value); | ||
| }; | ||
| const negate = () => { | ||
| let count = 1; | ||
| while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) { | ||
| advance(); | ||
| state.start++; | ||
| count++; | ||
| } | ||
| if (count % 2 === 0) { | ||
| return false; | ||
| } | ||
| state.negated = true; | ||
| state.start++; | ||
| return true; | ||
| }; | ||
| const increment = (type) => { | ||
| state[type]++; | ||
| stack.push(type); | ||
| }; | ||
| const decrement = (type) => { | ||
| state[type]--; | ||
| stack.pop(); | ||
| }; | ||
| const push = (tok) => { | ||
| if (prev.type === "globstar") { | ||
| const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace"); | ||
| const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren"); | ||
| if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) { | ||
| state.output = state.output.slice(0, -prev.output.length); | ||
| prev.type = "star"; | ||
| prev.value = "*"; | ||
| prev.output = star; | ||
| state.output += prev.output; | ||
| } | ||
| } | ||
| if (extglobs.length && tok.type !== "paren") { | ||
| extglobs[extglobs.length - 1].inner += tok.value; | ||
| } | ||
| if (tok.value || tok.output) append(tok); | ||
| if (prev && prev.type === "text" && tok.type === "text") { | ||
| prev.output = (prev.output || prev.value) + tok.value; | ||
| prev.value += tok.value; | ||
| return; | ||
| } | ||
| tok.prev = prev; | ||
| tokens.push(tok); | ||
| prev = tok; | ||
| }; | ||
| const extglobOpen = (type, value2) => { | ||
| const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" }; | ||
| token.prev = prev; | ||
| token.parens = state.parens; | ||
| token.output = state.output; | ||
| const output = (opts.capture ? "(" : "") + token.open; | ||
| increment("parens"); | ||
| push({ type, value: value2, output: state.output ? "" : ONE_CHAR }); | ||
| push({ type: "paren", extglob: true, value: advance(), output }); | ||
| extglobs.push(token); | ||
| }; | ||
| const extglobClose = (token) => { | ||
| let output = token.close + (opts.capture ? ")" : ""); | ||
| let rest; | ||
| if (token.type === "negate") { | ||
| let extglobStar = star; | ||
| if (token.inner && token.inner.length > 1 && token.inner.includes("/")) { | ||
| extglobStar = globstar(opts); | ||
| } | ||
| if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) { | ||
| output = token.close = `)$))${extglobStar}`; | ||
| } | ||
| if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) { | ||
| const expression = parse(rest, { ...options, fastpaths: false }).output; | ||
| output = token.close = `)${expression})${extglobStar})`; | ||
| } | ||
| if (token.prev.type === "bos") { | ||
| state.negatedExtglob = true; | ||
| } | ||
| } | ||
| push({ type: "paren", extglob: true, value, output }); | ||
| decrement("parens"); | ||
| }; | ||
| if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) { | ||
| let backslashes = false; | ||
| let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => { | ||
| if (first === "\\") { | ||
| backslashes = true; | ||
| return m; | ||
| } | ||
| if (first === "?") { | ||
| if (esc) { | ||
| return esc + first + (rest ? QMARK.repeat(rest.length) : ""); | ||
| } | ||
| if (index === 0) { | ||
| return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : ""); | ||
| } | ||
| return QMARK.repeat(chars.length); | ||
| } | ||
| if (first === ".") { | ||
| return DOT_LITERAL.repeat(chars.length); | ||
| } | ||
| if (first === "*") { | ||
| if (esc) { | ||
| return esc + first + (rest ? star : ""); | ||
| } | ||
| return star; | ||
| } | ||
| return esc ? m : `\\${m}`; | ||
| }); | ||
| if (backslashes === true) { | ||
| if (opts.unescape === true) { | ||
| output = output.replace(/\\/g, ""); | ||
| } else { | ||
| output = output.replace(/\\+/g, (m) => { | ||
| return m.length % 2 === 0 ? "\\\\" : m ? "\\" : ""; | ||
| }); | ||
| } | ||
| } | ||
| if (output === input && opts.contains === true) { | ||
| state.output = input; | ||
| return state; | ||
| } | ||
| state.output = utils.wrapOutput(output, state, options); | ||
| return state; | ||
| } | ||
| while (!eos()) { | ||
| value = advance(); | ||
| if (value === "\0") { | ||
| continue; | ||
| } | ||
| if (value === "\\") { | ||
| const next = peek(); | ||
| if (next === "/" && opts.bash !== true) { | ||
| continue; | ||
| } | ||
| if (next === "." || next === ";") { | ||
| continue; | ||
| } | ||
| if (!next) { | ||
| value += "\\"; | ||
| push({ type: "text", value }); | ||
| continue; | ||
| } | ||
| const match = /^\\+/.exec(remaining()); | ||
| let slashes = 0; | ||
| if (match && match[0].length > 2) { | ||
| slashes = match[0].length; | ||
| state.index += slashes; | ||
| if (slashes % 2 !== 0) { | ||
| value += "\\"; | ||
| } | ||
| } | ||
| if (opts.unescape === true) { | ||
| value = advance(); | ||
| } else { | ||
| value += advance(); | ||
| } | ||
| if (state.brackets === 0) { | ||
| push({ type: "text", value }); | ||
| continue; | ||
| } | ||
| } | ||
| if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) { | ||
| if (opts.posix !== false && value === ":") { | ||
| const inner = prev.value.slice(1); | ||
| if (inner.includes("[")) { | ||
| prev.posix = true; | ||
| if (inner.includes(":")) { | ||
| const idx = prev.value.lastIndexOf("["); | ||
| const pre = prev.value.slice(0, idx); | ||
| const rest2 = prev.value.slice(idx + 2); | ||
| const posix = POSIX_REGEX_SOURCE[rest2]; | ||
| if (posix) { | ||
| prev.value = pre + posix; | ||
| state.backtrack = true; | ||
| advance(); | ||
| if (!bos.output && tokens.indexOf(prev) === 1) { | ||
| bos.output = ONE_CHAR; | ||
| } | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") { | ||
| value = `\\${value}`; | ||
| } | ||
| if (value === "]" && (prev.value === "[" || prev.value === "[^")) { | ||
| value = `\\${value}`; | ||
| } | ||
| if (opts.posix === true && value === "!" && prev.value === "[") { | ||
| value = "^"; | ||
| } | ||
| prev.value += value; | ||
| append({ value }); | ||
| continue; | ||
| } | ||
| if (state.quotes === 1 && value !== '"') { | ||
| value = utils.escapeRegex(value); | ||
| prev.value += value; | ||
| append({ value }); | ||
| continue; | ||
| } | ||
| if (value === '"') { | ||
| state.quotes = state.quotes === 1 ? 0 : 1; | ||
| if (opts.keepQuotes === true) { | ||
| push({ type: "text", value }); | ||
| } | ||
| continue; | ||
| } | ||
| if (value === "(") { | ||
| increment("parens"); | ||
| push({ type: "paren", value }); | ||
| continue; | ||
| } | ||
| if (value === ")") { | ||
| if (state.parens === 0 && opts.strictBrackets === true) { | ||
| throw new SyntaxError(syntaxError("opening", "(")); | ||
| } | ||
| const extglob = extglobs[extglobs.length - 1]; | ||
| if (extglob && state.parens === extglob.parens + 1) { | ||
| extglobClose(extglobs.pop()); | ||
| continue; | ||
| } | ||
| push({ type: "paren", value, output: state.parens ? ")" : "\\)" }); | ||
| decrement("parens"); | ||
| continue; | ||
| } | ||
| if (value === "[") { | ||
| if (opts.nobracket === true || !remaining().includes("]")) { | ||
| if (opts.nobracket !== true && opts.strictBrackets === true) { | ||
| throw new SyntaxError(syntaxError("closing", "]")); | ||
| } | ||
| value = `\\${value}`; | ||
| } else { | ||
| increment("brackets"); | ||
| } | ||
| push({ type: "bracket", value }); | ||
| continue; | ||
| } | ||
| if (value === "]") { | ||
| if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) { | ||
| push({ type: "text", value, output: `\\${value}` }); | ||
| continue; | ||
| } | ||
| if (state.brackets === 0) { | ||
| if (opts.strictBrackets === true) { | ||
| throw new SyntaxError(syntaxError("opening", "[")); | ||
| } | ||
| push({ type: "text", value, output: `\\${value}` }); | ||
| continue; | ||
| } | ||
| decrement("brackets"); | ||
| const prevValue = prev.value.slice(1); | ||
| if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) { | ||
| value = `/${value}`; | ||
| } | ||
| prev.value += value; | ||
| append({ value }); | ||
| if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) { | ||
| continue; | ||
| } | ||
| const escaped = utils.escapeRegex(prev.value); | ||
| state.output = state.output.slice(0, -prev.value.length); | ||
| if (opts.literalBrackets === true) { | ||
| state.output += escaped; | ||
| prev.value = escaped; | ||
| continue; | ||
| } | ||
| prev.value = `(${capture}${escaped}|${prev.value})`; | ||
| state.output += prev.value; | ||
| continue; | ||
| } | ||
| if (value === "{" && opts.nobrace !== true) { | ||
| increment("braces"); | ||
| const open = { | ||
| type: "brace", | ||
| value, | ||
| output: "(", | ||
| outputIndex: state.output.length, | ||
| tokensIndex: state.tokens.length | ||
| }; | ||
| braces.push(open); | ||
| push(open); | ||
| continue; | ||
| } | ||
| if (value === "}") { | ||
| const brace = braces[braces.length - 1]; | ||
| if (opts.nobrace === true || !brace) { | ||
| push({ type: "text", value, output: value }); | ||
| continue; | ||
| } | ||
| let output = ")"; | ||
| if (brace.dots === true) { | ||
| const arr = tokens.slice(); | ||
| const range = []; | ||
| for (let i = arr.length - 1; i >= 0; i--) { | ||
| tokens.pop(); | ||
| if (arr[i].type === "brace") { | ||
| break; | ||
| } | ||
| if (arr[i].type !== "dots") { | ||
| range.unshift(arr[i].value); | ||
| } | ||
| } | ||
| output = expandRange(range, opts); | ||
| state.backtrack = true; | ||
| } | ||
| if (brace.comma !== true && brace.dots !== true) { | ||
| const out = state.output.slice(0, brace.outputIndex); | ||
| const toks = state.tokens.slice(brace.tokensIndex); | ||
| brace.value = brace.output = "\\{"; | ||
| value = output = "\\}"; | ||
| state.output = out; | ||
| for (const t of toks) { | ||
| state.output += t.output || t.value; | ||
| } | ||
| } | ||
| push({ type: "brace", value, output }); | ||
| decrement("braces"); | ||
| braces.pop(); | ||
| continue; | ||
| } | ||
| if (value === "|") { | ||
| if (extglobs.length > 0) { | ||
| extglobs[extglobs.length - 1].conditions++; | ||
| } | ||
| push({ type: "text", value }); | ||
| continue; | ||
| } | ||
| if (value === ",") { | ||
| let output = value; | ||
| const brace = braces[braces.length - 1]; | ||
| if (brace && stack[stack.length - 1] === "braces") { | ||
| brace.comma = true; | ||
| output = "|"; | ||
| } | ||
| push({ type: "comma", value, output }); | ||
| continue; | ||
| } | ||
| if (value === "/") { | ||
| if (prev.type === "dot" && state.index === state.start + 1) { | ||
| state.start = state.index + 1; | ||
| state.consumed = ""; | ||
| state.output = ""; | ||
| tokens.pop(); | ||
| prev = bos; | ||
| continue; | ||
| } | ||
| push({ type: "slash", value, output: SLASH_LITERAL }); | ||
| continue; | ||
| } | ||
| if (value === ".") { | ||
| if (state.braces > 0 && prev.type === "dot") { | ||
| if (prev.value === ".") prev.output = DOT_LITERAL; | ||
| const brace = braces[braces.length - 1]; | ||
| prev.type = "dots"; | ||
| prev.output += value; | ||
| prev.value += value; | ||
| brace.dots = true; | ||
| continue; | ||
| } | ||
| if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") { | ||
| push({ type: "text", value, output: DOT_LITERAL }); | ||
| continue; | ||
| } | ||
| push({ type: "dot", value, output: DOT_LITERAL }); | ||
| continue; | ||
| } | ||
| if (value === "?") { | ||
| const isGroup = prev && prev.value === "("; | ||
| if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") { | ||
| extglobOpen("qmark", value); | ||
| continue; | ||
| } | ||
| if (prev && prev.type === "paren") { | ||
| const next = peek(); | ||
| let output = value; | ||
| if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) { | ||
| output = `\\${value}`; | ||
| } | ||
| push({ type: "text", value, output }); | ||
| continue; | ||
| } | ||
| if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) { | ||
| push({ type: "qmark", value, output: QMARK_NO_DOT }); | ||
| continue; | ||
| } | ||
| push({ type: "qmark", value, output: QMARK }); | ||
| continue; | ||
| } | ||
| if (value === "!") { | ||
| if (opts.noextglob !== true && peek() === "(") { | ||
| if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) { | ||
| extglobOpen("negate", value); | ||
| continue; | ||
| } | ||
| } | ||
| if (opts.nonegate !== true && state.index === 0) { | ||
| negate(); | ||
| continue; | ||
| } | ||
| } | ||
| if (value === "+") { | ||
| if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") { | ||
| extglobOpen("plus", value); | ||
| continue; | ||
| } | ||
| if (prev && prev.value === "(" || opts.regex === false) { | ||
| push({ type: "plus", value, output: PLUS_LITERAL }); | ||
| continue; | ||
| } | ||
| if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) { | ||
| push({ type: "plus", value }); | ||
| continue; | ||
| } | ||
| push({ type: "plus", value: PLUS_LITERAL }); | ||
| continue; | ||
| } | ||
| if (value === "@") { | ||
| if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") { | ||
| push({ type: "at", extglob: true, value, output: "" }); | ||
| continue; | ||
| } | ||
| push({ type: "text", value }); | ||
| continue; | ||
| } | ||
| if (value !== "*") { | ||
| if (value === "$" || value === "^") { | ||
| value = `\\${value}`; | ||
| } | ||
| const match = REGEX_NON_SPECIAL_CHARS.exec(remaining()); | ||
| if (match) { | ||
| value += match[0]; | ||
| state.index += match[0].length; | ||
| } | ||
| push({ type: "text", value }); | ||
| continue; | ||
| } | ||
| if (prev && (prev.type === "globstar" || prev.star === true)) { | ||
| prev.type = "star"; | ||
| prev.star = true; | ||
| prev.value += value; | ||
| prev.output = star; | ||
| state.backtrack = true; | ||
| state.globstar = true; | ||
| consume(value); | ||
| continue; | ||
| } | ||
| let rest = remaining(); | ||
| if (opts.noextglob !== true && /^\([^?]/.test(rest)) { | ||
| extglobOpen("star", value); | ||
| continue; | ||
| } | ||
| if (prev.type === "star") { | ||
| if (opts.noglobstar === true) { | ||
| consume(value); | ||
| continue; | ||
| } | ||
| const prior = prev.prev; | ||
| const before = prior.prev; | ||
| const isStart = prior.type === "slash" || prior.type === "bos"; | ||
| const afterStar = before && (before.type === "star" || before.type === "globstar"); | ||
| if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) { | ||
| push({ type: "star", value, output: "" }); | ||
| continue; | ||
| } | ||
| const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace"); | ||
| const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren"); | ||
| if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) { | ||
| push({ type: "star", value, output: "" }); | ||
| continue; | ||
| } | ||
| while (rest.slice(0, 3) === "/**") { | ||
| const after = input[state.index + 4]; | ||
| if (after && after !== "/") { | ||
| break; | ||
| } | ||
| rest = rest.slice(3); | ||
| consume("/**", 3); | ||
| } | ||
| if (prior.type === "bos" && eos()) { | ||
| prev.type = "globstar"; | ||
| prev.value += value; | ||
| prev.output = globstar(opts); | ||
| state.output = prev.output; | ||
| state.globstar = true; | ||
| consume(value); | ||
| continue; | ||
| } | ||
| if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) { | ||
| state.output = state.output.slice(0, -(prior.output + prev.output).length); | ||
| prior.output = `(?:${prior.output}`; | ||
| prev.type = "globstar"; | ||
| prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)"); | ||
| prev.value += value; | ||
| state.globstar = true; | ||
| state.output += prior.output + prev.output; | ||
| consume(value); | ||
| continue; | ||
| } | ||
| if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") { | ||
| const end = rest[1] !== void 0 ? "|$" : ""; | ||
| state.output = state.output.slice(0, -(prior.output + prev.output).length); | ||
| prior.output = `(?:${prior.output}`; | ||
| prev.type = "globstar"; | ||
| prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`; | ||
| prev.value += value; | ||
| state.output += prior.output + prev.output; | ||
| state.globstar = true; | ||
| consume(value + advance()); | ||
| push({ type: "slash", value: "/", output: "" }); | ||
| continue; | ||
| } | ||
| if (prior.type === "bos" && rest[0] === "/") { | ||
| prev.type = "globstar"; | ||
| prev.value += value; | ||
| prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`; | ||
| state.output = prev.output; | ||
| state.globstar = true; | ||
| consume(value + advance()); | ||
| push({ type: "slash", value: "/", output: "" }); | ||
| continue; | ||
| } | ||
| state.output = state.output.slice(0, -prev.output.length); | ||
| prev.type = "globstar"; | ||
| prev.output = globstar(opts); | ||
| prev.value += value; | ||
| state.output += prev.output; | ||
| state.globstar = true; | ||
| consume(value); | ||
| continue; | ||
| } | ||
| const token = { type: "star", value, output: star }; | ||
| if (opts.bash === true) { | ||
| token.output = ".*?"; | ||
| if (prev.type === "bos" || prev.type === "slash") { | ||
| token.output = nodot + token.output; | ||
| } | ||
| push(token); | ||
| continue; | ||
| } | ||
| if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) { | ||
| token.output = value; | ||
| push(token); | ||
| continue; | ||
| } | ||
| if (state.index === state.start || prev.type === "slash" || prev.type === "dot") { | ||
| if (prev.type === "dot") { | ||
| state.output += NO_DOT_SLASH; | ||
| prev.output += NO_DOT_SLASH; | ||
| } else if (opts.dot === true) { | ||
| state.output += NO_DOTS_SLASH; | ||
| prev.output += NO_DOTS_SLASH; | ||
| } else { | ||
| state.output += nodot; | ||
| prev.output += nodot; | ||
| } | ||
| if (peek() !== "*") { | ||
| state.output += ONE_CHAR; | ||
| prev.output += ONE_CHAR; | ||
| } | ||
| } | ||
| push(token); | ||
| } | ||
| while (state.brackets > 0) { | ||
| if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]")); | ||
| state.output = utils.escapeLast(state.output, "["); | ||
| decrement("brackets"); | ||
| } | ||
| while (state.parens > 0) { | ||
| if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")")); | ||
| state.output = utils.escapeLast(state.output, "("); | ||
| decrement("parens"); | ||
| } | ||
| while (state.braces > 0) { | ||
| if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}")); | ||
| state.output = utils.escapeLast(state.output, "{"); | ||
| decrement("braces"); | ||
| } | ||
| if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) { | ||
| push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` }); | ||
| } | ||
| if (state.backtrack === true) { | ||
| state.output = ""; | ||
| for (const token of state.tokens) { | ||
| state.output += token.output != null ? token.output : token.value; | ||
| if (token.suffix) { | ||
| state.output += token.suffix; | ||
| } | ||
| } | ||
| } | ||
| return state; | ||
| }; | ||
| parse.fastpaths = (input, options) => { | ||
| const opts = { ...options }; | ||
| const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH; | ||
| const len = input.length; | ||
| if (len > max) { | ||
| throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`); | ||
| } | ||
| input = REPLACEMENTS[input] || input; | ||
| const { | ||
| DOT_LITERAL, | ||
| SLASH_LITERAL, | ||
| ONE_CHAR, | ||
| DOTS_SLASH, | ||
| NO_DOT, | ||
| NO_DOTS, | ||
| NO_DOTS_SLASH, | ||
| STAR, | ||
| START_ANCHOR | ||
| } = constants.globChars(opts.windows); | ||
| const nodot = opts.dot ? NO_DOTS : NO_DOT; | ||
| const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT; | ||
| const capture = opts.capture ? "" : "?:"; | ||
| const state = { negated: false, prefix: "" }; | ||
| let star = opts.bash === true ? ".*?" : STAR; | ||
| if (opts.capture) { | ||
| star = `(${star})`; | ||
| } | ||
| const globstar = (opts2) => { | ||
| if (opts2.noglobstar === true) return star; | ||
| return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`; | ||
| }; | ||
| const create = (str) => { | ||
| switch (str) { | ||
| case "*": | ||
| return `${nodot}${ONE_CHAR}${star}`; | ||
| case ".*": | ||
| return `${DOT_LITERAL}${ONE_CHAR}${star}`; | ||
| case "*.*": | ||
| return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`; | ||
| case "*/*": | ||
| return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`; | ||
| case "**": | ||
| return nodot + globstar(opts); | ||
| case "**/*": | ||
| return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`; | ||
| case "**/*.*": | ||
| return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`; | ||
| case "**/.*": | ||
| return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`; | ||
| default: { | ||
| const match = /^(.*?)\.(\w+)$/.exec(str); | ||
| if (!match) return; | ||
| const source2 = create(match[1]); | ||
| if (!source2) return; | ||
| return source2 + DOT_LITERAL + match[2]; | ||
| } | ||
| } | ||
| }; | ||
| const output = utils.removePrefix(input, state); | ||
| let source = create(output); | ||
| if (source && opts.strictSlashes !== true) { | ||
| source += `${SLASH_LITERAL}?`; | ||
| } | ||
| return source; | ||
| }; | ||
| parse_1 = parse; | ||
| return parse_1; | ||
| } | ||
| var picomatch_1$1; | ||
| var hasRequiredPicomatch$1; | ||
| function requirePicomatch$1 () { | ||
| if (hasRequiredPicomatch$1) return picomatch_1$1; | ||
| hasRequiredPicomatch$1 = 1; | ||
| const scan = /*@__PURE__*/ requireScan(); | ||
| const parse = /*@__PURE__*/ requireParse(); | ||
| const utils = /*@__PURE__*/ requireUtils(); | ||
| const constants = /*@__PURE__*/ requireConstants(); | ||
| const isObject = (val) => val && typeof val === "object" && !Array.isArray(val); | ||
| const picomatch = (glob, options, returnState = false) => { | ||
| if (Array.isArray(glob)) { | ||
| const fns = glob.map((input) => picomatch(input, options, returnState)); | ||
| const arrayMatcher = (str) => { | ||
| for (const isMatch of fns) { | ||
| const state2 = isMatch(str); | ||
| if (state2) return state2; | ||
| } | ||
| return false; | ||
| }; | ||
| return arrayMatcher; | ||
| } | ||
| const isState = isObject(glob) && glob.tokens && glob.input; | ||
| if (glob === "" || typeof glob !== "string" && !isState) { | ||
| throw new TypeError("Expected pattern to be a non-empty string"); | ||
| } | ||
| const opts = options || {}; | ||
| const posix = opts.windows; | ||
| const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true); | ||
| const state = regex.state; | ||
| delete regex.state; | ||
| let isIgnored = () => false; | ||
| if (opts.ignore) { | ||
| const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null }; | ||
| isIgnored = picomatch(opts.ignore, ignoreOpts, returnState); | ||
| } | ||
| const matcher = (input, returnObject = false) => { | ||
| const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix }); | ||
| const result = { glob, state, regex, posix, input, output, match, isMatch }; | ||
| if (typeof opts.onResult === "function") { | ||
| opts.onResult(result); | ||
| } | ||
| if (isMatch === false) { | ||
| result.isMatch = false; | ||
| return returnObject ? result : false; | ||
| } | ||
| if (isIgnored(input)) { | ||
| if (typeof opts.onIgnore === "function") { | ||
| opts.onIgnore(result); | ||
| } | ||
| result.isMatch = false; | ||
| return returnObject ? result : false; | ||
| } | ||
| if (typeof opts.onMatch === "function") { | ||
| opts.onMatch(result); | ||
| } | ||
| return returnObject ? result : true; | ||
| }; | ||
| if (returnState) { | ||
| matcher.state = state; | ||
| } | ||
| return matcher; | ||
| }; | ||
| picomatch.test = (input, regex, options, { glob, posix } = {}) => { | ||
| if (typeof input !== "string") { | ||
| throw new TypeError("Expected input to be a string"); | ||
| } | ||
| if (input === "") { | ||
| return { isMatch: false, output: "" }; | ||
| } | ||
| const opts = options || {}; | ||
| const format = opts.format || (posix ? utils.toPosixSlashes : null); | ||
| let match = input === glob; | ||
| let output = match && format ? format(input) : input; | ||
| if (match === false) { | ||
| output = format ? format(input) : input; | ||
| match = output === glob; | ||
| } | ||
| if (match === false || opts.capture === true) { | ||
| if (opts.matchBase === true || opts.basename === true) { | ||
| match = picomatch.matchBase(input, regex, options, posix); | ||
| } else { | ||
| match = regex.exec(output); | ||
| } | ||
| } | ||
| return { isMatch: Boolean(match), match, output }; | ||
| }; | ||
| picomatch.matchBase = (input, glob, options) => { | ||
| const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options); | ||
| return regex.test(utils.basename(input)); | ||
| }; | ||
| picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str); | ||
| picomatch.parse = (pattern, options) => { | ||
| if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options)); | ||
| return parse(pattern, { ...options, fastpaths: false }); | ||
| }; | ||
| picomatch.scan = (input, options) => scan(input, options); | ||
| picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => { | ||
| if (returnOutput === true) { | ||
| return state.output; | ||
| } | ||
| const opts = options || {}; | ||
| const prepend = opts.contains ? "" : "^"; | ||
| const append = opts.contains ? "" : "$"; | ||
| let source = `${prepend}(?:${state.output})${append}`; | ||
| if (state && state.negated === true) { | ||
| source = `^(?!${source}).*$`; | ||
| } | ||
| const regex = picomatch.toRegex(source, options); | ||
| if (returnState === true) { | ||
| regex.state = state; | ||
| } | ||
| return regex; | ||
| }; | ||
| picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => { | ||
| if (!input || typeof input !== "string") { | ||
| throw new TypeError("Expected a non-empty string"); | ||
| } | ||
| let parsed = { negated: false, fastpaths: true }; | ||
| if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) { | ||
| parsed.output = parse.fastpaths(input, options); | ||
| } | ||
| if (!parsed.output) { | ||
| parsed = parse(input, options); | ||
| } | ||
| return picomatch.compileRe(parsed, options, returnOutput, returnState); | ||
| }; | ||
| picomatch.toRegex = (source, options) => { | ||
| try { | ||
| const opts = options || {}; | ||
| return new RegExp(source, opts.flags || (opts.nocase ? "i" : "")); | ||
| } catch (err) { | ||
| if (options && options.debug === true) throw err; | ||
| return /$^/; | ||
| } | ||
| }; | ||
| picomatch.constants = constants; | ||
| picomatch_1$1 = picomatch; | ||
| return picomatch_1$1; | ||
| } | ||
| var picomatch_1; | ||
| var hasRequiredPicomatch; | ||
| function requirePicomatch () { | ||
| if (hasRequiredPicomatch) return picomatch_1; | ||
| hasRequiredPicomatch = 1; | ||
| const pico = /*@__PURE__*/ requirePicomatch$1(); | ||
| const utils = /*@__PURE__*/ requireUtils(); | ||
| function picomatch(glob, options, returnState = false) { | ||
| if (options && (options.windows === null || options.windows === void 0)) { | ||
| options = { ...options, windows: utils.isWindows() }; | ||
| } | ||
| return pico(glob, options, returnState); | ||
| } | ||
| Object.assign(picomatch, pico); | ||
| picomatch_1 = picomatch; | ||
| return picomatch_1; | ||
| } | ||
| var picomatchExports = /*@__PURE__*/ requirePicomatch(); | ||
| var picomatch = /*@__PURE__*/getDefaultExportFromCjs(picomatchExports); | ||
| const concurrentMap = async (items, concurrency, callback) => { | ||
| const pending = /* @__PURE__ */ new Set(); | ||
| let index = 0; | ||
| for await (const item of items) { | ||
| const currentIndex = index; | ||
| index += 1; | ||
| const p = callback(item, currentIndex); | ||
| pending.add(p); | ||
| p.then(() => { | ||
| pending.delete(p); | ||
| }, () => { | ||
| }); | ||
| if (pending.size >= concurrency) { | ||
| await Promise.race(pending); | ||
| } | ||
| } | ||
| await Promise.all(pending); | ||
| }; | ||
| const glob = async (root, globPattern, options) => { | ||
| const includeDot = options?.dot ?? false; | ||
| const isMatch = picomatch(globPattern, { dot: includeDot }); | ||
| const isRecursive = globPattern.includes("**"); | ||
| const results = []; | ||
| const rootPrefix = root.length + 1; | ||
| const crawl = async (directory) => { | ||
| const entries = await fs.readdir(directory, { withFileTypes: true }); | ||
| const subdirectories = []; | ||
| for (const entry of entries) { | ||
| const fullPath = `${directory}/${entry.name}`; | ||
| const relativePath = fullPath.slice(rootPrefix); | ||
| if (isMatch(relativePath)) { | ||
| results.push(fullPath); | ||
| continue; | ||
| } | ||
| if (entry.isDirectory() && isRecursive) { | ||
| if (!includeDot && entry.name.startsWith(".")) { | ||
| continue; | ||
| } | ||
| subdirectories.push(crawl(fullPath)); | ||
| } | ||
| } | ||
| await Promise.all(subdirectories); | ||
| }; | ||
| await crawl(root); | ||
| return results; | ||
| }; | ||
| const debug$2 = createDebug("poof:resolve"); | ||
| const toPosix = path.sep === "\\" ? (filePath) => filePath.replaceAll("\\", "/") : (filePath) => filePath; | ||
| const GLOB_CONCURRENCY = 50; | ||
| const validatePath = (target, cwd, dangerous) => { | ||
| const absoluteTarget = path.resolve(target); | ||
| const { root } = path.parse(absoluteTarget); | ||
| if (absoluteTarget === root) { | ||
| throw new Error(`Refusing to delete root directory: ${absoluteTarget}`); | ||
| } | ||
| if (!dangerous) { | ||
| const normalizedCwd = toPosix(path.resolve(cwd)); | ||
| const normalizedTarget = toPosix(absoluteTarget); | ||
| const isOutside = !normalizedTarget.startsWith(`${normalizedCwd}/`) && normalizedTarget !== normalizedCwd; | ||
| if (isOutside) { | ||
| throw new Error( | ||
| `Refusing to delete path outside cwd. Pass { dangerous: true } to allow: ${absoluteTarget}` | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
| const resolvePatterns = async (patterns, cwd, dangerous = false) => { | ||
| const files = []; | ||
| const notFound = []; | ||
| await concurrentMap(patterns, GLOB_CONCURRENCY, async (pattern) => { | ||
| const posixPattern = toPosix(pattern); | ||
| const fullPattern = path.isAbsolute(pattern) ? posixPattern : path.posix.join(toPosix(cwd), posixPattern); | ||
| const scanned = picomatch.scan(fullPattern); | ||
| debug$2(`pattern ${pattern} -> fullPattern ${fullPattern} (isGlob: ${scanned.isGlob})`); | ||
| const pathToValidate = scanned.isGlob ? scanned.base || cwd : fullPattern; | ||
| validatePath(pathToValidate, cwd, dangerous); | ||
| if (!scanned.isGlob) { | ||
| await fs.access(fullPattern).then( | ||
| () => { | ||
| debug$2(`explicit path exists: ${fullPattern}`); | ||
| files.push(fullPattern); | ||
| }, | ||
| () => { | ||
| debug$2(`explicit path not found: ${pattern}`); | ||
| notFound.push(pattern); | ||
| } | ||
| ); | ||
| return; | ||
| } | ||
| let root = scanned.base || toPosix(cwd); | ||
| if (root.endsWith("/")) { | ||
| root = root.slice(0, -1); | ||
| } | ||
| const descendIntoDotDirectories = /^\.[^\\/.]|[{,]\.[^\\/.]/.test(scanned.glob); | ||
| const globStart = performance.now(); | ||
| const matches = await glob(root, scanned.glob, { dot: descendIntoDotDirectories }); | ||
| debug$2(`glob pattern=${pattern} files=${matches.length} time=${(performance.now() - globStart).toFixed(2)}ms`); | ||
| for (const match of matches) { | ||
| files.push(match); | ||
| } | ||
| }); | ||
| return { | ||
| files, | ||
| notFound | ||
| }; | ||
| }; | ||
| const debug$1 = createDebug("poof:rm"); | ||
| const rmWorkerPath = fileURLToPath(import.meta.resolve("#rm-worker")); | ||
| const startRmWorker = () => { | ||
| debug$1(`spawning background rm process: ${rmWorkerPath}`); | ||
| const child = spawn(process.execPath, [rmWorkerPath], { | ||
| detached: true, | ||
| stdio: ["pipe", "ignore", "ignore"], | ||
| windowsHide: true | ||
| }); | ||
| const stdin = child.stdin; | ||
| child.unref(); | ||
| debug$1(`background rm process started (pid: ${child.pid})`); | ||
| return { | ||
| /** | ||
| * Stream path to child process (null-delimited for filenames with newlines). | ||
| * | ||
| * Backpressure handling is critical here for three reasons: | ||
| * 1. Instant exit: Without it, end() blocks until child consumes the ~64KB pipe buffer, | ||
| * causing the CLI to hang at exit instead of returning instantly. | ||
| * 2. Data safety: We only rename files at the pace we can communicate to the cleaner. | ||
| * If parent crashes, orphaned temp files are limited to what's in the pipe, not | ||
| * unbounded paths sitting in Node.js memory. | ||
| * 3. Memory: Large directories (monorepo node_modules) can have 500k+ files. | ||
| * Buffering all paths in memory risks OOM in constrained environments. | ||
| */ | ||
| write(filePath) { | ||
| debug$1(`queue for deletion: ${filePath}`); | ||
| const canContinue = stdin.write(`${filePath}\0`); | ||
| if (!canContinue) { | ||
| debug$1("backpressure - waiting for drain"); | ||
| return new Promise((resolve) => { | ||
| stdin.once("drain", resolve); | ||
| }); | ||
| } | ||
| }, | ||
| /** | ||
| * Signal end of paths and wait for buffer to flush to OS pipe. | ||
| * After this resolves, all paths are in the kernel pipe buffer and the | ||
| * detached child will continue cleanup even after parent exits. | ||
| */ | ||
| end: () => new Promise((resolve, reject) => { | ||
| debug$1("ending stdin stream"); | ||
| stdin.end( | ||
| (error) => error ? reject(error) : resolve() | ||
| ); | ||
| }) | ||
| }; | ||
| }; | ||
| const RETRY_COUNT = 3; | ||
| const isWindows = process.platform === "win32"; | ||
| const windowsLockingCodes = /* @__PURE__ */ new Set(["EBUSY", "EPERM"]); | ||
| const isWindowsLockingError = (error) => isWindows && windowsLockingCodes.has(error.code ?? ""); | ||
| const withRetry = async (operation, shouldRetry) => { | ||
| let lastError; | ||
| for (let attempt = 0; attempt < RETRY_COUNT; attempt += 1) { | ||
| try { | ||
| return await operation(); | ||
| } catch (error) { | ||
| lastError = error; | ||
| if (attempt < RETRY_COUNT - 1 && shouldRetry(error)) { | ||
| await setTimeout(100 * (attempt + 1)); | ||
| continue; | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
| throw lastError; | ||
| }; | ||
| const debug = createDebug("poof:rename"); | ||
| const RENAME_CONCURRENCY = 100; | ||
| const poof = async (patterns, options) => { | ||
| const patternArray = Array.isArray(patterns) ? patterns : [patterns]; | ||
| const cwd = options?.cwd ?? process.cwd(); | ||
| debug(`patterns: ${JSON.stringify(patternArray)}, cwd: ${cwd}`); | ||
| const resolveStart = performance.now(); | ||
| const { files, notFound } = await resolvePatterns(patternArray, cwd, options?.dangerous ?? false); | ||
| debug(`resolve files=${files.length} time=${(performance.now() - resolveStart).toFixed(2)}ms`); | ||
| const filesToDelete = files; | ||
| const errors = notFound.map((pattern) => { | ||
| const error = new Error(`Path not found: ${pattern}`); | ||
| error.code = "ENOENT"; | ||
| return { | ||
| path: pattern, | ||
| error | ||
| }; | ||
| }); | ||
| if (options?.dry) { | ||
| return { | ||
| deleted: files, | ||
| errors | ||
| }; | ||
| } | ||
| const deleted = []; | ||
| if (filesToDelete.length > 0) { | ||
| const renameStart = performance.now(); | ||
| const id = `poof-${crypto.randomUUID()}`; | ||
| const tempDir = path.join(os.tmpdir(), id); | ||
| let tempDirCreated; | ||
| const rmWriter = startRmWorker(); | ||
| const renamedParents = []; | ||
| await concurrentMap(filesToDelete, RENAME_CONCURRENCY, async (target, index) => { | ||
| const baseName = path.basename(target); | ||
| if (!tempDirCreated) { | ||
| tempDirCreated = fs.mkdir(tempDir).then(() => { | ||
| debug(`temp dir created: ${tempDir}`); | ||
| }); | ||
| } | ||
| await tempDirCreated; | ||
| const destinationPath = path.join(tempDir, `${index}-${baseName}`); | ||
| debug(`rename ${target} -> ${destinationPath}`); | ||
| try { | ||
| await withRetry(() => fs.rename(target, destinationPath), isWindowsLockingError); | ||
| renamedParents.push(target); | ||
| return; | ||
| } catch (error) { | ||
| const { code } = error; | ||
| debug(`rename failed: ${target} (code=${code})`); | ||
| if (code === "ENOENT") { | ||
| renamedParents.push(target); | ||
| return; | ||
| } | ||
| if (code !== "EXDEV") { | ||
| errors.push({ | ||
| path: target, | ||
| error | ||
| }); | ||
| return; | ||
| } | ||
| } | ||
| const fallbackPath = path.join(path.dirname(target), `.${id}-${index}-${baseName}`); | ||
| try { | ||
| await withRetry(() => fs.rename(target, fallbackPath), isWindowsLockingError); | ||
| await rmWriter.write(fallbackPath); | ||
| renamedParents.push(target); | ||
| } catch (fallbackError) { | ||
| const { code } = fallbackError; | ||
| if (code === "ENOENT") { | ||
| renamedParents.push(target); | ||
| return; | ||
| } | ||
| errors.push({ | ||
| path: target, | ||
| error: fallbackError | ||
| }); | ||
| } | ||
| }); | ||
| debug(`rename files=${renamedParents.length} time=${(performance.now() - renameStart).toFixed(2)}ms`); | ||
| const spawnStart = performance.now(); | ||
| if (tempDirCreated) { | ||
| await rmWriter.write(tempDir); | ||
| } | ||
| await rmWriter.end(); | ||
| debug(`spawn time=${(performance.now() - spawnStart).toFixed(2)}ms`); | ||
| const renamedSet = new Set(renamedParents); | ||
| for (const file of files) { | ||
| if (renamedSet.has(file)) { | ||
| deleted.push(file); | ||
| continue; | ||
| } | ||
| let dir = file; | ||
| while (dir.includes("/")) { | ||
| dir = dir.slice(0, Math.max(0, dir.lastIndexOf("/"))); | ||
| if (renamedSet.has(dir)) { | ||
| deleted.push(file); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| debug(`deleted ${deleted.length} files, ${errors.length} errors`); | ||
| return { | ||
| deleted, | ||
| errors | ||
| }; | ||
| }; | ||
| export { poof as default }; |
| #!/usr/bin/env node | ||
| import fs from 'node:fs/promises'; | ||
| const CONCURRENCY = 16; | ||
| const MAX_RETRIES = 3; | ||
| const RETRY_DELAY = 100; | ||
| async function* parseNullDelimitedPaths(stream) { | ||
| let buffer = Buffer.alloc(0); | ||
| for await (const chunk of stream) { | ||
| buffer = Buffer.concat([buffer, chunk]); | ||
| let nullIndex = buffer.indexOf(0); | ||
| while (nullIndex !== -1) { | ||
| const filePath = buffer.subarray(0, nullIndex); | ||
| if (filePath.length > 0) { | ||
| yield filePath; | ||
| } | ||
| buffer = buffer.subarray(nullIndex + 1); | ||
| nullIndex = buffer.indexOf(0); | ||
| } | ||
| } | ||
| if (buffer.length > 0) { | ||
| yield buffer; | ||
| } | ||
| } | ||
| const pool = /* @__PURE__ */ new Set(); | ||
| for await (const filePath of parseNullDelimitedPaths(process.stdin)) { | ||
| const task = fs.rm(filePath, { | ||
| recursive: true, | ||
| force: true, | ||
| maxRetries: MAX_RETRIES, | ||
| retryDelay: RETRY_DELAY | ||
| }).catch(() => { | ||
| }).then(() => { | ||
| pool.delete(task); | ||
| }); | ||
| pool.add(task); | ||
| if (pool.size >= CONCURRENCY) { | ||
| await Promise.race(pool); | ||
| } | ||
| } | ||
| await Promise.all(pool); |
+21
| MIT License | ||
| Copyright (c) Hiroki Osame <hiroki.osame@gmail.com> | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+19
-57
| { | ||
| "name": "poof", | ||
| "version": "2.2.0", | ||
| "description": "Simple data processing with decorators", | ||
| "main": "dist/index.js", | ||
| "jsnext:main": "lib/index.js", | ||
| "files": [ | ||
| "dist/index.js", | ||
| "lib/**/*.js" | ||
| ], | ||
| "version": "3.0.0", | ||
| "description": "Fast, non-blocking rm -rf alternative. Deletes files instantly while cleanup runs in the background.", | ||
| "keywords": [ | ||
| "assert", | ||
| "decorator", | ||
| "decorators", | ||
| "processing", | ||
| "validate", | ||
| "validation", | ||
| "validator" | ||
| "rm", | ||
| "rimraf", | ||
| "delete", | ||
| "remove", | ||
| "fast", | ||
| "cli" | ||
| ], | ||
| "homepage": "https://github.com/fatfisz/poof", | ||
| "repository": "https://github.com/fatfisz/poof.git", | ||
| "author": { | ||
| "name": "FatFisz", | ||
| "url": "https://github.com/fatfisz" | ||
| }, | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "prepublish": "grunt prepublish", | ||
| "test": "grunt test" | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "type": "module", | ||
| "bin": "./dist/cli.mjs", | ||
| "exports": "./dist/index.mjs", | ||
| "imports": { | ||
| "#rm-worker": "./dist/spawn-rm/worker.mjs" | ||
| }, | ||
| "dependencies": { | ||
| "poof-factory": "^2.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "~2.9.0", | ||
| "eslint-config-fatfisz": "~2.9.0", | ||
| "grunt": "^1.0.1", | ||
| "grunt-babel": "^5.0.3", | ||
| "grunt-cli": "^1.2.0", | ||
| "grunt-contrib-clean": "^1.0.0", | ||
| "grunt-eslint": "^18.1.0", | ||
| "grunt-mocha-test": "^0.12.7", | ||
| "grunt-rollup": "^0.7.1", | ||
| "load-grunt-tasks": "^3.5.0", | ||
| "mocha": "^2.5.3", | ||
| "mockery": "^1.7.0", | ||
| "rollup-plugin-babel": "^1.0.0", | ||
| "should": "^8.4.0", | ||
| "should-sinon": "0.0.5", | ||
| "sinon": "^2.0.0-pre" | ||
| }, | ||
| "babel": { | ||
| "loose": [ | ||
| "es6.classes", | ||
| "es6.destructuring", | ||
| "es6.forOf", | ||
| "es6.properties.computed", | ||
| "es6.spread" | ||
| ], | ||
| "optional": [ | ||
| "es7.decorators" | ||
| ] | ||
| "engines": { | ||
| "node": ">=20.8.0" | ||
| } | ||
| } | ||
| } |
+164
-226
@@ -1,310 +0,248 @@ | ||
| # Poof | ||
| <h2 align="center"> | ||
| <img width="240" src=".github/logo.png"> | ||
| <br><br> | ||
| <a href="https://npm.im/poof"><img src="https://badgen.net/npm/v/poof"></a> <a href="https://npm.im/poof"><img src="https://badgen.net/npm/dm/poof"></a> <a href="https://packagephobia.now.sh/result?p=poof"><img src="https://packagephobia.now.sh/badge?p=poof"></a> | ||
| </h2> | ||
| > Simple data processing with decorators | ||
| Ever `rm -rf`'d a large directory and sat there waiting for it to finish? With `poof` you no longer need to wait: | ||
| [](https://travis-ci.org/fatfisz/poof) | ||
| [](https://david-dm.org/fatfisz/poof?path=packages/poof) | ||
| [](https://david-dm.org/fatfisz/poof?path=packages/poof#info=devDependencies) | ||
| ```sh | ||
| $ poof ./large-file ./large-directory "**/globs" | ||
| ``` | ||
| Poof is a tool for creating data processing functions in a declarative way by utilising an upcoming JS feature - decorators. | ||
| ### What's "poof"? | ||
| `poof` is a fast, non-blocking CLI alternative to `rm -rf`, designed for deleting large files and directories without waiting for cleanup to complete. | ||
| It makes use of the awesome [validator](https://www.npmjs.com/package/validator) lib to provide assertion functions. Without it Poof probably wouldn't exist. | ||
| It works by quickly moving files and directories out of the way, then deleting them in the background. | ||
| This means large deletions finish instantly from your perspective, even when there's a lot of data to clean up. | ||
| ## Contents | ||
| On a large filesystem (4.7 GB, 190k files), `poof` returns control in ~0.6s while `rm -rf` takes ~28s and `rimraf` ~12s. Full benchmarks below. | ||
| - [Getting started](#getting-started) | ||
| - [Why use Poof?](#why-use-poof) | ||
| - [Example](#example) | ||
| - [Example explained](#example-explained) | ||
| - [The difference between poof and poof-cast](#the-difference-between-poof-and-poof-cast) | ||
| - [API](#api) | ||
| - [createProcessor(config)](#createprocessorconfig) | ||
| - [decorators](#decorators) | ||
| - [decorators.assert.method and decorators.assert.not.method](#decoratorsassertmethod-and-decoratorsassertnotmethod) | ||
| - [decorators.assert.hasType and decorators.assert.not.hasType](#decoratorsasserthastype-and-decoratorsassertnothastype) | ||
| - [decorators.assert.isInstanceOf and decorators.assert.not.isInstanceOf](#decoratorsassertisinstanceof-and-decoratorsassertnotisinstanceof) | ||
| - [decorators.assign](#decoratorsassign) | ||
| - [decorators.assignTo(key)](#decoratorsassigntokey) | ||
| - [decorators.filter(predicate)](#decoratorsfilterpredicate) | ||
| - [decorators.from(key)](#decoratorsfromkey) | ||
| - [decorators.ignoreIf(predicate)](#decoratorsignoreifpredicate) | ||
| - [decorators.ignoreIfUndefined](#decoratorsignoreifundefined) | ||
| - [decorators.map(mapper)](#decoratorsmapmapper) | ||
| - [decorators.set(value)](#decoratorssetvalue) | ||
| - [decorators.transform(transformer)](#decoratorstransformtransformer) | ||
| - [Some questions you might have](#some-questions-you-might-have) | ||
| - [How can I use decorators in my code?](#how-can-i-use-decorators-in-my-code) | ||
| - [Why the explicit assignment decorator?](#why-the-explicit-assignment-decorator) | ||
| - [What about nested structures?](#what-about-nested-structures) | ||
| - [Why is the field error exception a separate package?](#why-is-the-field-error-exception-a-separate-package) | ||
| - [Be careful with decorators!](#be-careful-with-decorators) | ||
| - [Contributing](#contributing) | ||
| - [License](#license) | ||
| ### Features | ||
| * ⚡ **Immediate return**: deletion doesn't block your shell | ||
| * 🗂 **Move-then-delete**: fast, atomic rename before cleanup | ||
| * 🛡 **Built-in safeguards**: root protection and directory scoping | ||
| * 🖥 **Cross-platform**: macOS, Linux, and Windows | ||
| ## Getting started | ||
| ## Install | ||
| Install the `poof` package with this command: | ||
| ```shell | ||
| npm install poof field-validation-error --save | ||
| ```sh | ||
| npm install -g poof | ||
| ``` | ||
| and/or install the `poof-cast` package with this command: | ||
| ```shell | ||
| npm install poof-cast field-validation-error -save | ||
| ``` | ||
| `field-validation-error` is a peer dependency of both `poof` packages. | ||
| ## CLI Usage | ||
| ### ES6 Data Structures | ||
| ```sh | ||
| # Delete files or directories | ||
| poof node_modules dist | ||
| Poof makes use of ES6 data structures, e.g. `WeakMap`, but doesn't include any polyfill. | ||
| Make sure you add a polyfill yourself if you want to support older browsers. | ||
| # Use glob patterns | ||
| poof "*.log" "temp-*" | ||
| ## Why use Poof? | ||
| # Recursive match with ** (searches all subdirectories) | ||
| poof "**/node_modules" "**/dist" | ||
| - it lets you describe data processing in a straightforward, declarative way | ||
| - it is especially useful for isomorphic websites - you can declare data validator once and use it both on the client-side and the on the server-side | ||
| - Poof processors are composable - you can pass the result from one processor to another, e.g. when you want to separate validation and transforming | ||
| ## Example | ||
| ```js | ||
| import FieldValidationError from 'field-validation-error'; | ||
| import { createProcessor, decorators } from 'poof-cast'; | ||
| const processIdAndIndex = createProcessor({ | ||
| @decorators.from('postId') | ||
| @decorators.assert.not.isNull('Missing post id') | ||
| @decorators.assert.isMongoId('Invalid id') | ||
| @decorators.transform(ObjectID) | ||
| @decorators.assign | ||
| _id() {}, | ||
| @decorators.assert.not.isNull('Missing index') | ||
| @decorators.assert.isInt('Invalid index', { min: 0 }) | ||
| @decorators.transform(Number) | ||
| @decorators.assign | ||
| index() {}, | ||
| }); | ||
| try { | ||
| const result = processIdAndIndex(request.body); | ||
| // Do something with the result... | ||
| } catch(error) { | ||
| if (error instanceof FieldValidationError) { | ||
| // Do something with error messages contained in `error.fields` | ||
| } | ||
| } | ||
| # Verbose output | ||
| poof --verbose ./large-directory | ||
| ``` | ||
| ## Example explained | ||
| ### Options | ||
| Poof library has two versions: [`poof`, and `poof-cast`](#the-difference-between-poof-and-poof-cast). Both of them have two exports: the [`createProcessor` function](#createprocessorconfig) and the [`decorators` object](#decorators). | ||
| | Flag | Alias | Description | | ||
| | ------------- | ----- | ---------------------------------------------- | | ||
| | `--dry` | `-d` | Preview files without deleting | | ||
| | `--verbose` | `-v` | Log each file as it's deleted | | ||
| | `--dangerous` | | Allow deleting paths outside current directory | | ||
| | `--version` | | Show version | | ||
| | `--help` | | Show help | | ||
| ```js | ||
| // First import the FieldValidationError and also tools from Poof. The | ||
| // `poof-cast` version additionaly casts data to String for assertions. More | ||
| // about it later. | ||
| import FieldValidationError from 'field-validation-error'; | ||
| import { createProcessor, decorators } from 'poof-cast'; | ||
| ## File matching | ||
| // The `createProcessor` function returns a processor based on the passed | ||
| // config object. | ||
| const processIdAndIndex = createProcessor({ | ||
| `poof` accepts explicit paths or [glob patterns](https://en.wikipedia.org/wiki/Glob_%28programming%29) for flexible file matching. | ||
| // This decorator tells to pick the data from the `postId` property of | ||
| // a passed object. | ||
| @decorators.from('postId') | ||
| > [!TIP] | ||
| > When using glob patterns, start with `--dry` to preview what will match before deleting. | ||
| // This decorator checks if the value is empty; if not, the error for this | ||
| // field is set to 'Missing post id' and this field's processing stops here. | ||
| @decorators.assert.not.isNull('Missing post id') | ||
| ### Quick refresher: shell quoting | ||
| // Similarly, check if the value is a MongoDB id. | ||
| @decorators.assert.isMongoId('Invalid id') | ||
| How unquoted glob patterns are expanded depends on your shell's settings (`dotglob`, `globstar`, etc.). | ||
| To get consistent behavior, quote the pattern so `poof` handles the matching itself. | ||
| // This decorator takes a function and uses it to transforms the value. | ||
| // In this case the ObjectID constructor is used. | ||
| @decorators.transform(ObjectID) | ||
| ```sh | ||
| # The shell expands the glob before poof runs | ||
| $ poof **/node_modules | ||
| // If you want to have the result of the processing contained in the result | ||
| // object, you have to do it explicitly with the `assign` decorator. | ||
| @decorators.assign | ||
| # Recommended: poof expands the glob | ||
| $ poof "**/node_modules" | ||
| ``` | ||
| // This defines the output property which will have the processed value. | ||
| _id() {}, | ||
| ### Basic patterns | ||
| ```sh | ||
| # Explicit paths | ||
| $ poof node_modules | ||
| // Assert that the value is not empty. | ||
| @decorators.assert.not.isNull('Missing index') | ||
| # Multiple paths | ||
| $ poof dist coverage | ||
| // Assert that the value is an integer, with a value of at least 0. | ||
| @decorators.assert.isInt('Invalid index', { min: 0 }) | ||
| # Wildcards in current directory | ||
| $ poof "*.log" | ||
| $ poof "temp-*" | ||
| ``` | ||
| // Cast to Number | ||
| @decorators.transform(Number) | ||
| ### Recursive patterns | ||
| // Pass to the output | ||
| @decorators.assign | ||
| Use `**` to match across nested directories: | ||
| // The result will land in the `index` property. | ||
| // Note that here we initially get the value from the `index` property, so | ||
| // the `from` decorator is not needed. | ||
| index() {}, | ||
| }); | ||
| ```sh | ||
| # All node_modules in a monorepo | ||
| $ poof "**/node_modules" | ||
| # All .log files recursively | ||
| $ poof "**/*.log" | ||
| try { | ||
| // Now the processor can be used with an object. | ||
| const result = processIdAndIndex(request.body); | ||
| // Do something with the result... | ||
| } catch(error) { | ||
| if (error instanceof FieldValidationError) { | ||
| // Do something with error messages contained in `error.fields` | ||
| } | ||
| } | ||
| # Multiple patterns | ||
| $ poof "**/dist" "**/coverage" "**/*.tmp" | ||
| ``` | ||
| So if `request.body` is: | ||
| ```js | ||
| { | ||
| postId: '507f1f77bcf86cd799439011', | ||
| index: '12', | ||
| } | ||
| ``` | ||
| then `result` would be: | ||
| ```js | ||
| { | ||
| _id: ObjectID('507f1f77bcf86cd799439011'), | ||
| index: 12, | ||
| } | ||
| ``` | ||
| ### Dotfiles (hidden files) | ||
| If instead `request.body` is: | ||
| ```js | ||
| { | ||
| index: '-1', | ||
| } | ||
| ``` | ||
| then you'd get a `FieldValidationError` with the `fields` property equal to: | ||
| ```js | ||
| { | ||
| _id: 'Missing post id', | ||
| index: 'Invalid index', | ||
| } | ||
| ``` | ||
| By default, glob wildcards (`*`, `**`) don't match dotfiles (files starting with `.`). This helps avoid accidentally deleting `.git`, `.env`, or other hidden files. | ||
| ## The difference between poof and poof-cast | ||
| To target dotfiles, explicitly include the `.` in your pattern: | ||
| While `poof` passes processed data for asserts without change, `poof-cast` casts it to string beforehand. The casting works the same as default JS string casting, with this exception: `null`, `undefined`, and `NaN` become `''` (empty string). | ||
| ```sh | ||
| # Delete all dotfiles in current directory | ||
| $ poof ".*" | ||
| This is quite useful for parsing request bodies which usually consist of strings - missing fields assume the value of `''` when auto-casting is on. Because of this `decorators.assert.isNull` from `poof-cast` can be used to check both for field presence and whether the value is a non-empty string. This of course reduces otherwise necessary boilerplate code. | ||
| # Delete .cache directories (not inside hidden dirs) | ||
| $ poof "**/.cache" | ||
| The [validator](https://www.npmjs.com/package/validator) library used to make the casting by itself before v. 5. Now it instead throws when the passed argument is not a string. Those exceptions can be thrown when using `poof` (without casting), so be careful when using that version. | ||
| # Delete a specific dotfile | ||
| $ poof .env.local | ||
| ``` | ||
| ## API | ||
| #### Searching inside hidden directories | ||
| Both `poof` and `poof-cast` export: | ||
| `**/.cache` finds `.cache` directories in regular directories, but does **not** scan inside other hidden directories like `.git`. This is intentional—scanning hidden directories is slow and rarely useful. | ||
| ### createProcessor(config) | ||
| To search inside hidden directories, start your pattern with `.*`: | ||
| Use this function with a config object to get a simple data processor. | ||
| ```sh | ||
| # Find .cache inside any hidden directory | ||
| $ poof ".*/**/.cache" | ||
| ``` | ||
| The processor either returns an output object or throws `FieldValidationError` if there was a validation error. | ||
| Or use brace expansion to target specific directories: | ||
| ### decorators | ||
| ```sh | ||
| # Search inside .config and src | ||
| $ poof "{.config,src}/**/.cache" | ||
| ``` | ||
| #### decorators.assert.method and decorators.assert.not.method | ||
| ### Negation patterns | ||
| Those contain all validation functions from the validator lib: `contains`, `equals`, `isAfter`, `isAlpha`, `isAlphanumeric`, `isAscii`, `isBase64`, `isBefore`, `isBoolean`, `isByteLength`, `isCreditCard`, `isCurrency`, `isDataURI`, `isDate`, `isDecimal`, `isDivisibleBy`, `isEmail`, `isFloat`, `isFQDN`, `isFullWidth`, `isHalfWidth`, `isHexadecimal`, `isHexColor`, `isIn`, `isInt`, `isIP`, `isISBN`, `isISIN`, `isISO8601`, `isJSON`, `isLength`, `isLowercase`, `isMACAddress`, `isMobilePhone`, `isMongoId`, `isMultibyte`, `isNull`, `isNumeric`, `isSurrogatePair`, `isUppercase`, `isURL`, `isUUID`, `isVariableWidth`, `isWhitelisted`, and `matches`. | ||
| Extglob negations like `!(pattern)` match everything *except* the specified pattern: | ||
| *The validator methods will be updated if necessary, but the new ones should be auto-detected in most cases.* | ||
| ```sh | ||
| # Delete everything except .gitkeep | ||
| $ poof "!(.gitkeep)" | ||
| ``` | ||
| The first argument is always a message that can be found in the thrown exception in case the validation failed. | ||
| > [!WARNING] | ||
| > Negations match dotfiles. `!(important.txt)` will match `.env`, `.git`, and other hidden files. Always use `--dry` first. | ||
| That is followed by other arguments, which are passed to the validation function as the second, third, and so on arguments. The first argument passed is the currently processed value. | ||
| ## Safety | ||
| So for example for `@decorators.assert.equals('Is different', 'expected')` the arguments passed to the `equals` validator will be the current value and `'expected'`, and if the currently processed value is different from `'expected'`, the error message for this field will be set to `'Is different'`. | ||
| `poof` includes guards to help prevent common accidents: | ||
| `decorators.assert.not` works almost the same, only the validation fails if the function returns `true`. | ||
| - **Root protection**: refuses to delete the filesystem root | ||
| - **Directory scoping**: won't delete paths outside `cwd` unless `--dangerous` is passed | ||
| - **Typo protection**: explicit paths that don't exist are reported as errors, so `poof ndoe_modoules` won't silently succeed | ||
| - **Script-friendly globs**: glob patterns with no matches exit silently, so `poof "*.log"` won't break your scripts | ||
| #### decorators.assert.hasType and decorators.assert.not.hasType | ||
| ## How it works | ||
| An additional assertion function that performs the `typeof` check on the current value and the passed argument. | ||
| Traditional `rm -rf` blocks until every file is unlinked. | ||
| For large directories, this means waiting on thousands of filesystem operations. | ||
| #### decorators.assert.isInstanceOf and decorators.assert.not.isInstanceOf | ||
| `poof` uses a different strategy: | ||
| An additional assertion function that performs the `instanceof` check on the current value and the passed argument. | ||
| 1. Resolve glob patterns and validate paths | ||
| 2. Spawn a detached cleanup process | ||
| 3. Rename files to a temp directory (constant-time, atomic) | ||
| 4. Stream renamed paths to the cleanup process as renames complete | ||
| 5. Exit process to return your shell while cleanup process continues in the background | ||
| #### decorators.assign | ||
| ### Cross-device fallback | ||
| Used to assign the processed value to the output object. When using, it's best to put this decorator last, because any further processing results won't be saved. | ||
| If the target is on a different filesystem (`EXDEV`), `poof` falls back to renaming in place with a hidden prefix (e.g., `.poof-uuid-large-directory`) and streams it directly to the cleaner. | ||
| #### decorators.assignTo(key) | ||
| ## Benchmarks | ||
| Just like `decorators.assign`, but assigns to a property named after the `key` argument. Use sparingly, only when the output property name needs to be computed. | ||
| Deleting `**/node_modules` directories from a synthetic fixture: | ||
| #### decorators.filter(predicate) | ||
| | Tool | Time | vs poof | | ||
| | -------- | ------- | ---------- | | ||
| | `poof` | 0.59s | — | | ||
| | `rimraf` | 12.32s | 21x slower | | ||
| | `rm -rf` | 27.82s | 48x slower | | ||
| Filters the current value using `predicate`. The current value is assumed to be an array. | ||
| Fixture: 4.7 GB, 190k files | ||
| #### decorators.from(key) | ||
| Environment: macOS 15.2, Apple M2 Max, SSD | ||
| The initial value for the processed field is taken from the input object using its key. If you want to use a value of a different field instead, use this decorator. | ||
| > [!NOTE] | ||
| > These benchmarks measure how long it takes to return control of your terminal, not actual deletion time. Background deletion continues after `poof` exits. `rm -rf` and `rimraf` measure actual deletion time. | ||
| #### decorators.ignoreIf(predicate) | ||
| ## JS API | ||
| The predicate is called with the processed value. If the result is `true`, then the processing is stopped for that field and it is omitted from the output object. | ||
| `poof` can also be used programmatically: | ||
| #### decorators.ignoreIfUndefined | ||
| ```ts | ||
| import poof from 'poof' | ||
| Sometimes you might want to process some data only if it's present. Use this decorator to avoid validation and transforming in case the processed value is `undefined`. It's equivalent to `decorators.ignoreIf((value) => typeof value === 'undefined')`. | ||
| await poof('./large-directory') | ||
| await poof(['**/dist', 'coverage']) | ||
| #### decorators.map(mapper) | ||
| const { deleted, errors } = await poof('./large-directory', { dry: true }) | ||
| ``` | ||
| Maps the current value using `mapper`. The current value is assumed to be an array. | ||
| ### Types | ||
| #### decorators.set(value) | ||
| ```ts | ||
| type Options = { | ||
| cwd?: string | ||
| dry?: boolean | ||
| dangerous?: boolean | ||
| } | ||
| Simply sets the processed value to the one passed in the argument. | ||
| type Failure = { | ||
| path: string | ||
| error: Error | ||
| } | ||
| #### decorators.transform(transformer) | ||
| type Result = { | ||
| deleted: string[] | ||
| errors: Failure[] | ||
| } | ||
| ``` | ||
| Takes transformer, applies it to the processed value, and sets it as a new processed value. Useful for type casting or otherwise transforming the validated data. | ||
| ## Alternatives | ||
| ## Some questions you might have | ||
| Some tools provide fast, non-blocking removal by moving files to the system trash: | ||
| ### How can I use decorators in my code? | ||
| - [trash](https://formulae.brew.sh/formula/trash) (macOS) | ||
| - [trash-cli](https://github.com/sindresorhus/trash-cli) (cross-platform) | ||
| You can use Babel 5 with an optional "es7.decorators" transformer, or use Babel 6 with [this legacy plugin](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy). There are some differences though, you can read about them [here](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy/blob/master/README.md). | ||
| These are useful for recoverable deletes, but large directories can accumulate in the trash and consume disk space. | ||
| ### Why the explicit assignment decorator? | ||
| `poof` permanently deletes files, freeing space immediately. | ||
| When I started creating what later became Poof I didn't always want to have all of the fields in the output object, and so I decided for the explicit assignment. Maybe in the future I'll add some options to enable auto-assignment for all fields in the object though. | ||
| ## Requirements | ||
| ### What about nested structures? | ||
| Node.js >= 20.19.6 | ||
| This was supposed to be a simple lib, and I didn't have a need to support nested structures with it. I might do it someday and I'm open to suggestions/PRs. | ||
| ### Why is the field error exception a separate package? | ||
| It makes sense to decouple the exception from the `poof` package because another package that handles this exception shouldn't be tied to `poof`. This problem is not contrived, it's an actual problem I had. | ||
| ## Be careful with decorators! | ||
| The decorators feature is still at stage 1, a proposal. | ||
| This means that the [current decorator spec](https://github.com/wycats/javascript-decorators) can change dramatically before it advances to the next stage. | ||
| With this said, no changes should affect your use of this library much. You will be mostly using the exterior (decorator application) which now has a final form more or less, while the interior (how the decorating works in Poof) will be kept up-to-date with the spec. | ||
| While some things may be set in stone, there is still a room for improvement. So if you care about decorators, please can take part in discussions at [wycats/javascript-decorators](https://github.com/wycats/javascript-decorators) and [jeffmo/es-class-fields-and-static-properties](https://github.com/jeffmo/es-class-fields-and-static-properties). | ||
| ## Contributing | ||
| In lieu of a formal style guide, take care to maintain the existing coding style. | ||
| Add unit tests for any new or changed functionality. Lint and test your code with `npm test`. | ||
| ## License | ||
| Copyright (c) 2016 Rafał Ruciński. Licensed under the MIT license. | ||
| MIT |
| 'use strict'; | ||
| function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
| var poofFactory = _interopDefault(require('poof-factory')); | ||
| var index = poofFactory(false); | ||
| module.exports = index; |
| import poofFactory from 'poof-factory'; | ||
| export default poofFactory(false); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
115126
632.21%0
-100%0
-100%6
50%2777
46183.33%Yes
NaN2
100%1
Infinity%249
-19.94%9
800%- Removed
- Removed
- Removed
- Removed