hopsule 0.9.5 → 0.9.7
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/install.js +7 -5
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -106,27 +106,29 @@ function downloadFile(url) {
|
|
|
106
106
|
if (timer) clearTimeout(timer);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
const follow = (
|
|
109
|
+
const follow = (currentUrl, redirects = 0) => {
|
|
110
110
|
if (redirects > 10) {
|
|
111
111
|
cleanup();
|
|
112
112
|
return reject(new Error("Too many redirects"));
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
if (timer) clearTimeout(timer);
|
|
115
116
|
timer = setTimeout(() => {
|
|
116
117
|
reject(new Error(`Download timed out after ${DOWNLOAD_TIMEOUT_MS / 1000}s`));
|
|
117
118
|
}, DOWNLOAD_TIMEOUT_MS);
|
|
118
119
|
|
|
119
120
|
const req = https
|
|
120
|
-
.get(
|
|
121
|
+
.get(currentUrl, { timeout: 30000, headers: { "User-Agent": "hopsule-npm-installer" } }, (res) => {
|
|
121
122
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
122
|
-
|
|
123
|
+
res.resume();
|
|
123
124
|
return follow(res.headers.location, redirects + 1);
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
if (res.statusCode !== 200) {
|
|
128
|
+
res.resume();
|
|
127
129
|
cleanup();
|
|
128
130
|
return reject(
|
|
129
|
-
new Error(`Download failed: HTTP ${res.statusCode} from ${
|
|
131
|
+
new Error(`Download failed: HTTP ${res.statusCode} from ${currentUrl}`)
|
|
130
132
|
);
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -190,7 +192,7 @@ function downloadFile(url) {
|
|
|
190
192
|
req.on("timeout", () => {
|
|
191
193
|
req.destroy();
|
|
192
194
|
cleanup();
|
|
193
|
-
reject(new Error(
|
|
195
|
+
reject(new Error(`Connection timed out (attempt to ${currentUrl.substring(0, 60)}...)`));
|
|
194
196
|
});
|
|
195
197
|
};
|
|
196
198
|
|