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
1 change: 1 addition & 0 deletions packages/rstack/rstack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define.test(async () => {
// Temporary projects may contain files that match Rstest's test glob.
exclude: ['**/test-temp-*/**'],
extends: withRslibConfig(),
testTimeout: 30_000,
source: {
tsconfigPath: './tests/tsconfig.json',
},
Expand Down
29 changes: 27 additions & 2 deletions packages/rstack/src/rspressConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { WatchFiles } from '@rsbuild/core';
import type { UserConfig } from '@rspress/core';
import { loadRstackConfig, type Configs } from './config.ts';

Expand All @@ -13,6 +14,30 @@ const resolveRspressConfig = async (configs: Configs): Promise<UserConfig> => {
};

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

if (!filePath) {
return config;
}

const watchFiles = config.builderConfig?.dev?.watchFiles;
const watchConfig: WatchFiles = {
paths: [filePath, ...dependencies],
type: 'restart',
};

return {
...config,
builderConfig: {
...config.builderConfig,
dev: {
...config.builderConfig?.dev,
watchFiles: [
...(watchFiles ? (Array.isArray(watchFiles) ? watchFiles : [watchFiles]) : []),
watchConfig,
],
},
},
};
};
2 changes: 1 addition & 1 deletion packages/rstack/tests/config/define-doc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ test('should build docs with define.doc config', async ({ prepareDist, execCli,
const output = getFileContent(files, 'index.html');

expect(output).toContain(expectedText);
}, 30_000);
});
4 changes: 2 additions & 2 deletions packages/rstack/tests/config/reload-app-config/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ define.app({
);

await waitForFile(dist2);
}, 30_000);
});

test('should reload config when an imported file changes', async ({ execCliAsync, logHelper }) => {
const configFile = path.join(import.meta.dirname, 'test-temp-import.config.ts');
Expand All @@ -70,4 +70,4 @@ define.app({
await writeFile(importedFile, '// changed\n');

await logHelper.expectLog('restarting server as test-temp-imported.ts changed');
}, 30_000);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Reload doc config
80 changes: 80 additions & 0 deletions packages/rstack/tests/config/reload-doc-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import { getRandomPort } from '@rstackjs/test-utils';
import { test } from '#test-helpers';

test('should restart doc dev server when Rstack config changes', async ({
execCliAsync,
logHelper,
}) => {
const configFile = path.join(import.meta.dirname, 'test-temp-rstack.config.ts');
const userWatchFile = path.join(import.meta.dirname, 'test-temp-user-watch.txt');

const writeConfig = (title: string) =>
writeFile(
configFile,
`import { define } from 'rstack';

define.doc({
root: 'docs',
title: '${title}',
builderConfig: {
dev: {
watchFiles: {
paths: ${JSON.stringify(userWatchFile)},
type: 'restart',
},
},
},
});
`,
);

await writeFile(userWatchFile, 'initial\n');
await writeConfig('before config change');

execCliAsync(`doc --config test-temp-rstack.config.ts --port ${await getRandomPort()}`);
await logHelper.expectBuildEnd();
logHelper.clearLogs();

await writeConfig('after config change');

await logHelper.expectLog('restarting server as test-temp-rstack.config.ts changed');
await logHelper.expectBuildEnd();
logHelper.clearLogs();

await writeFile(userWatchFile, 'changed\n');

await logHelper.expectLog('restarting server as test-temp-user-watch.txt changed');
await logHelper.expectBuildEnd();
});

test('should restart doc dev server when an imported config file changes', async ({
execCliAsync,
logHelper,
}) => {
const configFile = path.join(import.meta.dirname, 'test-temp-import.config.ts');
const importedFile = path.join(import.meta.dirname, 'test-temp-imported.ts');

await writeFile(importedFile, "export const title = 'before import change';\n");
await writeFile(
configFile,
`import { define } from 'rstack';
import { title } from './test-temp-imported.ts';

define.doc({
root: 'docs',
title,
});
`,
);

execCliAsync(`doc --config test-temp-import.config.ts --port ${await getRandomPort()}`);
await logHelper.expectBuildEnd();
logHelper.clearLogs();

await writeFile(importedFile, "export const title = 'after import change';\n");

await logHelper.expectLog('restarting server as test-temp-imported.ts changed');
await logHelper.expectBuildEnd();
});