Commit 7fa3eb5 1 parent a0bf104 commit 7fa3eb5 Copy full SHA for 7fa3eb5
File tree 1 file changed +23
-2
lines changed
packages/react-scripts/scripts/utils
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -14,9 +14,23 @@ const resolve = require('resolve');
14
14
const path = require ( 'path' ) ;
15
15
const paths = require ( '../../config/paths' ) ;
16
16
const os = require ( 'os' ) ;
17
+ const semver = require ( 'semver' ) ;
17
18
const immer = require ( 'react-dev-utils/immer' ) . produce ;
18
19
const globby = require ( 'react-dev-utils/globby' ) . sync ;
19
20
21
+ const hasJsxRuntime = ( ( ) => {
22
+ if ( process . env . DISABLE_NEW_JSX_TRANSFORM === 'true' ) {
23
+ return false ;
24
+ }
25
+
26
+ try {
27
+ require . resolve ( 'react/jsx-runtime' , { paths : [ paths . appPath ] } ) ;
28
+ return true ;
29
+ } catch ( e ) {
30
+ return false ;
31
+ }
32
+ } ) ( ) ;
33
+
20
34
function writeJson ( fileName , object ) {
21
35
fs . writeFileSync (
22
36
fileName ,
@@ -132,8 +146,15 @@ function verifyTypeScriptSetup() {
132
146
isolatedModules : { value : true , reason : 'implementation limitation' } ,
133
147
noEmit : { value : true } ,
134
148
jsx : {
135
- parsedValue : ts . JsxEmit . React ,
136
- suggested : 'react' ,
149
+ parsedValue :
150
+ hasJsxRuntime && semver . gte ( ts . version , '4.1.0-beta' )
151
+ ? ts . JsxEmit . ReactJsx
152
+ : ts . JsxEmit . React ,
153
+ value :
154
+ hasJsxRuntime && semver . gte ( ts . version , '4.1.0-beta' )
155
+ ? 'react-jsx'
156
+ : 'react' ,
157
+ reason : 'to support the new JSX transform in React 17' ,
137
158
} ,
138
159
paths : { value : undefined , reason : 'aliased imports are not supported' } ,
139
160
} ;
You can’t perform that action at this time.
0 commit comments