@@ -19,25 +19,6 @@ function writeJson(fileName, object) {
19
19
fs . writeFileSync ( fileName , JSON . stringify ( object , null , 2 ) + os . EOL ) ;
20
20
}
21
21
22
- const compilerOptions = {
23
- // These are suggested values and will be set when not present in the
24
- // tsconfig.json
25
- target : { suggested : 'es5' } ,
26
- allowJs : { suggested : true } ,
27
- skipLibCheck : { suggested : true } ,
28
- esModuleInterop : { suggested : true } ,
29
- allowSyntheticDefaultImports : { suggested : true } ,
30
- strict : { suggested : true } ,
31
-
32
- // These values are required and cannot be changed by the user
33
- module : { value : 'esnext' , reason : 'for import() and import/export' } ,
34
- moduleResolution : { value : 'node' , reason : 'to match webpack resolution' } ,
35
- resolveJsonModule : { value : true , reason : 'to match webpack loader' } ,
36
- isolatedModules : { value : true , reason : 'implementation limitation' } ,
37
- noEmit : { value : true } ,
38
- jsx : { value : 'preserve' , reason : 'JSX is compiled by Babel' } ,
39
- } ;
40
-
41
22
function verifyTypeScriptSetup ( ) {
42
23
let firstTimeSetup = false ;
43
24
@@ -86,8 +67,44 @@ function verifyTypeScriptSetup() {
86
67
process . exit ( 1 ) ;
87
68
}
88
69
70
+ const compilerOptions = {
71
+ // These are suggested values and will be set when not present in the
72
+ // tsconfig.json
73
+ // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent()
74
+ target : {
75
+ parsedValue : ts . ScriptTarget . ES5 ,
76
+ suggested : 'es5' ,
77
+ } ,
78
+ allowJs : { suggested : true } ,
79
+ skipLibCheck : { suggested : true } ,
80
+ esModuleInterop : { suggested : true } ,
81
+ allowSyntheticDefaultImports : { suggested : true } ,
82
+ strict : { suggested : true } ,
83
+
84
+ // These values are required and cannot be changed by the user
85
+ module : {
86
+ parsedValue : ts . ModuleKind . ESNext ,
87
+ value : 'esnext' ,
88
+ reason : 'for import() and import/export' ,
89
+ } ,
90
+ moduleResolution : {
91
+ parsedValue : ts . ModuleResolutionKind . NodeJs ,
92
+ value : 'node' ,
93
+ reason : 'to match webpack resolution' ,
94
+ } ,
95
+ resolveJsonModule : { value : true , reason : 'to match webpack loader' } ,
96
+ isolatedModules : { value : true , reason : 'implementation limitation' } ,
97
+ noEmit : { value : true } ,
98
+ jsx : {
99
+ parsedValue : ts . JsxEmit . Preserve ,
100
+ value : 'preserve' ,
101
+ reason : 'JSX is compiled by Babel' ,
102
+ } ,
103
+ } ;
104
+
89
105
const messages = [ ] ;
90
106
let tsconfig ;
107
+ let parsedOptions ;
91
108
try {
92
109
const { config, error } = ts . readConfigFile (
93
110
paths . appTsConfig ,
@@ -99,6 +116,21 @@ function verifyTypeScriptSetup() {
99
116
}
100
117
101
118
tsconfig = config ;
119
+
120
+ // Get TS to parse and resolve any "extends"
121
+ // Calling this function also mutates the tsconfig above,
122
+ // adding in "include" and "exclude", but the compilerOptions remain untouched
123
+ const result = ts . parseJsonConfigFileContent (
124
+ config ,
125
+ ts . sys ,
126
+ path . dirname ( paths . appTsConfig )
127
+ ) ;
128
+
129
+ if ( result . errors && result . errors . length ) {
130
+ throw result . errors [ 0 ] ;
131
+ }
132
+
133
+ parsedOptions = result . options ;
102
134
} catch ( _ ) {
103
135
console . error (
104
136
chalk . red . bold (
@@ -116,17 +148,20 @@ function verifyTypeScriptSetup() {
116
148
}
117
149
118
150
for ( const option of Object . keys ( compilerOptions ) ) {
119
- const { value, suggested, reason } = compilerOptions [ option ] ;
151
+ const { parsedValue, value, suggested, reason } = compilerOptions [ option ] ;
152
+
153
+ const valueToCheck = parsedValue === undefined ? value : parsedValue ;
154
+
120
155
if ( suggested != null ) {
121
- if ( tsconfig . compilerOptions [ option ] === undefined ) {
156
+ if ( parsedOptions [ option ] === undefined ) {
122
157
tsconfig . compilerOptions [ option ] = suggested ;
123
158
messages . push (
124
159
`${ chalk . cyan ( 'compilerOptions.' + option ) } to be ${ chalk . bold (
125
160
'suggested'
126
161
) } value: ${ chalk . cyan . bold ( suggested ) } (this can be changed)`
127
162
) ;
128
163
}
129
- } else if ( tsconfig . compilerOptions [ option ] !== value ) {
164
+ } else if ( parsedOptions [ option ] !== valueToCheck ) {
130
165
tsconfig . compilerOptions [ option ] = value ;
131
166
messages . push (
132
167
`${ chalk . cyan ( 'compilerOptions.' + option ) } ${ chalk . bold (
@@ -137,6 +172,7 @@ function verifyTypeScriptSetup() {
137
172
}
138
173
}
139
174
175
+ // tsconfig will have the merged "include" and "exclude" by this point
140
176
if ( tsconfig . include == null ) {
141
177
tsconfig . include = [ 'src' ] ;
142
178
messages . push (
0 commit comments