/** * @file Executable type detection for DLX and local filesystem paths. Provides * utilities to detect whether a path is a Node.js package or native binary * executable. Supports both DLX cache paths and local filesystem paths. Key * Functions: * * - detectExecutableType: Generic entry point for any path * - detectDlxExecutableType: DLX cache specific detection * - detectLocalExecutableType: Local filesystem specific detection Detection * Strategies: * - DLX cache: Check for node_modules/ directory * - Local paths: Check for package.json with bin field, then file extension */ export type PackageJsonPathEntry = { path: string | undefined; at: number; }; export type PackageJsonCacheEntry = { mtimeMs: number; content: object | undefined; }; export type ExecutableType = 'package' | 'binary' | 'unknown'; export interface ExecutableDetectionResult { type: ExecutableType; method: 'dlx-cache' | 'package-json' | 'file-extension'; packageJsonPath?: string | undefined; inDlxCache?: boolean | undefined; } /** * Detect executable type for paths in DLX cache. Uses filesystem structure * (node_modules/ presence). * * @example * ;```typescript * const result = detectDlxExecutableType('/tmp/.socket/_dlx/a1b2c3d4/tool') * console.log(result.type) // 'package' or 'binary' * ``` * * @param filePath - Path within DLX cache (~/.socket/_dlx/) * * @returns Detection result */ export declare function detectDlxExecutableType(filePath: string): ExecutableDetectionResult; /** * Detect if a path is a Node.js package or native binary executable. Works for * both DLX cache paths and local filesystem paths. * * Detection strategy: 1. If in DLX cache: Use detectDlxExecutableType() 2. * Otherwise: Use detectLocalExecutableType() * * @example * ;```typescript * const result = detectExecutableType('/path/to/tool') * if (result.type === 'package') { * spawnNode([filePath, ...args]) * } else { * spawn(filePath, args) * } * ``` * * @param filePath - Path to executable (DLX cache or local filesystem) * * @returns Detection result with type, method, and metadata */ export declare function detectExecutableType(filePath: string): ExecutableDetectionResult; /** * Detect executable type for local filesystem paths. Uses package.json and file * extension checks. * * @example * ;```typescript * const result = detectLocalExecutableType('/usr/local/bin/tool') * if (result.type === 'package') { * console.log('Node.js package at:', result.packageJsonPath) * } * ``` * * @param filePath - Local filesystem path (not in DLX cache) * * @returns Detection result */ export declare function detectLocalExecutableType(filePath: string): ExecutableDetectionResult; /** * Find package.json in the directory containing the file or parent directories. * Results are cached to avoid repeated directory traversal. * * @private * * @param filePath - Path to search from. * * @returns Path to package.json if found, undefined otherwise */ export declare function findPackageJson(filePath: string): string | undefined; /** * Check if a file path indicates a Node.js script. * * @example * ;```typescript * isJsFilePath('index.js') // true * isJsFilePath('lib.mjs') // true * isJsFilePath('tool.exe') // false * ``` * * @param filePath - Path to check. * * @returns True if file has .js, .mjs, or .cjs extension */ export declare function isJsFilePath(filePath: string): boolean; /** * Simplified helper: Is this a native binary executable? * * @example * ;```typescript * isNativeBinary('/usr/local/bin/tool') // true * isNativeBinary('/tmp/project/index.js') // false * ``` * * @param filePath - Path to check. * * @returns True if detected as native binary (not Node.js package) */ export declare function isNativeBinary(filePath: string): boolean; /** * Simplified helper: Is this a Node.js package? * * @example * ;```typescript * isNodePackage('/tmp/project/index.js') // true * isNodePackage('/usr/local/bin/tool') // false * ``` * * @param filePath - Path to check. * * @returns True if detected as Node.js package */ export declare function isNodePackage(filePath: string): boolean; /** * Set a package.json path cache entry, evicting the oldest when the LRU is * full. * * @private * * @param key - Start directory used as the cache key. * @param value - Resolved package.json path, or undefined for a negative entry. */ export declare function packageJsonPathCacheSet(key: string, value: string | undefined): void; /** * Read and parse package.json with caching. Results are cached to avoid * repeated file reads. * * @private * * @param packageJsonPath - Path to package.json. * * @returns Parsed package.json or null if invalid */ export declare function readPackageJson(packageJsonPath: string): object | undefined;