alurkerja-cli 1.0.1 → 1.0.2

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 (3) hide show
  1. package/index.js +51 -11
  2. package/index.js.backup +51 -11
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -56,15 +56,18 @@ function getVersion() {
56
56
  */
57
57
  async function downloadBinary(version, platform) {
58
58
  const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
59
- const downloadUrl = `${GITLAB_BASE}/-/releases/${version}/downloads/${binaryName}`;
59
+ const downloadUrl = `${GITLAB_BASE}/-/raw/master/dist/${binaryName}`;
60
60
 
61
61
  console.log(`📥 Downloading Alurkerja CLI ${version}...`);
62
62
 
63
63
  // Ensure install directory exists
64
64
  fs.mkdirSync(INSTALL_DIR, { recursive: true });
65
65
 
66
+ // Use temporary file to avoid ETXTBSY error
67
+ const tempPath = `${BINARY_PATH}.tmp`;
68
+
66
69
  return new Promise((resolve, reject) => {
67
- const file = fs.createWriteStream(BINARY_PATH);
70
+ const file = fs.createWriteStream(tempPath);
68
71
 
69
72
  const url = new URL(downloadUrl);
70
73
  const options = {
@@ -88,32 +91,69 @@ async function downloadBinary(version, platform) {
88
91
  };
89
92
  return https.get(redirectOptions, (redirectRes) => {
90
93
  redirectRes.pipe(file);
91
- redirectRes.on('end', resolve);
92
94
  });
93
95
  }
94
96
 
95
97
  if (res.statusCode !== 200) {
98
+ file.close();
99
+ fs.unlinkSync(tempPath);
96
100
  reject(new Error(`Download failed with status ${res.statusCode}`));
97
101
  return;
98
102
  }
99
103
 
100
104
  res.pipe(file);
101
- res.on('end', resolve);
102
105
  });
103
106
 
104
- req.on('error', reject);
107
+ req.on('error', (err) => {
108
+ file.close();
109
+ try { fs.unlinkSync(tempPath); } catch {}
110
+ reject(err);
111
+ });
112
+
105
113
  req.setTimeout(30000, () => {
106
114
  req.abort();
115
+ file.close();
116
+ try { fs.unlinkSync(tempPath); } catch {}
107
117
  reject(new Error('Download timeout'));
108
118
  });
109
119
 
110
- file.on('error', reject);
120
+ file.on('error', (err) => {
121
+ try { fs.unlinkSync(tempPath); } catch {}
122
+ reject(err);
123
+ });
124
+
111
125
  file.on('finish', () => {
112
- file.close();
113
- // Make executable on Unix systems
114
- if (platform.os !== 'windows') {
115
- fs.chmodSync(BINARY_PATH, '755');
116
- }
126
+ file.close((err) => {
127
+ if (err) {
128
+ try { fs.unlinkSync(tempPath); } catch {}
129
+ reject(err);
130
+ return;
131
+ }
132
+
133
+ // Make executable on Unix systems before renaming
134
+ if (platform.os !== 'windows') {
135
+ try {
136
+ fs.chmodSync(tempPath, '755');
137
+ } catch (err) {
138
+ try { fs.unlinkSync(tempPath); } catch {}
139
+ reject(new Error(`Failed to make binary executable: ${err.message}`));
140
+ return;
141
+ }
142
+ }
143
+
144
+ // Rename temp file to final path
145
+ try {
146
+ // Remove old binary if exists
147
+ if (fs.existsSync(BINARY_PATH)) {
148
+ fs.unlinkSync(BINARY_PATH);
149
+ }
150
+ fs.renameSync(tempPath, BINARY_PATH);
151
+ resolve();
152
+ } catch (err) {
153
+ try { fs.unlinkSync(tempPath); } catch {}
154
+ reject(new Error(`Failed to install binary: ${err.message}`));
155
+ }
156
+ });
117
157
  });
118
158
  });
119
159
  }
