Skip to content

Commit 05ef7bd

Browse files
jmeistrichthymikee
authored andcommitted
doctor: fix windows issues (#675)
* [Doctor] Don't check for watchman on Windows * [Doctor] Handle Android SDK not installed * [Doctor] Fix Android SDK check not working on Windows * [Doctor] Improve manual fix message for Android SDK * Change style of ANDROID_SDK check to reject * Change to use execa instead of exec
1 parent 5ed671f commit 05ef7bd

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

packages/cli/src/commands/doctor/healthchecks/androidSDK.js

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,52 @@ import chalk from 'chalk';
22
import {logManualInstallation} from './common';
33
import versionRanges from '../versionRanges';
44
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';
5+
import execa from 'execa';
6+
7+
const installMessage = `Read more about how to update Android SDK at ${chalk.dim(
8+
'https://developer.android.com/studio',
9+
)}`;
510

611
export default {
712
label: 'Android SDK',
8-
getDiagnosticsAsync: async ({SDKs}) => ({
9-
needsToBeFixed: doesSoftwareNeedToBeFixed({
10-
version: SDKs['Android SDK']['Build Tools'][0],
11-
versionRange: versionRanges.ANDROID_NDK,
12-
}),
13-
}),
13+
getDiagnosticsAsync: async ({SDKs}) => {
14+
let sdks = SDKs['Android SDK'];
15+
16+
// This is a workaround for envinfo's Android SDK check not working on
17+
// Windows. This can be removed when envinfo fixes it.
18+
// See the PR: https://github.com/tabrindle/envinfo/pull/119
19+
if (sdks === 'Not Found' && process.platform !== 'darwin') {
20+
try {
21+
const {stdout} = await execa(
22+
process.env.ANDROID_HOME
23+
? `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`
24+
: 'sdkmanager',
25+
['--list'],
26+
);
27+
28+
const matches = [];
29+
const regex = /build-tools;([\d|.]+)[\S\s]/g;
30+
let match = null;
31+
while ((match = regex.exec(stdout)) !== null) {
32+
matches.push(match[1]);
33+
}
34+
if (matches.length > 0) {
35+
sdks = {
36+
'Build Tools': matches,
37+
};
38+
}
39+
} catch {}
40+
}
41+
42+
return {
43+
needsToBeFixed:
44+
(sdks === 'Not Found' && installMessage) ||
45+
doesSoftwareNeedToBeFixed({
46+
version: sdks['Build Tools'][0],
47+
versionRange: versionRanges.ANDROID_NDK,
48+
}),
49+
};
50+
},
1451
runAutomaticFix: async ({loader, environmentInfo}) => {
1552
const version = environmentInfo.SDKs['Android SDK'][0];
1653
const isNDKInstalled = version !== 'Not Found';
@@ -19,15 +56,13 @@ export default {
1956

2057
if (isNDKInstalled) {
2158
return logManualInstallation({
22-
message: `Read more about how to update Android SDK at ${chalk.dim(
23-
'https://developer.android.com/studio',
24-
)}`,
59+
message: installMessage,
2560
});
2661
}
2762

2863
return logManualInstallation({
2964
healthcheck: 'Android SDK',
30-
url: 'https://developer.android.com/studio',
65+
url: 'https://facebook.github.io/react-native/docs/getting-started',
3166
});
3267
},
3368
};

packages/cli/src/commands/doctor/healthchecks/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export const HEALTHCHECK_TYPES = {
1616
export const getHealthchecks = ({contributor}) => ({
1717
common: {
1818
label: 'Common',
19-
healthchecks: [nodeJS, yarn, npm, watchman],
19+
healthchecks: [
20+
nodeJS,
21+
yarn,
22+
npm,
23+
...(process.platform === 'darwin' ? [watchman] : []),
24+
],
2025
},
2126
android: {
2227
label: 'Android',

0 commit comments

Comments
 (0)