Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Only perform watchman health check in development
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Jun 14, 2024
1 parent d517c0d commit ca2b99f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion desktop/doctor/src/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 26 additions & 16 deletions desktop/doctor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: {
Expand Down Expand Up @@ -421,11 +428,14 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks {
};
}

export async function runHealthchecks(): Promise<
export async function runHealthchecks(
isProduction: boolean,
): Promise<
Array<FlipperDoctor.CategoryResult | FlipperDoctor.SkippedHealthcheckCategory>
> {
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(
Expand Down
1 change: 1 addition & 0 deletions desktop/flipper-common/src/doctor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export namespace FlipperDoctor {
enablePhysicalIOS: boolean;
idbPath: string;
};
isProduction: boolean;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions desktop/flipper-server/src/utils/runHealthchecks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function runHealthcheck(
categoryName: keyof FlipperDoctor.Healthchecks,
ruleName: string,
): Promise<FlipperDoctor.HealthcheckResult> {
const healthchecks = getHealthchecks();
const healthchecks = getHealthchecks(options.isProduction);
const category = healthchecks[categoryName];
if (!category) {
throw new Error(`Unknown category: ${categoryName}`);
Expand Down
9 changes: 8 additions & 1 deletion desktop/flipper-ui/src/utils/runHealthchecks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ export type HealthcheckOptions = HealthcheckEventsHandler & HealthcheckSettings;

async function launchHealthchecks(options: HealthcheckOptions): Promise<void> {
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;
Expand All @@ -56,7 +60,10 @@ async function launchHealthchecks(options: HealthcheckOptions): Promise<void> {
await flipperServer
.exec(
'doctor-run-healthcheck',
{settings: options.settings},
{
settings: options.settings,
isProduction: envInfo.isProduction,
},
categoryKey as keyof FlipperDoctor.Healthchecks,
h.key,
)
Expand Down

0 comments on commit ca2b99f

Please sign in to comment.