Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
# yarn lint-staged
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,45 @@ describe('androidStudio', () => {
}".`,
);
});

it('detects Android Studio in the fallback Windows installation path', async () => {
// Make CLI think Android Studio was not found
environmentInfo.IDEs['Android Studio'] = 'Not Found';
// Force the platform to win32 for the test
const platformSpy = jest
.spyOn(process, 'platform', 'get')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are failing here, can you investigate that?

.mockReturnValue('win32');

// First WMIC (primary) returns empty, second (fallback) returns version
(execa as jest.Mock)
.mockResolvedValueOnce({stdout: ''})
.mockResolvedValueOnce({stdout: '4.2.1.0'});

const diagnostics = await androidStudio.getDiagnostics(environmentInfo);

expect(diagnostics.needsToBeFixed).toBe(false);
expect(diagnostics.version).toBe('4.2.1.0');

platformSpy.mockRestore();
});

it('detects when Android Studio is also not in fallback installation path', async () => {
// Make CLI think Android Studio was not found
environmentInfo.IDEs['Android Studio'] = 'Not Found';
// Force the platform to win32 for the test
const platformSpy = jest
.spyOn(process, 'platform', 'get')
.mockReturnValue('win32');

// First WMIC (primary) returns empty, second (fallback) returns version
(execa as jest.Mock)
.mockResolvedValueOnce({stdout: ''})
.mockResolvedValueOnce({stdout: ''});

const diagnostics = await androidStudio.getDiagnostics(environmentInfo);

expect(diagnostics.needsToBeFixed).toBe(true);

platformSpy.mockRestore();
});
});
33 changes: 30 additions & 3 deletions packages/cli-doctor/src/tools/healthchecks/androidStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,43 @@
if (needsToBeFixed && process.platform === 'win32') {
const archSuffix = process.arch === 'x64' ? '64' : '';

const androidStudioPath = join(
// Check if Android Studio is installed in one of its default locations
const primaryAndroidStudioPath = join(
getUserAndroidPath(),
'android-studio',
'bin',
`studio${archSuffix}.exe`,
).replace(/\\/g, '\\\\');
const {stdout} = await executeCommand(
`wmic datafile where name="${androidStudioPath}" get Version`,
`wmic datafile where name="${primaryAndroidStudioPath}" get Version`,
);
const version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();
let version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();

if (version !== '') {
return {
needsToBeFixed: false,
version,
};
}

// 2) fallback path under %LOCALAPPDATA%\Programs\Android Studio
// This is the path used by the JetBrains Toolbox / Android Studio installer
const altBase = process.env.LOCALAPPDATA || '';
const fallbackPath = join(
altBase,
'Programs',
'Android Studio',
'bin',
`studio${archSuffix}.exe`,
).replace(/\\/g, '\\\\');
try {
const { stdout } = await executeCommand(

Check warning on line 57 in packages/cli-doctor/src/tools/healthchecks/androidStudio.ts

View workflow job for this annotation

GitHub Actions / Lint

'stdout' is already declared in the upper scope on line 34 column 14

Check failure on line 57 in packages/cli-doctor/src/tools/healthchecks/androidStudio.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·stdout·` with `stdout`
`wmic datafile where name="${fallbackPath}" get Version`,
);
version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();
} catch {
version = '';
}

if (version === '') {
return missing;
Expand Down
Loading