From ad2ef080aae2e21bf04ad8e922719ceaa81f1e5f Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Fri, 25 Jul 2025 17:36:42 -0700 Subject: Fix so legacy custom themes still load. (#4757) Co-authored-by: matt korwel --- packages/cli/src/ui/themes/theme.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'packages/cli/src/ui/themes/theme.ts') diff --git a/packages/cli/src/ui/themes/theme.ts b/packages/cli/src/ui/themes/theme.ts index 3955014f..7d21af1d 100644 --- a/packages/cli/src/ui/themes/theme.ts +++ b/packages/cli/src/ui/themes/theme.ts @@ -323,6 +323,7 @@ export function createCustomTheme(customTheme: CustomTheme): Theme { export function validateCustomTheme(customTheme: Partial): { isValid: boolean; error?: string; + warning?: string; } { // Check required fields const requiredFields: Array = [ @@ -336,12 +337,17 @@ export function validateCustomTheme(customTheme: Partial): { 'AccentGreen', 'AccentYellow', 'AccentRed', - 'DiffAdded', - 'DiffRemoved', + // 'DiffAdded' and 'DiffRemoved' are not required as they were added after + // the theme format was defined. 'Comment', 'Gray', ]; + const recommendedFields: Array = [ + 'DiffAdded', + 'DiffRemoved', + ]; + for (const field of requiredFields) { if (!customTheme[field]) { return { @@ -351,6 +357,14 @@ export function validateCustomTheme(customTheme: Partial): { } } + const missingFields: string[] = []; + + for (const field of recommendedFields) { + if (!customTheme[field]) { + missingFields.push(field); + } + } + // Validate color format (basic hex validation) const colorFields: Array = [ 'Background', @@ -369,8 +383,8 @@ export function validateCustomTheme(customTheme: Partial): { ]; for (const field of colorFields) { - const color = customTheme[field] as string; - if (!isValidColor(color)) { + const color = customTheme[field] as string | undefined; + if (color !== undefined && !isValidColor(color)) { return { isValid: false, error: `Invalid color format for ${field}: ${color}`, @@ -386,7 +400,13 @@ export function validateCustomTheme(customTheme: Partial): { }; } - return { isValid: true }; + return { + isValid: true, + warning: + missingFields.length > 0 + ? `Missing field(s) ${missingFields.join(', ')}` + : undefined, + }; } /** -- cgit v1.2.3