Skip to content

Commit 81c2b3b

Browse files
feat: auto-update on start for global installs
On relay start, if a newer version is available and running from a global install, automatically runs bun/npm install -g in the background. bunx users get a hint to use @latest instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d5829b1 commit 81c2b3b

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/cli.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,24 @@ function isRunningViaBunx(): boolean {
4949
return import.meta.dir.includes("/.bun/install/cache/");
5050
}
5151

52-
/** Silently check for updates and print a one-liner if a newer version is available. */
52+
/** Silently check for updates and auto-apply if on a global install, or print hint for bunx. */
5353
async function checkForUpdates() {
5454
const latest = await fetchLatestVersion();
55-
if (latest && latest !== VERSION) {
56-
const hint = isRunningViaBunx()
57-
? `bunx ${NPM_PACKAGE}@latest start`
58-
: `relay update`;
59-
console.log(`${DIM}relay v${latest} is available (you have v${VERSION}). Run: ${hint}${RESET}`);
55+
if (!latest || latest === VERSION) return;
56+
57+
if (isRunningViaBunx()) {
58+
console.log(`${DIM}relay v${latest} is available. Run: bunx ${NPM_PACKAGE}@latest start${RESET}`);
59+
return;
60+
}
61+
62+
console.log(`${DIM}relay v${latest} available — auto-updating...${RESET}`);
63+
const bunCheck = await Bun.$`which bun`.quiet().nothrow();
64+
const installCmd = bunCheck.exitCode === 0
65+
? `bun install -g ${NPM_PACKAGE}@latest`
66+
: `npm install -g ${NPM_PACKAGE}@latest`;
67+
const result = await Bun.$`sh -c ${installCmd}`.quiet().nothrow();
68+
if (result.exitCode === 0) {
69+
console.log(`${DIM}Updated to v${latest}. Restart relay to apply.${RESET}`);
6070
}
6171
}
6272

0 commit comments

Comments
 (0)