Skip to content

Commit

Permalink
fix: vscode-test requires an internet connection (#295)
Browse files Browse the repository at this point in the history
- Fix not matching local versions when the platform contained a hyphen
  (e.g. darwin-arm64)
- Fix versions not being sorted correctly so old versions could be used

Closes #285
  • Loading branch information
connor4312 authored Dec 8, 2024
1 parent b36c862 commit 4d0a134
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const pipelineAsync = promisify(pipeline);
const vscodeStableReleasesAPI = `https://update.code.visualstudio.com/api/releases/stable`;
const vscodeInsiderReleasesAPI = `https://update.code.visualstudio.com/api/releases/insider`;

const downloadDirNameFormat = /^vscode-(?<platform>[a-z]+)-(?<version>[0-9.]+)$/;
const downloadDirNameFormat = /^vscode-(?<platform>[a-z0-9-]+)-(?<version>[0-9.]+)$/;
const makeDownloadDirName = (platform: string, version: Version) => `vscode-${platform}-${version.id}`;

const DOWNLOAD_ATTEMPTS = 3;
Expand All @@ -60,10 +60,10 @@ interface IFetchInferredOptions extends IFetchStableOptions {
(process as any).noAsar = true;

export const fetchStableVersions = onceWithoutRejections((released: boolean, timeout: number) =>
request.getJSON<string[]>(`${vscodeStableReleasesAPI}?released=${released}`, timeout)
request.getJSON<string[]>(`${vscodeStableReleasesAPI}?released=${released}`, timeout),
);
export const fetchInsiderVersions = onceWithoutRejections((released: boolean, timeout: number) =>
request.getJSON<string[]>(`${vscodeInsiderReleasesAPI}?released=${released}`, timeout)
request.getJSON<string[]>(`${vscodeInsiderReleasesAPI}?released=${released}`, timeout),
);

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ async function fallbackToLocalEntries(cachePath: string, platform: string, fromE
.filter(isDefined)
.filter((e) => e.groups!.platform === platform)
.map((e) => e.groups!.version)
.sort((a, b) => Number(b) - Number(a));
.sort((a, b) => semver.compare(b, a));

if (fallbackTo) {
console.warn(`Error retrieving VS Code versions, using already-installed version ${fallbackTo}`, fromError);
Expand Down Expand Up @@ -344,7 +344,7 @@ async function unzipVSCode(
reporter: ProgressReporter,
extractDir: string,
platform: DownloadPlatform,
{ format, stream, length, sha256 }: IDownload
{ format, stream, length, sha256 }: IDownload,
) {
const stagingFile = path.join(tmpdir(), `vscode-test-${Date.now()}.zip`);
const checksum = validateStream(stream, length, sha256);
Expand Down Expand Up @@ -414,7 +414,7 @@ function spawnDecompressorChild(command: string, args: ReadonlyArray<string>, in

child.on('error', reject);
child.on('exit', (code) =>
code === 0 ? resolve() : reject(new Error(`Failed to unzip archive, exited with ${code}`))
code === 0 ? resolve() : reject(new Error(`Failed to unzip archive, exited with ${code}`)),
);
});
}
Expand Down Expand Up @@ -563,17 +563,17 @@ export async function downloadAndUnzipVSCode(
version?: DownloadVersion,
platform?: DownloadPlatform,
reporter?: ProgressReporter,
extractSync?: boolean
extractSync?: boolean,
): Promise<string>;
export async function downloadAndUnzipVSCode(
versionOrOptions?: DownloadVersion | Partial<DownloadOptions>,
platform?: DownloadPlatform,
reporter?: ProgressReporter,
extractSync?: boolean
extractSync?: boolean,
): Promise<string> {
return await download(
typeof versionOrOptions === 'object'
? (versionOrOptions as Partial<DownloadOptions>)
: { version: versionOrOptions, platform, reporter, extractSync }
: { version: versionOrOptions, platform, reporter, extractSync },
);
}

0 comments on commit 4d0a134

Please sign in to comment.