UNPKG

go-get-folder-size

Version:

Get the size of a folder by recursively iterating through all its sub(files && folders). Use go, so high-speed

1,344 lines (1,343 loc) 41 kB
var dt = Object.defineProperty; var ft = (e, t, n) => t in e ? dt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n; var P = (e, t, n) => (ft(e, typeof t != "symbol" ? t + "" : t, n), n), K = (e, t, n) => { if (!t.has(e)) throw TypeError("Cannot " + n); }; var l = (e, t, n) => (K(e, t, "read from private field"), n ? n.call(e) : t.get(e)), S = (e, t, n) => { if (t.has(e)) throw TypeError("Cannot add the same private member more than once"); t instanceof WeakSet ? t.add(e) : t.set(e, n); }, I = (e, t, n, r) => (K(e, t, "write to private field"), r ? r.call(e, n) : t.set(e, n), n); var V = (e, t, n) => (K(e, t, "access private method"), n); import { Buffer as mt } from "buffer"; import E, { dirname as pt, resolve as ht } from "path"; import re, { ChildProcess as gt } from "child_process"; import w from "process"; import se, { createWriteStream as yt, createReadStream as bt } from "fs"; import St, { fileURLToPath as wt } from "url"; import { constants as Be } from "node:os"; import Et, { platform as xt, arch as Tt } from "os"; import { setTimeout as It } from "timers/promises"; import vt from "stream"; import { debuglog as Pt } from "util"; import { p as Ne } from "./index-4f2f13ba.mjs"; import { createInterface as Ct } from "readline"; var $t = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function je(e) { return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e; } var G = { exports: {} }, X, be; function At() { if (be) return X; be = 1, X = r, r.sync = i; var e = se; function t(o, s) { var a = s.pathExt !== void 0 ? s.pathExt : process.env.PATHEXT; if (!a || (a = a.split(";"), a.indexOf("") !== -1)) return !0; for (var c = 0; c < a.length; c++) { var u = a[c].toLowerCase(); if (u && o.substr(-u.length).toLowerCase() === u) return !0; } return !1; } function n(o, s, a) { return !o.isSymbolicLink() && !o.isFile() ? !1 : t(s, a); } function r(o, s, a) { e.stat(o, function(c, u) { a(c, c ? !1 : n(u, o, s)); }); } function i(o, s) { return n(e.statSync(o), o, s); } return X; } var q, Se; function Ot() { if (Se) return q; Se = 1, q = t, t.sync = n; var e = se; function t(o, s, a) { e.stat(o, function(c, u) { a(c, c ? !1 : r(u, s)); }); } function n(o, s) { return r(e.statSync(o), s); } function r(o, s) { return o.isFile() && i(o, s); } function i(o, s) { var a = o.mode, c = o.uid, u = o.gid, d = s.uid !== void 0 ? s.uid : process.getuid && process.getuid(), m = s.gid !== void 0 ? s.gid : process.getgid && process.getgid(), f = parseInt("100", 8), p = parseInt("010", 8), g = parseInt("001", 8), b = f | p, x = a & g || a & p && u === m || a & f && c === d || a & b && d === 0; return x; } return q; } var U; process.platform === "win32" || $t.TESTING_WINDOWS ? U = At() : U = Ot(); var Gt = ae; ae.sync = Rt; function ae(e, t, n) { if (typeof t == "function" && (n = t, t = {}), !n) { if (typeof Promise != "function") throw new TypeError("callback not provided"); return new Promise(function(r, i) { ae(e, t || {}, function(o, s) { o ? i(o) : r(s); }); }); } U(e, t || {}, function(r, i) { r && (r.code === "EACCES" || t && t.ignoreErrors) && (r = null, i = !1), n(r, i); }); } function Rt(e, t) { try { return U.sync(e, t || {}); } catch (n) { if (t && t.ignoreErrors || n.code === "EACCES") return !1; throw n; } } const C = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys", ke = E, Bt = C ? ";" : ":", Le = Gt, _e = (e) => Object.assign(new Error(`not found: ${e}`), { code: "ENOENT" }), Fe = (e, t) => { const n = t.colon || Bt, r = e.match(/\//) || C && e.match(/\\/) ? [""] : [ // windows always checks the cwd first ...C ? [process.cwd()] : [], ...(t.path || process.env.PATH || /* istanbul ignore next: very unusual */ "").split(n) ], i = C ? t.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "", o = C ? i.split(n) : [""]; return C && e.indexOf(".") !== -1 && o[0] !== "" && o.unshift(""), { pathEnv: r, pathExt: o, pathExtExe: i }; }, Me = (e, t, n) => { typeof t == "function" && (n = t, t = {}), t || (t = {}); const { pathEnv: r, pathExt: i, pathExtExe: o } = Fe(e, t), s = [], a = (u) => new Promise((d, m) => { if (u === r.length) return t.all && s.length ? d(s) : m(_e(e)); const f = r[u], p = /^".*"$/.test(f) ? f.slice(1, -1) : f, g = ke.join(p, e), b = !p && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + g : g; d(c(b, u, 0)); }), c = (u, d, m) => new Promise((f, p) => { if (m === i.length) return f(a(d + 1)); const g = i[m]; Le(u + g, { pathExt: o }, (b, x) => { if (!b && x) if (t.all) s.push(u + g); else return f(u + g); return f(c(u, d, m + 1)); }); }); return n ? a(0).then((u) => n(null, u), n) : a(0); }, Nt = (e, t) => { t = t || {}; const { pathEnv: n, pathExt: r, pathExtExe: i } = Fe(e, t), o = []; for (let s = 0; s < n.length; s++) { const a = n[s], c = /^".*"$/.test(a) ? a.slice(1, -1) : a, u = ke.join(c, e), d = !c && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + u : u; for (let m = 0; m < r.length; m++) { const f = d + r[m]; try { if (Le.sync(f, { pathExt: i })) if (t.all) o.push(f); else return f; } catch { } } } if (t.all && o.length) return o; if (t.nothrow) return null; throw _e(e); }; var jt = Me; Me.sync = Nt; var ce = { exports: {} }; const Ue = (e = {}) => { const t = e.env || process.env; return (e.platform || process.platform) !== "win32" ? "PATH" : Object.keys(t).reverse().find((r) => r.toUpperCase() === "PATH") || "Path"; }; ce.exports = Ue; ce.exports.default = Ue; var kt = ce.exports; const we = E, Lt = jt, _t = kt; function Ee(e, t) { const n = e.options.env || process.env, r = process.cwd(), i = e.options.cwd != null, o = i && process.chdir !== void 0 && !process.chdir.disabled; if (o) try { process.chdir(e.options.cwd); } catch { } let s; try { s = Lt.sync(e.command, { path: n[_t({ env: n })], pathExt: t ? we.delimiter : void 0 }); } catch { } finally { o && process.chdir(r); } return s && (s = we.resolve(i ? e.options.cwd : "", s)), s; } function Ft(e) { return Ee(e) || Ee(e, !0); } var Mt = Ft, ue = {}; const ie = /([()\][%!^"`<>&|;, *?])/g; function Ut(e) { return e = e.replace(ie, "^$1"), e; } function Dt(e, t) { return e = `${e}`, e = e.replace(/(\\*)"/g, '$1$1\\"'), e = e.replace(/(\\*)$/, "$1$1"), e = `"${e}"`, e = e.replace(ie, "^$1"), t && (e = e.replace(ie, "^$1")), e; } ue.command = Ut; ue.argument = Dt; var zt = /^#!(.*)/; const Wt = zt; var Ht = (e = "") => { const t = e.match(Wt); if (!t) return null; const [n, r] = t[0].replace(/#! ?/, "").split(" "), i = n.split("/").pop(); return i === "env" ? r : r ? `${i} ${r}` : i; }; const Y = se, Kt = Ht; function Vt(e) { const n = Buffer.alloc(150); let r; try { r = Y.openSync(e, "r"), Y.readSync(r, n, 0, 150, 0), Y.closeSync(r); } catch { } return Kt(n.toString()); } var Xt = Vt; const qt = E, xe = Mt, Te = ue, Yt = Xt, Zt = process.platform === "win32", Qt = /\.(?:com|exe)$/i, Jt = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i; function en(e) { e.file = xe(e); const t = e.file && Yt(e.file); return t ? (e.args.unshift(e.file), e.command = t, xe(e)) : e.file; } function tn(e) { if (!Zt) return e; const t = en(e), n = !Qt.test(t); if (e.options.forceShell || n) { const r = Jt.test(t); e.command = qt.normalize(e.command), e.command = Te.command(e.command), e.args = e.args.map((o) => Te.argument(o, r)); const i = [e.command].concat(e.args).join(" "); e.args = ["/d", "/s", "/c", `"${i}"`], e.command = process.env.comspec || "cmd.exe", e.options.windowsVerbatimArguments = !0; } return e; } function nn(e, t, n) { t && !Array.isArray(t) && (n = t, t = null), t = t ? t.slice(0) : [], n = Object.assign({}, n); const r = { command: e, args: t, options: n, file: void 0, original: { command: e, args: t } }; return n.shell ? r : tn(r); } var rn = nn; const le = process.platform === "win32"; function de(e, t) { return Object.assign(new Error(`${t} ${e.command} ENOENT`), { code: "ENOENT", errno: "ENOENT", syscall: `${t} ${e.command}`, path: e.command, spawnargs: e.args }); } function on(e, t) { if (!le) return; const n = e.emit; e.emit = function(r, i) { if (r === "exit") { const o = De(i, t); if (o) return n.call(e, "error", o); } return n.apply(e, arguments); }; } function De(e, t) { return le && e === 1 && !t.file ? de(t.original, "spawn") : null; } function sn(e, t) { return le && e === 1 && !t.file ? de(t.original, "spawnSync") : null; } var an = { hookChildProcess: on, verifyENOENT: De, verifyENOENTSync: sn, notFoundError: de }; const ze = re, fe = rn, me = an; function We(e, t, n) { const r = fe(e, t, n), i = ze.spawn(r.command, r.args, r.options); return me.hookChildProcess(i, r), i; } function cn(e, t, n) { const r = fe(e, t, n), i = ze.spawnSync(r.command, r.args, r.options); return i.error = i.error || me.verifyENOENTSync(i.status, r), i; } G.exports = We; G.exports.spawn = We; G.exports.sync = cn; G.exports._parse = fe; G.exports._enoent = me; var un = G.exports; const ln = /* @__PURE__ */ je(un); function dn(e) { const t = typeof e == "string" ? ` ` : ` `.charCodeAt(), n = typeof e == "string" ? "\r" : "\r".charCodeAt(); return e[e.length - 1] === t && (e = e.slice(0, -1)), e[e.length - 1] === n && (e = e.slice(0, -1)), e; } function He(e = {}) { const { env: t = process.env, platform: n = process.platform } = e; return n !== "win32" ? "PATH" : Object.keys(t).reverse().find((r) => r.toUpperCase() === "PATH") || "Path"; } function fn(e = {}) { const { cwd: t = w.cwd(), path: n = w.env[He()], execPath: r = w.execPath } = e; let i; const o = t instanceof URL ? St.fileURLToPath(t) : t; let s = E.resolve(o); const a = []; for (; i !== s; ) a.push(E.join(s, "node_modules/.bin")), i = s, s = E.resolve(s, ".."); return a.push(E.resolve(o, r, "..")), [...a, n].join(E.delimiter); } function mn({ env: e = w.env, ...t } = {}) { e = { ...e }; const n = He({ env: e }); return t.path = e[n], e[n] = fn(t), e; } const pn = (e, t, n, r) => { if (n === "length" || n === "prototype" || n === "arguments" || n === "caller") return; const i = Object.getOwnPropertyDescriptor(e, n), o = Object.getOwnPropertyDescriptor(t, n); !hn(i, o) && r || Object.defineProperty(e, n, o); }, hn = function(e, t) { return e === void 0 || e.configurable || e.writable === t.writable && e.enumerable === t.enumerable && e.configurable === t.configurable && (e.writable || e.value === t.value); }, gn = (e, t) => { const n = Object.getPrototypeOf(t); n !== Object.getPrototypeOf(e) && Object.setPrototypeOf(e, n); }, yn = (e, t) => `/* Wrapped ${e}*/ ${t}`, bn = Object.getOwnPropertyDescriptor(Function.prototype, "toString"), Sn = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name"), wn = (e, t, n) => { const r = n === "" ? "" : `with ${n.trim()}() `, i = yn.bind(null, r, t.toString()); Object.defineProperty(i, "name", Sn), Object.defineProperty(e, "toString", { ...bn, value: i }); }; function En(e, t, { ignoreNonConfigurable: n = !1 } = {}) { const { name: r } = e; for (const i of Reflect.ownKeys(t)) pn(e, t, i, n); return gn(e, t), wn(e, t, r), e; } const D = /* @__PURE__ */ new WeakMap(), Ke = (e, t = {}) => { if (typeof e != "function") throw new TypeError("Expected a function"); let n, r = 0; const i = e.displayName || e.name || "<anonymous>", o = function(...s) { if (D.set(o, ++r), r === 1) n = e.apply(this, s), e = null; else if (t.throw === !0) throw new Error(`Function \`${i}\` can only be called once`); return n; }; return En(o, e), D.set(o, r), o; }; Ke.callCount = (e) => { if (!D.has(e)) throw new Error(`The given function \`${e.name}\` is not wrapped by the \`onetime\` package`); return D.get(e); }; const xn = () => { const e = Xe - Ve + 1; return Array.from({ length: e }, Tn); }, Tn = (e, t) => ({ name: `SIGRT${t + 1}`, number: Ve + t, action: "terminate", description: "Application-specific signal (realtime)", standard: "posix" }), Ve = 34, Xe = 64, In = [ { name: "SIGHUP", number: 1, action: "terminate", description: "Terminal closed", standard: "posix" }, { name: "SIGINT", number: 2, action: "terminate", description: "User interruption with CTRL-C", standard: "ansi" }, { name: "SIGQUIT", number: 3, action: "core", description: "User interruption with CTRL-\\", standard: "posix" }, { name: "SIGILL", number: 4, action: "core", description: "Invalid machine instruction", standard: "ansi" }, { name: "SIGTRAP", number: 5, action: "core", description: "Debugger breakpoint", standard: "posix" }, { name: "SIGABRT", number: 6, action: "core", description: "Aborted", standard: "ansi" }, { name: "SIGIOT", number: 6, action: "core", description: "Aborted", standard: "bsd" }, { name: "SIGBUS", number: 7, action: "core", description: "Bus error due to misaligned, non-existing address or paging error", standard: "bsd" }, { name: "SIGEMT", number: 7, action: "terminate", description: "Command should be emulated but is not implemented", standard: "other" }, { name: "SIGFPE", number: 8, action: "core", description: "Floating point arithmetic error", standard: "ansi" }, { name: "SIGKILL", number: 9, action: "terminate", description: "Forced termination", standard: "posix", forced: !0 }, { name: "SIGUSR1", number: 10, action: "terminate", description: "Application-specific signal", standard: "posix" }, { name: "SIGSEGV", number: 11, action: "core", description: "Segmentation fault", standard: "ansi" }, { name: "SIGUSR2", number: 12, action: "terminate", description: "Application-specific signal", standard: "posix" }, { name: "SIGPIPE", number: 13, action: "terminate", description: "Broken pipe or socket", standard: "posix" }, { name: "SIGALRM", number: 14, action: "terminate", description: "Timeout or timer", standard: "posix" }, { name: "SIGTERM", number: 15, action: "terminate", description: "Termination", standard: "ansi" }, { name: "SIGSTKFLT", number: 16, action: "terminate", description: "Stack is empty or overflowed", standard: "other" }, { name: "SIGCHLD", number: 17, action: "ignore", description: "Child process terminated, paused or unpaused", standard: "posix" }, { name: "SIGCLD", number: 17, action: "ignore", description: "Child process terminated, paused or unpaused", standard: "other" }, { name: "SIGCONT", number: 18, action: "unpause", description: "Unpaused", standard: "posix", forced: !0 }, { name: "SIGSTOP", number: 19, action: "pause", description: "Paused", standard: "posix", forced: !0 }, { name: "SIGTSTP", number: 20, action: "pause", description: 'Paused using CTRL-Z or "suspend"', standard: "posix" }, { name: "SIGTTIN", number: 21, action: "pause", description: "Background process cannot read terminal input", standard: "posix" }, { name: "SIGBREAK", number: 21, action: "terminate", description: "User interruption with CTRL-BREAK", standard: "other" }, { name: "SIGTTOU", number: 22, action: "pause", description: "Background process cannot write to terminal output", standard: "posix" }, { name: "SIGURG", number: 23, action: "ignore", description: "Socket received out-of-band data", standard: "bsd" }, { name: "SIGXCPU", number: 24, action: "core", description: "Process timed out", standard: "bsd" }, { name: "SIGXFSZ", number: 25, action: "core", description: "File too big", standard: "bsd" }, { name: "SIGVTALRM", number: 26, action: "terminate", description: "Timeout or timer", standard: "bsd" }, { name: "SIGPROF", number: 27, action: "terminate", description: "Timeout or timer", standard: "bsd" }, { name: "SIGWINCH", number: 28, action: "ignore", description: "Terminal window size changed", standard: "bsd" }, { name: "SIGIO", number: 29, action: "terminate", description: "I/O is available", standard: "other" }, { name: "SIGPOLL", number: 29, action: "terminate", description: "Watched event", standard: "other" }, { name: "SIGINFO", number: 29, action: "ignore", description: "Request for process information", standard: "other" }, { name: "SIGPWR", number: 30, action: "terminate", description: "Device running out of power", standard: "systemv" }, { name: "SIGSYS", number: 31, action: "core", description: "Invalid system call", standard: "other" }, { name: "SIGUNUSED", number: 31, action: "terminate", description: "Invalid system call", standard: "other" } ], qe = () => { const e = xn(); return [...In, ...e].map(vn); }, vn = ({ name: e, number: t, description: n, action: r, forced: i = !1, standard: o }) => { const { signals: { [e]: s } } = Be, a = s !== void 0; return { name: e, number: a ? s : t, description: n, supported: a, action: r, forced: i, standard: o }; }, Pn = () => { const e = qe(); return Object.fromEntries(e.map(Cn)); }, Cn = ({ name: e, number: t, description: n, supported: r, action: i, forced: o, standard: s }) => [e, { name: e, number: t, description: n, supported: r, action: i, forced: o, standard: s }], $n = Pn(), An = () => { const e = qe(), t = Xe + 1, n = Array.from( { length: t }, (r, i) => On(i, e) ); return Object.assign({}, ...n); }, On = (e, t) => { const n = Gn(e, t); if (n === void 0) return {}; const { name: r, description: i, supported: o, action: s, forced: a, standard: c } = n; return { [e]: { name: r, number: e, description: i, supported: o, action: s, forced: a, standard: c } }; }, Gn = (e, t) => { const n = t.find(({ name: r }) => Be.signals[r] === e); return n !== void 0 ? n : t.find((r) => r.number === e); }; An(); const Rn = ({ timedOut: e, timeout: t, errorCode: n, signal: r, signalDescription: i, exitCode: o, isCanceled: s }) => e ? `timed out after ${t} milliseconds` : s ? "was canceled" : n !== void 0 ? `failed with ${n}` : r !== void 0 ? `was killed with ${r} (${i})` : o !== void 0 ? `failed with exit code ${o}` : "failed", Ie = ({ stdout: e, stderr: t, all: n, error: r, signal: i, exitCode: o, command: s, escapedCommand: a, timedOut: c, isCanceled: u, killed: d, parsed: { options: { timeout: m, cwd: f = w.cwd() } } }) => { o = o === null ? void 0 : o, i = i === null ? void 0 : i; const p = i === void 0 ? void 0 : $n[i].description, g = r && r.code, x = `Command ${Rn({ timedOut: c, timeout: m, errorCode: g, signal: i, signalDescription: p, exitCode: o, isCanceled: u })}: ${s}`, R = Object.prototype.toString.call(r) === "[object Error]", B = R ? `${x} ${r.message}` : x, N = [B, t, e].filter(Boolean).join(` `); return R ? (r.originalMessage = r.message, r.message = N) : r = new Error(N), r.shortMessage = B, r.command = s, r.escapedCommand = a, r.exitCode = o, r.signal = i, r.signalDescription = p, r.stdout = e, r.stderr = t, r.cwd = f, n !== void 0 && (r.all = n), "bufferedData" in r && delete r.bufferedData, r.failed = !0, r.timedOut = !!c, r.isCanceled = u, r.killed = d && !c, r; }, F = ["stdin", "stdout", "stderr"], Bn = (e) => F.some((t) => e[t] !== void 0), Nn = (e) => { if (!e) return; const { stdio: t } = e; if (t === void 0) return F.map((r) => e[r]); if (Bn(e)) throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${F.map((r) => `\`${r}\``).join(", ")}`); if (typeof t == "string") return t; if (!Array.isArray(t)) throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof t}\``); const n = Math.max(t.length, F.length); return Array.from({ length: n }, (r, i) => t[i]); }, $ = []; $.push("SIGHUP", "SIGINT", "SIGTERM"); process.platform !== "win32" && $.push( "SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT" // should detect profiler and enable/disable accordingly. // see #21 // 'SIGPROF' ); process.platform === "linux" && $.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT"); const M = (e) => !!e && typeof e == "object" && typeof e.removeListener == "function" && typeof e.emit == "function" && typeof e.reallyExit == "function" && typeof e.listeners == "function" && typeof e.kill == "function" && typeof e.pid == "number" && typeof e.on == "function", Z = Symbol.for("signal-exit emitter"), Q = globalThis, jn = Object.defineProperty.bind(Object); class kn { constructor() { P(this, "emitted", { afterExit: !1, exit: !1 }); P(this, "listeners", { afterExit: [], exit: [] }); P(this, "count", 0); P(this, "id", Math.random()); if (Q[Z]) return Q[Z]; jn(Q, Z, { value: this, writable: !1, enumerable: !1, configurable: !1 }); } on(t, n) { this.listeners[t].push(n); } removeListener(t, n) { const r = this.listeners[t], i = r.indexOf(n); i !== -1 && (i === 0 && r.length === 1 ? r.length = 0 : r.splice(i, 1)); } emit(t, n, r) { if (this.emitted[t]) return !1; this.emitted[t] = !0; let i = !1; for (const o of this.listeners[t]) i = o(n, r) === !0 || i; return t === "exit" && (i = this.emit("afterExit", n, r) || i), i; } } class Ye { } const Ln = (e) => ({ onExit(t, n) { return e.onExit(t, n); }, load() { return e.load(); }, unload() { return e.unload(); } }); class _n extends Ye { onExit() { return () => { }; } load() { } unload() { } } var z, y, h, A, O, v, T, W, Ze, H, Qe; class Fn extends Ye { constructor(n) { super(); S(this, W); S(this, H); // "SIGHUP" throws an `ENOSYS` error on Windows, // so use a supported signal instead /* c8 ignore start */ S(this, z, oe.platform === "win32" ? "SIGINT" : "SIGHUP"); /* c8 ignore stop */ S(this, y, new kn()); S(this, h, void 0); S(this, A, void 0); S(this, O, void 0); S(this, v, {}); S(this, T, !1); I(this, h, n), I(this, v, {}); for (const r of $) l(this, v)[r] = () => { const i = l(this, h).listeners(r); let { count: o } = l(this, y); const s = n; if (typeof s.__signal_exit_emitter__ == "object" && typeof s.__signal_exit_emitter__.count == "number" && (o += s.__signal_exit_emitter__.count), i.length === o) { this.unload(); const a = l(this, y).emit("exit", null, r), c = r === "SIGHUP" ? l(this, z) : r; a || n.kill(n.pid, c); } }; I(this, O, n.reallyExit), I(this, A, n.emit); } onExit(n, r) { if (!M(l(this, h))) return () => { }; l(this, T) === !1 && this.load(); const i = r != null && r.alwaysLast ? "afterExit" : "exit"; return l(this, y).on(i, n), () => { l(this, y).removeListener(i, n), l(this, y).listeners.exit.length === 0 && l(this, y).listeners.afterExit.length === 0 && this.unload(); }; } load() { if (!l(this, T)) { I(this, T, !0), l(this, y).count += 1; for (const n of $) try { const r = l(this, v)[n]; r && l(this, h).on(n, r); } catch { } l(this, h).emit = (n, ...r) => V(this, H, Qe).call(this, n, ...r), l(this, h).reallyExit = (n) => V(this, W, Ze).call(this, n); } } unload() { l(this, T) && (I(this, T, !1), $.forEach((n) => { const r = l(this, v)[n]; if (!r) throw new Error("Listener not defined for signal: " + n); try { l(this, h).removeListener(n, r); } catch { } }), l(this, h).emit = l(this, A), l(this, h).reallyExit = l(this, O), l(this, y).count -= 1); } } z = new WeakMap(), y = new WeakMap(), h = new WeakMap(), A = new WeakMap(), O = new WeakMap(), v = new WeakMap(), T = new WeakMap(), W = new WeakSet(), Ze = function(n) { return M(l(this, h)) ? (l(this, h).exitCode = n || 0, l(this, y).emit("exit", l(this, h).exitCode, null), l(this, O).call(l(this, h), l(this, h).exitCode)) : 0; }, H = new WeakSet(), Qe = function(n, ...r) { const i = l(this, A); if (n === "exit" && M(l(this, h))) { typeof r[0] == "number" && (l(this, h).exitCode = r[0]); const o = i.call(l(this, h), n, ...r); return l(this, y).emit("exit", l(this, h).exitCode, null), o; } else return i.call(l(this, h), n, ...r); }; const oe = globalThis.process, { /** * Called when the process is exiting, whether via signal, explicit * exit, or running out of stuff to do. * * If the global process object is not suitable for instrumentation, * then this will be a no-op. * * Returns a function that may be used to unload signal-exit. */ onExit: Mn, /** * Load the listeners. Likely you never need to call this, unless * doing a rather deep integration with signal-exit functionality. * Mostly exposed for the benefit of testing. * * @internal */ load: ai, /** * Unload the listeners. Likely you never need to call this, unless * doing a rather deep integration with signal-exit functionality. * Mostly exposed for the benefit of testing. * * @internal */ unload: ci } = Ln(M(oe) ? new Fn(oe) : new _n()), Un = 1e3 * 5, Dn = (e, t = "SIGTERM", n = {}) => { const r = e(t); return zn(e, t, n, r), r; }, zn = (e, t, n, r) => { if (!Wn(t, n, r)) return; const i = Kn(n), o = setTimeout(() => { e("SIGKILL"); }, i); o.unref && o.unref(); }, Wn = (e, { forceKillAfterTimeout: t }, n) => Hn(e) && t !== !1 && n, Hn = (e) => e === Et.constants.signals.SIGTERM || typeof e == "string" && e.toUpperCase() === "SIGTERM", Kn = ({ forceKillAfterTimeout: e = !0 }) => { if (e === !0) return Un; if (!Number.isFinite(e) || e < 0) throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`); return e; }, Vn = (e, t) => { e.kill() && (t.isCanceled = !0); }, Xn = (e, t, n) => { e.kill(t), n(Object.assign(new Error("Timed out"), { timedOut: !0, signal: t })); }, qn = (e, { timeout: t, killSignal: n = "SIGTERM" }, r) => { if (t === 0 || t === void 0) return r; let i; const o = new Promise((a, c) => { i = setTimeout(() => { Xn(e, n, c); }, t); }), s = r.finally(() => { clearTimeout(i); }); return Promise.race([o, s]); }, Yn = ({ timeout: e }) => { if (e !== void 0 && (!Number.isFinite(e) || e < 0)) throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`); }, Zn = async (e, { cleanup: t, detached: n }, r) => { if (!t || n) return r; const i = Mn(() => { e.kill(); }); return r.finally(() => { i(); }); }; function Je(e) { return e !== null && typeof e == "object" && typeof e.pipe == "function"; } function ve(e) { return Je(e) && e.writable !== !1 && typeof e._write == "function" && typeof e._writableState == "object"; } const Qn = (e) => e instanceof gt && typeof e.then == "function", J = (e, t, n) => { if (typeof n == "string") return e[t].pipe(yt(n)), e; if (ve(n)) return e[t].pipe(n), e; if (!Qn(n)) throw new TypeError("The second argument must be a string, a stream or an Execa child process."); if (!ve(n.stdin)) throw new TypeError("The target child process's stdin must be available."); return e[t].pipe(n.stdin), n; }, Jn = (e) => { e.stdout !== null && (e.pipeStdout = J.bind(void 0, e, "stdout")), e.stderr !== null && (e.pipeStderr = J.bind(void 0, e, "stderr")), e.all !== void 0 && (e.pipeAll = J.bind(void 0, e, "all")); }, et = async (e, { init: t, convertChunk: n, getSize: r, truncateChunk: i, addChunk: o, getFinalChunk: s, finalize: a }, { maxBuffer: c = Number.POSITIVE_INFINITY } = {}) => { if (!tr(e)) throw new Error("The first argument must be a Readable, a ReadableStream, or an async iterable."); const u = t(); u.length = 0; try { for await (const d of e) { const m = nr(d), f = n[m](d, u); tt({ convertedChunk: f, state: u, getSize: r, truncateChunk: i, addChunk: o, maxBuffer: c }); } return er({ state: u, convertChunk: n, getSize: r, truncateChunk: i, addChunk: o, getFinalChunk: s, maxBuffer: c }), a(u); } catch (d) { throw d.bufferedData = a(u), d; } }, er = ({ state: e, getSize: t, truncateChunk: n, addChunk: r, getFinalChunk: i, maxBuffer: o }) => { const s = i(e); s !== void 0 && tt({ convertedChunk: s, state: e, getSize: t, truncateChunk: n, addChunk: r, maxBuffer: o }); }, tt = ({ convertedChunk: e, state: t, getSize: n, truncateChunk: r, addChunk: i, maxBuffer: o }) => { const s = n(e), a = t.length + s; if (a <= o) { Pe(e, t, i, a); return; } const c = r(e, o - t.length); throw c !== void 0 && Pe(c, t, i, o), new rr(); }, Pe = (e, t, n, r) => { t.contents = n(e, t, r), t.length = r; }, tr = (e) => typeof e == "object" && e !== null && typeof e[Symbol.asyncIterator] == "function", nr = (e) => { var r; const t = typeof e; if (t === "string") return "string"; if (t !== "object" || e === null) return "others"; if ((r = globalThis.Buffer) != null && r.isBuffer(e)) return "buffer"; const n = Ce.call(e); return n === "[object ArrayBuffer]" ? "arrayBuffer" : n === "[object DataView]" ? "dataView" : Number.isInteger(e.byteLength) && Number.isInteger(e.byteOffset) && Ce.call(e.buffer) === "[object ArrayBuffer]" ? "typedArray" : "others"; }, { toString: Ce } = Object.prototype; class rr extends Error { constructor() { super("maxBuffer exceeded"); P(this, "name", "MaxBufferError"); } } const ir = (e) => e, or = () => { }, sr = ({ contents: e }) => e, nt = (e) => { throw new Error(`Streams in object mode are not supported: ${String(e)}`); }, rt = (e) => e.length; async function ar(e, t) { return et(e, gr, t); } const cr = () => ({ contents: new ArrayBuffer(0) }), ur = (e) => lr.encode(e), lr = new TextEncoder(), $e = (e) => new Uint8Array(e), Ae = (e) => new Uint8Array(e.buffer, e.byteOffset, e.byteLength), dr = (e, t) => e.slice(0, t), fr = (e, { contents: t, length: n }, r) => { const i = ot() ? pr(t, r) : mr(t, r); return new Uint8Array(i).set(e, n), i; }, mr = (e, t) => { if (t <= e.byteLength) return e; const n = new ArrayBuffer(it(t)); return new Uint8Array(n).set(new Uint8Array(e), 0), n; }, pr = (e, t) => { if (t <= e.maxByteLength) return e.resize(t), e; const n = new ArrayBuffer(t, { maxByteLength: it(t) }); return new Uint8Array(n).set(new Uint8Array(e), 0), n; }, it = (e) => Oe ** Math.ceil(Math.log(e) / Math.log(Oe)), Oe = 2, hr = ({ contents: e, length: t }) => ot() ? e : e.slice(0, t), ot = () => "resize" in ArrayBuffer.prototype, gr = { init: cr, convertChunk: { string: ur, buffer: $e, arrayBuffer: $e, dataView: Ae, typedArray: Ae, others: nt }, getSize: rt, truncateChunk: dr, addChunk: fr, getFinalChunk: or, finalize: hr }; async function st(e, t) { if (!("Buffer" in globalThis)) throw new Error("getStreamAsBuffer() is only supported in Node.js"); try { return Ge(await ar(e, t)); } catch (n) { throw n.bufferedData !== void 0 && (n.bufferedData = Ge(n.bufferedData)), n; } } const Ge = (e) => globalThis.Buffer.from(e); async function yr(e, t) { return et(e, xr, t); } const br = () => ({ contents: "", textDecoder: new TextDecoder() }), j = (e, { textDecoder: t }) => t.decode(e, { stream: !0 }), Sr = (e, { contents: t }) => t + e, wr = (e, t) => e.slice(0, t), Er = ({ textDecoder: e }) => { const t = e.decode(); return t === "" ? void 0 : t; }, xr = { init: br, convertChunk: { string: ir, buffer: j, arrayBuffer: j, dataView: j, typedArray: j, others: nt }, getSize: rt, truncateChunk: wr, addChunk: Sr, getFinalChunk: Er, finalize: sr }, { PassThrough: Tr } = vt; var Ir = function() { var e = [], t = new Tr({ objectMode: !0 }); return t.setMaxListeners(0), t.add = n, t.isEmpty = r, t.on("unpipe", i), Array.prototype.slice.call(arguments).forEach(n), t; function n(o) { return Array.isArray(o) ? (o.forEach(n), this) : (e.push(o), o.once("end", i.bind(null, o)), o.once("error", t.emit.bind(t, "error")), o.pipe(t, { end: !1 }), this); } function r() { return e.length == 0; } function i(o) { e = e.filter(function(s) { return s !== o; }), !e.length && t.readable && t.end(); } }; const vr = /* @__PURE__ */ je(Ir), Pr = (e) => { if (e !== void 0) throw new TypeError("The `input` and `inputFile` options cannot be both set."); }, Cr = ({ input: e, inputFile: t }) => typeof t != "string" ? e : (Pr(e), bt(t)), $r = (e, t) => { const n = Cr(t); n !== void 0 && (Je(n) ? n.pipe(e.stdin) : e.stdin.end(n)); }, Ar = (e, { all: t }) => { if (!t || !e.stdout && !e.stderr) return; const n = vr(); return e.stdout && n.add(e.stdout), e.stderr && n.add(e.stderr), n; }, ee = async (e, t) => { if (!(!e || t === void 0)) { await It(0), e.destroy(); try { return await t; } catch (n) { return n.bufferedData; } } }, te = (e, { encoding: t, buffer: n, maxBuffer: r }) => { if (!(!e || !n)) return t === "utf8" || t === "utf-8" ? yr(e, { maxBuffer: r }) : t === null || t === "buffer" ? st(e, { maxBuffer: r }) : Or(e, r, t); }, Or = async (e, t, n) => (await st(e, { maxBuffer: t })).toString(n), Gr = async ({ stdout: e, stderr: t, all: n }, { encoding: r, buffer: i, maxBuffer: o }, s) => { const a = te(e, { encoding: r, buffer: i, maxBuffer: o }), c = te(t, { encoding: r, buffer: i, maxBuffer: o }), u = te(n, { encoding: r, buffer: i, maxBuffer: o * 2 }); try { return await Promise.all([s, a, c, u]); } catch (d) { return Promise.all([ { error: d, signal: d.signal, timedOut: d.timedOut }, ee(e, a), ee(t, c), ee(n, u) ]); } }, Rr = (/* @__PURE__ */ (async () => { })()).constructor.prototype, Br = ["then", "catch", "finally"].map((e) => [ e, Reflect.getOwnPropertyDescriptor(Rr, e) ]), Re = (e, t) => { for (const [n, r] of Br) { const i = typeof t == "function" ? (...o) => Reflect.apply(r.value, t(), o) : r.value.bind(t); Reflect.defineProperty(e, n, { ...r, value: i }); } }, Nr = (e) => new Promise((t, n) => { e.on("exit", (r, i) => { t({ exitCode: r, signal: i }); }), e.on("error", (r) => { n(r); }), e.stdin && e.stdin.on("error", (r) => { n(r); }); }), at = (e, t = []) => Array.isArray(t) ? [e, ...t] : [e], jr = /^[\w.-]+$/, kr = (e) => typeof e != "string" || jr.test(e) ? e : `"${e.replaceAll('"', '\\"')}"`, Lr = (e, t) => at(e, t).join(" "), _r = (e, t) => at(e, t).map((n) => kr(n)).join(" "), Fr = Pt("execa").enabled, k = (e, t) => String(e).padStart(t, "0"), Mr = () => { const e = /* @__PURE__ */ new Date(); return `${k(e.getHours(), 2)}:${k(e.getMinutes(), 2)}:${k(e.getSeconds(), 2)}.${k(e.getMilliseconds(), 3)}`; }, Ur = (e, { verbose: t }) => { t && w.stderr.write(`[${Mr()}] ${e} `); }, Dr = 1e3 * 1e3 * 100, zr = ({ env: e, extendEnv: t, preferLocal: n, localDir: r, execPath: i }) => { const o = t ? { ...w.env, ...e } : e; return n ? mn({ env: o, cwd: r, execPath: i }) : o; }, Wr = (e, t, n = {}) => { const r = ln._parse(e, t, n); return e = r.command, t = r.args, n = r.options, n = { maxBuffer: Dr, buffer: !0, stripFinalNewline: !0, extendEnv: !0, preferLocal: !1, localDir: n.cwd || w.cwd(), execPath: w.execPath, encoding: "utf8", reject: !0, cleanup: !0, all: !1, windowsHide: !0, verbose: Fr, ...n }, n.env = zr(n), n.stdio = Nn(n), w.platform === "win32" && E.basename(e, ".exe") === "cmd" && t.unshift("/q"), { file: e, args: t, options: n, parsed: r }; }, ne = (e, t, n) => typeof t != "string" && !mt.isBuffer(t) ? n === void 0 ? void 0 : "" : e.stripFinalNewline ? dn(t) : t; function ct(e, t, n) { const r = Wr(e, t, n), i = Lr(e, t), o = _r(e, t); Ur(o, r.options), Yn(r.options); let s; try { s = re.spawn(r.file, r.args, r.options); } catch (p) { const g = new re.ChildProcess(), b = Promise.reject(Ie({ error: p, stdout: "", stderr: "", all: "", command: i, escapedCommand: o, parsed: r, timedOut: !1, isCanceled: !1, killed: !1 })); return Re(g, b), g; } const a = Nr(s), c = qn(s, r.options, a), u = Zn(s, r.options, c), d = { isCanceled: !1 }; s.kill = Dn.bind(null, s.kill.bind(s)), s.cancel = Vn.bind(null, s, d); const f = Ke(async () => { const [{ error: p, exitCode: g, signal: b, timedOut: x }, R, B, N] = await Gr(s, r.options, u), pe = ne(r.options, R), he = ne(r.options, B), ge = ne(r.options, N); if (p || g !== 0 || b !== null) { const ye = Ie({ error: p, exitCode: g, signal: b, stdout: pe, stderr: he, all: ge, command: i, escapedCommand: o, parsed: r, timedOut: x, isCanceled: r.options.signal ? r.options.signal.aborted : !1, killed: s.killed }); if (!r.options.reject) return ye; throw ye; } return { command: i, escapedCommand: o, exitCode: 0, stdout: pe, stderr: he, all: ge, failed: !1, timedOut: !1, isCanceled: !1, killed: !1 }; }); return $r(s, r.options), s.all = Ar(s, r.options), Jn(s), Re(s, f), s; } const Hr = typeof __dirname < "u" ? __dirname : pt(wt(import.meta.url)); let L = "", _ = null; function ut() { if (_) return _; const e = xt(); if (!/win32|linux|darwin/.test(e)) throw new Error(`${e} is not support`); const t = Tt(); if (!/amd64_v1|arm64|386|x64/.test(t)) throw new Error(`${t} is not support`); return _ = `${e === "win32" ? "windows" : e}_${t === "x64" ? "amd64_v1" : t}`, _; } function Kr(e = ut()) { return `go-get-folder-size${e.startsWith("windows") ? ".exe" : ""}`; } function lt() { if (L) return L; const e = ut(), t = Kr(e); return L = ht( Hr, `../dist/go-get-folder-size_${e}/${t}` ), L; } async function ui(e, t = !1, n = {}) { const { binPath: r = lt(), loose: i = !1 } = n, { stdout: o, stderr: s } = await ct(r, { cwd: e, env: { loose: String(i) } }); if (s) throw new Error(s); return t ? Ne(Number(o)) : Number(o); } function li(e = {}) { const { binPath: t = lt(), loose: n = !1 } = e; let r = /* @__PURE__ */ new Map(); const i = ct(t, { env: { ipc: String(!0), loose: String(n) } }), o = Ct({ input: i.stdout }); function s() { i.killed || (o.close(), i.cancel(), r.clear(), r = null); } let a = !1; function c(d) { if (a) return i.stdin.once("drain", () => { a = !1, i.stdin.write(`${d},`); }); a = !i.stdin.write(`${d},`); } o.on("line", (d) => { const [m, f] = d.split(","), { pretty: p, resolve: g } = r.get(m); g(p ? Ne(Number(f)) : Number(f)), r.delete(m); }), i.stderr.on("data", (d) => { const [m, ...f] = String(d).split(","), { reject: p } = r.get(m); p(new Error(f.toString())), r.delete(m); }), process.once("exit", () => { s(); }); async function u(d, m = !1) { return new Promise((f, p) => { r.set(d, { pretty: m, resolve: f, reject: p }), c(d); }); } return { close: s, getFolderSizeWithIpc: u }; } export { li as createGetFolderSizeBinIpc, Kr as detectBinName, lt as detectDefaultBinPath, ui as getFolderSizeBin, ut as inferVersion };