// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/detectors/advanced-framework-detector/modern-detector.ts
// Detects modern frontend frameworks: Astro, Fresh, HTMX, Qwik, SolidStart, etc.
import { join } from 'node:path';
import { fileExists, readFileContent } from './helpers.js';
async function detectIslandsAndHTMX(projectPath, deps) {
    if (deps.has('astro') ||
        (await fileExists(join(projectPath, 'astro.config.mjs'))) ||
        (await fileExists(join(projectPath, 'astro.config.ts')))) {
        return { framework: 'astro', architecture: 'islands' };
    }
    if (deps.has('fresh') || (await fileExists(join(projectPath, 'fresh.config.ts')))) {
        return { framework: 'fresh', architecture: 'islands' };
    }
    if (deps.has('htmx.org') || deps.has('htmx')) {
        return { framework: 'htmx', architecture: 'htmx' };
    }
    const indexHtml = await readFileContent(join(projectPath, 'index.html'));
    if (indexHtml.includes('htmx.org') || indexHtml.includes('htmx.min.js')) {
        return { framework: 'htmx', architecture: 'htmx' };
    }
    return { framework: null, architecture: null };
}
function detectDepsModernFramework(_projectPath, deps, pkg) {
    if (deps.has('@builder.io/qwik') || deps.has('@builder.io/qwik-city')) {
        return { framework: 'qwik', architecture: 'resumability' };
    }
    if (deps.has('solid-js') && deps.has('@solidjs/start')) {
        return { framework: 'solid-start', architecture: 'ssr' };
    }
    if (deps.has('@tanstack/router') && deps.has('@tanstack/start')) {
        return { framework: 'tanstack-start', architecture: 'ssr' };
    }
    if (deps.has('react-router')) {
        const version = pkg.dependencies?.['react-router'] ?? pkg.devDependencies?.['react-router'];
        if (version?.startsWith('7') || version?.startsWith('^7')) {
            return { framework: 'remix-v7', architecture: 'ssr' };
        }
    }
    return { framework: null, architecture: null };
}
export async function detectModernFramework(projectPath, deps, pkg) {
    const islandsResult = await detectIslandsAndHTMX(projectPath, deps);
    if (islandsResult.framework !== null) {
        return islandsResult;
    }
    return detectDepsModernFramework(projectPath, deps, pkg);
}
//# sourceMappingURL=modern-detector.js.map