pentect 0.0.35 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packaging/npm/install.js +37 -16
package/package.json
CHANGED
package/packaging/npm/install.js
CHANGED
|
@@ -50,27 +50,49 @@ async function packageVersion() {
|
|
|
50
50
|
return metadata.version?.replace(/^v/, '');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
export function retryableStatus(status) {
|
|
54
|
+
return status === 408 || status === 429 || status >= 500;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function fetchWithRetry(url, options = {}) {
|
|
58
|
+
const request = options.request || globalThis.fetch;
|
|
59
|
+
const wait = options.wait || ((milliseconds) => new Promise(
|
|
60
|
+
(resolveDelay) => setTimeout(resolveDelay, milliseconds),
|
|
61
|
+
));
|
|
62
|
+
const timeout = options.timeout || (() => AbortSignal.timeout(90_000));
|
|
63
|
+
let lastError;
|
|
64
|
+
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
65
|
+
try {
|
|
66
|
+
const response = await request(url, {
|
|
67
|
+
redirect: 'follow',
|
|
68
|
+
headers: { 'user-agent': 'pentect-npm-installer' },
|
|
69
|
+
signal: timeout(),
|
|
70
|
+
});
|
|
71
|
+
if (!retryableStatus(response.status) || attempt === 3) return response;
|
|
72
|
+
await response.body?.cancel();
|
|
73
|
+
lastError = new Error(`Download failed (${response.status} ${response.statusText})`);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
lastError = error;
|
|
76
|
+
if (attempt === 3) throw error;
|
|
77
|
+
}
|
|
78
|
+
await wait(attempt * 250);
|
|
79
|
+
}
|
|
80
|
+
throw lastError;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function download(url) {
|
|
84
|
+
const response = await fetchWithRetry(url);
|
|
59
85
|
if (!response.ok) throw new Error(`Download failed (${response.status} ${response.statusText})`);
|
|
60
86
|
return Buffer.from(await response.arrayBuffer());
|
|
61
87
|
}
|
|
62
88
|
|
|
63
|
-
async function downloadBinary(base, asset
|
|
64
|
-
const compressed = await
|
|
65
|
-
redirect: 'follow',
|
|
66
|
-
headers: { 'user-agent': 'pentect-npm-installer' },
|
|
67
|
-
signal,
|
|
68
|
-
});
|
|
89
|
+
async function downloadBinary(base, asset) {
|
|
90
|
+
const compressed = await fetchWithRetry(`${base}/${asset}.gz`);
|
|
69
91
|
if (compressed.ok) return gunzipSync(Buffer.from(await compressed.arrayBuffer()));
|
|
70
92
|
if (compressed.status !== 404) {
|
|
71
93
|
throw new Error(`Download failed (${compressed.status} ${compressed.statusText})`);
|
|
72
94
|
}
|
|
73
|
-
return download(`${base}/${asset}
|
|
95
|
+
return download(`${base}/${asset}`);
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
export async function install(version) {
|
|
@@ -81,10 +103,9 @@ export async function install(version) {
|
|
|
81
103
|
const base = tag === 'latest'
|
|
82
104
|
? `https://github.com/${repository}/releases/latest/download`
|
|
83
105
|
: `https://github.com/${repository}/releases/download/${tag}`;
|
|
84
|
-
const signal = AbortSignal.timeout(90_000);
|
|
85
106
|
const [binary, checksumFile] = await Promise.all([
|
|
86
|
-
downloadBinary(base, asset
|
|
87
|
-
download(`${base}/${asset}.sha256
|
|
107
|
+
downloadBinary(base, asset),
|
|
108
|
+
download(`${base}/${asset}.sha256`),
|
|
88
109
|
]);
|
|
89
110
|
const expected = expectedChecksum(checksumFile.toString('utf8'));
|
|
90
111
|
const actual = createHash('sha256').update(binary).digest('hex');
|