From 5eaed66ead363e29c324ce171ef6ebe01e694ad9 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 29 Jan 2024 13:35:09 -0700 Subject: [PATCH] fix: prefer user theme --- src/config/config.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 29398180d..444067015 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -332,7 +332,7 @@ export class Config implements IConfig { this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry if (!this.scopedEnvVarTrue('DISABLE_THEME')) { - const {theme} = await this.loadTheme() + const {theme} = await this.loadThemes() this.theme = theme } @@ -401,17 +401,30 @@ export class Config implements IConfig { } } - public async loadTheme(): Promise<{ - file: string + public async loadThemes(): Promise<{ + file: string | undefined theme: Theme | undefined }> { - const file = this.pjson.oclif.theme + const defaultThemeFile = this.pjson.oclif.theme ? resolve(this.root, this.pjson.oclif.theme) - : resolve(this.configDir, 'theme.json') - const themeRaw = await safeReadJson>(file) + : this.pjson.oclif.theme + const userThemeFile = resolve(this.configDir, 'theme.json') + + const [defaultTheme, userTheme] = await Promise.all([ + defaultThemeFile ? await safeReadJson>(defaultThemeFile) : undefined, + await safeReadJson>(userThemeFile), + ]) + + if (userTheme) { + return { + file: userThemeFile, + theme: parseTheme(userTheme), + } + } + return { - file, - theme: themeRaw ? parseTheme(themeRaw) : undefined, + file: defaultThemeFile, + theme: parseTheme(defaultTheme ?? {}), } }