|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { existsSync } from 'fs' |
6 | | -import os from 'os' |
7 | 6 |
|
| 7 | +import { |
| 8 | + type Arch, |
| 9 | + getArch, |
| 10 | + type Libc, |
| 11 | + getPlatform, |
| 12 | + type Platform, |
| 13 | +} from '../constants/platform.js' |
8 | 14 | import { |
9 | 15 | downloadGitHubRelease, |
10 | 16 | type DownloadGitHubReleaseConfig, |
11 | 17 | SOCKET_BTM_REPO, |
12 | 18 | } from './github.js' |
13 | 19 |
|
14 | | -/** |
15 | | - * Platform type for socket-btm binaries. |
16 | | - */ |
17 | | -export type Platform = 'darwin' | 'linux' | 'win32' |
18 | | - |
19 | | -/** |
20 | | - * Architecture type for socket-btm binaries. |
21 | | - */ |
22 | | -export type Arch = 'arm64' | 'x64' |
23 | | - |
24 | | -/** |
25 | | - * Linux libc variant. |
26 | | - */ |
27 | | -export type Libc = 'musl' | 'glibc' |
| 20 | +export type { Arch, Libc, Platform } |
28 | 21 |
|
29 | 22 | /** |
30 | 23 | * Configuration for downloading socket-btm binary releases. |
@@ -103,8 +96,7 @@ const ARCH_MAP: Record<string, string> = { |
103 | 96 | * @returns 'musl', 'glibc', or undefined (for non-Linux) |
104 | 97 | */ |
105 | 98 | export function detectLibc(): Libc | undefined { |
106 | | - const platform = os.platform() |
107 | | - if (platform !== 'linux') { |
| 99 | + if (getPlatform() !== 'linux') { |
108 | 100 | return undefined |
109 | 101 | } |
110 | 102 |
|
@@ -181,26 +173,24 @@ export async function downloadSocketBtmRelease( |
181 | 173 | // Binary download |
182 | 174 | const { |
183 | 175 | bin, |
184 | | - libc, |
| 176 | + libc = detectLibc(), |
185 | 177 | removeMacOSQuarantine = true, |
186 | | - targetArch, |
187 | | - targetPlatform, |
| 178 | + targetArch = getArch(), |
| 179 | + targetPlatform = getPlatform(), |
188 | 180 | } = config as SocketBtmBinaryConfig |
189 | 181 |
|
190 | 182 | // Default bin to tool if not provided (like brew/cargo) |
191 | 183 | const baseName = bin || tool |
192 | 184 |
|
193 | | - // Resolve platform and arch based on host if not specified |
194 | | - const platform = (targetPlatform || os.platform()) as Platform |
195 | | - const arch = (targetArch || os.arch()) as Arch |
196 | | - |
197 | | - // Auto-detect libc variant on Linux if not specified |
198 | | - const libcType = libc || detectLibc() |
199 | | - |
200 | 185 | // Build asset name and platform-arch identifier |
201 | | - const assetName = getBinaryAssetName(baseName, platform, arch, libcType) |
202 | | - const platformArch = getPlatformArch(platform, arch, libcType) |
203 | | - const binaryName = getBinaryName(baseName, platform) |
| 186 | + const assetName = getBinaryAssetName( |
| 187 | + baseName, |
| 188 | + targetPlatform, |
| 189 | + targetArch, |
| 190 | + libc, |
| 191 | + ) |
| 192 | + const platformArch = getPlatformArch(targetPlatform, targetArch, libc) |
| 193 | + const binaryName = getBinaryName(baseName, targetPlatform) |
204 | 194 |
|
205 | 195 | downloadConfig = { |
206 | 196 | owner: SOCKET_BTM_REPO.owner, |
@@ -282,7 +272,7 @@ export function getBinaryName( |
282 | 272 | export function getPlatformArch( |
283 | 273 | platform: Platform, |
284 | 274 | arch: Arch, |
285 | | - libc?: Libc, |
| 275 | + libc?: Libc | undefined, |
286 | 276 | ): string { |
287 | 277 | const mappedArch = ARCH_MAP[arch] |
288 | 278 | if (!mappedArch) { |
|
0 commit comments