Skip to content

Commit 7ba343c

Browse files
authored
Check for TypeScript install in preflight (#5516)
* Check for TypeScript install in preflight * Remove unused import
1 parent c019942 commit 7ba343c

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

packages/react-scripts/scripts/build.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ process.on('unhandledRejection', err => {
2222
// Ensure environment variables are read.
2323
require('../config/env');
2424
// @remove-on-eject-begin
25-
// Do the preflight check (only happens before eject).
25+
// Do the preflight checks (only happens before eject).
2626
const verifyPackageTree = require('./utils/verifyPackageTree');
2727
if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
2828
verifyPackageTree();
2929
}
30+
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
31+
verifyTypeScriptSetup();
3032
// @remove-on-eject-end
3133

3234
const path = require('path');

packages/react-scripts/scripts/start.js

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const verifyPackageTree = require('./utils/verifyPackageTree');
2727
if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
2828
verifyPackageTree();
2929
}
30+
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
31+
verifyTypeScriptSetup();
3032
// @remove-on-eject-end
3133

3234
const fs = require('fs');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// @remove-file-on-eject
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
const chalk = require('chalk');
12+
const fs = require('fs');
13+
const resolve = require('resolve');
14+
const paths = require('../../config/paths');
15+
16+
function verifyTypeScriptSetup() {
17+
if (!fs.existsSync(paths.appTsConfig)) {
18+
return;
19+
}
20+
21+
const isYarn = fs.existsSync(paths.yarnLockFile);
22+
23+
// Ensure typescript is installed
24+
try {
25+
resolve.sync('typescript', {
26+
basedir: paths.appNodeModules,
27+
});
28+
} catch (_) {
29+
console.error(
30+
chalk.red(
31+
'We detected a',
32+
chalk.bold('tsconfig.json'),
33+
"in your package root but couldn't find an installation of",
34+
chalk.bold('typescript') + '.'
35+
)
36+
);
37+
console.error();
38+
console.error(
39+
chalk.bold(
40+
'Please install',
41+
chalk.cyan.bold('typescript'),
42+
'by running',
43+
chalk.cyan.bold(
44+
isYarn ? 'yarn add typescript' : 'npm install typescript'
45+
) + '.'
46+
)
47+
);
48+
console.error(
49+
'If you are not trying to use TypeScript, please remove the ' +
50+
chalk.cyan('tsconfig.json') +
51+
' file from your package root.'
52+
);
53+
console.error();
54+
process.exit(1);
55+
}
56+
}
57+
58+
module.exports = verifyTypeScriptSetup;

0 commit comments

Comments
 (0)