Skip to content

discoverFiles processes a file once per include folder it falls under — overlapping includeFolders double every file #59

Closed

Description

@Shinrai

Summary

discoverFiles() (src/core/file-discovery.mjs) walks each entry of includeFolders independently and concatenates the results without de-duplicating. When the include folders overlap — most commonly "." next to subfolders — every file under the overlap is returned, and then processed, once per folder that contains it. Each processed file also runs its own git history/author lookups (src/utils/git.mjs), so the redundant work multiplies the slowest part of a run.

Reproduction

@cldmv/slothlet passes includeFolders: [".configs", ".github", "api_tests", ".", "src", "tests", "tools"] (plus .gitignore auto-detect and excludeFolders: ["coverage", "tmp", "node_modules", …]):

import { discoverFiles } from "@cldmv/fix-headers/src/core/file-discovery.mjs";

const files = await discoverFiles({ projectRoot, includeExtensions: [".mjs", ".cjs", ".jsonv", ".jsonc"], includeFolders, excludeFolders });
files.length;            // 1922
new Set(files).size;     // 964

(await discoverFiles({ projectRoot, includeExtensions, excludeFolders, includeFolders: ["."] })).length; // 964

npm run fix:headers reports Files scanned: 1922 for 964 real files, and took 514 s on a loaded machine.

Expected

Each file is discovered and processed once, however the include folders overlap.

Fix

  • De-duplicate the discovered list by resolved absolute path before returning it (e.g. collect into a Set), and skip a root that is itself inside an earlier root.
  • Optional follow-up: a way to include a folder non-recursively (e.g. { path: ".", recursive: false }), since "." currently always means the whole tree. Consumers that list "." to mean "root files only" get a whole-repo walk instead. With de-duplication and .gitignore applied that is harmless, so it is not needed to fix the doubling.

Activity

  1. added
    type: bug
    on Sep 28, 2026
  2. added theissue type on Sep 28, 2026
  3. added
    priority: medium
    semver: patch
    area: core
    status: not started
    status: in progress
    status: implemented
    and removed
    status: not started
    status: in progress
    on Sep 28, 2026
  4. Shinrai commented on Sep 28, 2026

    @Shinrai
    ContributorAuthor

    Merged into next via #60:

    • 01fc911 — discoverFiles() returns each file once when includeFolders overlap (the doubling fix).
    • bbe4c54 — the optional follow-up too: an include folder can be { path, recursive: false } to take only that folder's own files.

    Ships in v1.4.0 (release PR #47); this issue closes when that release lands on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corepriority: mediumsemver: patchstatus: implementedtype: bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions