|
| 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