mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-01 12:42:50 +08:00
Check for TypeScript install in preflight (#5516)
* Check for TypeScript install in preflight * Remove unused import
This commit is contained in:
4
packages/react-scripts/scripts/build.js
vendored
4
packages/react-scripts/scripts/build.js
vendored
@@ -22,11 +22,13 @@ process.on('unhandledRejection', err => {
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
// @remove-on-eject-begin
|
||||
// Do the preflight check (only happens before eject).
|
||||
// Do the preflight checks (only happens before eject).
|
||||
const verifyPackageTree = require('./utils/verifyPackageTree');
|
||||
if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
|
||||
verifyPackageTree();
|
||||
}
|
||||
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
|
||||
verifyTypeScriptSetup();
|
||||
// @remove-on-eject-end
|
||||
|
||||
const path = require('path');
|
||||
|
||||
2
packages/react-scripts/scripts/start.js
vendored
2
packages/react-scripts/scripts/start.js
vendored
@@ -27,6 +27,8 @@ const verifyPackageTree = require('./utils/verifyPackageTree');
|
||||
if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
|
||||
verifyPackageTree();
|
||||
}
|
||||
const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
|
||||
verifyTypeScriptSetup();
|
||||
// @remove-on-eject-end
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
58
packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
vendored
Normal file
58
packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// @remove-file-on-eject
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
const resolve = require('resolve');
|
||||
const paths = require('../../config/paths');
|
||||
|
||||
function verifyTypeScriptSetup() {
|
||||
if (!fs.existsSync(paths.appTsConfig)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const isYarn = fs.existsSync(paths.yarnLockFile);
|
||||
|
||||
// Ensure typescript is installed
|
||||
try {
|
||||
resolve.sync('typescript', {
|
||||
basedir: paths.appNodeModules,
|
||||
});
|
||||
} catch (_) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
'We detected a',
|
||||
chalk.bold('tsconfig.json'),
|
||||
"in your package root but couldn't find an installation of",
|
||||
chalk.bold('typescript') + '.'
|
||||
)
|
||||
);
|
||||
console.error();
|
||||
console.error(
|
||||
chalk.bold(
|
||||
'Please install',
|
||||
chalk.cyan.bold('typescript'),
|
||||
'by running',
|
||||
chalk.cyan.bold(
|
||||
isYarn ? 'yarn add typescript' : 'npm install typescript'
|
||||
) + '.'
|
||||
)
|
||||
);
|
||||
console.error(
|
||||
'If you are not trying to use TypeScript, please remove the ' +
|
||||
chalk.cyan('tsconfig.json') +
|
||||
' file from your package root.'
|
||||
);
|
||||
console.error();
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = verifyTypeScriptSetup;
|
||||
Reference in New Issue
Block a user