diff --git a/package-lock.json b/package-lock.json index 4bff27f..8e92610 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,11 +16,13 @@ "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@octokit/rest": "21.0.2", + "@types/adm-zip": "0.5.7", "@types/node": "22.6.1", "@types/proxy-from-env": "1.0.4", "@typescript-eslint/eslint-plugin": "8.7.0", "@typescript-eslint/parser": "8.7.0", "@vercel/ncc": "0.38.2", + "adm-zip": "0.5.16", "eslint": "8.57.1", "prettier": "3.3.3", "proxy": "2.2.0", @@ -1504,6 +1506,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@types/adm-zip": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.5.7.tgz", + "integrity": "sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/conventional-commits-parser": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@types/conventional-commits-parser/-/conventional-commits-parser-5.0.0.tgz", @@ -1771,6 +1783,16 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/adm-zip": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0" + } + }, "node_modules/agent-base": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", diff --git a/package.json b/package.json index dddd464..d676ab0 100644 --- a/package.json +++ b/package.json @@ -44,11 +44,13 @@ "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@octokit/rest": "21.0.2", + "@types/adm-zip": "0.5.7", "@types/node": "22.6.1", "@types/proxy-from-env": "1.0.4", "@typescript-eslint/eslint-plugin": "8.7.0", "@typescript-eslint/parser": "8.7.0", "@vercel/ncc": "0.38.2", + "adm-zip": "0.5.16", "eslint": "8.57.1", "prettier": "3.3.3", "proxy": "2.2.0", diff --git a/src/release.ts b/src/release.ts index 7cdb91c..7dd7d65 100644 --- a/src/release.ts +++ b/src/release.ts @@ -7,6 +7,7 @@ import { fetch, ProxyAgent } from "undici" import type { RequestInit } from "undici" import { extract } from "tar" import tmp from "tmp-promise" +import admzip from "adm-zip" import { COMBINED_PATH, NAME } from "./constants" const octokit = new Octokit({ request: { fetch: proxiedFetch } }) @@ -15,7 +16,10 @@ export async function findRelease(version: string) { const release = await getRelease(version) const releasePrefix = getAssetPrefix() const matchedAsset = release.data.assets.find(({ name }) => { - return name.startsWith(releasePrefix) && name.endsWith(".tar.gz") + return ( + name.startsWith(releasePrefix) && + (name.endsWith(".tar.gz") || name.endsWith(".zip")) + ) }) if (!matchedAsset) { throw new Error(`The binary '${releasePrefix}*' not found`) @@ -27,7 +31,14 @@ export async function downloadBinary(url: string) { const response = await proxiedFetch(url) const tmpfile = await tmp.file() await writeFile(tmpfile.path, Buffer.from(await response.arrayBuffer())) - await extract({ file: tmpfile.path, cwd: COMBINED_PATH, strict: true }) + + if (url.endsWith(".zip")) { + const zip = new admzip(tmpfile.path) + zip.extractAllTo(COMBINED_PATH, true) + } else { + await extract({ file: tmpfile.path, cwd: COMBINED_PATH, strict: true }) + } + await tmpfile.cleanup() }