dx: couldn't test new central.json locally
Massimo Melina committed
Apr 1, 2026 at 18:57 UTC
a8f4df7518fd99847e84e9a7e78627ae06c2444f
1 file changed
+38
-35
src/github.ts
+38
-35
@@ -2,7 +2,7 @@
2
3
import events from './events'
4
import {
5
- httpString, httpStream, unzip, AsapStream, debounceAsync, retry, popKey, onlyTruthy, waitFor, HOUR, DAY
5
+ httpString, httpStream, unzip, AsapStream, debounceAsync, retry, popKey, onlyTruthy, waitFor, HOUR, DAY, tryJson
6
} from './misc'
7
import {
8
DISABLING_SUFFIX, enablePlugin, findPluginByRepo, getInactivePlugins, getPluginInfo, isPluginRunning, mapPlugins,
@@ -279,38 +279,41 @@ const cachedCentralInfo = storedMap.singleSync('cachedCentralInfo', '') // persi
279
export let blacklistedInstalledPlugins: string[] = []
280
// centralized hosted information, to be used as little as possible
281
const FN = 'central.json'
282
-let builtIn = JSON.parse(fs.readFileSync(join(__dirname, '..', FN), 'utf8'))
282
+const builtInJson = fs.readFileSync(join(__dirname, '..', FN), 'utf8')
283
const branch = RUNNING_BETA ? VERSION.split('.')[1] : 'main'
284
-export const getProjectInfo = debounceAsync(
285
- () => argv.central === false ? Promise.resolve(builtIn) : readGithubFile(`${HFS_REPO}/${branch}/${FN}`)
286
- .catch(e => RUNNING_BETA ? readGithubFile(`${HFS_REPO}/main/${FN}`) : Promise.reject(e)) // for beta versions, try again with 'main'
287
- .then(JSON.parse, () => null)
288
- .then(async o => {
289
- await cachedCentralInfo.ready()
290
- if (o)
291
- cachedCentralInfo.set(o)
292
- o ||= { ...cachedCentralInfo.get() || builtIn } // fall back to built-in
293
- // merge byVersions info in the main object, but collect alerts separately, to preserve multiple instances
294
- const allAlerts: string[] = [o.alert]
295
- for (const [ver, more] of Object.entries(popKey(o, 'byVersion') || {}))
296
- if (VERSION.match(new RegExp(ver))) {
297
- allAlerts.push((more as any).alert)
298
- Object.assign(o, more)
299
- }
300
- _.remove(allAlerts, x => !x)
301
- alerts.set(was => {
302
- if (!_.isEqual(was, allAlerts))
303
- for (const a of allAlerts)
304
- console.log("ALERT:", a)
305
- return allAlerts
306
- })
307
- const black = onlyTruthy(Object.keys(o.repo_blacklist || {}).map(findPluginByRepo))
308
- blacklistedInstalledPlugins = onlyTruthy(black.map(x => _.isString(x.repo) && x.repo))
309
- if (black.length) {
310
- console.log("blacklisted plugins found:", black.join(', '))
311
- for (const p of black)
312
- enablePlugin(p.id, false)
313
- }
314
- return o
315
- }),
316
- { retain: HOUR, retainFailure: 60_000 })
\ No newline at end of file
284
+export const getProjectInfo = debounceAsync(async () => {
285
+ const txt = argv.central === false ? builtInJson
286
+ : await readGithubFile(`${HFS_REPO}/${branch}/${FN}`)
287
+ .catch(() => RUNNING_BETA ? readGithubFile(`${HFS_REPO}/main/${FN}`) : '') // for beta versions, try again with 'main'
288
+ .catch(() => '')
289
+ let obj = tryJson(txt)
290
+ await cachedCentralInfo.ready()
291
+ if (obj) {
292
+ cachedCentralInfo.set(obj)
293
+ obj = { ...obj } // so that later modifications are not done on the cached object
294
+ }
295
+ else
296
+ obj = { ...cachedCentralInfo.get() || JSON.parse(builtInJson) } // fall back to built-in
297
+ // merge byVersions info in the main object but collect alerts separately to preserve multiple instances
298
+ const allAlerts: string[] = [obj.alert]
299
+ for (const [ver, more] of Object.entries(popKey(obj, 'byVersion') || {}))
300
+ if (VERSION.match(new RegExp(ver))) {
301
+ allAlerts.push((more as any).alert)
302
+ Object.assign(obj, more)
303
+ }
304
+ _.remove(allAlerts, x => !x)
305
+ alerts.set(was => {
306
+ if (!_.isEqual(was, allAlerts))
307
+ for (const a of allAlerts)
308
+ console.log("ALERT:", a)
309
+ return allAlerts
310
+ })
311
+ const black = onlyTruthy(Object.keys(obj.repo_blacklist || {}).map(findPluginByRepo))
312
+ blacklistedInstalledPlugins = onlyTruthy(black.map(x => _.isString(x.repo) && x.repo))
313
+ if (black.length) {
314
+ console.log("blacklisted plugins found:", black.join(', '))
315
+ for (const p of black)
316
+ enablePlugin(p.id, false)
317
+ }
318
+ return obj
319
+}, { retain: HOUR, retainFailure: 60_000 })
\ No newline at end of file