@@ -103,13 +103,21 @@ export async function prepareConfig(
103
103
return config ;
104
104
}
105
105
106
+ function replaceConfigDirPlaceholder ( path : string , configDir : string ) {
107
+ return path . replace ( / \$ \{ c o n f i g D i r \} / g, configDir ) ;
108
+ }
109
+
106
110
/**
107
111
* loadConfig loads a config file from fs.
108
112
* @param {string } file file path to the config file that will be loaded.
109
113
* @param {IOutput } output the output instance to log error to.
110
114
* @returns {ITSConfig } a ITSConfig object
111
115
*/
112
- export const loadConfig = ( file : string , output : IOutput ) : ITSConfig => {
116
+ export const loadConfig = (
117
+ file : string ,
118
+ output : IOutput ,
119
+ baseConfigDir : string | null = null
120
+ ) : ITSConfig => {
113
121
if ( ! existsSync ( file ) ) {
114
122
output . error ( `File ${ file } not found` , true ) ;
115
123
}
@@ -129,15 +137,43 @@ export const loadConfig = (file: string, output: IOutput): ITSConfig => {
129
137
output . debug ( 'configDir' , configDir ) ;
130
138
const config : ITSConfig = { } ;
131
139
132
- if ( baseUrl ) config . baseUrl = baseUrl ;
140
+ if ( baseUrl ) {
141
+ if ( baseConfigDir !== null ) {
142
+ config . baseUrl = replaceConfigDirPlaceholder ( baseUrl , baseConfigDir ) ;
143
+ } else {
144
+ config . baseUrl = baseUrl ;
145
+ }
146
+ }
133
147
if ( outDir ) {
134
- config . outDir = isAbsolute ( outDir ) ? outDir : join ( configDir , outDir ) ;
148
+ let replacedOutDir = outDir ;
149
+ if ( baseConfigDir !== null ) {
150
+ replacedOutDir = replaceConfigDirPlaceholder ( outDir , baseConfigDir ) ;
151
+ }
152
+ config . outDir = isAbsolute ( replacedOutDir )
153
+ ? replacedOutDir
154
+ : join ( configDir , replacedOutDir ) ;
155
+ }
156
+ if ( paths ) {
157
+ if ( baseConfigDir !== null ) {
158
+ for ( const key in paths ) {
159
+ paths [ key ] = paths [ key ] . map ( ( path ) =>
160
+ replaceConfigDirPlaceholder ( path , baseConfigDir )
161
+ ) ;
162
+ }
163
+ }
164
+ config . paths = paths ;
135
165
}
136
- if ( paths ) config . paths = paths ;
137
166
if ( declarationDir ) {
138
- config . declarationDir = isAbsolute ( declarationDir )
139
- ? declarationDir
140
- : join ( configDir , declarationDir ) ;
167
+ let replacedDeclarationDir = declarationDir ;
168
+ if ( baseConfigDir !== null ) {
169
+ replacedDeclarationDir = replaceConfigDirPlaceholder (
170
+ declarationDir ,
171
+ baseConfigDir
172
+ ) ;
173
+ }
174
+ config . declarationDir = isAbsolute ( replacedDeclarationDir )
175
+ ? replacedDeclarationDir
176
+ : join ( configDir , replacedDeclarationDir ) ;
141
177
}
142
178
if ( TSCAliasConfig ?. replacers ) {
143
179
config . replacers = TSCAliasConfig . replacers ;
@@ -162,7 +198,7 @@ export const loadConfig = (file: string, output: IOutput): ITSConfig => {
162
198
...normalizeTsConfigExtendsOption ( ext , file ) . reduce < ITSConfig > (
163
199
( pre , ext ) => ( {
164
200
...pre ,
165
- ...loadConfig ( ext , output )
201
+ ...loadConfig ( ext , output , baseConfigDir ?? configDir )
166
202
} ) ,
167
203
{ }
168
204
) ,
0 commit comments