/** * Shared Utilities for Detectors * Common functions used across multiple detector files */ /** * Package.json type definition */ export type PackageJson = Record; /** * Dependencies map type */ export type DependencyMap = Record; /** * Read and parse package.json from a directory * * @param projectRoot - The root directory of the project * @returns Parsed package.json object or null if not found/invalid * * @example * const pkg = readPackageJson('/path/to/project'); * if (pkg) { * console.log(pkg.name); * } */ export declare function readPackageJson(projectRoot: string): PackageJson | null; /** * Get all dependencies from package.json (deps + devDeps combined) * * @param pkg - Parsed package.json object * @returns Combined dependencies and devDependencies map * * @example * const pkg = readPackageJson(projectRoot); * const deps = getDependencies(pkg); * if (deps.react) { * console.log(`React version: ${deps.react}`); * } */ export declare function getDependencies(pkg: PackageJson | null): DependencyMap; /** * Find a config file with various possible extensions * * @param projectRoot - The root directory of the project * @param baseName - The base name of the config file (e.g., 'next.config') * @param extensions - Array of extensions to try (e.g., ['.js', '.ts', '.mjs']) * @returns The full filename if found, or null * * @example * const configFile = findConfigFile(projectRoot, 'next.config', ['.js', '.mjs', '.ts']); * if (configFile) { * console.log(`Found: ${configFile}`); * } */ export declare function findConfigFile(projectRoot: string, baseName: string, extensions: string[]): string | null; /** * Check if a directory exists * * @param projectRoot - The root directory of the project * @param dirName - The directory name to check * @returns True if the directory exists * * @example * if (checkDirectoryExists(projectRoot, 'src')) { * console.log('Source directory found'); * } */ export declare function checkDirectoryExists(projectRoot: string, dirName: string): boolean; /** * Check if a file exists * * @param projectRoot - The root directory of the project * @param fileName - The file name to check * @returns True if the file exists * * @example * if (checkFileExists(projectRoot, 'vercel.json')) { * console.log('Vercel config found'); * } */ export declare function checkFileExists(projectRoot: string, fileName: string): boolean; /** * Find all dependencies matching a prefix pattern * * @param deps - Dependencies map * @param pattern - Prefix pattern to match (e.g., '@supabase/') * @returns Array of matching dependency names * * @example * const supabasePackages = findMatchingDeps(deps, '@supabase/'); * // Returns: ['@supabase/supabase-js', '@supabase/ssr', ...] */ export declare function findMatchingDeps(deps: DependencyMap, pattern: string): string[]; /** * Check if any dependency matches a pattern and return its version * * @param deps - Dependencies map * @param pattern - Prefix pattern to match * @returns Version string if found, undefined otherwise * * @example * const version = hasDependencyPattern(deps, '@supabase/'); * if (version) { * console.log(`Found supabase package: ${version}`); * } */ export declare function hasDependencyPattern(deps: DependencyMap, pattern: string): string | undefined; /** * Read file content safely * * @param filePath - Full path to the file * @returns File content as string, or null if read fails * * @example * const content = readFileSafe('/path/to/config.json'); * if (content) { * const config = JSON.parse(content); * } */ export declare function readFileSafe(filePath: string): string | null; /** * Parse JSON file safely * * @param projectRoot - The root directory of the project * @param fileName - The JSON file name * @returns Parsed JSON object or null if invalid * * @example * const config = parseJsonFile(projectRoot, 'tsconfig.json'); * if (config?.compilerOptions) { * console.log('TypeScript config found'); * } */ export declare function parseJsonFile(projectRoot: string, fileName: string): Record | null; /** * Common config file extensions */ export declare const CONFIG_EXTENSIONS: { /** JavaScript/TypeScript config extensions */ JS_TS: string[]; /** JSON/YAML config extensions */ DATA: string[]; /** All common config extensions */ ALL: string[]; }; /** * Get npm scripts from package.json * * @param pkg - Parsed package.json object * @returns Scripts object or empty object */ export declare function getScripts(pkg: PackageJson | null): Record; /** * Check if a specific npm script exists * * @param pkg - Parsed package.json object * @param scriptName - Name of the script to check * @returns True if the script exists */ export declare function hasScript(pkg: PackageJson | null, scriptName: string): boolean;