()
| 38 | * doesn't have a Linux libc). |
| 39 | */ |
| 40 | export function detectPlatform(): PlatformInfo { |
| 41 | const SYS_PLATFORM_MAP: Record<string, string> = { |
| 42 | linux: 'linux', |
| 43 | win32: 'win32', |
| 44 | darwin: 'darwin', |
| 45 | }; |
| 46 | const OS_MAP: Record<string, string> = { |
| 47 | linux: 'linux', |
| 48 | win32: 'windows', |
| 49 | darwin: 'macos', |
| 50 | }; |
| 51 | |
| 52 | const arch = os.arch(); |
| 53 | const libcFamily = detectLibc.familySync(); |
| 54 | const libcVersion = detectLibc.versionSync(); |
| 55 | |
| 56 | const platform: PlatformInfo = { |
| 57 | osName: 'manylinux', |
| 58 | archName: ARCH_MAP[arch] || arch, |
| 59 | osMajor: 2, |
| 60 | osMinor: 17, |
| 61 | os: OS_MAP[process.platform] || 'linux', |
| 62 | sysPlatform: SYS_PLATFORM_MAP[process.platform] || 'linux', |
| 63 | libc: 'gnu', |
| 64 | }; |
| 65 | |
| 66 | if (libcFamily === detectLibc.MUSL) { |
| 67 | platform.osName = 'musllinux'; |
| 68 | platform.libc = 'musl'; |
| 69 | } |
| 70 | |
| 71 | if (libcVersion) { |
| 72 | const parts = libcVersion.split('.'); |
| 73 | platform.osMajor = parseInt(parts[0], 10); |
| 74 | platform.osMinor = parseInt(parts[1], 10) || 0; |
| 75 | } |
| 76 | |
| 77 | return platform; |
| 78 | } |
| 79 | |
| 80 | /** Validate and normalize a VERCEL_BUILD_ARCH value. */ |
| 81 | export function validateBuildArch(arch: string): 'x86_64' | 'aarch64' { |
no test coverage detected