// Planu — JS/TS runtime detector (node, bun, deno)
import { join } from 'node:path';
import { hasAnyFile, readJsonFile } from '../detection-utils.js';
/**
 * SPEC-004 tech-debt: Detect JS/TS runtime (node, bun, deno).
 * - Deno: deno.json / deno.jsonc (no node_modules, URL imports, targets Deno Deploy)
 * - Bun: bun.lockb or elysia (Bun-native HTTP framework) in deps
 * - Node: default when neither Deno nor Bun signals are present
 */
export async function detectJsRuntime(projectPath) {
    // Deno: deno.json or deno.jsonc are definitive signals
    if (await hasAnyFile(projectPath, ['deno.json', 'deno.jsonc'])) {
        return 'deno';
    }
    // Bun: bun.lockb is definitive
    if (await hasAnyFile(projectPath, ['bun.lockb'])) {
        return 'bun';
    }
    // Bun: elysia is a Bun-native HTTP framework — check package.json deps
    const pkgJson = await readJsonFile(join(projectPath, 'package.json'));
    if (pkgJson) {
        const deps = {
            ...pkgJson.dependencies,
            ...pkgJson.devDependencies,
        };
        if ('elysia' in deps) {
            return 'bun';
        }
    }
    return null;
}
//# sourceMappingURL=js-runtime-detector.js.map