@jsenv/package-publish 1.11.49 → 1.11.50
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
CHANGED
|
@@ -8,7 +8,7 @@ export const fetchLatestInRegistry = async ({
|
|
|
8
8
|
token,
|
|
9
9
|
}) => {
|
|
10
10
|
const requestUrl = `${registryUrl}/${packageName}`;
|
|
11
|
-
const response = await
|
|
11
|
+
const response = await fetchWithRetryOnTransientError(requestUrl, {
|
|
12
12
|
method: "GET",
|
|
13
13
|
headers: {
|
|
14
14
|
// "user-agent": "jsenv",
|
|
@@ -38,6 +38,40 @@ export const fetchLatestInRegistry = async ({
|
|
|
38
38
|
return packageObject.versions[packageObject["dist-tags"].latest];
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
// The registry (or a middlebox) sometimes closes a keep-alive socket while a
|
|
42
|
+
// request is in flight, surfacing as "fetch failed" with ECONNRESET. Fetching a
|
|
43
|
+
// whole workspace fires many requests at once so one reset per run is common.
|
|
44
|
+
// These failures are transient by nature and cannot be prevented client-side,
|
|
45
|
+
// so retry a couple of times before giving up.
|
|
46
|
+
const TRANSIENT_NETWORK_ERROR_CODES = [
|
|
47
|
+
"ECONNRESET",
|
|
48
|
+
"ETIMEDOUT",
|
|
49
|
+
"EPIPE",
|
|
50
|
+
"EAI_AGAIN",
|
|
51
|
+
"UND_ERR_SOCKET",
|
|
52
|
+
];
|
|
53
|
+
const fetchWithRetryOnTransientError = async (url, options) => {
|
|
54
|
+
let attemptCount = 0;
|
|
55
|
+
while (true) {
|
|
56
|
+
attemptCount++;
|
|
57
|
+
try {
|
|
58
|
+
return await fetch(url, options);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
const errorCode = e.cause?.code;
|
|
61
|
+
if (
|
|
62
|
+
attemptCount >= 3 ||
|
|
63
|
+
!TRANSIENT_NETWORK_ERROR_CODES.includes(errorCode)
|
|
64
|
+
) {
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
const delay = attemptCount * 500;
|
|
68
|
+
await new Promise((resolve) => {
|
|
69
|
+
setTimeout(resolve, delay);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
41
75
|
const writeUnexpectedResponseStatus = ({
|
|
42
76
|
requestUrl,
|
|
43
77
|
responseStatus,
|