import { access } from "node:fs/promises"; import { join } from "node:path"; export type PathExists = (path: string) => Promise; async function defaultPathExists(path: string): Promise { try { await access(path); return true; } catch { return false; } } /** Resolve Readline's user configuration path without silently inventing one. */ export async function resolveUserInputrcPath( environment: Readonly> = process.env, homeDirectory = process.env.HOME, pathExists: PathExists = defaultPathExists, ): Promise { const explicit = environment.INPUTRC; if (explicit !== undefined && explicit.length > 0) return (await pathExists(explicit)) ? explicit : undefined; if (homeDirectory === undefined || homeDirectory.length === 0) return undefined; const conventional = join(homeDirectory, ".inputrc"); return (await pathExists(conventional)) ? conventional : undefined; }