1
1
import path from 'path' ;
2
2
import { convert } from 'tsconfig-to-swcconfig' ;
3
3
4
+ const DEFAULT_EXCLUDE = [ 'node_modules' ] ;
5
+
4
6
export const EXTENSIONS_TO_COMPILE = [ '.js' , '.ts' , '.mts' , '.mjs' , '.cjs' ] ;
5
7
6
8
function resolvePaths ( paths : Record < string , string [ ] > , baseUrl : string ) {
@@ -14,17 +16,41 @@ function resolvePaths(paths: Record<string, string[]>, baseUrl: string) {
14
16
return entries ;
15
17
}
16
18
17
- export function getSwcOptionsFromTsconfig ( projectPath : string , filename = 'tsconfig.json' ) {
19
+ export type GetSwcOptionsFromTsconfigOptions = {
20
+ projectPath : string ;
21
+ filename ?: string ;
22
+ additionalPaths ?: string [ ] ;
23
+ exclude ?: string | string [ ] ;
24
+ } ;
25
+
26
+ export function getSwcOptionsFromTsconfig ( {
27
+ projectPath,
28
+ filename = 'tsconfig.json' ,
29
+ additionalPaths,
30
+ exclude,
31
+ } : GetSwcOptionsFromTsconfigOptions ) {
18
32
const swcOptions = convert ( filename , projectPath ) ;
33
+ swcOptions . exclude = swcOptions . exclude || [ ] ;
19
34
swcOptions . jsc = {
20
35
...swcOptions . jsc ,
21
36
// SWC requires absolute path as baseUrl
22
37
baseUrl : projectPath ,
23
38
} ;
24
39
40
+ let customExclude : string [ ] = [ ] ;
41
+ if ( Array . isArray ( exclude ) ) {
42
+ customExclude = exclude ;
43
+ } else if ( exclude ) {
44
+ customExclude = [ exclude ] ;
45
+ }
46
+
47
+ swcOptions . exclude = [ ...( swcOptions . exclude || [ ] ) , ...DEFAULT_EXCLUDE , ...customExclude ] ;
48
+
25
49
// SWC don't compile referenced files like tsc, so we need collect all directories to compile.
26
50
const paths = swcOptions . jsc . paths || { } ;
27
- const directoriesToCompile = [ projectPath , ...resolvePaths ( paths , projectPath ) ] ;
51
+ const directoriesToCompile = [
52
+ ...new Set ( [ projectPath , ...resolvePaths ( paths , projectPath ) , ...( additionalPaths || [ ] ) ] ) ,
53
+ ] ;
28
54
29
55
return {
30
56
swcOptions,
0 commit comments