Skip to content

Commit

Permalink
feat: download arm64 version on relevant platforms
Browse files Browse the repository at this point in the history
Fixes #122
  • Loading branch information
connor4312 committed Jan 11, 2022
1 parent dc7ad13 commit 4bcf3d4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 2.0.3 | 2021-01-11

- Fix `@vscode/test-electron` auto updating
- Use arm64 version of VS Code on relevant platforms

### 2.0.2 | 2021-01-07

Expand Down
15 changes: 12 additions & 3 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
insidersDownloadDirToExecutablePath,
insidersDownloadDirMetadata,
getLatestInsidersMetadata,
systemDefaultPlatform
systemDefaultPlatform,
systemDefaultArchitecture
} from './util';
import { IncomingMessage } from 'http';
import { Extract as extract } from 'unzipper';
Expand Down Expand Up @@ -49,10 +50,17 @@ type StringLiteralUnion<T extends U, U = string> = T | (U & {});
export type DownloadVersion = StringLiteralUnion<'insiders' | 'stable'>;
export type DownloadPlatform = StringLiteralUnion<'darwin' | 'win32-archive' | 'win32-x64-archive' | 'linux-x64'>;

export const enum DownloadArchitecture {
X64 = 'x64',
X86 = 'ia32',
ARM64 = 'arm64',
}

export interface DownloadOptions {
readonly cachePath: string;
readonly version: DownloadVersion;
readonly platform: DownloadPlatform;
readonly architecture: DownloadArchitecture;
}

/**
Expand All @@ -67,7 +75,7 @@ async function downloadVSCodeArchive(options: DownloadOptions) {
fs.mkdirSync(options.cachePath);
}

const downloadUrl = getVSCodeDownloadUrl(options.version, options.platform);
const downloadUrl = getVSCodeDownloadUrl(options.version, options.platform, options.architecture);
const text = `Downloading VS Code ${options.version} from ${downloadUrl}`;
process.stdout.write(text);

Expand Down Expand Up @@ -179,6 +187,7 @@ export const defaultCachePath = path.resolve(extensionRoot, '.vscode-test');
export async function download(options?: Partial<DownloadOptions>): Promise<string> {
let version = options?.version;
const platform = options?.platform ?? systemDefaultPlatform;
const architecture = options?.architecture ?? systemDefaultArchitecture;
const cachePath = options?.cachePath ?? defaultCachePath;

if (version) {
Expand Down Expand Up @@ -229,7 +238,7 @@ export async function download(options?: Partial<DownloadOptions>): Promise<stri
}

try {
const { stream, format } = await downloadVSCodeArchive({ version, platform, cachePath });
const { stream, format } = await downloadVSCodeArchive({ version, architecture, platform, cachePath });
await unzipVSCode(downloadedPath, stream, format);
console.log(`Downloaded VS Code ${version} into ${downloadedPath}`);
} catch (err) {
Expand Down
30 changes: 24 additions & 6 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import * as path from 'path';
import { URL } from 'url';
import * as https from 'https';
import * as request from './request';
import { DownloadPlatform } from './download';
import { DownloadArchitecture, DownloadPlatform } from './download';
import * as createHttpsProxyAgent from 'https-proxy-agent';
import * as createHttpProxyAgent from 'http-proxy-agent';
import { readFileSync } from 'fs';
import { getProfileArguments, TestOptions } from './runTest';

export let systemDefaultPlatform: string;
export let systemDefaultPlatform: DownloadPlatform;

switch (process.platform) {
case 'darwin':
Expand All @@ -26,13 +26,31 @@ switch (process.platform) {
systemDefaultPlatform = 'linux-x64';
}

export function getVSCodeDownloadUrl(version: string, platform?: DownloadPlatform) {
const downloadPlatform = platform || systemDefaultPlatform;
export const systemDefaultArchitecture = process.arch === 'arm64'
? DownloadArchitecture.ARM64
: process.arch === 'ia32'
? DownloadArchitecture.X86
: DownloadArchitecture.X64;

export function getVSCodeDownloadUrl(version: string, platform = systemDefaultPlatform, architecture = systemDefaultArchitecture) {

let downloadSegment: string;
switch (platform) {
case 'darwin':
downloadSegment = architecture === DownloadArchitecture.ARM64 ? 'darwin-arm64' : 'darwin';
break;
case 'win32-archive':
downloadSegment = architecture === DownloadArchitecture.ARM64 ? 'win32-arm64-archive' : 'win32-archive';
break;
default:
downloadSegment = platform;
break;
}

if (version === 'insiders') {
return `https://update.code.visualstudio.com/latest/${downloadPlatform}/insider`;
return `https://update.code.visualstudio.com/latest/${downloadSegment}/insider`;
}
return `https://update.code.visualstudio.com/${version}/${downloadPlatform}/stable`;
return `https://update.code.visualstudio.com/${version}/${downloadSegment}/stable`;
}

let PROXY_AGENT: createHttpProxyAgent.HttpProxyAgent | undefined = undefined;
Expand Down

0 comments on commit 4bcf3d4

Please sign in to comment.