Skip to content

Commit

Permalink
feat: support function config
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and YunYouJun committed Aug 30, 2021
1 parent ffa266b commit 9556b57
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,22 @@ export async function resolveConfig(
return config
}

export async function resolveUserConfig(root: string) {
export async function resolveUserConfig(root: string): Promise<UserConfig> {
// load user config
const configPath = resolve(root, 'config.js')
const hasUserConfig = await fs.pathExists(configPath)
// always delete cache first before loading config
delete require.cache[configPath]
const userConfig: UserConfig = hasUserConfig ? require(configPath) : {}
const userConfig: UserConfig | (() => UserConfig) = hasUserConfig
? require(configPath)
: {}
if (hasUserConfig) {
debug(`loaded config at ${chalk.yellow(configPath)}`)
} else {
debug(`no config file found.`)
}

return userConfig
return typeof userConfig === 'function' ? userConfig() : userConfig
}

export async function resolveSiteData(
Expand Down

0 comments on commit 9556b57

Please sign in to comment.