Skip to content

Commit

Permalink
Update coursier version, support arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
etspaceman committed May 31, 2024
1 parent c34600f commit 0e6eb71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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
26 changes: 20 additions & 6 deletions src/coursier/download-coursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ 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"

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 +26,31 @@ 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 +92,7 @@ function downloadFile(url: string, targetFile: string): Promise<string> {
flags: "wx",
mode: 0o755,
});
response.pipe(file);
response.pipe(zlib.createUnzip()).pipe(file);

file.on("finish", () => {
console.log(`Finished downloaded file at ${targetFile}`);
Expand Down

0 comments on commit 0e6eb71

Please sign in to comment.