Skip to content

Commit

Permalink
Also check react version before setting jsx value in tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Oct 23, 2020
1 parent dccc7fc commit ba0e466
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ const semver = require('semver');
const immer = require('react-dev-utils/immer').produce;
const globby = require('react-dev-utils/globby').sync;

const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve('react/jsx-runtime', { paths: [paths.appPath] });
return true;
} catch (e) {
return false;
}
})();

function writeJson(fileName, object) {
fs.writeFileSync(
fileName,
Expand Down Expand Up @@ -134,8 +147,11 @@ function verifyTypeScriptSetup() {
noEmit: { value: true },
jsx: {
parsedValue: ts.JsxEmit.React,
value: semver.gte(ts.version, '4.1.0-beta') ? 'react-jsx' : 'react',
reason: 'to support the new JSX transform in React 17'
value:
hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta')
? 'react-jsx'
: 'react',
reason: 'to support the new JSX transform in React 17',
},
paths: { value: undefined, reason: 'aliased imports are not supported' },
};
Expand Down

0 comments on commit ba0e466

Please sign in to comment.