Open
Description
Bear in mind that recursive-readdir
has the following signature/type declaration:
type IgnoreFunction = (file: string, stats: fs.Stats) => boolean;
type Ignores = ReadonlyArray<string | IgnoreFunction>;
type Callback = (error: Error, files: string[]) => void;
type RecursiveReadDir = (path: string, ignores: Ignores, callback: Callback) => void;
So if ignores
is passed, you need to add a filter
that has an opposite predicate.
// original
const files = await recursiveReaddir(dir, [
(file) => {
const parts = file.split(path.sep);
return parts.length > 1 && IGNORED_DIRECTORIES.includes(parts[0]);
})
]);
// change
const files = (await fs.readdir(dir, { recursive: true })).filter((file) => {
const parts = file.split(path.sep);
return parts.length <=1 || !IGNORED_DIRECTORIES.includes(parts[0]);
});