From 4dcb19b7ea2c61a3456427cdddbd936cc8868da9 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Tue, 6 Aug 2024 11:25:19 -0700 Subject: [PATCH 1/2] cloudflared supports arm64 now https://github.com/cloudflare/cloudflared/releases --- src/install.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install.ts b/src/install.ts index f06d856..053c6f3 100644 --- a/src/install.ts +++ b/src/install.ts @@ -13,7 +13,7 @@ const LINUX_URL: Partial> = { }; const MACOS_URL: Partial> = { - arm64: "cloudflared-darwin-amd64.tgz", + arm64: "cloudflared-darwin-arm64.tgz", x64: "cloudflared-darwin-amd64.tgz", }; From 087d967d244f06189c12d4cd6ecd0fe97c911f57 Mon Sep 17 00:00:00 2001 From: JacobLinCool Date: Wed, 7 Aug 2024 04:05:14 +0800 Subject: [PATCH 2/2] fix: fallback to x64 for old versions on macos --- src/install.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/install.ts b/src/install.ts index 053c6f3..05e8b24 100644 --- a/src/install.ts +++ b/src/install.ts @@ -60,10 +60,15 @@ export async function install_linux(to: string, version = CLOUDFLARED_VERSION): } export async function install_macos(to: string, version = CLOUDFLARED_VERSION): Promise { - const file = MACOS_URL[process.arch]; + let arch = process.arch; + if (version !== "latest" && version_number(version) < 20240802) { + // arm64 is only supported starting from 2024.8.2 + arch = "x64"; + } + const file = MACOS_URL[arch]; if (file === undefined) { - throw new UnsupportedError("Unsupported architecture: " + process.arch); + throw new UnsupportedError("Unsupported architecture: " + arch); } await download(resolve_base(version) + file, `${to}.tgz`); @@ -130,3 +135,8 @@ function download(url: string, to: string, redirect = 0): Promise { request.end(); }); } + +function version_number(semver: string): number { + const [major, minor, patch] = semver.split(".").map(Number); + return major * 10000 + minor * 100 + patch; +}