From 45c0074581f02f0b36c24a19896db87a06bbd627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Sep 2019 17:01:44 +0200 Subject: [PATCH 1/4] doctor: add types --- .flowconfig | 2 +- .../src/commands/doctor/checkInstallation.js | 11 +++- packages/cli/src/commands/doctor/doctor.js | 44 ++++++++++++- .../healthchecks/androidHomeEnvVariable.js | 4 +- .../doctor/healthchecks/androidNDK.js | 13 +++- .../doctor/healthchecks/androidSDK.js | 12 +++- .../commands/doctor/healthchecks/common.js | 13 +++- .../src/commands/doctor/healthchecks/index.js | 9 ++- .../commands/doctor/healthchecks/iosDeploy.js | 6 +- .../commands/doctor/healthchecks/nodeJS.js | 7 +- .../doctor/healthchecks/packageManagers.js | 6 +- .../commands/doctor/healthchecks/watchman.js | 4 +- .../src/commands/doctor/healthchecks/xcode.js | 7 +- .../src/commands/doctor/printFixOptions.js | 5 +- .../src/commands/doctor/runAutomaticFix.js | 10 +++ packages/cli/src/commands/doctor/types.js | 64 +++++++++++++++++++ .../cli/src/commands/doctor/versionRanges.js | 1 + 17 files changed, 194 insertions(+), 24 deletions(-) create mode 100644 packages/cli/src/commands/doctor/types.js diff --git a/.flowconfig b/.flowconfig index 0563c1419..028f9aaac 100644 --- a/.flowconfig +++ b/.flowconfig @@ -27,7 +27,7 @@ esproposal.export_star_as=enable esproposal.optional_chaining=enable esproposal.nullish_coalescing=enable module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' -module.name_mapper='types' -> '/types/index.js' +module.name_mapper='^types' -> '/types/index.js' suppress_type=$FlowIssue suppress_type=$FlowFixMe diff --git a/packages/cli/src/commands/doctor/checkInstallation.js b/packages/cli/src/commands/doctor/checkInstallation.js index 1a42a7f79..6a9647f96 100644 --- a/packages/cli/src/commands/doctor/checkInstallation.js +++ b/packages/cli/src/commands/doctor/checkInstallation.js @@ -1,3 +1,4 @@ +// @flow import semver from 'semver'; import commandExists from 'command-exists'; @@ -6,7 +7,7 @@ const PACKAGE_MANAGERS = { NPM: 'NPM', }; -const isSoftwareInstalled = async command => { +const isSoftwareInstalled = async (command: string) => { try { await commandExists(command); @@ -16,7 +17,13 @@ const isSoftwareInstalled = async command => { } }; -const doesSoftwareNeedToBeFixed = ({version, versionRange}) => +const doesSoftwareNeedToBeFixed = ({ + version, + versionRange, +}: { + version: string, + versionRange: string, +}) => version === 'Not Found' || !semver.satisfies(semver.coerce(version), versionRange); diff --git a/packages/cli/src/commands/doctor/doctor.js b/packages/cli/src/commands/doctor/doctor.js index 3cf14324e..0592dcfa5 100644 --- a/packages/cli/src/commands/doctor/doctor.js +++ b/packages/cli/src/commands/doctor/doctor.js @@ -1,10 +1,14 @@ +// @flow import chalk from 'chalk'; import envinfo from 'envinfo'; +import Ora from 'ora'; import {logger} from '@react-native-community/cli-tools'; import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks'; import {getLoader} from '../../tools/loader'; import printFixOptions, {KEYS} from './printFixOptions'; import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from './runAutomaticFix'; +import type {ConfigT} from 'types'; +import type {EnvironmentInfo} from './types'; const printCategory = ({label, key}) => { if (key > 0) { @@ -14,7 +18,15 @@ const printCategory = ({label, key}) => { logger.log(chalk.dim(label)); }; -const printIssue = ({label, needsToBeFixed, isRequired}) => { +const printIssue = ({ + label, + needsToBeFixed, + isRequired, +}: { + label: string, + needsToBeFixed: boolean, + isRequired: boolean, +}) => { const symbol = needsToBeFixed ? isRequired ? chalk.red('✖') @@ -29,7 +41,16 @@ const printOverallStats = ({errors, warnings}) => { logger.log(`${chalk.bold('Warnings:')} ${warnings}`); }; -export default (async function runDoctor(argv, ctx, options) { +type FlagsT = { + fix: boolean | void, + contributor: boolean | void, +}; + +export default (async function runDoctor( + argv: Array, + ctx: ConfigT, + options: FlagsT, +) { const Loader = getLoader(); const loader = new Loader(); @@ -48,7 +69,24 @@ export default (async function runDoctor(argv, ctx, options) { ), ); - const iterateOverHealthChecks = async ({label, healthchecks}) => ({ + const iterateOverHealthChecks = async ({ + label, + healthchecks, + }: { + label: string, + healthchecks: Array<{ + label: string, + visible: boolean, + isRequired: boolean, + getDiagnostics: ( + envInfor: EnvironmentInfo, + ) => {version: string, needsToBeFixed: boolean}, + getDiagnosticsAsync: ( + envInfor: EnvironmentInfo, + ) => Promise<{version: string, needsToBeFixed: boolean}>, + runAutomaticFix: (args: {loader: typeof Ora}) => Promise, + }>, + }) => ({ label, healthchecks: (await Promise.all( healthchecks.map(async healthcheck => { diff --git a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js index 92902223e..7572448de 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js @@ -1,4 +1,6 @@ +// @flow import chalk from 'chalk'; +import Ora from 'ora'; import {logManualInstallation} from './common'; // List of answers on how to set `ANDROID_HOME` for each platform @@ -15,7 +17,7 @@ export default { getDiagnostics: () => ({ needsToBeFixed: !process.env.ANDROID_HOME, }), - runAutomaticFix: async ({loader}) => { + runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { loader.info(); logManualInstallation({ diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.js b/packages/cli/src/commands/doctor/healthchecks/androidNDK.js index 0f07e58ea..848994597 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.js @@ -1,17 +1,26 @@ +// @flow import chalk from 'chalk'; +import Ora from 'ora'; import {logManualInstallation} from './common'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; +import type {EnvironmentInfo} from '../types'; export default { label: 'Android NDK', - getDiagnosticsAsync: async ({SDKs}) => ({ + getDiagnosticsAsync: async ({SDKs}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: SDKs['Android SDK']['Android NDK'], versionRange: versionRanges.ANDROID_NDK, }), }), - runAutomaticFix: async ({loader, environmentInfo}) => { + runAutomaticFix: async ({ + loader, + environmentInfo, + }: { + loader: typeof Ora, + environmentInfo: EnvironmentInfo, + }) => { const version = environmentInfo.SDKs['Android SDK']['Android NDK']; const isNDKInstalled = version !== 'Not Found'; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js b/packages/cli/src/commands/doctor/healthchecks/androidSDK.js index 7707a9d87..1faa8d3cb 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.js @@ -1,4 +1,6 @@ +// @flow import chalk from 'chalk'; +import Ora from 'ora'; import {logManualInstallation} from './common'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; @@ -10,7 +12,7 @@ const installMessage = `Read more about how to update Android SDK at ${chalk.dim export default { label: 'Android SDK', - getDiagnosticsAsync: async ({SDKs}) => { + getDiagnosticsAsync: async ({SDKs}: EnvironmentInfo) => { let sdks = SDKs['Android SDK']; // This is a workaround for envinfo's Android SDK check not working on @@ -48,7 +50,13 @@ export default { }), }; }, - runAutomaticFix: async ({loader, environmentInfo}) => { + runAutomaticFix: async ({ + loader, + environmentInfo, + }: { + loader: typeof Ora, + environmentInfo: EnvironmentInfo, + }) => { const version = environmentInfo.SDKs['Android SDK'][0]; const isNDKInstalled = version !== 'Not Found'; diff --git a/packages/cli/src/commands/doctor/healthchecks/common.js b/packages/cli/src/commands/doctor/healthchecks/common.js index cc48db2c5..1bce843c3 100644 --- a/packages/cli/src/commands/doctor/healthchecks/common.js +++ b/packages/cli/src/commands/doctor/healthchecks/common.js @@ -1,10 +1,21 @@ +// @flow import logger from '@react-native-community/cli-tools/build/logger'; import chalk from 'chalk'; // Space is necessary to keep correct ordering on screen const logMessage = message => logger.log(` ${message}`); -const logManualInstallation = ({healthcheck, url, command, message}) => { +const logManualInstallation = ({ + healthcheck = '', + url, + command, + message, +}: { + healthcheck?: string, + url?: string, + command?: string, + message?: string, +}) => { if (message) { return logMessage(message); } diff --git a/packages/cli/src/commands/doctor/healthchecks/index.js b/packages/cli/src/commands/doctor/healthchecks/index.js index 19d49a93f..c95ddf644 100644 --- a/packages/cli/src/commands/doctor/healthchecks/index.js +++ b/packages/cli/src/commands/doctor/healthchecks/index.js @@ -1,3 +1,4 @@ +// @flow import nodeJS from './nodeJS'; import {yarn, npm} from './packageManagers'; import watchman from './watchman'; @@ -13,7 +14,12 @@ export const HEALTHCHECK_TYPES = { WARNING: 'WARNING', }; -export const getHealthchecks = ({contributor}) => ({ +type Options = { + fix: boolean | void, + contributor: boolean | void, +}; + +export const getHealthchecks = ({contributor}: Options) => ({ common: { label: 'Common', healthchecks: [ @@ -25,7 +31,6 @@ export const getHealthchecks = ({contributor}) => ({ }, android: { label: 'Android', - // TODO: Android NDK should be shown only with a special flag healthchecks: [ androidHomeEnvVariable, androidSDK, diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js index 37bec8bb4..d4df9774b 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js @@ -1,4 +1,6 @@ +// @flow import execa from 'execa'; +import Ora from 'ora'; import {isSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; import {packageManager} from './packageManagers'; import {logManualInstallation} from './common'; @@ -21,7 +23,7 @@ export default { getDiagnosticsAsync: async () => ({ needsToBeFixed: !(await isSoftwareInstalled('ios-deploy')), }), - runAutomaticFix: async ({loader}) => { + runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { const installationCommand = getInstallationCommand(); // This means that we couldn't "guess" the package manager @@ -36,7 +38,7 @@ export default { } try { - const installationCommandArgs = installationCommand.split(' '); + const installationCommandArgs = (installationCommand || '').split(' '); await execa( installationCommandArgs[0], diff --git a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js b/packages/cli/src/commands/doctor/healthchecks/nodeJS.js index bae6bc910..562ed3d15 100644 --- a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js +++ b/packages/cli/src/commands/doctor/healthchecks/nodeJS.js @@ -1,17 +1,20 @@ +// @flow +import Ora from 'ora'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import {logManualInstallation} from './common'; +import type {EnvironmentInfo} from '../types'; export default { label: 'Node.js', - getDiagnostics: ({Binaries}) => ({ + getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ version: Binaries.Node.version, needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Node.version, versionRange: versionRanges.NODE_JS, }), }), - runAutomaticFix: async ({loader}) => { + runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { loader.fail(); logManualInstallation({ diff --git a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js index d14a917b3..5ed9a2b26 100644 --- a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js +++ b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js @@ -1,3 +1,4 @@ +// @flow import fs from 'fs'; import versionRanges from '../versionRanges'; import { @@ -5,6 +6,7 @@ import { doesSoftwareNeedToBeFixed, } from '../checkInstallation'; import {install} from '../../../tools/install'; +import type {EnvironmentInfo} from '../types'; const packageManager = (() => { if (fs.existsSync('yarn.lock')) { @@ -20,7 +22,7 @@ const packageManager = (() => { const yarn = { label: 'yarn', - getDiagnostics: ({Binaries}) => ({ + getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ version: Binaries.Node.version, needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Yarn.version, @@ -37,7 +39,7 @@ const yarn = { const npm = { label: 'npm', - getDiagnostics: ({Binaries}) => ({ + getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.npm.version, versionRange: versionRanges.NPM, diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.js b/packages/cli/src/commands/doctor/healthchecks/watchman.js index e32967b99..d4857577b 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.js +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.js @@ -1,10 +1,12 @@ +// @flow import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import {install} from '../../../tools/install'; +import type {EnvironmentInfo} from '../types'; export default { label: 'Watchman', - getDiagnostics: ({Binaries}) => ({ + getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Watchman.version, versionRange: versionRanges.WATCHMAN, diff --git a/packages/cli/src/commands/doctor/healthchecks/xcode.js b/packages/cli/src/commands/doctor/healthchecks/xcode.js index c16900886..0cd01ded7 100644 --- a/packages/cli/src/commands/doctor/healthchecks/xcode.js +++ b/packages/cli/src/commands/doctor/healthchecks/xcode.js @@ -1,16 +1,19 @@ +// @flow +import Ora from 'ora'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import {logManualInstallation} from './common'; +import type {EnvironmentInfo} from '../types'; export default { label: 'Xcode', - getDiagnostics: ({IDEs}) => ({ + getDiagnostics: ({IDEs}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: IDEs.Xcode.version.split('/')[0], versionRange: versionRanges.XCODE, }), }), - runAutomaticFix: ({loader}) => { + runAutomaticFix: ({loader}: {loader: typeof Ora}) => { loader.info(); logManualInstallation({ diff --git a/packages/cli/src/commands/doctor/printFixOptions.js b/packages/cli/src/commands/doctor/printFixOptions.js index ecd589d7b..9134f8c0f 100644 --- a/packages/cli/src/commands/doctor/printFixOptions.js +++ b/packages/cli/src/commands/doctor/printFixOptions.js @@ -1,5 +1,7 @@ +// @flow import chalk from 'chalk'; import {logger} from '@react-native-community/cli-tools'; + const KEYS = { FIX_ALL_ISSUES: 'f', FIX_ERRORS: 'e', @@ -28,9 +30,10 @@ const printOptions = () => { }; export {KEYS}; -export default ({onKeyPress}) => { +export default ({onKeyPress}: {onKeyPress: any}) => { printOptions(); + // $FlowFixMe process.stdin.setRawMode(true); process.stdin.resume(); process.stdin.setEncoding('utf8'); diff --git a/packages/cli/src/commands/doctor/runAutomaticFix.js b/packages/cli/src/commands/doctor/runAutomaticFix.js index e16731ae2..561f054a1 100644 --- a/packages/cli/src/commands/doctor/runAutomaticFix.js +++ b/packages/cli/src/commands/doctor/runAutomaticFix.js @@ -1,7 +1,9 @@ +// @flow import chalk from 'chalk'; import ora from 'ora'; import logger from '../../tools/logger'; import {HEALTHCHECK_TYPES} from './healthchecks'; +import type {EnvironmentInfo} from './types'; const AUTOMATIC_FIX_LEVELS = { ALL_ISSUES: 'ALL_ISSUES', @@ -16,9 +18,17 @@ export default async ({ stats, loader, environmentInfo, +}:{ + healthchecks: any, + automaticFixLevel: $Values, + stats:{errors: any, warnings: any}, + loader: typeof ora, + environmentInfo: EnvironmentInfo, }) => { // Remove the fix options from screen + // $FlowFixMe process.stdout.moveCursor(0, -6); + // $FlowFixMe process.stdout.clearScreenDown(); const totalIssuesBasedOnFixLevel = { diff --git a/packages/cli/src/commands/doctor/types.js b/packages/cli/src/commands/doctor/types.js new file mode 100644 index 000000000..9a58a8cd9 --- /dev/null +++ b/packages/cli/src/commands/doctor/types.js @@ -0,0 +1,64 @@ +// @flow +export type EnvironmentInfo = { + System: { + OS: string, + CPU: string, + Memory: string, + Shell: { + version: string, + path: string, + }, + }, + Binaries: { + Node: { + version: string, + path: string, + }, + Yarn: { + version: string, + path: string, + }, + npm: { + version: string, + path: string, + }, + Watchman: { + version: string, + path: string, + }, + }, + SDKs: { + 'iOS SDK': { + Platforms: string[], + }, + 'Android SDK': { + 'API Levels': string[], + 'Build Tools': string[], + 'System Images': string[], + 'Android NDK': string, + }, + }, + IDEs: { + 'Android Studio': string, + Emacs: { + version: string, + path: string, + }, + Nano: { + version: string, + path: string, + }, + VSCode: { + version: string, + path: string, + }, + Vim: { + version: string, + path: string, + }, + Xcode: { + version: string, + path: string, + }, + }, +}; diff --git a/packages/cli/src/commands/doctor/versionRanges.js b/packages/cli/src/commands/doctor/versionRanges.js index d67496bd6..d1909f150 100644 --- a/packages/cli/src/commands/doctor/versionRanges.js +++ b/packages/cli/src/commands/doctor/versionRanges.js @@ -1,3 +1,4 @@ +// @flow export default { // Common NODE_JS: '>= 8.3', From 809bdfbca38c6f73aa136d3dd76378d25e873d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 9 Sep 2019 18:08:36 +0200 Subject: [PATCH 2/4] --amend --- packages/cli/src/commands/doctor/doctor.js | 26 ++++++------------- .../healthchecks/androidHomeEnvVariable.js | 7 ++--- .../doctor/healthchecks/androidNDK.js | 8 +++--- .../doctor/healthchecks/androidSDK.js | 21 +++++++++------ .../commands/doctor/healthchecks/cocoaPods.js | 8 +++--- .../commands/doctor/healthchecks/iosDeploy.js | 7 ++--- .../commands/doctor/healthchecks/nodeJS.js | 8 +++--- .../doctor/healthchecks/packageManagers.js | 15 ++++++----- .../commands/doctor/healthchecks/watchman.js | 3 ++- .../src/commands/doctor/healthchecks/xcode.js | 10 +++---- .../src/commands/doctor/runAutomaticFix.js | 4 +-- packages/cli/src/commands/doctor/types.js | 15 +++++++++++ 12 files changed, 74 insertions(+), 58 deletions(-) diff --git a/packages/cli/src/commands/doctor/doctor.js b/packages/cli/src/commands/doctor/doctor.js index 0592dcfa5..474bd6e43 100644 --- a/packages/cli/src/commands/doctor/doctor.js +++ b/packages/cli/src/commands/doctor/doctor.js @@ -1,14 +1,13 @@ // @flow import chalk from 'chalk'; import envinfo from 'envinfo'; -import Ora from 'ora'; import {logger} from '@react-native-community/cli-tools'; import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks'; import {getLoader} from '../../tools/loader'; import printFixOptions, {KEYS} from './printFixOptions'; import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from './runAutomaticFix'; import type {ConfigT} from 'types'; -import type {EnvironmentInfo} from './types'; +import type {HealthCheckInterface} from './types'; const printCategory = ({label, key}) => { if (key > 0) { @@ -74,18 +73,7 @@ export default (async function runDoctor( healthchecks, }: { label: string, - healthchecks: Array<{ - label: string, - visible: boolean, - isRequired: boolean, - getDiagnostics: ( - envInfor: EnvironmentInfo, - ) => {version: string, needsToBeFixed: boolean}, - getDiagnosticsAsync: ( - envInfor: EnvironmentInfo, - ) => Promise<{version: string, needsToBeFixed: boolean}>, - runAutomaticFix: (args: {loader: typeof Ora}) => Promise, - }>, + healthchecks: Array, }) => ({ label, healthchecks: (await Promise.all( @@ -94,9 +82,9 @@ export default (async function runDoctor( return; } - const {needsToBeFixed} = healthcheck.getDiagnostics - ? healthcheck.getDiagnostics(environmentInfo) - : await healthcheck.getDiagnosticsAsync(environmentInfo); + const {needsToBeFixed} = await healthcheck.getDiagnostics( + environmentInfo, + ); // Assume that it's required unless specified otherwise const isRequired = healthcheck.isRequired !== false; @@ -104,7 +92,7 @@ export default (async function runDoctor( return { label: healthcheck.label, - needsToBeFixed, + needsToBeFixed: Boolean(needsToBeFixed), runAutomaticFix: healthcheck.runAutomaticFix, isRequired, type: needsToBeFixed @@ -125,6 +113,7 @@ export default (async function runDoctor( ); const iterateOverCategories = categories => + // $FlowFixMe - bad Object.values typings Promise.all(categories.map(iterateOverHealthChecks)); const healthchecksPerCategory = await iterateOverCategories( @@ -167,6 +156,7 @@ export default (async function runDoctor( } const onKeyPress = async key => { + // $FlowFixMe process.stdin.setRawMode(false); process.stdin.removeAllListeners('data'); diff --git a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js index 7572448de..410b9855d 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js @@ -2,6 +2,7 @@ import chalk from 'chalk'; import Ora from 'ora'; import {logManualInstallation} from './common'; +import type {HealthCheckInterface} from '../types'; // List of answers on how to set `ANDROID_HOME` for each platform const URLS = { @@ -12,9 +13,9 @@ const URLS = { const label = 'ANDROID_HOME'; -export default { +export default ({ label, - getDiagnostics: () => ({ + getDiagnostics: async () => ({ needsToBeFixed: !process.env.ANDROID_HOME, }), runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { @@ -26,4 +27,4 @@ export default { )}.`, }); }, -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.js b/packages/cli/src/commands/doctor/healthchecks/androidNDK.js index 848994597..d3481e1fe 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.js @@ -4,11 +4,11 @@ import Ora from 'ora'; import {logManualInstallation} from './common'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; -import type {EnvironmentInfo} from '../types'; +import type {EnvironmentInfo, HealthCheckInterface} from '../types'; -export default { +export default ({ label: 'Android NDK', - getDiagnosticsAsync: async ({SDKs}: EnvironmentInfo) => ({ + getDiagnostics: async ({SDKs}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: SDKs['Android SDK']['Android NDK'], versionRange: versionRanges.ANDROID_NDK, @@ -39,4 +39,4 @@ export default { url: 'https://developer.android.com/ndk/downloads', }); }, -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js b/packages/cli/src/commands/doctor/healthchecks/androidSDK.js index 1faa8d3cb..c82e0eaf5 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.js @@ -5,14 +5,15 @@ import {logManualInstallation} from './common'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import execa from 'execa'; +import type {EnvironmentInfo, 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', - getDiagnosticsAsync: async ({SDKs}: EnvironmentInfo) => { + getDiagnostics: async ({SDKs}: EnvironmentInfo) => { let sdks = SDKs['Android SDK']; // This is a workaround for envinfo's Android SDK check not working on @@ -20,6 +21,7 @@ export default { // See the PR: https://github.com/tabrindle/envinfo/pull/119 if (sdks === 'Not Found' && process.platform !== 'darwin') { try { + // $FlowFixMe bad execa types const {stdout} = await execa( process.env.ANDROID_HOME ? `${process.env.ANDROID_HOME}/tools/bin/sdkmanager` @@ -31,7 +33,9 @@ export default { const regex = /build-tools;([\d|.]+)[\S\s]/g; let match = null; while ((match = regex.exec(stdout)) !== null) { - matches.push(match[1]); + if (match) { + matches.push(match[1]); + } } if (matches.length > 0) { sdks = { @@ -44,10 +48,11 @@ export default { return { needsToBeFixed: (sdks === 'Not Found' && installMessage) || - doesSoftwareNeedToBeFixed({ - version: sdks['Build Tools'][0], - versionRange: versionRanges.ANDROID_NDK, - }), + (sdks !== 'Not Found' && + doesSoftwareNeedToBeFixed({ + version: sdks['Build Tools'][0], + versionRange: versionRanges.ANDROID_NDK, + })), }; }, runAutomaticFix: async ({ @@ -73,4 +78,4 @@ export default { url: 'https://facebook.github.io/react-native/docs/getting-started', }); }, -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js index dd8597b99..5644278c6 100644 --- a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js +++ b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js @@ -1,10 +1,12 @@ +// @flow import {isSoftwareInstalled} from '../checkInstallation'; import {installCocoaPods} from '../../../tools/installPods'; +import {type HealthCheckInterface} from '../types'; -export default { +export default ({ label: 'CocoaPods', - getDiagnosticsAsync: async () => ({ + getDiagnostics: async () => ({ needsToBeFixed: !(await isSoftwareInstalled('pod')), }), runAutomaticFix: async ({loader}) => await installCocoaPods(loader), -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js index d4df9774b..7c104e240 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js @@ -4,6 +4,7 @@ import Ora from 'ora'; import {isSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; import {packageManager} from './packageManagers'; import {logManualInstallation} from './common'; +import type {HealthCheckInterface} from '../types'; const getInstallationCommand = () => { if (packageManager === PACKAGE_MANAGERS.YARN) { @@ -17,10 +18,10 @@ const getInstallationCommand = () => { return undefined; }; -export default { +export default ({ label: 'ios-deploy', isRequired: false, - getDiagnosticsAsync: async () => ({ + getDiagnostics: async () => ({ needsToBeFixed: !(await isSoftwareInstalled('ios-deploy')), }), runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { @@ -53,4 +54,4 @@ export default { }); } }, -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js b/packages/cli/src/commands/doctor/healthchecks/nodeJS.js index 562ed3d15..a4dfdd8eb 100644 --- a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js +++ b/packages/cli/src/commands/doctor/healthchecks/nodeJS.js @@ -3,11 +3,11 @@ import Ora from 'ora'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import {logManualInstallation} from './common'; -import type {EnvironmentInfo} from '../types'; +import type {EnvironmentInfo, HealthCheckInterface} from '../types'; -export default { +export default ({ label: 'Node.js', - getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}: EnvironmentInfo) => ({ version: Binaries.Node.version, needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Node.version, @@ -22,4 +22,4 @@ export default { url: 'https://nodejs.org/en/download/', }); }, -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js index 5ed9a2b26..92433c7ad 100644 --- a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js +++ b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js @@ -1,12 +1,13 @@ // @flow import fs from 'fs'; +import Ora from 'ora'; import versionRanges from '../versionRanges'; import { PACKAGE_MANAGERS, doesSoftwareNeedToBeFixed, } from '../checkInstallation'; import {install} from '../../../tools/install'; -import type {EnvironmentInfo} from '../types'; +import type {EnvironmentInfo, HealthCheckInterface} from '../types'; const packageManager = (() => { if (fs.existsSync('yarn.lock')) { @@ -20,9 +21,9 @@ const packageManager = (() => { return undefined; })(); -const yarn = { +const yarn: HealthCheckInterface = { label: 'yarn', - getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}: EnvironmentInfo) => ({ version: Binaries.Node.version, needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.Yarn.version, @@ -33,13 +34,13 @@ const yarn = { // or if we can't identify that the user uses yarn or npm visible: packageManager === PACKAGE_MANAGERS.YARN || packageManager === undefined, - runAutomaticFix: async ({loader}) => + runAutomaticFix: async ({loader}: typeof Ora) => await install('yarn', 'https://yarnpkg.com/docs/install', loader), }; -const npm = { +const npm: HealthCheckInterface = { label: 'npm', - getDiagnostics: ({Binaries}: EnvironmentInfo) => ({ + getDiagnostics: async ({Binaries}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: Binaries.npm.version, versionRange: versionRanges.NPM, @@ -49,7 +50,7 @@ const npm = { // or if we can't identify that the user uses yarn or npm visible: packageManager === PACKAGE_MANAGERS.NPM || packageManager === undefined, - runAutomaticFix: async ({loader}) => + runAutomaticFix: async ({loader}: typeof Ora) => await install('node', 'https://nodejs.org/', loader), }; diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.js b/packages/cli/src/commands/doctor/healthchecks/watchman.js index d4857577b..798708a78 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.js +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.js @@ -1,4 +1,5 @@ // @flow +import Ora from 'ora'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import {install} from '../../../tools/install'; @@ -12,7 +13,7 @@ export default { versionRange: versionRanges.WATCHMAN, }), }), - runAutomaticFix: async ({loader}) => + runAutomaticFix: async ({loader}: typeof Ora) => await install( 'watchman', 'https://facebook.github.io/watchman/docs/install.html', diff --git a/packages/cli/src/commands/doctor/healthchecks/xcode.js b/packages/cli/src/commands/doctor/healthchecks/xcode.js index 0cd01ded7..74ac04a7c 100644 --- a/packages/cli/src/commands/doctor/healthchecks/xcode.js +++ b/packages/cli/src/commands/doctor/healthchecks/xcode.js @@ -3,17 +3,17 @@ import Ora from 'ora'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import {logManualInstallation} from './common'; -import type {EnvironmentInfo} from '../types'; +import type {EnvironmentInfo, HealthCheckInterface} from '../types'; -export default { +export default ({ label: 'Xcode', - getDiagnostics: ({IDEs}: EnvironmentInfo) => ({ + getDiagnostics: async ({IDEs}: EnvironmentInfo) => ({ needsToBeFixed: doesSoftwareNeedToBeFixed({ version: IDEs.Xcode.version.split('/')[0], versionRange: versionRanges.XCODE, }), }), - runAutomaticFix: ({loader}: {loader: typeof Ora}) => { + runAutomaticFix: async ({loader}: {loader: typeof Ora}) => { loader.info(); logManualInstallation({ @@ -21,4 +21,4 @@ export default { url: 'https://developer.apple.com/xcode/', }); }, -}; +}: HealthCheckInterface); diff --git a/packages/cli/src/commands/doctor/runAutomaticFix.js b/packages/cli/src/commands/doctor/runAutomaticFix.js index 561f054a1..f954dd9b7 100644 --- a/packages/cli/src/commands/doctor/runAutomaticFix.js +++ b/packages/cli/src/commands/doctor/runAutomaticFix.js @@ -18,10 +18,10 @@ export default async ({ stats, loader, environmentInfo, -}:{ +}: { healthchecks: any, automaticFixLevel: $Values, - stats:{errors: any, warnings: any}, + stats: {errors: any, warnings: any}, loader: typeof ora, environmentInfo: EnvironmentInfo, }) => { diff --git a/packages/cli/src/commands/doctor/types.js b/packages/cli/src/commands/doctor/types.js index 9a58a8cd9..3793e8d9b 100644 --- a/packages/cli/src/commands/doctor/types.js +++ b/packages/cli/src/commands/doctor/types.js @@ -1,4 +1,6 @@ // @flow +import Ora from 'ora'; + export type EnvironmentInfo = { System: { OS: string, @@ -62,3 +64,16 @@ export type EnvironmentInfo = { }, }, }; + +export type HealthCheckInterface = { + label: string, + visible?: boolean | void, + isRequired?: boolean, + getDiagnostics: ( + environmentInfo: EnvironmentInfo, + ) => Promise<{version?: string, needsToBeFixed: boolean | string}>, + runAutomaticFix: (args: { + loader: typeof Ora, + environmentInfo: EnvironmentInfo, + }) => Promise | void, +}; From f9edd853912a3dbc3778d542bcd05c3bf53bcbb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 9 Sep 2019 18:15:58 +0200 Subject: [PATCH 3/4] --amend --- packages/cli/src/commands/doctor/healthchecks/iosDeploy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js index 7c104e240..b4a8e9aed 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js @@ -36,10 +36,11 @@ export default ({ healthcheck: 'ios-deploy', url: 'https://github.com/ios-control/ios-deploy#readme', }); + return; } try { - const installationCommandArgs = (installationCommand || '').split(' '); + const installationCommandArgs = installationCommand.split(' '); await execa( installationCommandArgs[0], From e80c03e489378e70e4a30ecb1cec6163ca7cf2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 9 Sep 2019 18:22:51 +0200 Subject: [PATCH 4/4] fix install cocoapods not awaiting results --- packages/cli/src/tools/installPods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/tools/installPods.js b/packages/cli/src/tools/installPods.js index b8f8853fe..6ce743dac 100644 --- a/packages/cli/src/tools/installPods.js +++ b/packages/cli/src/tools/installPods.js @@ -121,7 +121,7 @@ async function installPods({ await execa('pod', ['--version']); } catch (e) { loader.info(); - installCocoaPods(loader); + await installCocoaPods(loader); } if (shouldUpdatePods) {