fix(installer): improve Windows compatibility for shell detection and paths

Closes #461
This commit is contained in:
YeonGyu-Kim
2026-02-24 21:42:04 +09:00
parent 55b9ad60d8
commit 6ba1d675b9
10 changed files with 234 additions and 18 deletions
@@ -0,0 +1,39 @@
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
import { findBashPath } from "./shell-path"
describe("shell-path", () => {
let originalPlatform: NodeJS.Platform
let originalComspec: string | undefined
beforeEach(() => {
originalPlatform = process.platform
originalComspec = process.env.COMSPEC
})
afterEach(() => {
Object.defineProperty(process, "platform", { value: originalPlatform })
if (originalComspec !== undefined) {
process.env.COMSPEC = originalComspec
return
}
delete process.env.COMSPEC
})
test("#given Windows platform with COMSPEC #when findBashPath is called #then returns COMSPEC path", () => {
Object.defineProperty(process, "platform", { value: "win32" })
process.env.COMSPEC = "C:\\Windows\\System32\\cmd.exe"
const result = findBashPath()
expect(result).toBe("C:\\Windows\\System32\\cmd.exe")
})
test("#given Windows platform without COMSPEC #when findBashPath is called #then returns default cmd path", () => {
Object.defineProperty(process, "platform", { value: "win32" })
delete process.env.COMSPEC
const result = findBashPath()
expect(result).toBe("C:\\Windows\\System32\\cmd.exe")
})
})
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs"
const DEFAULT_ZSH_PATHS = ["/bin/zsh", "/usr/bin/zsh", "/usr/local/bin/zsh"]
const DEFAULT_BASH_PATHS = ["/bin/bash", "/usr/bin/bash", "/usr/local/bin/bash"]
const DEFAULT_WINDOWS_CMD_PATH = "C:\\Windows\\System32\\cmd.exe"
function findShellPath(
defaultPaths: string[],
@@ -19,9 +20,17 @@ function findShellPath(
}
export function findZshPath(customZshPath?: string): string | null {
if (process.platform === "win32") {
return process.env.COMSPEC?.trim() || DEFAULT_WINDOWS_CMD_PATH
}
return findShellPath(DEFAULT_ZSH_PATHS, customZshPath)
}
export function findBashPath(): string | null {
if (process.platform === "win32") {
return process.env.COMSPEC?.trim() || DEFAULT_WINDOWS_CMD_PATH
}
return findShellPath(DEFAULT_BASH_PATHS)
}