MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / checkForUpdates

Function checkForUpdates

cli/release-staging/index.js:463–523  ·  view source on GitHub ↗
(runningProcess, exitListener)

Source from the content-addressed store, hash-verified

461}
462
463async function checkForUpdates(runningProcess, exitListener) {
464 try {
465 const currentVersion = getCurrentVersion()
466
467 const latestVersion = await getLatestVersion()
468 if (!latestVersion) return
469
470 if (
471 // Download new version if current version is unknown or outdated.
472 currentVersion === null ||
473 compareVersions(currentVersion, latestVersion) < 0
474 ) {
475 term.clearLine()
476
477 runningProcess.removeListener('exit', exitListener)
478
479 await new Promise((resolve) => {
480 let exited = false
481 runningProcess.once('exit', () => {
482 exited = true
483 resolve()
484 })
485 runningProcess.kill('SIGTERM')
486 setTimeout(() => {
487 if (!exited) {
488 runningProcess.kill('SIGKILL')
489 // Safety: resolve after giving SIGKILL time to take effect
490 setTimeout(() => resolve(), 1000)
491 }
492 }, 5000)
493 })
494
495 resetTerminal({ exitAlternateScreen: true })
496 console.log(`Update available: ${currentVersion} → ${latestVersion}`)
497
498 await downloadBinary(latestVersion)
499
500 const newChild = spawn(CONFIG.binaryPath, process.argv.slice(2), {
501 stdio: 'inherit',
502 detached: false,
503 })
504
505 newChild.on('exit', (code, signal) => {
506 resetTerminal({
507 exitAlternateScreen: shouldExitAlternateScreen(code, signal),
508 })
509 printCrashDiagnostics(code, signal)
510 process.exit(signal ? 1 : (code || 0))
511 })
512
513 newChild.on('error', (err) => {
514 console.error('Failed to start codecane:', err.message)
515 process.exit(1)
516 })
517
518 return new Promise(() => {})
519 }
520 } catch (error) {

Callers 1

mainFunction · 0.70

Calls 12

setTimeoutFunction · 0.85
removeListenerMethod · 0.80
onceMethod · 0.80
getCurrentVersionFunction · 0.70
getLatestVersionFunction · 0.70
compareVersionsFunction · 0.70
resetTerminalFunction · 0.70
downloadBinaryFunction · 0.70
printCrashDiagnosticsFunction · 0.70
onMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected