( options?: ShellConfigOptions, )
| 140 | * @param options Optional overrides for testing (env, homedir) |
| 141 | */ |
| 142 | export async function findValidClaudeAlias( |
| 143 | options?: ShellConfigOptions, |
| 144 | ): Promise<string | null> { |
| 145 | const aliasTarget = await findClaudeAlias(options) |
| 146 | if (!aliasTarget) return null |
| 147 | |
| 148 | const home = options?.homedir ?? osHomedir() |
| 149 | |
| 150 | // Expand ~ to home directory |
| 151 | const expandedPath = aliasTarget.startsWith('~') |
| 152 | ? aliasTarget.replace('~', home) |
| 153 | : aliasTarget |
| 154 | |
| 155 | // Check if the target exists and is executable |
| 156 | try { |
| 157 | const stats = await stat(expandedPath) |
| 158 | // Check if it's a file (could be executable or symlink) |
| 159 | if (stats.isFile() || stats.isSymbolicLink()) { |
| 160 | return aliasTarget |
| 161 | } |
| 162 | } catch { |
| 163 | // Target doesn't exist or can't be accessed |
| 164 | } |
| 165 | |
| 166 | return null |
| 167 | } |
| 168 |
no test coverage detected