|
1 | | -import fetch from 'node-fetch'; |
2 | | -import { mkdirSync, chmodSync, existsSync, readFileSync } from 'fs'; |
3 | | -import { fileURLToPath } from 'url'; |
4 | | -import { dirname, join } from 'path'; |
5 | | -import { pipeline } from 'stream/promises'; |
| 1 | +import { mkdirSync, chmodSync, existsSync, readFileSync } from 'node:fs'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { dirname, join } from 'node:path'; |
| 4 | +import { pipeline } from 'node:stream/promises'; |
6 | 5 | import * as tar from 'tar'; |
7 | 6 |
|
8 | 7 | const __filename = fileURLToPath(import.meta.url); |
9 | 8 | const __dirname = dirname(__filename); |
10 | 9 |
|
11 | | -function getPlatform() { |
12 | | - const type = process.platform; |
13 | | - const arch = process.arch; |
14 | | - |
15 | | - if (type === 'win32' && arch === 'x64') { |
16 | | - return 'x86_64-pc-windows-msvc'; |
17 | | - } |
18 | | - |
19 | | - if (type === 'linux' && arch === 'x64') { |
20 | | - return 'x86_64-unknown-linux-musl'; |
21 | | - } |
22 | | - |
23 | | - if (type === 'linux' && arch === 'arm64') { |
24 | | - return 'aarch64-unknown-linux-musl'; |
25 | | - } |
26 | | - |
27 | | - if (type === 'darwin' && arch === 'x64') { |
28 | | - return 'x86_64-apple-darwin'; |
29 | | - } |
| 10 | +function isPlatform(platform, arch) { |
| 11 | + return process.platform === platform && process.arch === arch; |
| 12 | +} |
30 | 13 |
|
31 | | - if (type === 'darwin' && arch === 'arm64') { |
32 | | - return 'aarch64-apple-darwin'; |
33 | | - } |
| 14 | +function getPlatform() { |
| 15 | + if (isPlatform('win32', 'x64')) return 'x86_64-pc-windows-msvc'; |
| 16 | + if (isPlatform('linux', 'x64')) return 'x86_64-unknown-linux-musl'; |
| 17 | + if (isPlatform('linux', 'arm64')) return 'aarch64-unknown-linux-musl'; |
| 18 | + if (isPlatform('darwin', 'x64')) return 'x86_64-apple-darwin'; |
| 19 | + if (isPlatform('darwin', 'arm64')) return 'aarch64-apple-darwin'; |
34 | 20 |
|
35 | | - throw new Error(`Unsupported platform: ${type} ${arch}. Please create an issue at https://github.com/coralogix/protofetch/issues`); |
| 21 | + throw new Error(`Unsupported platform: ${process.platform} ${process.arch}. Please create an issue at https://github.com/coralogix/protofetch/issues`); |
36 | 22 | } |
37 | 23 |
|
38 | 24 | function getVersion() { |
@@ -63,8 +49,7 @@ async function downloadBinary(options = {}) { |
63 | 49 | for (let attempt = 1; attempt <= 3; attempt++) { |
64 | 50 | try { |
65 | 51 | const response = await fetch(url, { |
66 | | - redirect: 'follow', |
67 | | - timeout: 60000 |
| 52 | + redirect: 'follow' |
68 | 53 | }); |
69 | 54 |
|
70 | 55 | if (!response.ok) { |
|
0 commit comments