gitbasher 3.8.0 → 3.8.1

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.
Files changed (2) hide show
  1. package/download-release.js +78 -26
  2. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  const https = require('https');
2
+ const http = require('http');
2
3
  const fs = require('fs');
3
4
  const path = require('path');
4
5
 
@@ -18,31 +19,82 @@ if (!fs.existsSync(BIN_DIR)) {
18
19
  fs.mkdirSync(BIN_DIR, { recursive: true });
19
20
  }
20
21
 
21
- // Download the release asset
22
- console.log(`Downloading gitbasher v${VERSION} from GitHub releases...`);
23
- const file = fs.createWriteStream(BIN_PATH);
24
-
25
- https.get(RELEASE_URL, (response) => {
26
- if (response.statusCode === 302 || response.statusCode === 301) {
27
- // Follow redirect
28
- https.get(response.headers.location, (redirectResponse) => {
29
- redirectResponse.pipe(file);
30
- file.on('finish', () => {
31
- file.close();
32
- fs.chmodSync(BIN_PATH, 0o755);
33
- console.log('Download complete!');
22
+ // Download function with redirect handling
23
+ function download(url, outputPath, maxRedirects = 5) {
24
+ return new Promise((resolve, reject) => {
25
+ if (maxRedirects === 0) {
26
+ reject(new Error('Too many redirects'));
27
+ return;
28
+ }
29
+
30
+ const client = url.startsWith('https') ? https : http;
31
+ const file = fs.createWriteStream(outputPath);
32
+ let downloadedBytes = 0;
33
+ let totalBytes = 0;
34
+
35
+ client.get(url, (response) => {
36
+ // Handle redirects
37
+ if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 307 || response.statusCode === 308) {
38
+ file.close();
39
+ fs.unlinkSync(outputPath);
40
+ const redirectUrl = response.headers.location;
41
+ if (!redirectUrl) {
42
+ reject(new Error('Redirect location not found'));
43
+ return;
44
+ }
45
+ // Resolve relative redirects
46
+ const redirectUrlFull = redirectUrl.startsWith('http')
47
+ ? redirectUrl
48
+ : new URL(redirectUrl, url).href;
49
+ return download(redirectUrlFull, outputPath, maxRedirects - 1)
50
+ .then(resolve)
51
+ .catch(reject);
52
+ }
53
+
54
+ // Handle errors
55
+ if (response.statusCode !== 200) {
56
+ file.close();
57
+ fs.unlinkSync(outputPath);
58
+ reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));
59
+ return;
60
+ }
61
+
62
+ // Track download progress
63
+ totalBytes = parseInt(response.headers['content-length'] || '0', 10);
64
+ if (totalBytes > 0) {
65
+ response.on('data', (chunk) => {
66
+ downloadedBytes += chunk.length;
67
+ });
68
+ }
69
+
70
+ // Pipe response to file
71
+ response.pipe(file);
72
+
73
+ file.on('finish', () => {
74
+ file.close();
75
+ fs.chmodSync(outputPath, 0o755);
76
+ if (totalBytes > 0) {
77
+ const sizeKB = (downloadedBytes / 1024).toFixed(1);
78
+ console.log(`✓ Downloaded ${sizeKB}KB`);
79
+ } else {
80
+ console.log('✓ Download complete');
81
+ }
82
+ resolve();
83
+ });
84
+ }).on('error', (err) => {
85
+ file.close();
86
+ if (fs.existsSync(outputPath)) {
87
+ fs.unlinkSync(outputPath);
88
+ }
89
+ reject(err);
34
90
  });
35
91
  });
36
- } else {
37
- response.pipe(file);
38
- file.on('finish', () => {
39
- file.close();
40
- fs.chmodSync(BIN_PATH, 0o755);
41
- console.log('Download complete!');
42
- });
43
- }
44
- }).on('error', (err) => {
45
- fs.unlinkSync(BIN_PATH);
46
- console.error(`Error downloading release: ${err.message}`);
47
- process.exit(1);
48
- });
92
+ }
93
+
94
+ // Download the release asset
95
+ console.log(`Downloading gitbasher v${VERSION}...`);
96
+ download(RELEASE_URL, BIN_PATH)
97
+ .catch((err) => {
98
+ console.error(`✗ Error downloading release: ${err.message}`);
99
+ process.exit(1);
100
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitbasher",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "Simple bash utility that makes git easy to use",
5
5
  "keywords": [
6
6
  "git",