fix: beta versions could fail at loading central.json file if their specific branch is missing

Massimo Melina committed Aug 10, 2025 at 23:51 UTC 1dd98b00ea3891e2dd636d2f423b8d1e5f699b15
2 files changed +5 -4
src/const.ts
-1
@@ -30,7 +30,6 @@ export const BUILD_TIMESTAMP = fs.statSync(PKG_PATH).mtime.toISOString()
30 const pkg = JSON.parse(fs.readFileSync(PKG_PATH,'utf8'))
31 export const VERSION = pkg.version
32 export const RUNNING_BETA = VERSION.includes('-')
33 -export const HFS_REPO_BRANCH = RUNNING_BETA ? VERSION.split('.')[1] : 'main'
33 export const IS_WINDOWS = process.platform === 'win32'
34 export const IS_MAC = process.platform === 'darwin'
35 export const IS_BINARY = !/node|bun/.test(basename(process.execPath)) // this won't be node if pkg was used
src/github.ts
+5 -3
@@ -12,8 +12,8 @@ import {
12 import { ApiError } from './apiMiddleware'
13 import _ from 'lodash'
14 import {
15 - HFS_REPO, HFS_REPO_BRANCH, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_NOT_ACCEPTABLE,
16 - HTTP_SERVER_ERROR, VERSION
15 + HFS_REPO, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_NOT_ACCEPTABLE, HTTP_SERVER_ERROR, VERSION,
16 + RUNNING_BETA,
17 } from './const'
18 import { access, readFile, rename, rm, writeFile } from 'fs/promises'
19 import { join } from 'path'
@@ -257,8 +257,10 @@ export let blacklistedInstalledPlugins: string[] = []
257 // centralized hosted information, to be used as little as possible
258 const FN = 'central.json'
259 let builtIn = JSON.parse(fs.readFileSync(join(__dirname, '..', FN), 'utf8'))
260 +const branch = RUNNING_BETA ? VERSION.split('.')[1] : 'main'
261 export const getProjectInfo = debounceAsync(
261 - () => argv.central === false ? Promise.resolve(builtIn) : readGithubFile(`${HFS_REPO}/${HFS_REPO_BRANCH}/${FN}`)
262 + () => argv.central === false ? Promise.resolve(builtIn) : readGithubFile(`${HFS_REPO}/${branch}/${FN}`)
263 + .catch(e => RUNNING_BETA ? readGithubFile(`${HFS_REPO}/main/${FN}`) : Promise.reject(e)) // for beta versions, try again with 'main'
264 .then(JSON.parse, () => null)
265 .then(o => {
266 if (o)