Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "1.0.11",
"version": "1.0.12",
"type": "module",
"bin": {
"spawn": "cli.js"
Expand Down
53 changes: 27 additions & 26 deletions packages/cli/src/update-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,22 @@ function performAutoUpdate(latestVersion: string, jsonOutput = false): void {
const platform = isWindows() ? "windows" : "unix";
validateInstallScript(scriptContent, platform);

if (isWindows()) {
// Windows: write to temp file and execute via PowerShell
const tmpFile = path.join(tmpdir(), `spawn-install-${Date.now()}.ps1`);
fs.writeFileSync(tmpFile, scriptContent);
const psResult = tryCatch(() =>
// Write install script to temp file, execute, and guarantee cleanup.
// Uses tryCatch so cleanup always runs before any error is re-thrown.
const tmpExt = isWindows() ? "ps1" : "sh";
const tmpFile = path.join(tmpdir(), `spawn-install-${Date.now()}.${tmpExt}`);
fs.writeFileSync(
tmpFile,
scriptContent,
isWindows()
? undefined
: {
mode: 0o700,
},
);

const execResult = tryCatch(() => {
if (isWindows()) {
executor.execFileSync(
"powershell.exe",
[
Expand All @@ -348,21 +359,8 @@ function performAutoUpdate(latestVersion: string, jsonOutput = false): void {
{
stdio: installStdio,
},
),
);
// Best-effort cleanup of temp file
tryCatchIf(isFileError, () => fs.unlinkSync(tmpFile));
if (!psResult.ok) {
throw psResult.error;
}
} else {
// macOS/Linux: write to temp file and execute via bash to avoid
// command injection and ARG_MAX limits (consistent with Windows path)
const tmpFile = path.join(tmpdir(), `spawn-install-${Date.now()}.sh`);
fs.writeFileSync(tmpFile, scriptContent, {
mode: 0o700,
});
const bashResult = tryCatch(() =>
);
} else {
executor.execFileSync(
"bash",
[
Expand All @@ -371,13 +369,16 @@ function performAutoUpdate(latestVersion: string, jsonOutput = false): void {
{
stdio: installStdio,
},
),
);
// Best-effort cleanup of temp file
tryCatchIf(isFileError, () => fs.unlinkSync(tmpFile));
if (!bashResult.ok) {
throw bashResult.error;
);
}
});

// Cleanup runs unconditionally — tryCatch above captures any exec error
// without short-circuiting, so we always reach this line.
tryCatchIf(isFileError, () => fs.unlinkSync(tmpFile));

if (!execResult.ok) {
throw execResult.error;
}
});

Expand Down
Loading