apex-dev 3.10.18 → 3.10.19
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/cli.js +42 -7
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -152,10 +152,12 @@ function downloadBinary(destPath) {
|
|
|
152
152
|
|
|
153
153
|
return new Promise((resolve, reject) => {
|
|
154
154
|
const file = fs.createWriteStream(destPath, { mode: 0o755 });
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
const DOWNLOAD_TIMEOUT = 10000;
|
|
156
|
+
|
|
157
|
+
const req = https
|
|
158
|
+
.get(url, { timeout: DOWNLOAD_TIMEOUT }, (response) => {
|
|
157
159
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
158
|
-
https.get(response.headers.location, (redirectRes) => {
|
|
160
|
+
const redirectReq = https.get(response.headers.location, { timeout: DOWNLOAD_TIMEOUT }, (redirectRes) => {
|
|
159
161
|
if (redirectRes.statusCode !== 200) {
|
|
160
162
|
reject(new Error(`Download failed with status ${redirectRes.statusCode}`));
|
|
161
163
|
return;
|
|
@@ -165,7 +167,12 @@ function downloadBinary(destPath) {
|
|
|
165
167
|
file.close();
|
|
166
168
|
resolve();
|
|
167
169
|
});
|
|
168
|
-
})
|
|
170
|
+
});
|
|
171
|
+
redirectReq.on("error", reject);
|
|
172
|
+
redirectReq.on("timeout", () => {
|
|
173
|
+
redirectReq.destroy();
|
|
174
|
+
reject(new Error("Download timed out after 10s"));
|
|
175
|
+
});
|
|
169
176
|
return;
|
|
170
177
|
}
|
|
171
178
|
if (response.statusCode !== 200) {
|
|
@@ -177,8 +184,13 @@ function downloadBinary(destPath) {
|
|
|
177
184
|
file.close();
|
|
178
185
|
resolve();
|
|
179
186
|
});
|
|
180
|
-
})
|
|
181
|
-
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
req.on("error", reject);
|
|
190
|
+
req.on("timeout", () => {
|
|
191
|
+
req.destroy();
|
|
192
|
+
reject(new Error("Download timed out after 10s"));
|
|
193
|
+
});
|
|
182
194
|
});
|
|
183
195
|
}
|
|
184
196
|
|
|
@@ -186,7 +198,17 @@ async function ensureBinary() {
|
|
|
186
198
|
const localPath = getLocalBinaryPath();
|
|
187
199
|
|
|
188
200
|
if (fs.existsSync(localPath)) {
|
|
189
|
-
|
|
201
|
+
// Check for empty/partial downloads and remove them
|
|
202
|
+
try {
|
|
203
|
+
const stat = fs.statSync(localPath);
|
|
204
|
+
if (stat.size === 0) {
|
|
205
|
+
fs.unlinkSync(localPath);
|
|
206
|
+
} else {
|
|
207
|
+
return localPath;
|
|
208
|
+
}
|
|
209
|
+
} catch {
|
|
210
|
+
try { fs.unlinkSync(localPath); } catch {}
|
|
211
|
+
}
|
|
190
212
|
}
|
|
191
213
|
|
|
192
214
|
try {
|
|
@@ -195,6 +217,7 @@ async function ensureBinary() {
|
|
|
195
217
|
return localPath;
|
|
196
218
|
} catch (err) {
|
|
197
219
|
console.error(`Failed to download binary: ${err.message}`);
|
|
220
|
+
try { fs.unlinkSync(localPath); } catch {}
|
|
198
221
|
return null;
|
|
199
222
|
}
|
|
200
223
|
}
|
|
@@ -221,6 +244,10 @@ function runWithBun() {
|
|
|
221
244
|
const child = spawn(bunPath, [distPath, ...process.argv.slice(2)], {
|
|
222
245
|
stdio: "inherit",
|
|
223
246
|
});
|
|
247
|
+
child.on("error", (err) => {
|
|
248
|
+
console.error(`Failed to launch bun: ${err.message}`);
|
|
249
|
+
process.exit(1);
|
|
250
|
+
});
|
|
224
251
|
child.on("exit", (code) => {
|
|
225
252
|
process.exit(code || 0);
|
|
226
253
|
});
|
|
@@ -229,6 +256,10 @@ function runWithBun() {
|
|
|
229
256
|
const child = spawn(bunPath, [scriptPath, ...process.argv.slice(2)], {
|
|
230
257
|
stdio: "inherit",
|
|
231
258
|
});
|
|
259
|
+
child.on("error", (err) => {
|
|
260
|
+
console.error(`Failed to launch bun: ${err.message}`);
|
|
261
|
+
process.exit(1);
|
|
262
|
+
});
|
|
232
263
|
child.on("exit", (code) => {
|
|
233
264
|
process.exit(code || 0);
|
|
234
265
|
});
|
|
@@ -329,6 +360,10 @@ async function main() {
|
|
|
329
360
|
const child = spawn(binaryPath, args, {
|
|
330
361
|
stdio: "inherit",
|
|
331
362
|
});
|
|
363
|
+
child.on("error", (err) => {
|
|
364
|
+
console.error(`Failed to launch binary: ${err.message}`);
|
|
365
|
+
process.exit(1);
|
|
366
|
+
});
|
|
332
367
|
child.on("exit", (code) => {
|
|
333
368
|
process.exit(code || 0);
|
|
334
369
|
});
|
package/dist/index.js
CHANGED