@neodx/vfs
Version:
Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover
65 lines (64 loc) • 1.52 kB
JavaScript
import {
combineAbortSignals as e,
tryCreateTimeoutSignal as t,
some as a,
compact as r,
isDefined as i,
True as n,
False as c,
concurrently as s,
isTypeOfString as o
} from '@neodx/std';
import { join as l } from 'pathe';
import { c as f } from '../_internal/create-vfs-plugin-CTZbwgZU.mjs';
function h() {
return f('scan', e => {
async function t(t, a) {
return await p(e, o(t) ? { ...a, path: t } : t);
}
return (e.scan = t), e;
});
}
async function p(
o,
{
path: f = '.',
cache: h = u(),
filter: p = n,
signal: d,
barrier: m = c,
timeout: v,
maxDepth: w,
withFileTypes: y
} = {}
) {
let b = e([d, t(v)]),
P = a(...r([m, i(w) && (({ depth: e }) => e >= w)])),
j = [];
async function g(e) {
b.throwIfAborted(), Object.freeze(e);
let t = o.resolve(f, e.relativePath),
a = await (h.visited[t] ??= o.readDir(t, { withFileTypes: !0 }));
await s(
a,
async t => {
b.throwIfAborted();
let a = { relativePath: l(e.relativePath, t.name), dirent: t, depth: e.depth + 1 };
p(a) && j.push(a), t.isDirectory() && !P(a) && (await g(a));
},
10
);
}
return await g({ relativePath: '.', depth: 0 }), y ? j : j.map(e => e.relativePath);
}
let u = () => {
let e = {};
return {
visited: e,
clear() {
for (let t of Object.keys(e)) delete e[t];
}
};
};
export { u as createScanVfsCache, h as scan, p as scanVfs };
//# sourceMappingURL=scan.mjs.map