From be52b24cfba3ca11d5e6ab318a7094830589ed67 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sun, 21 Oct 2018 18:38:32 -0400 Subject: [PATCH 1/2] Check for TypeScript install in preflight --- packages/react-scripts/scripts/build.js | 4 +- packages/react-scripts/scripts/start.js | 2 + .../scripts/utils/verifyTypeScriptSetup.js | 59 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 955f1a0fb54..ccf35fc9229 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -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'); diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index db04d758efa..f48e12d371a 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -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'); diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js new file mode 100644 index 00000000000..16185ce53e5 --- /dev/null +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -0,0 +1,59 @@ +// @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 path = require('path'); +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; From edb0f07043748f5ef6596cdc307d4a7c81804c84 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Sun, 21 Oct 2018 18:45:47 -0400 Subject: [PATCH 2/2] Remove unused import --- packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js index 16185ce53e5..4b16a0b5a48 100644 --- a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -10,7 +10,6 @@ const chalk = require('chalk'); const fs = require('fs'); -const path = require('path'); const resolve = require('resolve'); const paths = require('../../config/paths');