fix(ide): Fix bug where companion extension was not being installed on Windows correctly (#6576)

This commit is contained in:
Shreya Keshive 2025-08-19 13:25:11 -07:00 committed by GitHub
parent 24858b319a
commit ed1fc4ddb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 12 deletions

View File

@ -16,6 +16,14 @@ vi.mock('fs');
vi.mock('os'); vi.mock('os');
describe('ide-installer', () => { describe('ide-installer', () => {
beforeEach(() => {
vi.spyOn(os, 'homedir').mockReturnValue('/home/user');
});
afterEach(() => {
vi.restoreAllMocks();
});
describe('getIdeInstaller', () => { describe('getIdeInstaller', () => {
it('should return a VsCodeInstaller for "vscode"', () => { it('should return a VsCodeInstaller for "vscode"', () => {
const installer = getIdeInstaller(DetectedIde.VSCode); const installer = getIdeInstaller(DetectedIde.VSCode);
@ -33,11 +41,6 @@ describe('ide-installer', () => {
installer = getIdeInstaller(DetectedIde.VSCode)!; installer = getIdeInstaller(DetectedIde.VSCode)!;
vi.spyOn(child_process, 'execSync').mockImplementation(() => ''); vi.spyOn(child_process, 'execSync').mockImplementation(() => '');
vi.spyOn(fs, 'existsSync').mockReturnValue(false); vi.spyOn(fs, 'existsSync').mockReturnValue(false);
vi.spyOn(os, 'homedir').mockReturnValue('/home/user');
});
afterEach(() => {
vi.restoreAllMocks();
}); });
describe('install', () => { describe('install', () => {

View File

@ -26,13 +26,22 @@ export interface InstallResult {
async function findVsCodeCommand(): Promise<string | null> { async function findVsCodeCommand(): Promise<string | null> {
// 1. Check PATH first. // 1. Check PATH first.
try { try {
child_process.execSync( if (process.platform === 'win32') {
process.platform === 'win32' const result = child_process
? `where.exe ${VSCODE_COMMAND}` .execSync(`where.exe ${VSCODE_COMMAND}`)
: `command -v ${VSCODE_COMMAND}`, .toString()
{ stdio: 'ignore' }, .trim();
); // `where.exe` can return multiple paths. Return the first one.
return VSCODE_COMMAND; const firstPath = result.split(/\r?\n/)[0];
if (firstPath) {
return firstPath;
}
} else {
child_process.execSync(`command -v ${VSCODE_COMMAND}`, {
stdio: 'ignore',
});
return VSCODE_COMMAND;
}
} catch { } catch {
// Not in PATH, continue to check common locations. // Not in PATH, continue to check common locations.
} }