Skip to content

Commit fa53530

Browse files
committed
Hoist compiler options
1 parent e0939b6 commit fa53530

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ function writeJson(fileName, object) {
1919
fs.writeFileSync(fileName, JSON.stringify(object, null, 2) + os.EOL);
2020
}
2121

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+
// This 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+
isolatedModules: { value: true, reason: 'implementation limitation' },
36+
noEmit: { value: true },
37+
jsx: { value: 'preserve', reason: 'JSX is compiled by Babel' },
38+
};
39+
2240
function verifyTypeScriptSetup() {
2341
if (!fs.existsSync(paths.appTsConfig)) {
2442
if (!paths.appIndexJs.match(/\.ts?$/)) {
@@ -82,23 +100,6 @@ function verifyTypeScriptSetup() {
82100
tsconfig.compilerOptions = {};
83101
}
84102

85-
const compilerOptions = {
86-
target: { suggested: 'es5' },
87-
allowJs: { suggested: true },
88-
skipLibCheck: { suggested: true },
89-
module: { value: 'esnext', reason: 'for import() and import/export' },
90-
moduleResolution: { value: 'node', reason: 'to match webpack resolution' },
91-
isolatedModules: { value: true, reason: 'implementation limitation' },
92-
noEmit: { value: true },
93-
jsx: { value: 'preserve', reason: 'JSX is compiled by Babel' },
94-
esModuleInterop: { value: true, reason: 'Babel compatibility' },
95-
allowSyntheticDefaultImports: {
96-
value: true,
97-
reason: 'Babel compatibility',
98-
},
99-
strict: { suggested: true },
100-
};
101-
102103
for (const option of Object.keys(compilerOptions)) {
103104
const { value, suggested, reason } = compilerOptions[option];
104105
if (suggested != null) {

0 commit comments

Comments
 (0)