Skip to content

Commit

Permalink
Check for TypeScript install in preflight (facebook#5516)
Browse files Browse the repository at this point in the history
* Check for TypeScript install in preflight

* Remove unused import
  • Loading branch information
Timer authored and nate770 committed Oct 30, 2018
1 parent b6796da commit 9b8a11e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions packages/react-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
58 changes: 58 additions & 0 deletions packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9b8a11e

Please sign in to comment.