Skip to content

Commit

Permalink
fix: add support for .zip files in binary download
Browse files Browse the repository at this point in the history
  • Loading branch information
lumirlumir committed Jan 9, 2025
1 parent c78ecb0 commit c84c197
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } })
Expand All @@ -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`)
Expand All @@ -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()
}

Expand Down

0 comments on commit c84c197

Please sign in to comment.