Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/rstack/src/rspressConfig.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import type { WatchFiles } from '@rsbuild/core';
import type { UserConfig } from '@rspress/core';
import { loadRstackConfig, type Configs } from './config.ts';
import { resolveConfigLayers } from './configLayers.ts';

const resolveRspressConfig = async (configs: Configs): Promise<UserConfig> => {
const docConfig = configs.doc;
if (!docConfig) {
return {};
export const resolveRspressConfig = async (
layers: readonly Configs[],
): Promise<UserConfig> => {
const configs = await resolveConfigLayers(layers, 'doc');
if (configs.length <= 1) {
return configs[0] ?? {};
}
if (typeof docConfig === 'function') {
return docConfig();
}
return docConfig;

const { mergeDocConfig } = await import('@rspress/core');
return mergeDocConfig(...configs);
};

export default async (): Promise<UserConfig> => {
const { configs, filePath, dependencies } = await loadRstackConfig();
const config = await resolveRspressConfig(configs);
const config = await resolveRspressConfig([configs]);

if (!filePath) {
return config;
Expand Down
43 changes: 43 additions & 0 deletions packages/rstack/tests/config/doc-merge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, test } from 'rstack/test';
import { resolveRspressConfig } from '../../src/rspressConfig.ts';

test('merges doc layers using native Rspress rules', async () => {
const sharedRspack = () => ({ name: 'shared' });
const projectRspack = () => ({ name: 'project' });
const config = await resolveRspressConfig([
{
doc: {
title: 'Shared',
plugins: [{ name: 'shared-plugin' }],
builderConfig: {
source: { define: { SHARED: true, ENV: 'base' } },
dev: { watchFiles: [{ paths: ['./shared.md'] }] },
tools: { rspack: sharedRspack },
},
},
},
{
doc: {
title: 'Project',
plugins: [{ name: 'project-plugin' }],
builderConfig: {
source: { define: { ENV: 'production' } },
dev: { watchFiles: [{ paths: ['./project.md'] }] },
tools: { rspack: projectRspack },
},
},
},
]);

expect(config).toEqual({
title: 'Project',
plugins: [{ name: 'shared-plugin' }, { name: 'project-plugin' }],
builderConfig: {
source: { define: { SHARED: true, ENV: 'production' } },
dev: {
watchFiles: [{ paths: ['./shared.md'] }, { paths: ['./project.md'] }],
},
tools: { rspack: projectRspack },
},
});
});
Loading