Skip to content

Commit db7a6ec

Browse files
committed
feat(config): expose config loader APIs
1 parent a5dbe91 commit db7a6ec

7 files changed

Lines changed: 45 additions & 2 deletions

File tree

packages/rstack/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"types": "./dist/index.d.ts",
1919
"default": "./dist/index.js"
2020
},
21+
"./config": {
22+
"types": "./dist/configExports.d.ts",
23+
"default": "./dist/configExports.js"
24+
},
2125
"./app": {
2226
"types": "./dist/app.d.ts",
2327
"default": "./dist/app.js"

packages/rstack/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default defineConfig({
88
source: {
99
entry: {
1010
index: './src/index.ts',
11+
configExports: './src/configExports.ts',
1112
rsbuildConfig: './src/rsbuildConfig.ts',
1213
rslibConfig: './src/rslibConfig.ts',
1314
rslintConfig: './src/rslintConfig.ts',

packages/rstack/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export type Configs = {
2121
staged?: StagedConfig;
2222
};
2323

24-
type LoadedRstackConfig = {
24+
export type LoadedRstackConfig = {
2525
configs: Configs;
2626
filePath: string | null;
2727
dependencies: string[];
2828
};
2929

30-
type LoadRstackConfigOptions = {
30+
export type LoadRstackConfigOptions = {
3131
/**
3232
* The path to the Rstack config file, can be a relative or absolute path.
3333
* If `configFilePath` is not provided, the config path set by the CLI is used.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Public configuration APIs exposed through `rstack/config`. */
2+
export {
3+
loadRstackConfig,
4+
type Configs,
5+
type LoadedRstackConfig,
6+
type LoadRstackConfigOptions,
7+
} from './config.ts';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from 'rstack/test';
2+
3+
test('should expose only the config loader API from `rstack/config`', async () => {
4+
const config = await import('rstack/config');
5+
6+
expect(Object.keys(config)).toEqual(['loadRstackConfig']);
7+
});

packages/rstack/tests/types/resolution-bundler/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import 'rstack/test/importMeta';
44
import 'rstack/types';
55
import { define } from 'rstack';
66
import { createRsbuild, defineConfig as defineAppConfig } from 'rstack/app';
7+
import {
8+
loadRstackConfig,
9+
type Configs,
10+
type LoadedRstackConfig,
11+
type LoadRstackConfigOptions,
12+
} from 'rstack/config';
713
import { defineConfig as defineLibConfig } from 'rstack/lib';
814
import { js, ts } from 'rstack/lint';
915
import { expect as importedExpect, test as importedTest } from 'rstack/test';
1016

1117
const appConfig = defineAppConfig({});
1218
const libConfig = defineLibConfig({});
19+
const loadOptions: LoadRstackConfigOptions = { configFilePath: 'rstack.config.ts' };
20+
const loadedConfig: Promise<LoadedRstackConfig> = loadRstackConfig(loadOptions);
21+
const configs: Configs = {};
22+
23+
void loadedConfig;
24+
void configs;
1325

1426
createRsbuild({ config: appConfig });
1527
define.app(appConfig);

packages/rstack/tests/types/resolution-nodenext/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import 'rstack/test/importMeta';
44
import 'rstack/types';
55
import { define } from 'rstack';
66
import { createRsbuild, defineConfig as defineAppConfig } from 'rstack/app';
7+
import {
8+
loadRstackConfig,
9+
type Configs,
10+
type LoadedRstackConfig,
11+
type LoadRstackConfigOptions,
12+
} from 'rstack/config';
713
import { defineConfig as defineLibConfig } from 'rstack/lib';
814
import { js, ts } from 'rstack/lint';
915
import { expect as importedExpect, test as importedTest } from 'rstack/test';
1016

1117
const appConfig = defineAppConfig({});
1218
const libConfig = defineLibConfig({});
19+
const loadOptions: LoadRstackConfigOptions = { configFilePath: 'rstack.config.ts' };
20+
const loadedConfig: Promise<LoadedRstackConfig> = loadRstackConfig(loadOptions);
21+
const configs: Configs = {};
22+
23+
void loadedConfig;
24+
void configs;
1325

1426
createRsbuild({ config: appConfig });
1527
define.app(appConfig);

0 commit comments

Comments
 (0)