@@ -29,28 +29,83 @@ for (const extension of extensions) {
29
29
}
30
30
}
31
31
32
+ function getUserProvidedConfigOverwrite ( ) : TypeScriptConfigOverwrite {
33
+ return config . configOverwrite || { } ;
34
+ }
35
+
36
+ function getImplicitConfigOverwrite ( ) : TypeScriptConfigOverwrite {
37
+ const baseCompilerOptionsOverwrite = {
38
+ skipLibCheck : true ,
39
+ sourceMap : false ,
40
+ inlineSourceMap : false ,
41
+ } ;
42
+
43
+ switch ( config . mode ) {
44
+ case 'write-dts' :
45
+ return {
46
+ compilerOptions : {
47
+ ...baseCompilerOptionsOverwrite ,
48
+ declaration : true ,
49
+ emitDeclarationOnly : true ,
50
+ noEmit : false ,
51
+ } ,
52
+ } ;
53
+ case 'write-tsbuildinfo' :
54
+ case 'write-references' :
55
+ return {
56
+ compilerOptions : {
57
+ ...baseCompilerOptionsOverwrite ,
58
+ declaration : true ,
59
+ emitDeclarationOnly : false ,
60
+ noEmit : false ,
61
+ } ,
62
+ } ;
63
+ }
64
+
65
+ return {
66
+ compilerOptions : baseCompilerOptionsOverwrite ,
67
+ } ;
68
+ }
69
+
70
+ function applyConfigOverwrite (
71
+ baseConfig : TypeScriptConfigOverwrite ,
72
+ ...overwriteConfigs : TypeScriptConfigOverwrite [ ]
73
+ ) : TypeScriptConfigOverwrite {
74
+ let config = baseConfig ;
75
+
76
+ for ( const overwriteConfig of overwriteConfigs ) {
77
+ config = {
78
+ ...( config || { } ) ,
79
+ ...( overwriteConfig || { } ) ,
80
+ compilerOptions : {
81
+ ...( config ?. compilerOptions || { } ) ,
82
+ ...( overwriteConfig ?. compilerOptions || { } ) ,
83
+ } ,
84
+ } ;
85
+ }
86
+
87
+ return config ;
88
+ }
89
+
32
90
export function parseConfig (
33
91
configFileName : string ,
34
- configFileContext : string ,
35
- configOverwriteJSON : TypeScriptConfigOverwrite = { }
92
+ configFileContext : string
36
93
) : ts . ParsedCommandLine {
37
94
const configFilePath = forwardSlash ( configFileName ) ;
38
- const parsedConfigFileJSON = typescript . readConfigFile (
95
+
96
+ const { config : baseConfig , error : readConfigError } = typescript . readConfigFile (
39
97
configFilePath ,
40
98
parseConfigFileHost . readFile
41
99
) ;
42
100
43
- const overwrittenConfigFileJSON = {
44
- ...( parsedConfigFileJSON . config || { } ) ,
45
- ...configOverwriteJSON ,
46
- compilerOptions : {
47
- ...( ( parsedConfigFileJSON . config || { } ) . compilerOptions || { } ) ,
48
- ...( configOverwriteJSON . compilerOptions || { } ) ,
49
- } ,
50
- } ;
101
+ const overwrittenConfig = applyConfigOverwrite (
102
+ baseConfig || { } ,
103
+ getImplicitConfigOverwrite ( ) ,
104
+ getUserProvidedConfigOverwrite ( )
105
+ ) ;
51
106
52
107
const parsedConfigFile = typescript . parseJsonConfigFileContent (
53
- overwrittenConfigFileJSON ,
108
+ overwrittenConfig ,
54
109
parseConfigFileHost ,
55
110
configFileContext
56
111
) ;
@@ -61,7 +116,7 @@ export function parseConfig(
61
116
...parsedConfigFile . options ,
62
117
configFilePath : configFilePath ,
63
118
} ,
64
- errors : parsedConfigFileJSON . error ? [ parsedConfigFileJSON . error ] : parsedConfigFile . errors ,
119
+ errors : readConfigError ? [ readConfigError ] : parsedConfigFile . errors ,
65
120
} ;
66
121
}
67
122
@@ -79,36 +134,8 @@ export function getParseConfigIssues(): Issue[] {
79
134
80
135
export function getParsedConfig ( force = false ) {
81
136
if ( ! parsedConfig || force ) {
82
- parseConfigDiagnostics = [ ] ;
83
-
84
- parsedConfig = parseConfig ( config . configFile , config . context , config . configOverwrite ) ;
85
-
86
- const configFilePath = forwardSlash ( config . configFile ) ;
87
- const parsedConfigFileJSON = typescript . readConfigFile (
88
- configFilePath ,
89
- parseConfigFileHost . readFile
90
- ) ;
91
- const overwrittenConfigFileJSON = {
92
- ...( parsedConfigFileJSON . config || { } ) ,
93
- ...config . configOverwrite ,
94
- compilerOptions : {
95
- ...( ( parsedConfigFileJSON . config || { } ) . compilerOptions || { } ) ,
96
- ...( config . configOverwrite . compilerOptions || { } ) ,
97
- } ,
98
- } ;
99
- parsedConfig = typescript . parseJsonConfigFileContent (
100
- overwrittenConfigFileJSON ,
101
- parseConfigFileHost ,
102
- config . context
103
- ) ;
104
- parsedConfig . options . configFilePath = configFilePath ;
105
- parsedConfig . errors = parsedConfigFileJSON . error
106
- ? [ parsedConfigFileJSON . error ]
107
- : parsedConfig . errors ;
108
-
109
- if ( parsedConfig . errors ) {
110
- parseConfigDiagnostics . push ( ...parsedConfig . errors ) ;
111
- }
137
+ parsedConfig = parseConfig ( config . configFile , config . context ) ;
138
+ parseConfigDiagnostics = parsedConfig . errors || [ ] ;
112
139
}
113
140
114
141
return parsedConfig ;
0 commit comments