Skip to content

Commit

Permalink
support site config .extends being an array
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Oct 24, 2023
1 parent a31e143 commit 77a3499
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 11 additions & 3 deletions __tests__/e2e/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ const sidebar: DefaultTheme.Config['sidebar'] = {
}

export default defineConfig({
title: 'Example',
description: 'An example app using VitePress.',
extends: [
{
title: 'Example',
description: 'An example app using VitePress.'
},
{
themeConfig: {
sidebar
}
}
],
themeConfig: {
sidebar,
search: {
provider: 'local',
options: {
Expand Down
9 changes: 7 additions & 2 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ async function resolveConfigExtends(
): Promise<UserConfig> {
const resolved = await (typeof config === 'function' ? config() : config)
if (resolved.extends) {
const base = await resolveConfigExtends(resolved.extends)
return mergeConfig(base, resolved)
const extendsRaw = [resolved.extends].flat()
const manyBases = await Promise.all(
extendsRaw.map((config) => resolveConfigExtends(config))
)
// or reduceRight() depending on which side gets priority
const singleBase = manyBases.reduce((prev, curr) => mergeConfig(prev, curr))
return mergeConfig(singleBase, resolved)
}
return resolved
}
Expand Down
2 changes: 1 addition & 1 deletion src/node/siteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface TransformPageContext {

export interface UserConfig<ThemeConfig = any>
extends LocaleSpecificConfig<ThemeConfig> {
extends?: RawConfigExports<ThemeConfig>
extends?: RawConfigExports<ThemeConfig> | RawConfigExports<ThemeConfig>[]

base?: string
srcDir?: string
Expand Down

0 comments on commit 77a3499

Please sign in to comment.