// engine/detectors/library-detector-node.ts — Node.js library detection
// SPEC-004 tech-debt: Reads package.json (dependencies + devDependencies)
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
// === Node.js library catalog ===
const NODE_ORM_LIBS = ['prisma', 'drizzle-orm', 'typeorm', 'sequelize', 'mongoose'];
const NODE_VALIDATION_LIBS = ['zod', 'yup', 'joi', 'valibot'];
const NODE_QUEUE_LIBS = ['bullmq', 'agenda', 'bee-queue'];
// === Detection helpers ===
function filterPresent(catalog, deps) {
    return catalog.filter((lib) => deps.has(lib));
}
// === Node.js dependency collection ===
export async function collectPackageJsonDeps(projectPath) {
    try {
        const content = await readFile(join(projectPath, 'package.json'), 'utf-8');
        const pkg = JSON.parse(content);
        return new Set([
            ...Object.keys(pkg.dependencies ?? {}),
            ...Object.keys(pkg.devDependencies ?? {}),
        ]);
    }
    catch {
        return new Set();
    }
}
// === Public API ===
/**
 * Detect popular Node.js libraries in a project.
 * Reads package.json (dependencies + devDependencies).
 */
export async function detectNodeLibraries(projectPath) {
    const deps = await collectPackageJsonDeps(projectPath);
    return {
        orm: filterPresent(NODE_ORM_LIBS, deps),
        validation: filterPresent(NODE_VALIDATION_LIBS, deps),
        queue: filterPresent(NODE_QUEUE_LIBS, deps),
    };
}
//# sourceMappingURL=library-detector-node.js.map