// src/cli/package-root.ts
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
import { t } from '../i18n/translate.js';
export function getPackageRoot() {
    let cur = dirname(fileURLToPath(import.meta.url));
    while (cur !== dirname(cur)) {
        const pj = join(cur, 'package.json');
        if (existsSync(pj)) {
            try {
                const pkg = JSON.parse(readFileSync(pj, 'utf8'));
                if (pkg.name === 'ae-tracking' || pkg.name === '@thinkingdata/ae-tracking')
                    return cur;
            }
            catch { /* keep walking */ }
        }
        cur = dirname(cur);
    }
    throw new Error(t('error.package_root_not_found'));
}
