fix(cli): respect platform shell for --on-complete
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { spawnWithWindowsHide } from "../../shared/spawn-with-windows-hide"
|
||||
import { log } from "../../shared"
|
||||
import { detectShellType, log } from "../../shared"
|
||||
|
||||
async function readOutput(
|
||||
stream: ReadableStream<Uint8Array> | undefined,
|
||||
@@ -20,6 +20,24 @@ async function readOutput(
|
||||
}
|
||||
}
|
||||
|
||||
function resolveHookShellCommand(command: string): string[] {
|
||||
const shellType = detectShellType()
|
||||
|
||||
switch (shellType) {
|
||||
case "powershell": {
|
||||
const powershellExecutable = process.platform === "win32" ? "powershell.exe" : "pwsh"
|
||||
return [powershellExecutable, "-NoProfile", "-Command", command]
|
||||
}
|
||||
case "cmd":
|
||||
return [process.env.ComSpec || "cmd.exe", "/d", "/s", "/c", command]
|
||||
case "csh":
|
||||
return ["csh", "-c", command]
|
||||
case "unix":
|
||||
default:
|
||||
return ["sh", "-c", command]
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeOnCompleteHook(options: {
|
||||
command: string
|
||||
sessionId: string
|
||||
@@ -37,7 +55,8 @@ export async function executeOnCompleteHook(options: {
|
||||
log("Running on-complete hook", { command: trimmedCommand })
|
||||
|
||||
try {
|
||||
const proc = spawnWithWindowsHide(["sh", "-c", trimmedCommand], {
|
||||
const shellCommand = resolveHookShellCommand(trimmedCommand)
|
||||
const proc = spawnWithWindowsHide(shellCommand, {
|
||||
env: {
|
||||
...process.env,
|
||||
SESSION_ID: sessionId,
|
||||
|
||||
Reference in New Issue
Block a user