import { existsSync, readFileSync } from "node:fs";
import { join, relative } from "node:path";
import ignore from "ignore";
function readIgnoreFile(path) {
    if (!existsSync(path))
        return [];
    return readFileSync(path, "utf-8")
        .split(/\r?\n/)
        .map((line) => line.trim())
        .filter((line) => line && !line.startsWith("#"));
}
export function createMemoryIgnoreMatcher(projectRoot) {
    const matcher = ignore();
    matcher.add(readIgnoreFile(join(projectRoot, ".gitignore")));
    matcher.add(readIgnoreFile(join(projectRoot, ".threadwellignore")));
    matcher.add([".threadwell/artifacts/**", ".threadwell/exports/**", ".env", ".env.*", "*.pem", "*.key"]);
    return {
        ignores(path) {
            const relativePath = relative(projectRoot, path).replaceAll("\\", "/");
            if (!relativePath || relativePath.startsWith(".."))
                return false;
            return matcher.ignores(relativePath);
        },
    };
}
//# sourceMappingURL=ignore.js.map