diff --git a/packages/cli/src/commands/doctor/checkInstallation.ts b/packages/cli/src/commands/doctor/checkInstallation.ts index bb65d0d56..e896a00cb 100644 --- a/packages/cli/src/commands/doctor/checkInstallation.ts +++ b/packages/cli/src/commands/doctor/checkInstallation.ts @@ -6,13 +6,13 @@ export enum PACKAGE_MANAGERS { NPM = 'NPM', } -const checkSoftwareInstalled = async (command: string) => { +const isSoftwareNotInstalled = async (command: string): Promise => { try { await commandExists(command); return false; } catch (_ignored) { - return 'should be installed'; + return true; } }; @@ -22,14 +22,14 @@ const doesSoftwareNeedToBeFixed = ({ }: { version: string; versionRange: string; -}) => { +}): boolean => { const coercedVersion = semver.coerce(version); + return ( - (version === 'Not Found' || - coercedVersion === null || - !semver.satisfies(coercedVersion, versionRange)) && - `version ${versionRange} is required` + version === 'Not Found' || + coercedVersion === null || + !semver.satisfies(coercedVersion, versionRange) ); }; -export {checkSoftwareInstalled, doesSoftwareNeedToBeFixed}; +export {isSoftwareNotInstalled, doesSoftwareNeedToBeFixed}; diff --git a/packages/cli/src/commands/doctor/doctor.ts b/packages/cli/src/commands/doctor/doctor.ts index 8dec8f4fc..d8e818028 100644 --- a/packages/cli/src/commands/doctor/doctor.ts +++ b/packages/cli/src/commands/doctor/doctor.ts @@ -81,7 +81,7 @@ export default (async (_, __, options) => { return { label: healthcheck.label, needsToBeFixed: Boolean(needsToBeFixed), - description: String(needsToBeFixed), + description: healthcheck.description, runAutomaticFix: healthcheck.runAutomaticFix, isRequired, type: needsToBeFixed diff --git a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts index 37362ed54..a32bb2c42 100644 --- a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts +++ b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts @@ -14,14 +14,14 @@ describe('androidHomeEnvVariables', () => { jest.resetAllMocks(); }); - it('returns a message if no ANDROID_HOME is defined', async () => { + it('returns true if no ANDROID_HOME is defined', async () => { delete process.env.ANDROID_HOME; const environmentInfo = await getEnvironmentInfo(); const diagnostics = await androidHomeEnvVariables.getDiagnostics( environmentInfo, ); - expect(typeof diagnostics.needsToBeFixed).toBe('string'); + expect(diagnostics.needsToBeFixed).toBe(true); }); it('returns false if ANDROID_HOME is defined', async () => { diff --git a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts index cbb865060..823c88e23 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts @@ -23,7 +23,7 @@ const message = `Read more about how to set the ${label} at ${chalk.dim( export default { label, getDiagnostics: async () => ({ - needsToBeFixed: !process.env.ANDROID_HOME && message, + needsToBeFixed: !process.env.ANDROID_HOME, }), runAutomaticFix: async ({loader}: {loader: Ora}) => { loader.info(); diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts index 994d2a501..360ba32f4 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts @@ -7,12 +7,13 @@ import {EnvironmentInfo, HealthCheckInterface} from '../types'; export default { label: 'Android NDK', + description: 'required for building React Native from the source', getDiagnostics: async ({SDKs}: EnvironmentInfo) => { const androidSdk = SDKs['Android SDK']; return { needsToBeFixed: doesSoftwareNeedToBeFixed({ version: - androidSdk === 'Not Found' ? 'Not Found' : androidSdk['Android NDK'], + androidSdk === 'Not Found' ? androidSdk : androidSdk['Android NDK'], versionRange: versionRanges.ANDROID_NDK, }), }; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts index 7424995dd..a53b56487 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts @@ -11,6 +11,7 @@ const installMessage = `Read more about how to update Android SDK at ${chalk.dim export default { label: 'Android SDK', + description: 'required for building and installing your app on Android', getDiagnostics: async ({SDKs}) => { let sdks = SDKs['Android SDK']; @@ -48,12 +49,11 @@ export default { return { needsToBeFixed: - (sdks === 'Not Found' && installMessage) || - (sdks !== 'Not Found' && - doesSoftwareNeedToBeFixed({ - version: sdks['Build Tools'][0], - versionRange: versionRanges.ANDROID_SDK, - })), + sdks === 'Not Found' || + doesSoftwareNeedToBeFixed({ + version: sdks['Build Tools'][0], + versionRange: versionRanges.ANDROID_SDK, + }), }; }, runAutomaticFix: async ({loader, environmentInfo}) => { diff --git a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts index 9d50c1f31..a797848d0 100644 --- a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts +++ b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts @@ -1,7 +1,7 @@ import execa from 'execa'; import chalk from 'chalk'; import {logger} from '@react-native-community/cli-tools'; -import {checkSoftwareInstalled} from '../checkInstallation'; +import {isSoftwareNotInstalled} from '../checkInstallation'; import { promptCocoaPodsInstallationQuestion, runSudo, @@ -12,8 +12,9 @@ import {HealthCheckInterface} from '../types'; export default { label: 'CocoaPods', + description: 'required for installing iOS dependencies', getDiagnostics: async () => ({ - needsToBeFixed: await checkSoftwareInstalled('pod'), + needsToBeFixed: await isSoftwareNotInstalled('pod'), }), runAutomaticFix: async ({loader}) => { loader.stop(); diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts index 877fda56a..f90cc2ed8 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts @@ -3,7 +3,7 @@ import chalk from 'chalk'; // @ts-ignore untyped import inquirer from 'inquirer'; import {logger} from '@react-native-community/cli-tools'; -import {checkSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; +import {isSoftwareNotInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; import {packageManager} from './packageManagers'; import {logManualInstallation, removeMessage} from './common'; import {HealthCheckInterface} from '../types'; @@ -57,8 +57,10 @@ const installLibrary = async ({ export default { label, isRequired: false, + description: + 'required for installing your app on a physical device with the CLI', getDiagnostics: async () => ({ - needsToBeFixed: await checkSoftwareInstalled('ios-deploy'), + needsToBeFixed: await isSoftwareNotInstalled('ios-deploy'), }), runAutomaticFix: async ({loader}) => { loader.stop(); diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.ts b/packages/cli/src/commands/doctor/healthchecks/watchman.ts index c0a5f9cbf..64e898001 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.ts +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.ts @@ -7,6 +7,8 @@ const label = 'Watchman'; export default { label, + description: + 'used for watching changes in the filesystem when in development mode', getDiagnostics: async ({Binaries}) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Watchman.version, diff --git a/packages/cli/src/commands/doctor/healthchecks/xcode.ts b/packages/cli/src/commands/doctor/healthchecks/xcode.ts index 128632b0c..503a74490 100644 --- a/packages/cli/src/commands/doctor/healthchecks/xcode.ts +++ b/packages/cli/src/commands/doctor/healthchecks/xcode.ts @@ -5,6 +5,7 @@ import {HealthCheckInterface} from '../types'; export default { label: 'Xcode', + description: 'required for building and installing your app on iOS', getDiagnostics: async ({IDEs}) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: IDEs.Xcode.version.split('/')[0], diff --git a/packages/cli/src/commands/doctor/types.ts b/packages/cli/src/commands/doctor/types.ts index b710eaa17..e051cc52d 100644 --- a/packages/cli/src/commands/doctor/types.ts +++ b/packages/cli/src/commands/doctor/types.ts @@ -86,6 +86,7 @@ export type HealthCheckInterface = { label: string; visible?: boolean | void; isRequired?: boolean; + description?: string; getDiagnostics: ( environmentInfo: EnvironmentInfo, ) => Promise<{version?: string; needsToBeFixed: boolean | string}>; @@ -95,7 +96,7 @@ export type HealthCheckInterface = { export type HealthCheckResult = { label: string; needsToBeFixed: boolean; - description: string; + description: string | undefined; runAutomaticFix: RunAutomaticFix; isRequired: boolean; type?: string;