@@ -53,6 +53,7 @@ import {
5353 calcLongestCommonPath ,
5454 checkMFPlugin ,
5555 color ,
56+ getAbsolutePath ,
5657 isEmptyObject ,
5758 isObject ,
5859 nodeBuiltInModules ,
@@ -1084,11 +1085,16 @@ const composeExternalHelpersConfig = (
10841085 return defaultConfig ;
10851086} ;
10861087
1087- async function composeLibRsbuildConfig ( config : LibConfig , root : string ) {
1088+ async function composeLibRsbuildConfig ( config : LibConfig ) {
10881089 checkMFPlugin ( config ) ;
1089- const pkgJson = readPackageJson ( root ) ;
1090+
1091+ // Get the absolute path of the root directory to align with Rsbuild's default behavior
1092+ const rootPath = config . root
1093+ ? getAbsolutePath ( process . cwd ( ) , config . root )
1094+ : process . cwd ( ) ;
1095+ const pkgJson = readPackageJson ( rootPath ) ;
10901096 const { compilerOptions } = await loadTsconfig (
1091- root ,
1097+ rootPath ,
10921098 config . source ?. tsconfigPath ,
10931099 ) ;
10941100 const cssModulesAuto = config . output ?. cssModules ?. auto ?? true ;
@@ -1147,7 +1153,7 @@ async function composeLibRsbuildConfig(config: LibConfig, root: string) {
11471153 const { entryConfig, lcp } = await composeEntryConfig (
11481154 config . source ?. entry ,
11491155 config . bundle ,
1150- root ,
1156+ rootPath ,
11511157 cssModulesAuto ,
11521158 ) ;
11531159 const cssConfig = composeCssConfig ( lcp , config . bundle ) ;
@@ -1191,7 +1197,6 @@ async function composeLibRsbuildConfig(config: LibConfig, root: string) {
11911197
11921198export async function composeCreateRsbuildConfig (
11931199 rslibConfig : RslibConfig ,
1194- root : string ,
11951200) : Promise < RsbuildConfigWithLibInfo [ ] > {
11961201 const constantRsbuildConfig = await createConstantRsbuildConfig ( ) ;
11971202 const { lib : libConfigsArray , ...sharedRsbuildConfig } = rslibConfig ;
@@ -1210,7 +1215,7 @@ export async function composeCreateRsbuildConfig(
12101215
12111216 // Merge the configuration of each environment based on the shared Rsbuild
12121217 // configuration and Lib configuration in the settings.
1213- const libRsbuildConfig = await composeLibRsbuildConfig ( userConfig , root ) ;
1218+ const libRsbuildConfig = await composeLibRsbuildConfig ( userConfig ) ;
12141219
12151220 // Reset certain fields because they will be completely overridden by the upcoming merge.
12161221 // We don't want to retain them in the final configuration.
@@ -1266,12 +1271,9 @@ export async function composeCreateRsbuildConfig(
12661271
12671272export async function composeRsbuildEnvironments (
12681273 rslibConfig : RslibConfig ,
1269- root : string ,
12701274) : Promise < Record < string , EnvironmentConfig > > {
1271- const rsbuildConfigWithLibInfo = await composeCreateRsbuildConfig (
1272- rslibConfig ,
1273- root ,
1274- ) ;
1275+ const rsbuildConfigWithLibInfo =
1276+ await composeCreateRsbuildConfig ( rslibConfig ) ;
12751277
12761278 // User provided ids should take precedence over generated ids.
12771279 const usedIds = rsbuildConfigWithLibInfo
0 commit comments