* Actively discover the source files an `include` whitelist forces in. `git * ls-files` never lists gitignored files, so a filtered filesystem walk of just * the opted-in subtrees (`includeStaticRoots`) is the only way to find them. * Returns project-root-relative, normalized source-file paths.
( rootDir: string, include: Ignore, exclude: Ignore | null, roots: string[], overrides: Record<string, Language>, )
| 790 | * `.gitignore` is deliberately NOT consulted: overriding it is the whole point. |
| 791 | */ |
| 792 | function collectIncludedFiles( |
| 793 | rootDir: string, |
| 794 | include: Ignore, |
| 795 | exclude: Ignore | null, |
| 796 | roots: string[], |
| 797 | overrides: Record<string, Language>, |
| 798 | ): Set<string> { |
| 799 | const out = new Set<string>(); |
| 800 | const defaults = defaultsOnlyIgnore(); |
| 801 | const visited = new Set<string>(); |
| 802 | |
| 803 | const consider = (abs: string, rel: string, isDir: boolean): void => { |
| 804 | if (isDir) { |
| 805 | if (defaults.ignores(rel + '/')) return; // never node_modules/dist/… via include |
| 806 | // An explicit `exclude` always wins over `include`; prune the whole subtree |
| 807 | // here so a large excluded dir (a committed frontend's own vendored deps, |
| 808 | // build output, …) is never walked — the per-file guard below still catches |
| 809 | // anything a directory pattern doesn't, so this is a pure efficiency win. |
| 810 | if (exclude && exclude.ignores(rel + '/')) return; |
| 811 | walk(abs); |
| 812 | } else { |
| 813 | if (defaults.ignores(rel)) return; |
| 814 | if (!include.ignores(rel)) return; |
| 815 | if (exclude && exclude.ignores(rel)) return; |
| 816 | if (!isSourceFile(rel, overrides, rootDir)) return; |
| 817 | out.add(rel); |
| 818 | } |
| 819 | }; |
| 820 | |
| 821 | function walk(absDir: string): void { |
| 822 | let realDir: string; |
| 823 | try { |
| 824 | realDir = walkRealpath(absDir); |
| 825 | } catch { |
| 826 | return; |
| 827 | } |
| 828 | if (visited.has(realDir)) return; // symlink-cycle guard |
| 829 | visited.add(realDir); |
| 830 | |
| 831 | let entries: fs.Dirent[]; |
| 832 | try { |
| 833 | entries = fs.readdirSync(absDir, { withFileTypes: true }); |
| 834 | } catch { |
| 835 | return; |
| 836 | } |
| 837 | for (const entry of entries) { |
| 838 | if (entry.name === '.git' || isCodeGraphDataDir(entry.name)) continue; |
| 839 | const abs = path.join(absDir, entry.name); |
| 840 | const rel = normalizePath(path.relative(rootDir, abs)); |
| 841 | if (!rel || escapesRoot(rel)) continue; |
| 842 | if (entry.isSymbolicLink()) { |
| 843 | try { |
| 844 | const st = fs.statSync(fs.realpathSync(abs)); |
| 845 | consider(abs, rel, st.isDirectory()); |
| 846 | } catch { |
| 847 | // broken symlink — skip |
| 848 | } |
| 849 | continue; |
no test coverage detected