1
1
const path = require ( 'path' ) ;
2
+ const semver = require ( 'semver' ) ;
2
3
3
4
4
5
/* ****************************************************************************************************************** *
@@ -9,24 +10,36 @@ function getTransformedFile(transformerKind) {
9
10
process . env . TSP_SKIP_CACHE = true ;
10
11
const tsInstance = require ( 'ts-patch/compiler' ) ;
11
12
12
- console . log ( 'TS version: ' , tsInstance . version ) ;
13
+ console . log ( ` 'TS version: ${ tsInstance . version } \nNode Version: ${ process . version . slice ( 1 ) } ` ) ;
13
14
14
15
const configPath = path . join ( __dirname , `tsconfig.${ transformerKind } .json` ) ;
15
16
const configText = tsInstance . sys . readFile ( configPath ) ;
16
- const configParseResult = tsInstance . parseConfigFileTextToJson ( configPath , configText ) ;
17
- const config = configParseResult . config ;
18
17
19
- config . compilerOptions . noEmit = false ;
20
- config . compilerOptions . skipLibCheck = true ;
21
- config . compilerOptions . outDir = 'dist' ;
18
+ /* Parse config */
19
+ let compilerOptions ;
20
+ if ( semver . lt ( tsInstance . version , '5.5.0' , { includePrerelease : false } ) ) {
21
+ const configParseResult = tsInstance . parseConfigFileTextToJson ( configPath , configText ) ;
22
+ compilerOptions = configParseResult . config . compilerOptions ;
23
+ } else {
24
+ const configSourceFile = tsInstance . createSourceFile ( configPath , configText , tsInstance . ScriptTarget . Latest ) ;
25
+ const configParseResult = tsInstance . parseJsonSourceFileConfigFileContent ( configSourceFile , tsInstance . sys , path . dirname ( configPath ) , undefined , configPath ) ;
26
+ compilerOptions = configParseResult . options ;
27
+ }
28
+
29
+ /* Overwrite options */
30
+ Object . assign ( compilerOptions , {
31
+ noEmit : false ,
32
+ skipLibCheck : true ,
33
+ outDir : 'dist' ,
34
+ } ) ;
22
35
23
36
const emittedFiles = new Map ( ) ;
24
37
25
38
const writeFile = ( fileName , content ) => emittedFiles . set ( fileName , content ) ;
26
39
27
40
const program = tsInstance . createProgram ( {
28
41
rootNames : [ path . join ( __dirname , 'src' , 'index.ts' ) ] ,
29
- options : config . compilerOptions ,
42
+ options : compilerOptions ,
30
43
} ) ;
31
44
32
45
program . emit ( undefined , writeFile ) ;
0 commit comments