package/index.js.backup CHANGED
@@ -56,15 +56,18 @@ function getVersion() {
56
56
  */
57
57
  async function downloadBinary(version, platform) {
58
58
  const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
59
- const downloadUrl = `${GITLAB_BASE}/-/releases/${version}/downloads/${binaryName}`;
59
+ const downloadUrl = `${GITLAB_BASE}/-/raw/master/dist/${binaryName}`;
60
60
 
61
61
  console.log(`📥 Downloading Alurkerja CLI ${version}...`);
62
62
 
63
63
  // Ensure install directory exists
64
64
  fs.mkdirSync(INSTALL_DIR, { recursive: true });
65
65
 
66
+ // Use temporary file to avoid ETXTBSY error
67
+ const tempPath = `${BINARY_PATH}.tmp`;
68
+
66
69
  return new Promise((resolve, reject) => {
67
- const file = fs.createWriteStream(BINARY_PATH);
70
+ const file = fs.createWriteStream(tempPath);
68
71
 
69
72
  const url = new URL(downloadUrl);
70
73
  const options = {
@@ -88,32 +91,69 @@ async function downloadBinary(version, platform) {
88
91
  };
89
92
  return https.get(redirectOptions, (redirectRes) => {
90
93
  redirectRes.pipe(file);
91
- redirectRes.on('end', resolve);
92
94
  });
93
95
  }
94
96
 
95
97
  if (res.statusCode !== 200) {
98
+ file.close();
99
+ fs.unlinkSync(tempPath);
96
100
  reject(new Error(`Download failed with status ${res.statusCode}`));
97
101
  return;
98
102
  }
99
103
 
100
104
  res.pipe(file);
101
- res.on('end', resolve);
102
105
  });
103
106
 
104
- req.on('error', reject);
107
+ req.on('error', (err) => {
108
+ file.close();
109
+ try { fs.unlinkSync(tempPath); } catch {}
110
+ reject(err);
111
+ });
112
+
105
113
  req.setTimeout(30000, () => {
106
114
  req.abort();
115
+ file.close();
116
+ try { fs.unlinkSync(tempPath); } catch {}
107
117
  reject(new Error('Download timeout'));
108
118
  });
109
119
 
110
- file.on('error', reject);
120
+ file.on('error', (err) => {
121
+ try { fs.unlinkSync(tempPath); } catch {}
122
+ reject(err);
123
+ });
124
+
111
125
  file.on('finish', () => {
112
- file.close();
113
- // Make executable on Unix systems
114
- if (platform.os !== 'windows') {
115
- fs.chmodSync(BINARY_PATH, '755');
116
- }
126
+ file.close((err) => {
127
+ if (err) {
128
+ try { fs.unlinkSync(tempPath); } catch {}
129
+ reject(err);
130
+ return;
131
+ }
132
+
133
+ // Make executable on Unix systems before renaming
134
+ if (platform.os !== 'windows') {
135
+ try {
136
+ fs.chmodSync(tempPath, '755');
137
+ } catch (err) {
138
+ try { fs.unlinkSync(tempPath); } catch {}
139
+ reject(new Error(`Failed to make binary executable: ${err.message}`));
140
+ return;
141
+ }
142
+ }
143
+
144
+ // Rename temp file to final path
145
+ try {
146
+ // Remove old binary if exists
147
+ if (fs.existsSync(BINARY_PATH)) {
148
+ fs.unlinkSync(BINARY_PATH);
149
+ }
150
+ fs.renameSync(tempPath, BINARY_PATH);
151
+ resolve();
152
+ } catch (err) {
153
+ try { fs.unlinkSync(tempPath); } catch {}
154
+ reject(new Error(`Failed to install binary: ${err.message}`));
155
+ }
156
+ });
117
157
  });
118
158
  });
119
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alurkerja-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Alurkerja CLI - npx wrapper for Go binary",
5
5
  "main": "index.js",
6
6
  "private": false,