From 0e6eb71f933e7ea85e5d38401aaa35d1e2513259 Mon Sep 17 00:00:00 2001 From: Eric Meisel Date: Fri, 31 May 2024 10:18:25 -0500 Subject: [PATCH] Update coursier version, support arm64 --- src/coursier/coursier.ts | 5 ++++- src/coursier/download-coursier.ts | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/coursier/coursier.ts b/src/coursier/coursier.ts index 8a0c72e..b1f864a 100644 --- a/src/coursier/coursier.ts +++ b/src/coursier/coursier.ts @@ -9,7 +9,10 @@ export function getCoursierExecutable(extensionPath: string): Promise { 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" ); } }); diff --git a/src/coursier/download-coursier.ts b/src/coursier/download-coursier.ts index 7034866..855bf2e 100644 --- a/src/coursier/download-coursier.ts +++ b/src/coursier/download-coursier.ts @@ -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 { function binPath(filename: string) { return path.join(extensionPath, filename); @@ -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 { @@ -78,7 +92,7 @@ function downloadFile(url: string, targetFile: string): Promise { flags: "wx", mode: 0o755, }); - response.pipe(file); + response.pipe(zlib.createUnzip()).pipe(file); file.on("finish", () => { console.log(`Finished downloaded file at ${targetFile}`);