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
37 changes: 20 additions & 17 deletions packages/rstack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,26 @@ export const define: Define = {

export const loadRstackConfig = async (): Promise<Configs> => {
const state = getConfigState();
state.configs = {};

await loadConfig({
loader: 'native',
exportName: false,
...(state.configPath !== undefined
? { path: state.configPath }
: {
configFileNames: [
'rstack.config.ts',
'rstack.config.js',
'rstack.config.mts',
'rstack.config.mjs',
],
}),
});
try {
await loadConfig({
loader: 'native',
exportName: false,
...(state.configPath !== undefined
? { path: state.configPath }
: {
configFileNames: [
'rstack.config.ts',
'rstack.config.js',
'rstack.config.mts',
'rstack.config.mjs',
],
}),
});

const result = state.configs;
state.configs = {};
return result;
return state.configs;
} finally {
state.configs = {};
}
};
17 changes: 17 additions & 0 deletions packages/rstack/test/config/load-state/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'node:path';
import { expect, test } from 'rstack/test';
import { getConfigState, loadRstackConfig } from '../../../src/config.ts';

test('should reset config state before and after loading', async () => {
const state = getConfigState();
state.configs = { app: {} };
state.configPath = path.join(import.meta.dirname, 'rstack.config.ts');

try {
await expect(loadRstackConfig()).rejects.toThrow('test config error');
expect(state.configs).toEqual({});
} finally {
state.configs = {};
delete state.configPath;
}
});
4 changes: 4 additions & 0 deletions packages/rstack/test/config/load-state/rstack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { define } from 'rstack';

define.app({});
throw new Error('test config error');