11import type { RsbuildConfigDefinition } from '@rsbuild/core' ;
2+ import type { ConfigParams as RslibConfigParams , RslibConfig } from '@rslib/core' ;
23import type { RstestConfigExport } from '@rstest/core' ;
34
4- export type ConfigType = 'app' | 'test' ;
5+ export type ConfigType = 'app' | 'lib' | ' test';
56
6- type Config = RsbuildConfigDefinition | RstestConfigExport ;
7+ export type RslibConfigDefinition =
8+ | RslibConfig
9+ | ( ( params : RslibConfigParams ) => RslibConfig | Promise < RslibConfig > ) ;
10+
11+ type Config = RsbuildConfigDefinition | RslibConfigDefinition | RstestConfigExport ;
712
813const registry = new Map < ConfigType , Config > ( ) ;
914
1015export function getConfig ( type : 'app' ) : RsbuildConfigDefinition | undefined ;
16+ export function getConfig ( type : 'lib' ) : RslibConfigDefinition | undefined ;
1117export function getConfig ( type : 'test' ) : RstestConfigExport | undefined ;
1218export function getConfig ( type : ConfigType ) : Config | undefined {
13- const result = registry . get ( type ) ;
14- return result ;
19+ return registry . get ( type ) ;
1520}
1621
1722export const clearConfig = ( ) => {
@@ -32,11 +37,17 @@ type Define = {
3237 * This config is used by the `rs dev`, `rs build`, and `rs preview` commands.
3338 */
3439 app : ( config : RsbuildConfigDefinition ) => void ;
40+ /**
41+ * Defines the Rslib config for libraries.
42+ *
43+ * This config is used by the `rs lib` command.
44+ */
45+ lib : ( config : RslibConfigDefinition ) => void ;
3546 /**
3647 * Defines the Rstest config for tests.
3748 *
38- * This config is used by the `rs test` command.
39- *
49+ * This config is used by the `rs test` command.
50+ *
4051 * If `define.app` is also used, Rstest automatically extends the app config unless
4152 * `extends` is set explicitly.
4253 */
@@ -45,5 +56,6 @@ type Define = {
4556
4657export const define : Define = {
4758 app : ( config ) => setConfig ( 'app' , config ) ,
59+ lib : ( config ) => setConfig ( 'lib' , config ) ,
4860 test : ( config ) => setConfig ( 'test' , config ) ,
4961} ;
0 commit comments