Skip to content

Write HTML. Render video. Built for agents.

fix(cli): use 'where' instead of 'which' on Windows for FFmpeg and br… (#336)

Wangd1f992570a2a
diff --git a/packages/cli/src/browser/ffmpeg.ts b/packages/cli/src/browser/ffmpeg.ts
index b9e1d28947..5dcaebc4f4 100644
--- a/packages/cli/src/browser/ffmpeg.ts
+++ b/packages/cli/src/browser/ffmpeg.ts
@@ -2,12 +2,17 @@ import { execSync } from "node:child_process";
export function findFFmpeg(): string | undefined {
try {
- const result = execSync("which ffmpeg", {
+ const cmd = process.platform === "win32" ? "where ffmpeg" : "which ffmpeg";
+ const output = execSync(cmd, {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
timeout: 5000,
- }).trim();
- return result || undefined;
+ });
+ const first = output
+ .split(/\r?\n/)
+ .map((s) => s.trim())
+ .find(Boolean);
+ return first || undefined;
} catch {
return undefined;
}
diff --git a/packages/cli/src/browser/manager.ts b/packages/cli/src/browser/manager.ts
index 4ca5a4ab4d..eaab48d955 100644
--- a/packages/cli/src/browser/manager.ts
+++ b/packages/cli/src/browser/manager.ts
@@ -38,12 +38,17 @@ const SYSTEM_CHROME_PATHS: ReadonlyArray<string> =
function whichBinary(name: string): string | undefined {
try {
- const result = execSync(`which ${name}`, {
+ const cmd = process.platform === "win32" ? `where ${name}` : `which ${name}`;
+ const output = execSync(cmd, {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
timeout: 5000,
- }).trim();
- return result || undefined;
+ });
+ const first = output
+ .split(/\r?\n/)
+ .map((s) => s.trim())
+ .find(Boolean);
+ return first || undefined;
} catch {
return undefined;
}
diff --git a/packages/cli/src/tts/synthesize.ts b/packages/cli/src/tts/synthesize.ts
index 8f75cb1a8c..e2a5984fa9 100644
--- a/packages/cli/src/tts/synthesize.ts
+++ b/packages/cli/src/tts/synthesize.ts
@@ -11,20 +11,26 @@ import { ensureModel, ensureVoices, DEFAULT_VOICE } from "./manager.js";
function findPython(): string | undefined {
for (const name of ["python3", "python"]) {
try {
- const result = execFileSync("which", [name], {
+ const cmd = process.platform === "win32" ? "where" : "which";
+ const output = execFileSync(cmd, [name], {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
timeout: 5000,
- }).trim();
+ });
+ const first = output
+ .split(/\r?\n/)
+ .map((s) => s.trim())
+ .find(Boolean);
+ if (!first) continue;
// Verify it's Python 3
- const version = execFileSync(result, ["--version"], {
+ const version = execFileSync(first, ["--version"], {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
timeout: 5000,
}).trim();
- if (version.includes("Python 3")) return result;
+ if (version.includes("Python 3")) return first;
} catch {
// not found or not Python 3
}
diff --git a/packages/cli/src/utils/clipboard.ts b/packages/cli/src/utils/clipboard.ts
index fd4b962e6f..f20dad7252 100644
--- a/packages/cli/src/utils/clipboard.ts
+++ b/packages/cli/src/utils/clipboard.ts
@@ -31,9 +31,10 @@ function detectProvider(): ClipboardProvider | undefined {
{ cmd: "xclip", args: ["-selection", "clipboard"] },
{ cmd: "xsel", args: ["--clipboard", "--input"] },
];
+ const cmd = process.platform === "win32" ? "where" : "which";
for (const p of candidates) {
- const which = spawnSync("which", [p.cmd], { stdio: "ignore" });
- if (which.status === 0) return p;
+ const result = spawnSync(cmd, [p.cmd], { stdio: "ignore" });
+ if (result.status === 0) return p;
}
return undefined;
}
diff --git a/packages/cli/src/whisper/manager.ts b/packages/cli/src/whisper/manager.ts
index e2dffff607..4a1237a2a0 100644
--- a/packages/cli/src/whisper/manager.ts
+++ b/packages/cli/src/whisper/manager.ts
@@ -22,12 +22,17 @@ function getModelUrl(model: string): string {
function whichBinary(name: string): string | undefined {
try {
- const result = execFileSync("which", [name], {
+ const cmd = process.platform === "win32" ? "where" : "which";
+ const output = execFileSync(cmd, [name], {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
timeout: 5000,
- }).trim();
- return result || undefined;
+ });
+ const first = output
+ .split(/\r?\n/)
+ .map((s) => s.trim())
+ .find(Boolean);
+ return first || undefined;
} catch {
return undefined;
}