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
2 changes: 1 addition & 1 deletion .agents/skills/rstack-cli-best-practices/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Use `rs -h` for top-level help, and `rs <command> -h` for command help where sup

Key behavior:

- `rs test` extends `define.app` through `@rstest/adapter-rsbuild` and `define.lib` through `@rstest/adapter-rslib` unless `define.test` already sets `extends`.
- Unless `define.test` already sets `extends`, `rs test` extends `define.app` through `@rstest/adapter-rsbuild` or falls back to `define.lib` through `@rstest/adapter-rslib`. The app config takes precedence when both are defined.
- `rs doc` requires the optional `@rspress/core` dependency.

## rstack.config.ts
Expand Down
4 changes: 2 additions & 2 deletions packages/rstack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ type Define = {
*
* This config is used by the `rs test` command.
*
* If `define.app` is also used, Rstest automatically extends the app config unless
* `extends` is set explicitly.
* Unless `extends` is set explicitly, Rstest automatically extends `define.app` or
* falls back to `define.lib`. The app config takes precedence when both are defined.
*/
test: (config: RstestConfigExport) => void;
/**
Expand Down
20 changes: 14 additions & 6 deletions packages/rstack/src/rstestConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const extendsConfig = async (configs: Configs, testConfig: RstestConfig, params:
return testConfig;
}

// Prefer the app when both app and lib are defined. Merging both adapters can
// introduce conflicting runtime, resolve, and source transform settings.
const appConfig = configs.app;
if (appConfig) {
const { withRsbuildConfig } = await import(
Expand All @@ -15,9 +17,12 @@ const extendsConfig = async (configs: Configs, testConfig: RstestConfig, params:
);
const config = typeof appConfig === 'function' ? await appConfig(params) : appConfig;

testConfig.extends = withRsbuildConfig({
config,
});
return {
...testConfig,
extends: withRsbuildConfig({
config,
}),
};
}

const libConfig = configs.lib;
Expand All @@ -28,9 +33,12 @@ const extendsConfig = async (configs: Configs, testConfig: RstestConfig, params:
);
const config = typeof libConfig === 'function' ? await libConfig(params) : libConfig;

testConfig.extends = withRslibConfig({
config,
});
return {
...testConfig,
extends: withRslibConfig({
config,
}),
};
}

return testConfig;
Expand Down
7 changes: 7 additions & 0 deletions packages/rstack/test/config/define-app-lib/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from 'rstack/test';

declare const RSTACK_INHERITED_CONFIG: string;

test('inherits the app config', () => {
expect(RSTACK_INHERITED_CONFIG).toBe('app');
});
5 changes: 5 additions & 0 deletions packages/rstack/test/config/define-app-lib/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test } from '#test-helpers';

test('should prefer define.app when app and lib are both defined', ({ execCli }) => {
execCli('test');
});
22 changes: 22 additions & 0 deletions packages/rstack/test/config/define-app-lib/rstack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { define } from 'rstack';

define.app({
source: {
define: {
RSTACK_INHERITED_CONFIG: JSON.stringify('app'),
},
},
});

define.lib({
lib: [{}],
source: {
define: {
RSTACK_INHERITED_CONFIG: JSON.stringify('lib'),
},
},
});

define.test({
include: ['./fixture.ts'],
});