Skip to content

Commit 1f91b6d

Browse files
dloicLoïc DARDANT
andauthored
fix: be able to read more complex buildToolsVersion definitions (#2531)
Co-authored-by: Loïc DARDANT <[email protected]>
1 parent 1447731 commit 1f91b6d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/cli-doctor/src/tools/healthchecks/__tests__/androidSDK.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ describe('androidSDK', () => {
7575
expect(diagnostics.needsToBeFixed).toBe(true);
7676
});
7777

78+
it('reads buildToolsVersion when using more complex definition', async () => {
79+
// Override mock file
80+
writeFiles(mockWorkingDir, {
81+
'android/build.gradle': `
82+
buildscript {
83+
ext {
84+
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
85+
minSdkVersion = 16
86+
compileSdkVersion = 28
87+
targetSdkVersion = 28
88+
}
89+
}
90+
`,
91+
});
92+
// @ts-ignore
93+
environmentInfo.SDKs['Android SDK'] = {
94+
'Build Tools': ['34.0.0'],
95+
};
96+
(execa as unknown as jest.Mock).mockResolvedValue({stdout: ''});
97+
const diagnostics = await androidSDK.getDiagnostics(environmentInfo);
98+
expect(diagnostics.needsToBeFixed).toBe(false);
99+
});
100+
78101
it('returns false if the SDK version is in range', async () => {
79102
// To avoid having to provide fake versions for all the Android SDK tools
80103
// @ts-ignore

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ const getBuildToolsVersion = (projectRoot = ''): string => {
4949
// Get only the portion of the declaration of `buildToolsVersion`
5050
.substring(buildToolsVersionIndex)
5151
.split('\n')[0]
52-
// Get only the the value of `buildToolsVersion`
53-
.match(/\d|\../g) || []
54-
).join('');
52+
// Get only the value of `buildToolsVersion`
53+
.match(/\d+\.\d+\.\d+/g) || []
54+
).at(0);
5555

5656
return buildToolsVersion || 'Not Found';
5757
};

0 commit comments

Comments
 (0)