diff --git a/packages/cli/src/commands/doctor/doctor.js b/packages/cli/src/commands/doctor/doctor.js index f310f8cac..dfc11c47b 100644 --- a/packages/cli/src/commands/doctor/doctor.js +++ b/packages/cli/src/commands/doctor/doctor.js @@ -2,6 +2,7 @@ import chalk from 'chalk'; import envinfo from 'envinfo'; import {logger} from '@react-native-community/cli-tools'; +// $FlowFixMe - converted to TS import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks'; // $FlowFixMe - converted to TS import {getLoader} from '../../tools/loader'; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts index fe5de0bc9..994d2a501 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts @@ -7,12 +7,16 @@ import {EnvironmentInfo, HealthCheckInterface} from '../types'; export default { label: 'Android NDK', - getDiagnostics: async ({SDKs}: EnvironmentInfo) => ({ - needsToBeFixed: doesSoftwareNeedToBeFixed({ - version: SDKs['Android SDK']['Android NDK'], - versionRange: versionRanges.ANDROID_NDK, - }), - }), + getDiagnostics: async ({SDKs}: EnvironmentInfo) => { + const androidSdk = SDKs['Android SDK']; + return { + needsToBeFixed: doesSoftwareNeedToBeFixed({ + version: + androidSdk === 'Not Found' ? 'Not Found' : androidSdk['Android NDK'], + versionRange: versionRanges.ANDROID_NDK, + }), + }; + }, runAutomaticFix: async ({ loader, environmentInfo, @@ -20,8 +24,9 @@ export default { loader: Ora; environmentInfo: EnvironmentInfo; }) => { - const version = environmentInfo.SDKs['Android SDK']['Android NDK']; - const isNDKInstalled = version !== 'Not Found'; + const androidSdk = environmentInfo.SDKs['Android SDK']; + const isNDKInstalled = + androidSdk !== 'Not Found' && androidSdk['Android NDK'] !== 'Not Found'; loader.fail(); diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts similarity index 79% rename from packages/cli/src/commands/doctor/healthchecks/androidSDK.js rename to packages/cli/src/commands/doctor/healthchecks/androidSDK.ts index 947b3c9c9..7424995dd 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts @@ -1,22 +1,17 @@ -// @flow import chalk from 'chalk'; -import Ora from 'ora'; -// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; -// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; -// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import execa from 'execa'; -import type {EnvironmentInfo, HealthCheckInterface} from '../types'; +import {HealthCheckInterface} from '../types'; const installMessage = `Read more about how to update Android SDK at ${chalk.dim( 'https://developer.android.com/studio', )}`; -export default ({ +export default { label: 'Android SDK', - getDiagnostics: async ({SDKs}: EnvironmentInfo) => { + getDiagnostics: async ({SDKs}) => { let sdks = SDKs['Android SDK']; // This is a workaround for envinfo's Android SDK check not working on @@ -43,6 +38,9 @@ export default ({ if (matches.length > 0) { sdks = { 'Build Tools': matches, + 'API Levels': 'Not Found', + 'Android NDK': 'Not Found', + 'System Images': 'Not Found', }; } } catch {} @@ -58,14 +56,8 @@ export default ({ })), }; }, - runAutomaticFix: async ({ - loader, - environmentInfo, - }: { - loader: typeof Ora, - environmentInfo: EnvironmentInfo, - }) => { - const version = environmentInfo.SDKs['Android SDK'][0]; + runAutomaticFix: async ({loader, environmentInfo}) => { + const version = environmentInfo.SDKs['Android SDK']; const isSDKInstalled = version !== 'Not Found'; loader.fail(); @@ -81,4 +73,4 @@ export default ({ url: 'https://facebook.github.io/react-native/docs/getting-started', }); }, -}: HealthCheckInterface); +} as HealthCheckInterface; diff --git a/packages/cli/src/commands/doctor/healthchecks/index.js b/packages/cli/src/commands/doctor/healthchecks/index.ts similarity index 86% rename from packages/cli/src/commands/doctor/healthchecks/index.js rename to packages/cli/src/commands/doctor/healthchecks/index.ts index 9b94f942b..b439dfd2d 100644 --- a/packages/cli/src/commands/doctor/healthchecks/index.js +++ b/packages/cli/src/commands/doctor/healthchecks/index.ts @@ -1,14 +1,10 @@ -// @flow import nodeJS from './nodeJS'; import {yarn, npm} from './packageManagers'; import watchman from './watchman'; -// $FlowFixMe - converted to TS import androidHomeEnvVariable from './androidHomeEnvVariable'; import androidSDK from './androidSDK'; -// $FlowFixMe - converted to TS import androidNDK from './androidNDK'; import xcode from './xcode'; -// $FlowFixMe - converted to TS import cocoaPods from './cocoaPods'; import iosDeploy from './iosDeploy'; @@ -18,8 +14,8 @@ export const HEALTHCHECK_TYPES = { }; type Options = { - fix: boolean | void, - contributor: boolean | void, + fix: boolean | void; + contributor: boolean | void; }; export const getHealthchecks = ({contributor}: Options) => ({ diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts similarity index 84% rename from packages/cli/src/commands/doctor/healthchecks/iosDeploy.js rename to packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts index 90498b332..cfc2ddabf 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts @@ -1,12 +1,8 @@ -// @flow import execa from 'execa'; -import Ora from 'ora'; -// $FlowFixMe - converted to TS import {checkSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; import {packageManager} from './packageManagers'; -// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; -import type {HealthCheckInterface} from '../types'; +import {HealthCheckInterface} from '../types'; const getInstallationCommand = () => { if (packageManager === PACKAGE_MANAGERS.YARN) { @@ -20,13 +16,13 @@ const getInstallationCommand = () => { return undefined; }; -export default ({ +export default { label: 'ios-deploy', isRequired: false, getDiagnostics: async () => ({ needsToBeFixed: await checkSoftwareInstalled('ios-deploy'), }), - runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { + runAutomaticFix: async ({loader}) => { const installationCommand = getInstallationCommand(); // This means that we couldn't "guess" the package manager @@ -59,4 +55,4 @@ export default ({ }); } }, -}: HealthCheckInterface); +} as HealthCheckInterface; diff --git a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js b/packages/cli/src/commands/doctor/healthchecks/nodeJS.ts similarity index 57% rename from packages/cli/src/commands/doctor/healthchecks/nodeJS.js rename to packages/cli/src/commands/doctor/healthchecks/nodeJS.ts index ce0a4b91a..c7291b584 100644 --- a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js +++ b/packages/cli/src/commands/doctor/healthchecks/nodeJS.ts @@ -1,23 +1,18 @@ -// @flow -import Ora from 'ora'; -// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; -// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; -// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; -import type {EnvironmentInfo, HealthCheckInterface} from '../types'; +import {HealthCheckInterface} from '../types'; -export default ({ +export default { label: 'Node.js', - getDiagnostics: async ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}) => ({ version: Binaries.Node.version, needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Node.version, versionRange: versionRanges.NODE_JS, }), }), - runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { + runAutomaticFix: async ({loader}) => { loader.fail(); logManualInstallation({ @@ -25,4 +20,4 @@ export default ({ url: 'https://nodejs.org/en/download/', }); }, -}: HealthCheckInterface); +} as HealthCheckInterface; diff --git a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js b/packages/cli/src/commands/doctor/healthchecks/packageManagers.ts similarity index 70% rename from packages/cli/src/commands/doctor/healthchecks/packageManagers.js rename to packages/cli/src/commands/doctor/healthchecks/packageManagers.ts index f2e369b4b..f6ef8f389 100644 --- a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js +++ b/packages/cli/src/commands/doctor/healthchecks/packageManagers.ts @@ -1,16 +1,11 @@ -// @flow import fs from 'fs'; -import Ora from 'ora'; -// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; import { PACKAGE_MANAGERS, doesSoftwareNeedToBeFixed, - // $FlowFixMe - converted to TS } from '../checkInstallation'; -// $FlowFixMe - converted to TS import {install} from '../../../tools/install'; -import type {EnvironmentInfo, HealthCheckInterface} from '../types'; +import {HealthCheckInterface} from '../types'; const packageManager = (() => { if (fs.existsSync('yarn.lock')) { @@ -26,7 +21,7 @@ const packageManager = (() => { const yarn: HealthCheckInterface = { label: 'yarn', - getDiagnostics: async ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}) => ({ version: Binaries.Node.version, needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Yarn.version, @@ -37,13 +32,18 @@ const yarn: HealthCheckInterface = { // or if we can't identify that the user uses yarn or npm visible: packageManager === PACKAGE_MANAGERS.YARN || packageManager === undefined, - runAutomaticFix: async ({loader}: typeof Ora) => - await install('yarn', 'https://yarnpkg.com/docs/install', loader), + runAutomaticFix: async ({loader}) => + await install({ + pkg: 'yarn', + label: 'yarn', + source: 'https://yarnpkg.com/docs/install', + loader, + }), }; const npm: HealthCheckInterface = { label: 'npm', - getDiagnostics: async ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.npm.version, versionRange: versionRanges.NPM, @@ -53,8 +53,13 @@ const npm: HealthCheckInterface = { // or if we can't identify that the user uses yarn or npm visible: packageManager === PACKAGE_MANAGERS.NPM || packageManager === undefined, - runAutomaticFix: async ({loader}: typeof Ora) => - await install('node', 'https://nodejs.org/', loader), + runAutomaticFix: async ({loader}) => + await install({ + pkg: 'node', + label: 'node', + source: 'https://nodejs.org/', + loader, + }), }; export {packageManager, yarn, npm}; diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.js b/packages/cli/src/commands/doctor/healthchecks/watchman.ts similarity index 64% rename from packages/cli/src/commands/doctor/healthchecks/watchman.js rename to packages/cli/src/commands/doctor/healthchecks/watchman.ts index 4706b6746..c0a5f9cbf 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.js +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.ts @@ -1,28 +1,23 @@ -// @flow -import Ora from 'ora'; -// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; -// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; -// $FlowFixMe - converted to TS import {install} from '../../../tools/install'; -import type {EnvironmentInfo} from '../types'; +import {HealthCheckInterface} from '../types'; const label = 'Watchman'; export default { label, - getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Watchman.version, versionRange: versionRanges.WATCHMAN, }), }), - runAutomaticFix: async ({loader}: typeof Ora) => + runAutomaticFix: async ({loader}) => await install({ pkg: 'watchman', label, source: 'https://facebook.github.io/watchman/docs/install.html', loader, }), -}; +} as HealthCheckInterface; diff --git a/packages/cli/src/commands/doctor/healthchecks/xcode.js b/packages/cli/src/commands/doctor/healthchecks/xcode.ts similarity index 56% rename from packages/cli/src/commands/doctor/healthchecks/xcode.js rename to packages/cli/src/commands/doctor/healthchecks/xcode.ts index dffd1e408..128632b0c 100644 --- a/packages/cli/src/commands/doctor/healthchecks/xcode.js +++ b/packages/cli/src/commands/doctor/healthchecks/xcode.ts @@ -1,22 +1,17 @@ -// @flow -import Ora from 'ora'; -// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; -// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; -// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; -import type {EnvironmentInfo, HealthCheckInterface} from '../types'; +import {HealthCheckInterface} from '../types'; -export default ({ +export default { label: 'Xcode', - getDiagnostics: async ({IDEs}: EnvironmentInfo) => ({ + getDiagnostics: async ({IDEs}) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: IDEs.Xcode.version.split('/')[0], versionRange: versionRanges.XCODE, }), }), - runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { + runAutomaticFix: async ({loader}) => { loader.info(); logManualInstallation({ @@ -24,4 +19,4 @@ export default ({ url: 'https://developer.apple.com/xcode/', }); }, -}: HealthCheckInterface); +} as HealthCheckInterface; diff --git a/packages/cli/src/commands/doctor/runAutomaticFix.js b/packages/cli/src/commands/doctor/runAutomaticFix.js index ac201526c..fbf14ad59 100644 --- a/packages/cli/src/commands/doctor/runAutomaticFix.js +++ b/packages/cli/src/commands/doctor/runAutomaticFix.js @@ -2,6 +2,7 @@ import chalk from 'chalk'; import ora from 'ora'; import {logger} from '@react-native-community/cli-tools'; +// $FlowFixMe - converted to TS import {HEALTHCHECK_TYPES} from './healthchecks'; import type {EnvironmentInfo} from './types'; diff --git a/packages/cli/src/commands/doctor/types.ts b/packages/cli/src/commands/doctor/types.ts index 3489827e0..07ed78a84 100644 --- a/packages/cli/src/commands/doctor/types.ts +++ b/packages/cli/src/commands/doctor/types.ts @@ -32,12 +32,14 @@ export type EnvironmentInfo = { 'iOS SDK': { Platforms: string[]; }; - 'Android SDK': { - 'API Levels': string[]; - 'Build Tools': string[]; - 'System Images': string[]; - 'Android NDK': string; - }; + 'Android SDK': + | { + 'API Levels': string[] | 'Not Found'; + 'Build Tools': string[] | 'Not Found'; + 'System Images': string[] | 'Not Found'; + 'Android NDK': string | 'Not Found'; + } + | 'Not Found'; }; IDEs: { 'Android Studio': string;