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
131 lines (130 loc) • 5.34 kB
JavaScript
import { resolve as C } from "path";
import { p as w } from "./index-4f2f13ba.mjs";
import { readdir as O, lstat as V } from "fs/promises";
const _ = /* @__PURE__ */ Object.create(null), I = (t) => {
var e;
return ((e = globalThis.process) == null ? void 0 : e.env) || { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
}, o = new Proxy(_, { get(t, e) {
return I()[e] ?? _[e];
}, has(t, e) {
const s = I();
return e in s || e in _;
}, set(t, e, s) {
const E = I(!0);
return E[e] = s, !0;
}, deleteProperty(t, e) {
if (!e)
return !1;
const s = I(!0);
return delete s[e], !0;
}, ownKeys() {
const t = I(!0);
return Object.keys(t);
} }), Y = typeof process < "u" && process.env && process.env.NODE_ENV || "", G = [["APPVEYOR"], ["AWS_AMPLIFY", "AWS_APP_ID", { ci: !0 }], ["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"], ["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"], ["APPCIRCLE", "AC_APPCIRCLE"], ["BAMBOO", "bamboo_planKey"], ["BITBUCKET", "BITBUCKET_COMMIT"], ["BITRISE", "BITRISE_IO"], ["BUDDY", "BUDDY_WORKSPACE_ID"], ["BUILDKITE"], ["CIRCLE", "CIRCLECI"], ["CIRRUS", "CIRRUS_CI"], ["CLOUDFLARE_PAGES", "CF_PAGES", { ci: !0 }], ["CODEBUILD", "CODEBUILD_BUILD_ARN"], ["CODEFRESH", "CF_BUILD_ID"], ["DRONE"], ["DRONE", "DRONE_BUILD_EVENT"], ["DSARI"], ["GITHUB_ACTIONS"], ["GITLAB", "GITLAB_CI"], ["GITLAB", "CI_MERGE_REQUEST_ID"], ["GOCD", "GO_PIPELINE_LABEL"], ["LAYERCI"], ["HUDSON", "HUDSON_URL"], ["JENKINS", "JENKINS_URL"], ["MAGNUM"], ["NETLIFY"], ["NETLIFY", "NETLIFY_LOCAL", { ci: !1 }], ["NEVERCODE"], ["RENDER"], ["SAIL", "SAILCI"], ["SEMAPHORE"], ["SCREWDRIVER"], ["SHIPPABLE"], ["SOLANO", "TDDIUM"], ["STRIDER"], ["TEAMCITY", "TEAMCITY_VERSION"], ["TRAVIS"], ["VERCEL", "NOW_BUILDER"], ["VERCEL", "VERCEL", { ci: !1 }], ["VERCEL", "VERCEL_ENV", { ci: !1 }], ["APPCENTER", "APPCENTER_BUILD_ID"], ["CODESANDBOX", "CODESANDBOX_SSE", { ci: !1 }], ["STACKBLITZ"], ["STORMKIT"], ["CLEAVR"], ["ZEABUR"], ["CODESPHERE", "CODESPHERE_APP_ID", { ci: !0 }], ["RAILWAY", "RAILWAY_PROJECT_ID"], ["RAILWAY", "RAILWAY_SERVICE_ID"]];
function W() {
var t, e, s, E, l, a;
if ((t = globalThis.process) != null && t.env)
for (const r of G) {
const T = r[1] || r[0];
if ((e = globalThis.process) != null && e.env[T])
return { name: r[0].toLowerCase(), ...r[2] };
}
return ((E = (s = globalThis.process) == null ? void 0 : s.env) == null ? void 0 : E.SHELL) === "/bin/jsh" && ((a = (l = globalThis.process) == null ? void 0 : l.versions) != null && a.webcontainer) ? { name: "stackblitz", ci: !1 } : { name: "", ci: !1 };
}
const y = W();
y.name;
function i(t) {
return t ? t !== "false" : !1;
}
var f;
const K = ((f = globalThis.process) == null ? void 0 : f.platform) || "", d = i(o.CI) || y.ci !== !1;
var N, P;
const F = i(((N = globalThis.process) == null ? void 0 : N.stdout) && ((P = globalThis.process) == null ? void 0 : P.stdout.isTTY));
i(o.DEBUG);
const z = Y === "test" || i(o.TEST);
i(o.MINIMAL);
const H = /^win/i.test(K);
!i(o.NO_COLOR) && (i(o.FORCE_COLOR) || (F || H) && o.TERM);
var h, p;
const u = (((p = (h = globalThis.process) == null ? void 0 : h.versions) == null ? void 0 : p.node) || "").replace(/^v/, "") || null;
Number(u == null ? void 0 : u.split(".")[0]);
const j = globalThis.process || /* @__PURE__ */ Object.create(null), S = { versions: {} };
new Proxy(j, { get(t, e) {
if (e === "env")
return o;
if (e in t)
return t[e];
if (e in S)
return S[e];
} });
var g, B;
const Z = ((B = (g = globalThis.process) == null ? void 0 : g.release) == null ? void 0 : B.name) === "node";
var b, U;
const k = !!globalThis.Bun || !!((U = (b = globalThis.process) == null ? void 0 : b.versions) != null && U.bun), x = !!globalThis.Deno, J = !!globalThis.fastly, X = !!globalThis.Netlify, Q = !!globalThis.EdgeRuntime;
var m;
const q = ((m = globalThis.navigator) == null ? void 0 : m.userAgent) === "Cloudflare-Workers", $ = !!globalThis.__lagon__, ee = [[X, "netlify"], [Q, "edge-light"], [q, "workerd"], [J, "fastly"], [x, "deno"], [k, "bun"], [Z, "node"], [$, "lagon"]];
function te() {
const t = ee.find((e) => e[0]);
if (t)
return { name: t[1] };
}
const L = te(), se = (L == null ? void 0 : L.name) || "";
async function M(t) {
const { size: e } = await V(t);
return e;
}
async function ne(t) {
try {
return await M(t);
} catch {
return 0;
}
}
async function oe(t, e = !1, s) {
const { loose: E = !1 } = s || {};
let l = 0;
const a = (n) => l += n, r = E ? ne : M;
if (se === "bun") {
const n = await O(t, {
recursive: !0,
withFileTypes: !0
});
if (n.length === 0)
return R();
const c = n.map(async (D) => {
if (!D.isFile())
return;
const v = await r(C(t, D.name));
a(v);
});
return await Promise.all(c), R();
}
const T = await O(t, {
withFileTypes: !0
});
if (T.length === 0)
return R();
const A = [];
for (const n of T) {
if (n.isFile()) {
const c = C(t, n.name);
A.push(
r(c).then(a)
);
continue;
}
if (n.isDirectory()) {
const c = C(t, n.name);
A.push(
oe(c, !1, s).then(a)
);
}
}
return await Promise.all(A), R();
function R() {
return e ? w(l) : l;
}
}
export {
oe as getFolderSize
};