Exploring ListRecursively Function In Unbuild/src/utils.ts
listRecursively function in unbuild/src/utils.ts recursively lists files & dirs. Uses Set to prevent duplicates, calls walk function for each dir.
In this article, we will review a function named listRecursively found in unbuild/src/utils.ts
export function listRecursively(path: string): string[] {
const filenames = new Set<string>();
const walk = (path: string): void => {
const files = readdirSync(path);
for (const file of files) {
const fullPath = resolve(path, file);
if (statSync(fullPath).isDirectory()) {
filenames.add(fullPath + "/");
walk(fullPath);
} else {
filenames.add(fullPath);
}
}
};
walk(path);
return [...filenames];
}
This codes...