pentect 0.0.68 → 0.0.70
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/README.md +1 -1
- package/package.json +1 -1
- package/packaging/npm/install.js +23 -8
package/README.md
CHANGED
package/package.json
CHANGED
package/packaging/npm/install.js
CHANGED
|
@@ -54,7 +54,7 @@ export function retryableStatus(status) {
|
|
|
54
54
|
return status === 408 || status === 429 || status >= 500;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export async function
|
|
57
|
+
export async function downloadWithRetry(url, options = {}) {
|
|
58
58
|
const request = options.request || globalThis.fetch;
|
|
59
59
|
const wait = options.wait || ((milliseconds) => new Promise(
|
|
60
60
|
(resolveDelay) => setTimeout(resolveDelay, milliseconds),
|
|
@@ -68,9 +68,24 @@ export async function fetchWithRetry(url, options = {}) {
|
|
|
68
68
|
headers: { 'user-agent': 'pentect-npm-installer' },
|
|
69
69
|
signal: timeout(),
|
|
70
70
|
});
|
|
71
|
-
if (!
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
await response.body?.cancel();
|
|
73
|
+
if (!retryableStatus(response.status) || attempt === 3) {
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
status: response.status,
|
|
77
|
+
statusText: response.statusText,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
lastError = new Error(`Download failed (${response.status} ${response.statusText})`);
|
|
81
|
+
} else {
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
status: response.status,
|
|
85
|
+
statusText: response.statusText,
|
|
86
|
+
bytes: Buffer.from(await response.arrayBuffer()),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
74
89
|
} catch (error) {
|
|
75
90
|
lastError = error;
|
|
76
91
|
if (attempt === 3) throw error;
|
|
@@ -81,14 +96,14 @@ export async function fetchWithRetry(url, options = {}) {
|
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
async function download(url) {
|
|
84
|
-
const response = await
|
|
99
|
+
const response = await downloadWithRetry(url);
|
|
85
100
|
if (!response.ok) throw new Error(`Download failed (${response.status} ${response.statusText})`);
|
|
86
|
-
return
|
|
101
|
+
return response.bytes;
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
async function downloadBinary(base, asset) {
|
|
90
|
-
const compressed = await
|
|
91
|
-
if (compressed.ok) return gunzipSync(
|
|
105
|
+
const compressed = await downloadWithRetry(`${base}/${asset}.gz`);
|
|
106
|
+
if (compressed.ok) return gunzipSync(compressed.bytes);
|
|
92
107
|
if (compressed.status !== 404) {
|
|
93
108
|
throw new Error(`Download failed (${compressed.status} ${compressed.statusText})`);
|
|
94
109
|
}
|