Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coursier version, support arm64 #26

Merged
merged 9 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"activationEvents": [
"onLanguage:smithy"
],
"extensionKind": ["workspace"],
"main": "./out/src/extension",
"contributes": {
"configuration": {
Expand Down Expand Up @@ -105,7 +106,9 @@
"concat-map": "^0.0.2",
"follow-redirects": "^1.14.9",
"semver": "^7.5.0",
"vscode-languageclient": "^8.0.0"
"unzip-stream": "^0.3.4",
"vscode-languageclient": "^8.0.0",
"unzip-stream": "^0.3.4"
},
"devDependencies": {
"@types/follow-redirects": "^1.14.1",
Expand Down
5 changes: 4 additions & 1 deletion src/coursier/coursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export function getCoursierExecutable(extensionPath: string): Promise<string> {
return downloadCoursierIfRequired(
extensionPath,
process.platform,
"v2.0.13"
process.arch,
// Have to use a commit hash for now since the launchers repository is untagged
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
);
}
});
Expand Down
34 changes: 28 additions & 6 deletions src/coursier/download-coursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { https } from "follow-redirects";
import { IncomingMessage } from "http";
import * as fs from "fs";
import { access, mkdir } from "fs/promises";
import * as zlib from "zlib";
import * as unzip from "unzip-stream";

export function downloadCoursierIfRequired(
extensionPath: string,
platform: string,
versionPath: string
arch: String,
versionPath: string,
versionPathArm64: String
): Promise<string> {
function binPath(filename: string) {
return path.join(extensionPath, filename);
Expand All @@ -23,20 +27,34 @@ export function downloadCoursierIfRequired(

const supportedTargets = {
darwin: {
url: `https://github.com/coursier/coursier/releases/download/${versionPath}/cs-x86_64-apple-darwin`,
url: `https://github.com/coursier/launchers/raw/${versionPath}/cs-x86_64-apple-darwin.gz`,
bin: binPath("coursier"),
},
linux: {
url: `https://github.com/coursier/coursier/releases/download/${versionPath}/cs-x86_64-pc-linux`,
url: `https://github.com/coursier/launchers/raw/${versionPath}/cs-x86_64-pc-linux.gz`,
bin: binPath("coursier"),
},
win32: {
url: `https://github.com/coursier/coursier/releases/download/${versionPath}/cs-x86_64-pc-win32.exe`,
url: `https://github.com/coursier/launchers/raw/${versionPath}/cs-x86_64-pc-win32.zip`,
bin: binPath("coursier.exe"),
},
};

const target = supportedTargets[platform];
const supportedTargetsArm64 = {
darwin: {
url: `https://github.com/VirtusLab/coursier-m1/releases/download/${versionPathArm64}/cs-aarch64-apple-darwin.gz`,
bin: binPath("coursier"),
},
linux: {
url: `https://github.com/VirtusLab/coursier-m1/releases/download/${versionPathArm64}/cs-aarch64-pc-linux.gz`,
bin: binPath("coursier"),
},
};

const target =
arch === "arm64"
? supportedTargetsArm64[platform]
: supportedTargets[platform];
if (target === undefined) {
return Promise.reject(`Unsupported platform ${platform}.`);
} else {
Expand Down Expand Up @@ -78,7 +96,11 @@ function downloadFile(url: string, targetFile: string): Promise<string> {
flags: "wx",
mode: 0o755,
});
response.pipe(file);
targetFile.endsWith(".exe")
? response.pipe(unzip.Parse()).on("entry", (entry) => {
entry.pipe(file);
})
: response.pipe(zlib.createUnzip()).pipe(file);

file.on("finish", () => {
console.log(`Finished downloaded file at ${targetFile}`);
Expand Down
38 changes: 36 additions & 2 deletions tests/coursier/download-coursier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,35 @@ import { join } from "path";
const dir = join(tmpdir(), p);
rmSync(dir, { recursive: true, force: true });
mkdirSync(dir, { recursive: true });
return downloadCoursierIfRequired(dir, p, "v2.0.13").then((x) => {
return downloadCoursierIfRequired(
dir,
p,
"x64",
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
).then((x) => {
expect(existsSync(x)).toBeTruthy();
accessSync(x, constants.X_OK);
});
},
25 * 1000
);
});

["darwin", "linux"].forEach((p) => {
test(
`download on platform: ${p}`,
() => {
const dir = join(tmpdir(), p);
rmSync(dir, { recursive: true, force: true });
mkdirSync(dir, { recursive: true });
return downloadCoursierIfRequired(
dir,
p,
"arm64",
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
).then((x) => {
expect(existsSync(x)).toBeTruthy();
accessSync(x, constants.X_OK);
});
Expand All @@ -21,6 +49,12 @@ import { join } from "path";

test(`fails on unknown platform`, () => {
return expect(
downloadCoursierIfRequired(tmpdir(), "unsupported", "v2.0.13")
downloadCoursierIfRequired(
tmpdir(),
"unsupported",
"x64",
"56971135cd9b08eaefed13b4d6b7a95ba9cce572",
"v2.1.10"
)
).rejects.toEqual("Unsupported platform unsupported.");
});
12 changes: 10 additions & 2 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading