gitbasher 3.8.1 → 3.9.0
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/download-release.js +23 -4
- package/package.json +1 -1
package/download-release.js
CHANGED
|
@@ -31,10 +31,20 @@ function download(url, outputPath, maxRedirects = 5) {
|
|
|
31
31
|
const file = fs.createWriteStream(outputPath);
|
|
32
32
|
let downloadedBytes = 0;
|
|
33
33
|
let totalBytes = 0;
|
|
34
|
+
|
|
35
|
+
// Add timeout (30 seconds)
|
|
36
|
+
const timeout = setTimeout(() => {
|
|
37
|
+
file.close();
|
|
38
|
+
if (fs.existsSync(outputPath)) {
|
|
39
|
+
fs.unlinkSync(outputPath);
|
|
40
|
+
}
|
|
41
|
+
reject(new Error('Download timeout after 30s'));
|
|
42
|
+
}, 30000);
|
|
34
43
|
|
|
35
44
|
client.get(url, (response) => {
|
|
36
45
|
// Handle redirects
|
|
37
46
|
if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 307 || response.statusCode === 308) {
|
|
47
|
+
clearTimeout(timeout);
|
|
38
48
|
file.close();
|
|
39
49
|
fs.unlinkSync(outputPath);
|
|
40
50
|
const redirectUrl = response.headers.location;
|
|
@@ -71,17 +81,19 @@ function download(url, outputPath, maxRedirects = 5) {
|
|
|
71
81
|
response.pipe(file);
|
|
72
82
|
|
|
73
83
|
file.on('finish', () => {
|
|
84
|
+
clearTimeout(timeout);
|
|
74
85
|
file.close();
|
|
75
86
|
fs.chmodSync(outputPath, 0o755);
|
|
76
87
|
if (totalBytes > 0) {
|
|
77
88
|
const sizeKB = (downloadedBytes / 1024).toFixed(1);
|
|
78
|
-
|
|
89
|
+
process.stderr.write(`✓ Downloaded ${sizeKB}KB\n`);
|
|
79
90
|
} else {
|
|
80
|
-
|
|
91
|
+
process.stderr.write('✓ Download complete\n');
|
|
81
92
|
}
|
|
82
93
|
resolve();
|
|
83
94
|
});
|
|
84
95
|
}).on('error', (err) => {
|
|
96
|
+
clearTimeout(timeout);
|
|
85
97
|
file.close();
|
|
86
98
|
if (fs.existsSync(outputPath)) {
|
|
87
99
|
fs.unlinkSync(outputPath);
|
|
@@ -92,9 +104,16 @@ function download(url, outputPath, maxRedirects = 5) {
|
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
// Download the release asset
|
|
95
|
-
|
|
107
|
+
// Use stderr for progress so it's visible during npm install
|
|
108
|
+
process.stderr.write(`Downloading gitbasher v${VERSION}...\n`);
|
|
109
|
+
const startTime = Date.now();
|
|
110
|
+
|
|
96
111
|
download(RELEASE_URL, BIN_PATH)
|
|
112
|
+
.then(() => {
|
|
113
|
+
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
114
|
+
process.stderr.write(`✓ Installed in ${duration}s\n`);
|
|
115
|
+
})
|
|
97
116
|
.catch((err) => {
|
|
98
|
-
|
|
117
|
+
process.stderr.write(`✗ Error downloading release: ${err.message}\n`);
|
|
99
118
|
process.exit(1);
|
|
100
119
|
});
|