1
1
import * as chalk from 'chalk' ;
2
+ import * as path from 'path' ;
2
3
import { fork } from 'child_process' ;
3
4
import * as chokidar from 'chokidar' ;
4
5
import { readFileSync } from 'fs' ;
@@ -53,7 +54,7 @@ export class SwcCompiler extends BaseCompiler {
53
54
if ( extras . typeCheck ) {
54
55
this . runTypeChecker ( configuration , tsConfigPath , appName , extras ) ;
55
56
}
56
- await this . runSwc ( swcOptions , extras , swcrcFilePath ) ;
57
+ await this . runSwc ( configuration , swcOptions , extras , swcrcFilePath ) ;
57
58
58
59
if ( onSuccess ) {
59
60
onSuccess ( ) ;
@@ -66,7 +67,7 @@ export class SwcCompiler extends BaseCompiler {
66
67
if ( extras . typeCheck ) {
67
68
await this . runTypeChecker ( configuration , tsConfigPath , appName , extras ) ;
68
69
}
69
- await this . runSwc ( swcOptions , extras , swcrcFilePath ) ;
70
+ await this . runSwc ( configuration , swcOptions , extras , swcrcFilePath ) ;
70
71
if ( onSuccess ) {
71
72
onSuccess ( ) ;
72
73
}
@@ -150,6 +151,7 @@ export class SwcCompiler extends BaseCompiler {
150
151
}
151
152
152
153
private async runSwc (
154
+ configuration : Required < Configuration > ,
153
155
options : ReturnType < typeof swcDefaultsFactory > ,
154
156
extras : SwcCompilerExtras ,
155
157
swcrcFilePath ?: string ,
@@ -162,6 +164,17 @@ export class SwcCompiler extends BaseCompiler {
162
164
const swcRcFile = await this . getSwcRcFileContentIfExists ( swcrcFilePath ) ;
163
165
const swcOptions = this . deepMerge ( options . swcOptions , swcRcFile ) ;
164
166
167
+ // jsc.baseUrl should be resolved by the caller, if it's passed as an object.
168
+ // https://github.com/swc-project/swc/pull/7827
169
+ if ( swcOptions ?. jsc ?. baseUrl ) {
170
+ if ( swcrcFilePath ) {
171
+ swcOptions . jsc . baseUrl = path . join ( path . dirname ( swcrcFilePath ) , swcOptions . jsc . baseUrl )
172
+ } else {
173
+ swcOptions . jsc . baseUrl = path . join ( path . dirname ( configuration . sourceRoot ) , swcOptions . jsc . baseUrl )
174
+ }
175
+
176
+ }
177
+
165
178
await swcCli . default ( {
166
179
...options ,
167
180
swcOptions,
@@ -178,7 +191,7 @@ export class SwcCompiler extends BaseCompiler {
178
191
} catch ( err ) {
179
192
console . error (
180
193
ERROR_PREFIX +
181
- ' Failed to load "@swc/cli" and "@swc/core" packages. Please, install them by running "npm i -D @swc/cli @swc/core".' ,
194
+ ' Failed to load "@swc/cli" and "@swc/core" packages. Please, install them by running "npm i -D @swc/cli @swc/core".' ,
182
195
) ;
183
196
process . exit ( 1 ) ;
184
197
}
@@ -193,7 +206,7 @@ export class SwcCompiler extends BaseCompiler {
193
206
if ( swcrcFilePath !== undefined ) {
194
207
console . error (
195
208
ERROR_PREFIX +
196
- ` Failed to load "${ swcrcFilePath } ". Please, check if the file exists and is valid JSON.` ,
209
+ ` Failed to load "${ swcrcFilePath } ". Please, check if the file exists and is valid JSON.` ,
197
210
) ;
198
211
process . exit ( 1 ) ;
199
212
}
0 commit comments