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

Function checkForUpdates

cli/release/index.js:483–535  ·  view source on GitHub ↗
(runningProcess, exitListener)

Source from the content-addressed store, hash-verified

481}
482
483async function checkForUpdates(runningProcess, exitListener) {
484 try {
485 const currentVersion = getCurrentVersion()
486
487 const latestVersion = await getLatestVersion()
488 if (!latestVersion) return
489
490 if (
491 // Download new version if current version is unknown or outdated.
492 currentVersion === null ||
493 compareVersions(currentVersion, latestVersion) < 0
494 ) {
495 term.clearLine()
496
497 runningProcess.removeListener('exit', exitListener)
498
499 await new Promise((resolve) => {
500 let exited = false
501 runningProcess.once('exit', () => {
502 exited = true
503 resolve()
504 })
505 runningProcess.kill('SIGTERM')
506 setTimeout(() => {
507 if (!exited) {
508 runningProcess.kill('SIGKILL')
509 // Safety: resolve after giving SIGKILL time to take effect
510 setTimeout(() => resolve(), 1000)
511 }
512 }, 5000)
513 })
514
515 resetTerminal({ exitAlternateScreen: true })
516 console.log(`Update available: ${currentVersion} → ${latestVersion}`)
517
518 await downloadBinary(latestVersion)
519
520 const newChild = spawnInstalledBinary({ detached: false })
521
522 newChild.on('exit', (code, signal) => {
523 resetTerminal({
524 exitAlternateScreen: shouldExitAlternateScreen(code, signal),
525 })
526 printCrashDiagnostics(code, signal)
527 process.exit(signal ? 1 : (code || 0))
528 })
529
530 return new Promise(() => {})
531 }
532 } catch (error) {
533 // Ignore update failures
534 }
535}
536
537function printCrashDiagnostics(code, signal) {
538 // Windows NTSTATUS codes (unsigned DWORD)

Callers 1

mainFunction · 0.70

Calls 13

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

Tested by

no test coverage detected