/** * @file Private internals for `spawn/*` modules — the `@npmcli/promise-spawn` * lazy loader, the per-spawn ANSI-stripping helper, the WeakMap stack cache, * the binary-path cache shared between `spawn` and `spawnSync`, and the * sanitized-resolution glue both entry points run a bare command name * through. Underscore prefix excludes this file from the public exports map. */ export declare const stackCache: WeakMap; export declare const spawnBinPathCache: Map; export declare const windowsScriptExtRegExp: RegExp; /** * A command resolved for spawning, plus the PATH the child must be given. */ export interface SpawnBinResolution { /** * Command to hand to the spawn primitive — an absolute path when resolution * succeeded, the original name when it did not, or a bare stem on the * Windows shell path. */ command: string; /** * PATH to force into the child environment, or `undefined` to leave the * child's PATH alone. Set only when the operating system or a shell will run * its own search for `command`. */ searchPath: string | undefined; /** * `true` when `command` resolved outside the untrusted root. */ trusted: boolean; } /** * Inputs a spawn entry point hands to {@link resolveSpawnBin}. */ export interface SpawnBinResolveConfig { /** * Working directory the child will run in. Doubles as the untrusted root. */ cwd?: string | undefined; /** * Environment the child will run with, already merged over `process.env`. */ env?: NodeJS.ProcessEnv | undefined; /** * The spawn `shell` option. */ shell?: boolean | string | undefined; } /** * Apply the Windows `shell: true` script-extension handling, and decide * whether the child needs the sanitized PATH. * * Cmd.exe struggles to launch a full path to a `.cmd` / `.bat` / `.ps1` file, * so the historical fix hands it the bare stem and lets PATHEXT re-resolve — * the same trick npm's promise-spawn, cross-spawn, and execa use. cmd.exe * searches the current directory FIRST, so the stem is only handed over when * the resolution was trusted AND the child's working directory holds no * same-named script; the child then also gets the sanitized PATH so the * re-search can only reach trusted directories. * * An absolute command needs no PATH override — nothing re-searches for it. * * @example * ;```typescript * applyCmdExeStem( * { command: 'C:\\tools\\gh.cmd', searchPath: 'C:\\tools', trusted: true }, * { shell: true }, * ) * // { command: 'gh', searchPath: 'C:\\tools', trusted: true } * ``` */ export declare function applyCmdExeStem(resolution: SpawnBinResolution, config: SpawnBinResolveConfig): SpawnBinResolution; /** * Lazily load the `@npmcli/promise-spawn` module to avoid Webpack bundling * issues. Required because the upstream module uses CJS dynamic-require * patterns that Webpack flags. */ export declare function getNpmCliPromiseSpawn(): any; /** * Report whether the child's working directory holds a script cmd.exe would * find before it consults PATH. cmd.exe always searches the current directory * first, so stripping a resolved path back to a bare stem is only safe when no * such collision exists. * * @example * ;```typescript * hasCmdExeShadowInDir('npm', 'C:\\repo', '.COM;.EXE;.CMD') // true when C:\repo\npm.cmd exists * ``` */ export declare function hasCmdExeShadowInDir(stem: string, dirPath: string, pathExt: string): boolean; /** * Resolve the command a spawn entry point should actually launch. * * A path-like input passes through untouched. A bare name goes through * {@link resolveSanitizedExecutable} against the child's own environment, with * the child's working directory as the untrusted root, and falls back to a * dropped PATH entry only when no trusted directory supplies the command. * * @example * ;```typescript * resolveSpawnBin('git', { cwd: '/scan/target' }) * // { command: '/usr/bin/git', searchPath: undefined, trusted: true } * ``` */ export declare function resolveSpawnBin(cmd: string, config: SpawnBinResolveConfig): SpawnBinResolution; /** * Strip ANSI escape codes from spawn result stdout and stderr. Modifies the * result object in place to remove color codes and formatting. * * @param {unknown} result - Spawn result object with stdout/stderr properties. * * @returns {unknown} The modified result object */ export declare function stripAnsiFromSpawnResult(result: unknown): unknown;