Skip to content

Commit 4d0a134

Browse files
authored
fix: vscode-test requires an internet connection (#295)
- 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
1 parent b36c862 commit 4d0a134

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/download.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const pipelineAsync = promisify(pipeline);
3434
const vscodeStableReleasesAPI = `https://update.code.visualstudio.com/api/releases/stable`;
3535
const vscodeInsiderReleasesAPI = `https://update.code.visualstudio.com/api/releases/insider`;
3636

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

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

6262
export const fetchStableVersions = onceWithoutRejections((released: boolean, timeout: number) =>
63-
request.getJSON<string[]>(`${vscodeStableReleasesAPI}?released=${released}`, timeout)
63+
request.getJSON<string[]>(`${vscodeStableReleasesAPI}?released=${released}`, timeout),
6464
);
6565
export const fetchInsiderVersions = onceWithoutRejections((released: boolean, timeout: number) =>
66-
request.getJSON<string[]>(`${vscodeInsiderReleasesAPI}?released=${released}`, timeout)
66+
request.getJSON<string[]>(`${vscodeInsiderReleasesAPI}?released=${released}`, timeout),
6767
);
6868

6969
/**
@@ -134,7 +134,7 @@ async function fallbackToLocalEntries(cachePath: string, platform: string, fromE
134134
.filter(isDefined)
135135
.filter((e) => e.groups!.platform === platform)
136136
.map((e) => e.groups!.version)
137-
.sort((a, b) => Number(b) - Number(a));
137+
.sort((a, b) => semver.compare(b, a));
138138

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

415415
child.on('error', reject);
416416
child.on('exit', (code) =>
417-
code === 0 ? resolve() : reject(new Error(`Failed to unzip archive, exited with ${code}`))
417+
code === 0 ? resolve() : reject(new Error(`Failed to unzip archive, exited with ${code}`)),
418418
);
419419
});
420420
}
@@ -563,17 +563,17 @@ export async function downloadAndUnzipVSCode(
563563
version?: DownloadVersion,
564564
platform?: DownloadPlatform,
565565
reporter?: ProgressReporter,
566-
extractSync?: boolean
566+
extractSync?: boolean,
567567
): Promise<string>;
568568
export async function downloadAndUnzipVSCode(
569569
versionOrOptions?: DownloadVersion | Partial<DownloadOptions>,
570570
platform?: DownloadPlatform,
571571
reporter?: ProgressReporter,
572-
extractSync?: boolean
572+
extractSync?: boolean,
573573
): Promise<string> {
574574
return await download(
575575
typeof versionOrOptions === 'object'
576576
? (versionOrOptions as Partial<DownloadOptions>)
577-
: { version: versionOrOptions, platform, reporter, extractSync }
577+
: { version: versionOrOptions, platform, reporter, extractSync },
578578
);
579579
}

0 commit comments

Comments
 (0)