Skip to content

Commit

Permalink
feat(doctor): select healthchecks based on where command was ran
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak committed Aug 14, 2023
1 parent 7165558 commit 25f8d52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@react-native-community/cli-tools": "12.0.0-alpha.7",
"chalk": "^4.1.2",
"command-exists": "^1.2.8",
"deepmerge": "^4.3.1",
"envinfo": "^7.7.2",
"execa": "^5.0.0",
"hermes-profile-transformer": "^0.0.6",
Expand Down
30 changes: 26 additions & 4 deletions packages/cli-doctor/src/tools/healthchecks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {Healthchecks, HealthCheckCategory} from '../../types';
import loadConfig from '@react-native-community/cli-config';
import xcodeEnv from './xcodeEnv';
import packager from './packager';
import deepmerge from 'deepmerge';

export const HEALTHCHECK_TYPES = {
ERROR: 'ERROR',
Expand All @@ -29,20 +30,40 @@ type Options = {
export const getHealthchecks = ({contributor}: Options): Healthchecks => {
let additionalChecks: HealthCheckCategory[] = [];

let projectSpecificHealthchecks = {};

// Doctor can run in a detached mode, where there isn't a config so this can fail
try {
let config = loadConfig();
additionalChecks = config.healthChecks;

if (config) {
projectSpecificHealthchecks = {
common: {
label: 'Common',
healthchecks: [packager],
},
android: {
label: 'Android',
healthchecks: [androidSDK],
},
...(process.platform === 'darwin' && {
ios: {
label: 'iOS',
healthchecks: [xcodeEnv],
},
}),
};
}
} catch {}

return {
const defaultHealthchecks = {
common: {
label: 'Common',
healthchecks: [
nodeJS,
yarn,
npm,
packager,
...(process.platform === 'darwin' ? [watchman] : []),
],
},
Expand All @@ -52,7 +73,6 @@ export const getHealthchecks = ({contributor}: Options): Healthchecks => {
adb,
jdk,
androidStudio,
androidSDK,
androidHomeEnvVariable,
...(contributor ? [androidNDK] : []),
],
Expand All @@ -61,10 +81,12 @@ export const getHealthchecks = ({contributor}: Options): Healthchecks => {
? {
ios: {
label: 'iOS',
healthchecks: [xcode, ruby, cocoaPods, iosDeploy, xcodeEnv],
healthchecks: [xcode, ruby, cocoaPods, iosDeploy],
},
}
: {}),
...additionalChecks,
};

return deepmerge(defaultHealthchecks, projectSpecificHealthchecks);
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5379,6 +5379,11 @@ deepmerge@^4.3.0:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.0.tgz#65491893ec47756d44719ae520e0e2609233b59b"
integrity sha512-z2wJZXrmeHdvYJp/Ux55wIjqo81G5Bp4c+oELTW+7ar6SogWHajt5a9gO3s3IDaGSAXjDk0vlQKN3rms8ab3og==

deepmerge@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a"
integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down

0 comments on commit 25f8d52

Please sign in to comment.