Skip to content

Commit

Permalink
fix: install-vsix on windows using file patterns (#1654)
Browse files Browse the repository at this point in the history
  • Loading branch information
pospisilf authored Dec 2, 2024
1 parent 7ca8d9b commit 95bc417
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions packages/extester/src/extester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as path from 'path';
import * as os from 'os';
import { URL } from 'url';
import pjson from '../package.json';
import { globSync } from 'glob';

export { ReleaseQuality };
export { MochaOptions } from 'mocha';
Expand Down Expand Up @@ -102,27 +103,62 @@ export class ExTester {
let target = vsixFile;
if (vsixFile) {
try {
// Attempt to handle vsixFile as a URL
const uri = new URL(vsixFile);
if (!(process.platform === 'win32' && /^\w:/.test(uri.protocol))) {
target = path.basename(vsixFile);
target = await this.code.downloadExtension(uri.toString());
this.code.installExtension(target);
} catch (urlError) {
//Convert Windows-style paths to Unix-style for glob
const normalizedPattern = vsixFile.replace(/\\/g, '/');
const vsixFiles = globSync(normalizedPattern);

if (vsixFiles.length === 0) {
throw new Error(`No VSIX files found matching pattern: ${vsixFile}`);
}
} catch (err) {
if (!fs.existsSync(vsixFile)) {
throw new Error(`File ${vsixFile} does not exist`);

for (const file of vsixFiles) {
try {
const normalizedPath = path.normalize(file);
const target = await this.processVsixFile(normalizedPath);
this.code.installExtension(target);
} catch (error) {
console.error(`Error installing ${file}:`, error);
}
}
}
if (target !== vsixFile) {
target = await this.code.downloadExtension(vsixFile);
}
} else {
await this.code.packageExtension(useYarn);
this.code.installExtension(target);
}
this.code.installExtension(target);

if (installDependencies) {
this.code.installDependencies();
}
}

/**
* Processes a given VSIX file path or URL to validate and return the appropriate value.
*
* @param filePath The file path or URL of the VSIX file to process.
* @returns Resolves to the processed file path or base name if the input is a valid URL.
*/
private async processVsixFile(filePath: string): Promise<string> {
console.log(`Processing VSIX file: ${filePath}`);
try {
const uri = new URL(filePath);
console.log(`Parsed URI: ${uri}`);
if (!(process.platform === 'win32' && /^[a-zA-Z]:/.test(uri.protocol))) {
return path.basename(filePath);
}
} catch {
console.log(`File is not a valid URL. Checking existence: ${filePath}`);
await fs.stat(filePath).catch(() => {
throw new Error(`File ${filePath} does not exist.`);
});
}
return filePath;
}

/**
* Install an extension from VS Code marketplace into the test instance
* @param id id of the extension to install
Expand Down

0 comments on commit 95bc417

Please sign in to comment.