nearbyFiles
uses node:path
TypeScript files near a mirror that aren't in it and mention any of names: the rest of its git repository
(or its parent directory), leaving out installed packages, build output, hidden directories and codebases.
import { git } from "#codebase/tcmts/cli/mirror"; import type { Mirror } from "#codebase/tcmts/cli/mirror"; import fs from "node:fs"; import path from "node:path"; export function nearbyFiles(m: Mirror, names: string[]): string[] { const top = git(m.dir, "rev-parse", "--show-toplevel") ?? path.dirname(m.dir); const mirrored = new Set(Object.keys(m.files).map((rel) => path.join(m.dir, rel))); const out: string[] = []; const walk = (dir: string) => { for (const e of fs.readdirSync(dir, { withFileTypes: true })) { const p = path.join(dir, e.name); if (e.isDirectory()) { if (!e.name.startsWith(".") && !["node_modules", "dist", "build", "coverage"].includes(e.name) && !fs.existsSync(path.join(p, ".tcm"))) walk(p); continue; } if (!/\.(m|c)?tsx?$/.test(e.name) || /\.d\.(m|c)?ts$/.test(e.name) || mirrored.has(p)) continue; const text = fs.readFileSync(p, "utf8"); if (names.some((n) => text.includes(n))) out.push(p); } }; walk(top); return out; }