From 1f91b6d9e656f3c5d36228862bc2b380e7771313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dardant?= Date: Fri, 29 Nov 2024 16:25:22 +0100 Subject: [PATCH] fix: be able to read more complex buildToolsVersion definitions (#2531) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc DARDANT --- .../healthchecks/__tests__/androidSDK.test.ts | 23 +++++++++++++++++++ .../src/tools/healthchecks/androidSDK.ts | 6 ++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/cli-doctor/src/tools/healthchecks/__tests__/androidSDK.test.ts b/packages/cli-doctor/src/tools/healthchecks/__tests__/androidSDK.test.ts index 7b47c6a14..73f25748d 100644 --- a/packages/cli-doctor/src/tools/healthchecks/__tests__/androidSDK.test.ts +++ b/packages/cli-doctor/src/tools/healthchecks/__tests__/androidSDK.test.ts @@ -75,6 +75,29 @@ describe('androidSDK', () => { expect(diagnostics.needsToBeFixed).toBe(true); }); + it('reads buildToolsVersion when using more complex definition', async () => { + // Override mock file + writeFiles(mockWorkingDir, { + 'android/build.gradle': ` + buildscript { + ext { + buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0' + minSdkVersion = 16 + compileSdkVersion = 28 + targetSdkVersion = 28 + } + } + `, + }); + // @ts-ignore + environmentInfo.SDKs['Android SDK'] = { + 'Build Tools': ['34.0.0'], + }; + (execa as unknown as jest.Mock).mockResolvedValue({stdout: ''}); + const diagnostics = await androidSDK.getDiagnostics(environmentInfo); + expect(diagnostics.needsToBeFixed).toBe(false); + }); + it('returns false if the SDK version is in range', async () => { // To avoid having to provide fake versions for all the Android SDK tools // @ts-ignore diff --git a/packages/cli-doctor/src/tools/healthchecks/androidSDK.ts b/packages/cli-doctor/src/tools/healthchecks/androidSDK.ts index 852a35c20..60ecafe35 100644 --- a/packages/cli-doctor/src/tools/healthchecks/androidSDK.ts +++ b/packages/cli-doctor/src/tools/healthchecks/androidSDK.ts @@ -49,9 +49,9 @@ const getBuildToolsVersion = (projectRoot = ''): string => { // Get only the portion of the declaration of `buildToolsVersion` .substring(buildToolsVersionIndex) .split('\n')[0] - // Get only the the value of `buildToolsVersion` - .match(/\d|\../g) || [] - ).join(''); + // Get only the value of `buildToolsVersion` + .match(/\d+\.\d+\.\d+/g) || [] + ).at(0); return buildToolsVersion || 'Not Found'; };