@@ -21,8 +21,6 @@ const reservedPatterns = args[1]
21
21
? args [ 1 ] . split ( '|' ) . map ( part => new RegExp ( part ) )
22
22
: [ ] ;
23
23
24
- let tsconfig = { } ;
25
-
26
24
function help ( ) {
27
25
console . error ( 'usage: ' ) ;
28
26
console . error (
@@ -36,24 +34,14 @@ if (!src.length) {
36
34
process . exit ( 1 ) ;
37
35
}
38
36
39
- if ( fs . existsSync ( 'tsconfig.json' ) ) {
40
- tsconfig = JSON . parse ( fs . readFileSync ( 'tsconfig.json' ) ) . compilerOptions ;
41
- // Map moduleResolution to the appropriate enum.
42
- switch ( tsconfig . moduleResolution ) {
43
- case 'node' :
44
- tsconfig . moduleResolution = ts . ModuleResolutionKind . NodeJs ;
45
- break ;
46
- case 'node16' :
47
- tsconfig . moduleResolution = ts . ModuleResolutionKind . Node16 ;
48
- break ;
49
- case 'nodenext' :
50
- tsconfig . moduleResolution = ts . ModuleResolutionKind . NodeNext ;
51
- break ;
52
- case 'classic' :
53
- tsconfig . moduleResolution = ts . ModuleResolutionKind . Classic ;
54
- break ;
55
- default :
56
- break ;
37
+ function getTsConfigCompilerOptions ( ) {
38
+ // Since extract-meta can be run on JavaScript sources, if trying to get the
39
+ // config doesn't work, we can fall back gracefully.
40
+ try {
41
+ const tsconfig = ts . getParsedCommandLineOfConfigFile ( 'tsconfig.json' , { esModuleInterop : true } , ts . sys ) ;
42
+ return tsconfig ?. options ?? { } ;
43
+ } catch {
44
+ return { } ;
57
45
}
58
46
}
59
47
@@ -204,7 +192,7 @@ function gatherComponents(sources, components = {}) {
204
192
return components ;
205
193
}
206
194
207
- const program = ts . createProgram ( filepaths , { ... tsconfig , esModuleInterop : true } ) ;
195
+ const program = ts . createProgram ( filepaths , getTsConfigCompilerOptions ( ) ) ;
208
196
const checker = program . getTypeChecker ( ) ;
209
197
210
198
const coerceValue = t => {
0 commit comments