Skip to content

Commit ec46afd

Browse files
committed
AutoUpdate: use latest.json instead of npm for brew installs
1 parent 25d9213 commit ec46afd

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

src/app/AutoUpdate.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,32 @@ export function AutoUpdate(props: Props) {
161161
if (state.latest_version !== null) return;
162162

163163
const local_version = process.env.CLI_VERSION;
164-
const latest_version = await get_latest_version();
165164
const is_brew_bun_standalone = get_is_brew_bun_standalone();
166-
patch({ local_version, latest_version, is_brew_bun_standalone });
167-
}
168165

169-
async function get_latest_version() {
170166
const timeout_ms = is_finite_value(props.timeoutMs) ? props.timeoutMs : 2 * 1000;
171167
const timeout = get_timeout_fn(timeout_ms, "AutoUpdate timeout");
172-
const npm_json = await timeout(fetch_json(`https://registry.npmjs.org/${props.name}`));
173-
const maybe_version = npm_json?.["dist-tags"]?.latest;
174-
if (typeof maybe_version === "string") {
175-
return maybe_version;
168+
const latest_version = await timeout(get_latest_version(is_brew_bun_standalone));
169+
170+
patch({ local_version, latest_version, is_brew_bun_standalone });
171+
}
172+
173+
async function get_latest_version(is_brew_bun_standalone: boolean) {
174+
if (is_brew_bun_standalone) {
175+
// prettier-ignore
176+
const brew_json = await fetch_json("https://raw.githubusercontent.com/magus/homebrew-git-stack/refs/heads/master/latest.json");
177+
const maybe_version = brew_json.version;
178+
if (typeof maybe_version === "string") {
179+
return maybe_version;
180+
}
181+
throw new Error("Unable to retrieve latest version from brew");
182+
} else {
183+
const npm_json = await fetch_json(`https://registry.npmjs.org/${props.name}`);
184+
const maybe_version = npm_json?.["dist-tags"]?.latest;
185+
if (typeof maybe_version === "string") {
186+
return maybe_version;
187+
}
188+
throw new Error("Unable to retrieve latest version from npm");
176189
}
177-
throw new Error("Unable to retrieve latest version from npm");
178190
}
179191

180192
function get_is_brew_bun_standalone() {

0 commit comments

Comments
 (0)