codebuff 1.0.436 → 1.0.438
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/index.js +43 -37
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -117,10 +117,13 @@ function streamToString(stream) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
function getCurrentVersion() {
|
|
120
|
-
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
try {
|
|
122
|
+
if (!fs.existsSync(CONFIG.binaryPath)) {
|
|
123
|
+
resolve('error')
|
|
124
|
+
return
|
|
125
|
+
}
|
|
121
126
|
|
|
122
|
-
try {
|
|
123
|
-
return new Promise((resolve, reject) => {
|
|
124
127
|
const child = spawn(CONFIG.binaryPath, ['--version'], {
|
|
125
128
|
cwd: os.homedir(),
|
|
126
129
|
stdio: 'pipe',
|
|
@@ -160,10 +163,10 @@ function getCurrentVersion() {
|
|
|
160
163
|
clearTimeout(timeout)
|
|
161
164
|
resolve('error')
|
|
162
165
|
})
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
resolve('error')
|
|
168
|
+
}
|
|
169
|
+
})
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
function compareVersions(v1, v2) {
|
|
@@ -296,10 +299,9 @@ async function ensureBinaryExists() {
|
|
|
296
299
|
}
|
|
297
300
|
}
|
|
298
301
|
|
|
299
|
-
async function checkForUpdates(runningProcess, exitListener) {
|
|
302
|
+
async function checkForUpdates(runningProcess, exitListener, retry) {
|
|
300
303
|
try {
|
|
301
304
|
const currentVersion = await getCurrentVersion()
|
|
302
|
-
if (!currentVersion) return
|
|
303
305
|
|
|
304
306
|
const latestVersion = await getLatestVersion()
|
|
305
307
|
if (!latestVersion) return
|
|
@@ -333,48 +335,52 @@ async function checkForUpdates(runningProcess, exitListener) {
|
|
|
333
335
|
|
|
334
336
|
await downloadBinary(latestVersion)
|
|
335
337
|
|
|
336
|
-
|
|
337
|
-
const newChild = spawn(CONFIG.binaryPath, process.argv.slice(2), {
|
|
338
|
-
stdio: 'inherit',
|
|
339
|
-
detached: false,
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
// Set up exit handler for the new process
|
|
343
|
-
newChild.on('exit', (code) => {
|
|
344
|
-
process.exit(code || 0)
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
// Don't return - keep this function running to maintain the wrapper
|
|
348
|
-
return new Promise(() => {}) // Never resolves, keeps wrapper alive
|
|
338
|
+
await retry()
|
|
349
339
|
}
|
|
350
340
|
} catch (error) {
|
|
351
341
|
// Silently ignore update check errors
|
|
352
342
|
}
|
|
353
343
|
}
|
|
354
344
|
|
|
355
|
-
async function main() {
|
|
345
|
+
async function main(firstRun = false) {
|
|
356
346
|
await ensureBinaryExists()
|
|
357
347
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
348
|
+
let error = null
|
|
349
|
+
try {
|
|
350
|
+
// Start codebuff
|
|
351
|
+
const child = spawn(CONFIG.binaryPath, process.argv.slice(2), {
|
|
352
|
+
stdio: 'inherit',
|
|
353
|
+
})
|
|
362
354
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
355
|
+
// Store reference to the exit listener so we can remove it during updates
|
|
356
|
+
const exitListener = (code) => {
|
|
357
|
+
process.exit(code || 0)
|
|
358
|
+
}
|
|
367
359
|
|
|
368
|
-
|
|
360
|
+
child.on('exit', exitListener)
|
|
369
361
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
362
|
+
if (firstRun) {
|
|
363
|
+
// Check for updates in background
|
|
364
|
+
setTimeout(() => {
|
|
365
|
+
if (!error) {
|
|
366
|
+
checkForUpdates(child, exitListener, main)
|
|
367
|
+
}
|
|
368
|
+
}, 100)
|
|
369
|
+
}
|
|
370
|
+
} catch (err) {
|
|
371
|
+
error = err
|
|
372
|
+
if (firstRun) {
|
|
373
|
+
console.error('❌ Codebuff failed to start:', error.message)
|
|
374
|
+
console.log('Redownloading Codebuff...')
|
|
375
|
+
// Binary could be corrupted (killed before download completed), so delete and retry.
|
|
376
|
+
fs.unlinkSync(CONFIG.binaryPath)
|
|
377
|
+
await main()
|
|
378
|
+
}
|
|
379
|
+
}
|
|
374
380
|
}
|
|
375
381
|
|
|
376
382
|
// Run the main function
|
|
377
|
-
main().catch((error) => {
|
|
383
|
+
main(true).catch((error) => {
|
|
378
384
|
console.error('❌ Unexpected error:', error.message)
|
|
379
385
|
process.exit(1)
|
|
380
386
|
})
|