@neodx/vfs
Version:
Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover
49 lines (46 loc) • 1.29 kB
JavaScript
import { walkGlob } from '@neodx/glob';
import { isTypeOfString } from '@neodx/std';
import { c as createVfsPlugin } from '../_internal/create-vfs-plugin-BzqnUd8c.mjs';
import { scanVfs, createScanVfsCache } from './scan.mjs';
function glob() {
return createVfsPlugin('glob', vfs => {
async function globImpl(globOrParams, params) {
return await globVfs(
vfs,
Array.isArray(globOrParams) || isTypeOfString(globOrParams)
? {
...params,
glob: globOrParams
}
: globOrParams
);
}
vfs.glob = globImpl;
return vfs;
});
}
async function globVfs(
vfs,
{ glob, ignore, timeout, signal, log = vfs.log.child('glob'), maxDepth }
) {
const cache = createScanVfsCache();
return await walkGlob(glob, {
timeout,
ignore,
signal,
log,
async reader({ path, isIgnored, isMatched, signal }) {
if (await vfs.isFile(path)) return isMatched(path) ? [''] : [];
return await scanVfs(vfs, {
path,
cache,
signal,
maxDepth,
filter: ({ relativePath }) => isMatched(relativePath),
barrier: ({ relativePath }) => isIgnored(relativePath)
});
}
});
}
export { glob, globVfs };
//# sourceMappingURL=glob.mjs.map