Archived
fix: run doctor version checks under fish
The doctor "can find npm/pi" checks wrap the version command in a POSIX subshell, `(cmd --version 2>&1 || true)`. Fish treats `( ... )` as command substitution syntax and forbids it in command position, so every fish user saw false-negative failures: fish: command substitutions not allowed in command position command -v npm && (npm --version 2>&1 || true) Branch on the detected service shell and emit fish's `begin; ...; end` grouping for fish, mirroring the existing fish-aware quoting in serviceShellQuote. Bash and zsh keep the POSIX subshell. Also guard the `main()` invocation with an ESM main-module check so the CLI helpers can be imported by tests without side effects, and add a regression test covering the bash, zsh, and fish command shapes.
This commit is contained in:
+12
-6
@@ -902,8 +902,12 @@ function commandCheck(command: string): string {
|
||||
return `command -v ${command}`;
|
||||
}
|
||||
|
||||
function commandWithVersionCheck(command: string): string {
|
||||
return `${commandCheck(command)} && (${command} --version 2>&1 || true)`;
|
||||
export function commandWithVersionCheck(command: string): string {
|
||||
const found = commandCheck(command);
|
||||
if (detectServiceShell().name === "fish") {
|
||||
return `${found} && begin; ${command} --version 2>&1 || true; end`;
|
||||
}
|
||||
return `${found} && (${command} --version 2>&1 || true)`;
|
||||
}
|
||||
|
||||
function nodeVersionCheck(): string {
|
||||
@@ -1088,7 +1092,9 @@ async function main(): Promise<void> {
|
||||
else throw new Error(`Unknown command: ${command}`);
|
||||
}
|
||||
|
||||
main().catch((error: unknown) => {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
});
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
main().catch((error: unknown) => {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user