Skip to content

Commit

Permalink
fix: Add more type guard at loadConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesin11 committed Aug 10, 2020
1 parent 6674a4c commit 1c41aae
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ export const loadConfig = (configPath?: string): YamlConfig => {
configPath = configPath ?? defaultPath

const config = yaml.safeLoad(fs.readFileSync(configPath, 'utf8'))
config.configDir = path.dirname(path.resolve(configPath))
if (!config || typeof config !== "object") throw `Failed to load ${configPath} or config is not object`

if (process.env['CI_ANALYZER_DEBUG']) {
console.debug('Parsed config file:')
console.debug(JSON.stringify(config, null, 2))
}

return config as YamlConfig
return {
...config,
...{ configDir: path.dirname(path.resolve(configPath)) }
} as YamlConfig
}

0 comments on commit 1c41aae

Please sign in to comment.