Skip to content

Commit

Permalink
fix: runtime error TypeError: color.hex is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOricil committed Nov 7, 2023
1 parent 624ad8c commit a9e86e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import {Command} from '../command'
import {CLIError, error, exit, warn} from '../errors'
import {getHelpFlagAdditions} from '../help/util'
import {Hook, Hooks, PJSON, Topic} from '../interfaces'
import {ArchTypes, Config as IConfig, LoadOptions, PlatformTypes, Theme, VersionDetails} from '../interfaces/config'
import {
ArchTypes,
Config as IConfig,
LoadOptions,
PlatformTypes,
Theme,
VersionDetails,
parseTheme,
} from '../interfaces/config'
import {Plugin as IPlugin, Options} from '../interfaces/plugin'
import {loadWithData} from '../module-loader'
import {OCLIF_MARKER_OWNER, Performance} from '../performance'
Expand Down Expand Up @@ -335,7 +343,7 @@ export class Config implements IConfig {
const OCLIF_ENABLE_THEME = process.env.OCLIF_ENABLE_THEME === 'true'
this.enableTheme = OCLIF_ENABLE_THEME ?? this.pjson.oclif.enableTheme ?? false
if (this.enableTheme) {
this.theme = this.pjson.oclif.theme ?? DEFAULT_THEME
this.theme = this.pjson.oclif?.theme ? parseTheme(this.pjson.oclif?.theme) : DEFAULT_THEME
}

this.userAgent = `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`
Expand Down
12 changes: 12 additions & 0 deletions src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export interface Theme {
version?: Color
}

export function parseTheme(json: any): Theme {
const theme: Theme = {}

for (const prop in json) {
if (Object.prototype.hasOwnProperty.call(json, prop)) {
theme[prop as keyof Theme] = new Color(json[prop])
}
}

return theme
}

export interface Config {
/**
* process.arch
Expand Down

0 comments on commit a9e86e9

Please sign in to comment.