// Planu — Shared helpers for mobile detection (SPEC-013)
import { readFile, readdir } from 'node:fs/promises';
import { join, extname } from 'node:path';
const SKIP_DIRS = new Set(['node_modules', '.git', 'Pods', 'build', 'DerivedData']);
export async function safeReadFile(p) {
    try {
        return await readFile(p, 'utf-8');
    }
    catch {
        return null;
    }
}
export async function safeReaddir(p) {
    try {
        return await readdir(p);
    }
    catch {
        return [];
    }
}
export async function walkForExt(dir, ext, results, limit, depth) {
    if (results.length >= limit || depth > 6) {
        return;
    }
    const entries = await safeReaddir(dir);
    for (const entry of entries) {
        if (results.length >= limit) {
            return;
        }
        if (SKIP_DIRS.has(entry)) {
            continue;
        }
        const fullPath = join(dir, entry);
        if (extname(entry) === ext) {
            results.push(fullPath);
        }
        else if (!entry.includes('.') || entry.endsWith('.xcodeproj') || entry.endsWith('.lproj')) {
            await walkForExt(fullPath, ext, results, limit, depth + 1);
        }
    }
}
//# sourceMappingURL=mobile-detector-shared.js.map