UNPKG

@neodx/vfs

Version:

Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover

56 lines (55 loc) 1.48 kB
var e = require('@neodx/std'), t = require('pathe'), r = require('../_internal/create-vfs-plugin-Bg0LL_-h.cjs'); async function a( r, { path: a = '.', cache: n = i(), filter: s = e.True, signal: c, barrier: o = e.False, timeout: l, maxDepth: u, withFileTypes: f } = {} ) { let h = e.combineAbortSignals([c, e.tryCreateTimeoutSignal(l)]), p = e.some(...e.compact([o, e.isDefined(u) && (({ depth: e }) => e >= u)])), d = []; async function y(i) { h.throwIfAborted(), Object.freeze(i); let c = r.resolve(a, i.relativePath), o = await (n.visited[c] ??= r.readDir(c, { withFileTypes: !0 })); await e.concurrently( o, async e => { h.throwIfAborted(); let r = { relativePath: t.join(i.relativePath, e.name), dirent: e, depth: i.depth + 1 }; s(r) && d.push(r), e.isDirectory() && !p(r) && (await y(r)); }, 10 ); } return await y({ relativePath: '.', depth: 0 }), f ? d : d.map(e => e.relativePath); } const i = () => { let e = {}; return { visited: e, clear() { for (let t of Object.keys(e)) delete e[t]; } }; }; (exports.createScanVfsCache = i), (exports.scan = function () { return r.createVfsPlugin('scan', t => { async function r(r, i) { return await a(t, e.isTypeOfString(r) ? { ...i, path: r } : r); } return (t.scan = r), t; }); }), (exports.scanVfs = a); //# sourceMappingURL=scan.cjs.map