Skip to content

Commit 3e8b653

Browse files
authored
feat: normalize tsconfigPath in environment configuration (#5263)
1 parent b0844b4 commit 3e8b653

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

packages/core/src/createContext.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ export async function updateEnvironmentContext(
9898
context.environments ||= {};
9999

100100
for (const [index, [name, config]] of Object.entries(configs).entries()) {
101-
const tsconfigPath = config.source.tsconfigPath
102-
? getAbsolutePath(context.rootPath, config.source.tsconfigPath)
103-
: undefined;
104-
101+
const { tsconfigPath } = config.source;
105102
const browserslist = await getBrowserslistByEnvironment(
106103
context.rootPath,
107104
config,

packages/core/src/provider/initConfigs.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
updateContextByNormalizedConfig,
55
updateEnvironmentContext,
66
} from '../createContext';
7-
import { camelCase, color, pick } from '../helpers';
7+
import { camelCase, color, getAbsolutePath, pick } from '../helpers';
88
import { isDebug, logger } from '../logger';
99
import { mergeRsbuildConfig } from '../mergeConfig';
1010
import { initPlugins } from '../pluginManager';
@@ -160,6 +160,15 @@ const validateRsbuildConfig = (config: NormalizedConfig) => {
160160
}
161161
};
162162

163+
/**
164+
* Initialize the Rsbuild config
165+
* 1. Initialize the Rsbuild plugins
166+
* 2. Run all the `modifyRsbuildConfig` hooks
167+
* 3. Normalize the Rsbuild config, merge with the default config
168+
* 4. Initialize the configs for each environment
169+
* 5. Run all the `modifyEnvironmentConfig` hooks
170+
* 6. Validate the final Rsbuild config
171+
*/
163172
export async function initRsbuildConfig({
164173
context,
165174
pluginManager,
@@ -207,14 +216,26 @@ export async function initRsbuildConfig({
207216
name,
208217
);
209218

210-
environments[name] = {
219+
const normalizedEnvironmentConfig = {
211220
...environmentConfig,
212221
dev: {
213222
...environmentConfig.dev,
214223
...rsbuildSharedDev,
215224
},
216225
server,
217226
};
227+
228+
const { tsconfigPath } = normalizedEnvironmentConfig.source;
229+
230+
// Ensure the `tsconfigPath` is an absolute path
231+
if (tsconfigPath) {
232+
normalizedEnvironmentConfig.source.tsconfigPath = getAbsolutePath(
233+
context.rootPath,
234+
tsconfigPath,
235+
);
236+
}
237+
238+
environments[name] = normalizedEnvironmentConfig;
218239
}
219240

220241
context.normalizedConfig = {

0 commit comments

Comments
 (0)