From ca2b99fdc435d3e22b36fe91a4916d0c0b12c38d Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Fri, 14 Jun 2024 06:55:56 -0700 Subject: [PATCH] Only perform watchman health check in development Summary: This healthcheck is only needed for metro / local development so running it in production builds is just noisy for the user Reviewed By: antonk52 Differential Revision: D58580890 fbshipit-source-id: 582844e475a0c8eb72dd493ebd0b2a37c0a16089 --- desktop/doctor/src/cli.tsx | 2 +- desktop/doctor/src/index.tsx | 42 ++++++++++++------- desktop/flipper-common/src/doctor.tsx | 1 + .../src/utils/runHealthchecks.tsx | 4 +- .../flipper-ui/src/utils/runHealthchecks.tsx | 9 +++- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/desktop/doctor/src/cli.tsx b/desktop/doctor/src/cli.tsx index 668b36a4fbc..dd1b1089776 100644 --- a/desktop/doctor/src/cli.tsx +++ b/desktop/doctor/src/cli.tsx @@ -13,7 +13,7 @@ import {getEnvInfo} from './environmentInfo'; (async () => { const environmentInfo = await getEnvInfo(); console.log(JSON.stringify(environmentInfo)); - const healthchecks = getHealthchecks(); + const healthchecks = getHealthchecks(false); const results = await Promise.all( Object.entries(healthchecks).map(async ([key, category]) => [ key, diff --git a/desktop/doctor/src/index.tsx b/desktop/doctor/src/index.tsx index 207153ada9b..660581a3dac 100644 --- a/desktop/doctor/src/index.tsx +++ b/desktop/doctor/src/index.tsx @@ -20,7 +20,9 @@ import type {FlipperDoctor} from 'flipper-common'; import * as fs_extra from 'fs-extra'; import {validateSelectedXcodeVersion} from './fb-stubs/validateSelectedXcodeVersion'; -export function getHealthchecks(): FlipperDoctor.Healthchecks { +export function getHealthchecks( + isProduction: boolean, +): FlipperDoctor.Healthchecks { return { common: { label: 'Common', @@ -40,19 +42,24 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks { }; }, }, - { - key: 'common.watchman', - label: 'Watchman Installed', - run: async (_: FlipperDoctor.EnvironmentInfo) => { - const isAvailable = await isWatchmanAvailable(); - return { - hasProblem: !isAvailable, - message: isAvailable - ? ['common.watchman--installed'] - : ['common.watchman--not_installed'], - }; - }, - }, + + ...(!isProduction + ? [ + { + key: 'common.watchman', + label: 'Watchman Installed', + run: async (_: FlipperDoctor.EnvironmentInfo) => { + const isAvailable = await isWatchmanAvailable(); + return { + hasProblem: !isAvailable, + message: isAvailable + ? ['common.watchman--installed'] + : ['common.watchman--not_installed'], + }; + }, + } as FlipperDoctor.Healthcheck, + ] + : []), ], }, android: { @@ -421,11 +428,14 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks { }; } -export async function runHealthchecks(): Promise< +export async function runHealthchecks( + isProduction: boolean, +): Promise< Array > { const environmentInfo = await getEnvInfo(); - const healthchecks: FlipperDoctor.Healthchecks = getHealthchecks(); + const healthchecks: FlipperDoctor.Healthchecks = + getHealthchecks(isProduction); const results: Array< FlipperDoctor.CategoryResult | FlipperDoctor.SkippedHealthcheckCategory > = await Promise.all( diff --git a/desktop/flipper-common/src/doctor.tsx b/desktop/flipper-common/src/doctor.tsx index 7798b635669..cc444bed1b2 100644 --- a/desktop/flipper-common/src/doctor.tsx +++ b/desktop/flipper-common/src/doctor.tsx @@ -136,6 +136,7 @@ export namespace FlipperDoctor { enablePhysicalIOS: boolean; idbPath: string; }; + isProduction: boolean; }; /** diff --git a/desktop/flipper-server/src/utils/runHealthchecks.tsx b/desktop/flipper-server/src/utils/runHealthchecks.tsx index b9cd80e1929..728ce170680 100644 --- a/desktop/flipper-server/src/utils/runHealthchecks.tsx +++ b/desktop/flipper-server/src/utils/runHealthchecks.tsx @@ -14,7 +14,7 @@ import produce from 'immer'; export async function getHealthChecks( options: FlipperDoctor.HealthcheckSettings, ) { - return produce(getHealthchecks(), (healthchecks) => { + return produce(getHealthchecks(options.isProduction), (healthchecks) => { if (!options.settings.enableAndroid) { healthchecks.android = { label: healthchecks.android.label, @@ -47,7 +47,7 @@ export async function runHealthcheck( categoryName: keyof FlipperDoctor.Healthchecks, ruleName: string, ): Promise { - const healthchecks = getHealthchecks(); + const healthchecks = getHealthchecks(options.isProduction); const category = healthchecks[categoryName]; if (!category) { throw new Error(`Unknown category: ${categoryName}`); diff --git a/desktop/flipper-ui/src/utils/runHealthchecks.tsx b/desktop/flipper-ui/src/utils/runHealthchecks.tsx index 977562b3a57..8fcb3da14f7 100644 --- a/desktop/flipper-ui/src/utils/runHealthchecks.tsx +++ b/desktop/flipper-ui/src/utils/runHealthchecks.tsx @@ -40,8 +40,12 @@ export type HealthcheckOptions = HealthcheckEventsHandler & HealthcheckSettings; async function launchHealthchecks(options: HealthcheckOptions): Promise { const flipperServer = getFlipperServer(); + + const envInfo = await flipperServer.exec('environment-info'); + const healthchecks = await flipperServer.exec('doctor-get-healthchecks', { settings: options.settings, + isProduction: envInfo.isProduction, }); options.startHealthchecks(healthchecks); let hasProblems = false; @@ -56,7 +60,10 @@ async function launchHealthchecks(options: HealthcheckOptions): Promise { await flipperServer .exec( 'doctor-run-healthcheck', - {settings: options.settings}, + { + settings: options.settings, + isProduction: envInfo.isProduction, + }, categoryKey as keyof FlipperDoctor.Healthchecks, h.key, )