/** * @file Look up binaries on PATH. Two pairs of public functions: `which` / * `whichSync` — wrap the upstream `which` package, returning the first * matching path (or array with `{ all: true }`). Path-like inputs (absolute * paths, `./relative`, `../relative`) bypass PATH resolution and pass through * unchanged. Both are tolerant — they return `null` for not-found instead of * throwing. `whichReal` / `whichRealSync` — same but resolve the result * through `resolveRealBinSync` so the caller gets the underlying script path * (e.g., `npm-cli.js`) rather than the wrapper. Default `nothrow: true` so a * missing binary returns `undefined` instead of bubbling a `which` package * error. `whichLocalBin` resolves a tool from the project-local * `node_modules/.bin` (the inverse of `findRealBin`, which skips it). Caching * matches `shared.binPathCache` and `binPathAllCache`. Both caches * validate hits with `existsSync` so a tool reinstall mid-session doesn't * return a stale path. */ import type { WhichLocalBinOptions, WhichOptions } from '../types.js'; /** * Build the binPathCache / binPathAllCache key for a whichReal / * whichRealSync lookup. Resolution depends on binName plus every option * that changes what upstream which actually searches - path and pathExt - * so two callers resolving the same binName under different search roots * (e.g. different options.path) must not collide on the same cache entry * and hand each other a stale or mismatched answer. */ export declare function binCacheKey(binName: string, options: WhichOptions): string; /** * Find an executable in the system PATH asynchronously. * * This function resolves binary names to their full paths by searching the * system PATH. It should only be used for binary names, never paths. An input * that is already an absolute or relative path is returned as-is without PATH * resolution. * * Binary name vs. path detection: * * - Binary names: 'npm', 'git', 'node' - will be resolved via PATH * - Absolute paths: '/usr/bin/node', 'C:\Program Files\nodejs\node.exe' - * returned as-is * - Relative paths: './node', '../bin/npm' - returned as-is * * @example * ;```typescript * // Resolve binary names * await which('node') // '/usr/local/bin/node' * await which('npm') // '/usr/local/bin/npm' * await which('nonexistent') // null * * // Paths are returned as-is * await which('/usr/bin/node') // '/usr/bin/node' * await which('./local-script') // './local-script' * ``` * * @param {string} binName - The binary name to resolve (e.g., 'npm', 'git') * @param {WhichOptions | undefined} options - Options for resolution. * * @returns {Promise} Promise resolving to the full * path, the original path, or null if not found. */ export declare function which(binName: string, options?: WhichOptions | undefined): Promise; /** * Resolve a tool installed in the project-local `node_modules/.bin` to its * ABSOLUTE path. This is the inverse of findRealBin: that helper skips the * shadow bins in node_modules/.bin to find the real package manager behind a * tool's shim, whereas whichLocalBin WANTS the local bin — it is for spawning a * dev dependency's own CLI such as oxlint, vitest, or tsc directly instead of * through `pnpm exec`. Returns the platform-correct absolute path (the .cmd / * .exe shim on Windows, the symlink on POSIX), falling back to a plain PATH * lookup, or undefined when the tool resolves nowhere. `options.cwd` overrides * the project root whose node_modules/.bin is searched (default * getNodeProcess().cwd()); an explicit `options.path` replaces that local bin * dir entirely. * * In npm's terminology this is "local" (vs "global" with `-g`): a locally * installed package's executables are linked into node_modules/.bin. See * https://docs.npmjs.com/cli/v11/configuring-npm/folders#executables. * * @example * ;```typescript * whichLocalBin('oxlint') // '/repo/node_modules/.bin/oxlint' * whichLocalBin('missing') // undefined * ``` */ export declare function whichLocalBin(binName: string, options?: WhichLocalBinOptions | undefined): string | undefined; /** * Find a binary in the system PATH and resolve to the real underlying script * asynchronously. Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the * actual .js files they execute. * * @example * ;```typescript * const npmPath = await whichReal('npm') * // e.g. '/usr/local/lib/node_modules/npm/bin/npm-cli.js' * ``` * * @throws {Error} If the binary is not found and nothrow is false. */ export declare function whichReal(binName: string, options?: WhichOptions | undefined): Promise; /** * Find a binary in the system PATH and resolve to the real underlying script * synchronously. Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the * actual .js files they execute. * * @example * ;```typescript * const npmPath = whichRealSync('npm') * // e.g. '/usr/local/lib/node_modules/npm/bin/npm-cli.js' * ``` * * @throws {Error} If the binary is not found and nothrow is false. */ export declare function whichRealSync(binName: string, options?: WhichOptions | undefined): string | string[] | undefined; /** * Find an executable in the system PATH synchronously. * * This function resolves binary names to their full paths by searching the * system PATH. It should only be used for binary names, never paths. An input * that is already an absolute or relative path is returned as-is without PATH * resolution. * * Binary name vs. path detection: * * - Binary names: 'npm', 'git', 'node' - will be resolved via PATH * - Absolute paths: '/usr/bin/node', 'C:\Program Files\nodejs\node.exe' - * returned as-is * - Relative paths: './node', '../bin/npm' - returned as-is * * @example * ;```typescript * // Resolve binary names * whichSync('node') // '/usr/local/bin/node' * whichSync('npm') // '/usr/local/bin/npm' * whichSync('nonexistent') // null * * // Paths are returned as-is * whichSync('/usr/bin/node') // '/usr/bin/node' * whichSync('./local-script') // './local-script' * ``` * * @param {string} binName - The binary name to resolve (e.g., 'npm', 'git') * @param {WhichOptions | undefined} options - Options for resolution. * * @returns {string | string[] | null} The full path to the binary, the original * path if input is a path, or null if not found. */ export declare function whichSync(binName: string, options?: WhichOptions | undefined): string | string[] | null;