@@ -14,6 +14,7 @@ const resolve = require('resolve');
1414const  path  =  require ( 'path' ) ; 
1515const  paths  =  require ( '../../config/paths' ) ; 
1616const  os  =  require ( 'os' ) ; 
17+ const  immer  =  require ( 'react-dev-utils/immer' ) . produce ; 
1718
1819function  writeJson ( fileName ,  object )  { 
1920  fs . writeFileSync ( fileName ,  JSON . stringify ( object ,  null ,  2 )  +  os . EOL ) ; 
@@ -103,10 +104,11 @@ function verifyTypeScriptSetup() {
103104  } ; 
104105
105106  const  messages  =  [ ] ; 
106-   let  tsconfig ; 
107-   let  parsedOptions ; 
107+   let  appTsConfig ; 
108+   let  parsedTsConfig ; 
109+   let  parsedCompilerOptions ; 
108110  try  { 
109-     const  {  config,  error }  =  ts . readConfigFile ( 
111+     const  {  config :  readTsConfig ,  error }  =  ts . readConfigFile ( 
110112      paths . appTsConfig , 
111113      ts . sys . readFile 
112114    ) ; 
@@ -115,22 +117,25 @@ function verifyTypeScriptSetup() {
115117      throw  error ; 
116118    } 
117119
118-     tsconfig  =  config ; 
120+     appTsConfig  =  readTsConfig ; 
119121
120122    // Get TS to parse and resolve any "extends" 
121123    // Calling this function also mutates the tsconfig above, 
122124    // 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-     ) ; 
125+     let  result ; 
126+     parsedTsConfig  =  immer ( readTsConfig ,  config  =>  { 
127+       result  =  ts . parseJsonConfigFileContent ( 
128+         config , 
129+         ts . sys , 
130+         path . dirname ( paths . appTsConfig ) 
131+       ) ; 
132+     } ) ; 
128133
129134    if  ( result . errors  &&  result . errors . length )  { 
130135      throw  result . errors [ 0 ] ; 
131136    } 
132137
133-     parsedOptions  =  result . options ; 
138+     parsedCompilerOptions  =  result . options ; 
134139  }  catch  ( _ )  { 
135140    console . error ( 
136141      chalk . red . bold ( 
@@ -142,8 +147,8 @@ function verifyTypeScriptSetup() {
142147    process . exit ( 1 ) ; 
143148  } 
144149
145-   if  ( tsconfig . compilerOptions  ==  null )  { 
146-     tsconfig . compilerOptions  =  { } ; 
150+   if  ( appTsConfig . compilerOptions  ==  null )  { 
151+     appTsConfig . compilerOptions  =  { } ; 
147152    firstTimeSetup  =  true ; 
148153  } 
149154
@@ -153,16 +158,16 @@ function verifyTypeScriptSetup() {
153158    const  valueToCheck  =  parsedValue  ===  undefined  ? value  : parsedValue ; 
154159
155160    if  ( suggested  !=  null )  { 
156-       if  ( parsedOptions [ option ]  ===  undefined )  { 
157-         tsconfig . compilerOptions [ option ]  =  suggested ; 
161+       if  ( parsedCompilerOptions [ option ]  ===  undefined )  { 
162+         appTsConfig . compilerOptions [ option ]  =  suggested ; 
158163        messages . push ( 
159164          `${ chalk . cyan ( 'compilerOptions.'  +  option ) } ${ chalk . bold (  
160165            'suggested'  
161166          ) }   value: ${ chalk . cyan . bold ( suggested ) } 
162167        ) ; 
163168      } 
164-     }  else  if  ( parsedOptions [ option ]  !==  valueToCheck )  { 
165-       tsconfig . compilerOptions [ option ]  =  value ; 
169+     }  else  if  ( parsedCompilerOptions [ option ]  !==  valueToCheck )  { 
170+       appTsConfig . compilerOptions [ option ]  =  value ; 
166171      messages . push ( 
167172        `${ chalk . cyan ( 'compilerOptions.'  +  option ) } ${ chalk . bold (  
168173          'must'  
@@ -173,14 +178,14 @@ function verifyTypeScriptSetup() {
173178  } 
174179
175180  // tsconfig will have the merged "include" and "exclude" by this point 
176-   if  ( tsconfig . include  ==  null )  { 
177-     tsconfig . include  =  [ 'src' ] ; 
181+   if  ( parsedTsConfig . include  ==  null )  { 
182+     appTsConfig . include  =  [ 'src' ] ; 
178183    messages . push ( 
179184      `${ chalk . cyan ( 'include' ) } ${ chalk . cyan . bold ( 'src' ) }  
180185    ) ; 
181186  } 
182-   if  ( tsconfig . exclude  ==  null )  { 
183-     tsconfig . exclude  =  [ '**/__tests__/**' ,  '**/?*test.*' ,  '**/?*spec.*' ] ; 
187+   if  ( parsedTsConfig . exclude  ==  null )  { 
188+     appTsConfig . exclude  =  [ '**/__tests__/**' ,  '**/?*test.*' ,  '**/?*spec.*' ] ; 
184189    messages . push ( `${ chalk . cyan ( 'exclude' ) }  ) ; 
185190  } 
186191
@@ -207,7 +212,7 @@ function verifyTypeScriptSetup() {
207212      } ) ; 
208213      console . warn ( ) ; 
209214    } 
210-     writeJson ( paths . appTsConfig ,  tsconfig ) ; 
215+     writeJson ( paths . appTsConfig ,  appTsConfig ) ; 
211216  } 
212217
213218  // Copy type declarations associated with this version of `react-scripts` 
0 commit comments