Skip to content

Commit 9a6d8a8

Browse files
committed
Use curl to check for updates
1 parent 2b3ce21 commit 9a6d8a8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

server/updateCheck.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export async function checkForUpdate(
6666
updateAvailable: isNewerVersion(VERSION, latestVersion),
6767
updateInstructions: buildUpdateInstructions({ packageManager, host: options?.host, version: latestVersion }),
6868
};
69-
} catch {
69+
} catch (err) {
70+
const message = err instanceof Error ? err.message : String(err);
71+
process.stderr.write(`open-plan-annotator: update check error: ${message}\n`);
7072
return buildNoUpdateResult(packageManager, options?.host);
7173
}
7274
}

shared/versionInfo.mjs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,24 @@ export function isNewerVersion(current, latest) {
6767
}
6868

6969
export async function fetchLatestVersion(packageName = "open-plan-annotator") {
70-
const response = await fetch(`${NPM_REGISTRY_BASE_URL}/${encodeURIComponent(packageName)}/latest`, {
71-
headers: { "User-Agent": "open-plan-annotator-update-check", Accept: "application/json" },
72-
signal: AbortSignal.timeout(10_000),
73-
});
70+
const url = `${NPM_REGISTRY_BASE_URL}/${encodeURIComponent(packageName)}/latest`;
71+
72+
// Shell out to curl instead of using fetch/node:https — both hang inside
73+
// compiled bun binaries due to a DNS resolution bug.
74+
const { execFileSync } = await import("node:child_process");
7475

75-
if (!response.ok) {
76-
throw new Error(`npm registry responded with ${response.status}`);
76+
try {
77+
execFileSync("curl", ["--version"], { stdio: "ignore", timeout: 2_000 });
78+
} catch {
79+
throw new Error("curl not available, skipping update check");
7780
}
7881

79-
const payload = await response.json();
82+
const body = execFileSync("curl", ["-sf", "-H", "Accept: application/json", "-H", "User-Agent: open-plan-annotator-update-check", url], {
83+
timeout: 10_000,
84+
encoding: "utf8",
85+
});
86+
87+
const payload = JSON.parse(body);
8088
if (!payload || typeof payload !== "object" || typeof payload.version !== "string") {
8189
throw new Error("npm registry response did not include a version string");
8290
}

0 commit comments

Comments
 (0)