Skip to content

Commit 4fac063

Browse files
feat(doctor): adjust healthchecks based on where command was ran (#2049)
* feat(doctor): select healthchecks based on where command was ran * chore: add info when running outside of project. * chore: align dependencies * fix: ensure that command has been run in React Native project
1 parent 29db2ac commit 4fac063

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

packages/cli-doctor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@react-native-community/cli-tools": "12.0.0-alpha.13",
1515
"chalk": "^4.1.2",
1616
"command-exists": "^1.2.8",
17+
"deepmerge": "^4.3.0",
1718
"envinfo": "^7.7.2",
1819
"execa": "^5.0.0",
1920
"hermes-profile-transformer": "^0.0.6",

packages/cli-doctor/src/tools/healthchecks/index.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {Healthchecks, HealthCheckCategory} from '../../types';
1515
import loadConfig from '@react-native-community/cli-config';
1616
import xcodeEnv from './xcodeEnv';
1717
import packager from './packager';
18+
import deepmerge from 'deepmerge';
19+
import {logger} from '@react-native-community/cli-tools';
1820

1921
export const HEALTHCHECK_TYPES = {
2022
ERROR: 'ERROR',
@@ -28,21 +30,48 @@ type Options = {
2830

2931
export const getHealthchecks = ({contributor}: Options): Healthchecks => {
3032
let additionalChecks: HealthCheckCategory[] = [];
33+
let projectSpecificHealthchecks = {};
34+
let config;
3135

3236
// Doctor can run in a detached mode, where there isn't a config so this can fail
3337
try {
34-
let config = loadConfig();
38+
config = loadConfig();
3539
additionalChecks = config.healthChecks;
40+
41+
if (config.reactNativePath) {
42+
projectSpecificHealthchecks = {
43+
common: {
44+
label: 'Common',
45+
healthchecks: [packager],
46+
},
47+
android: {
48+
label: 'Android',
49+
healthchecks: [androidSDK],
50+
},
51+
...(process.platform === 'darwin' && {
52+
ios: {
53+
label: 'iOS',
54+
healthchecks: [xcodeEnv],
55+
},
56+
}),
57+
};
58+
}
3659
} catch {}
3760

38-
return {
61+
if (!config) {
62+
logger.log();
63+
logger.info(
64+
'Detected that command has been run outside of React Native project, running basic healthchecks.',
65+
);
66+
}
67+
68+
const defaultHealthchecks = {
3969
common: {
4070
label: 'Common',
4171
healthchecks: [
4272
nodeJS,
4373
yarn,
4474
npm,
45-
packager,
4675
...(process.platform === 'darwin' ? [watchman] : []),
4776
],
4877
},
@@ -52,7 +81,6 @@ export const getHealthchecks = ({contributor}: Options): Healthchecks => {
5281
adb,
5382
jdk,
5483
androidStudio,
55-
androidSDK,
5684
androidHomeEnvVariable,
5785
...(contributor ? [androidNDK] : []),
5886
],
@@ -61,10 +89,12 @@ export const getHealthchecks = ({contributor}: Options): Healthchecks => {
6189
? {
6290
ios: {
6391
label: 'iOS',
64-
healthchecks: [xcode, ruby, cocoaPods, iosDeploy, xcodeEnv],
92+
healthchecks: [xcode, ruby, cocoaPods, iosDeploy],
6593
},
6694
}
6795
: {}),
6896
...additionalChecks,
6997
};
98+
99+
return deepmerge(defaultHealthchecks, projectSpecificHealthchecks);
70100
};

0 commit comments

Comments
 (0)