Skip to content

Replace recursive-readdir with native readdir from node:fs/promises #177

Open
@MichaelDeBoey

Description

@MichaelDeBoey

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]);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    umbrella issueThis issue contains a list of dependents of a package and tracks the progress in each

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions