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

Function checkForUpdates

freebuff/cli/release/index.js:471–522  ·  view source on GitHub ↗
(runningProcess, exitListener)

Source from the content-addressed store, hash-verified

469}
470
471async function checkForUpdates(runningProcess, exitListener) {
472 try {
473 const currentVersion = getCurrentVersion()
474
475 const latestVersion = await getLatestVersion()
476 if (!latestVersion) return
477
478 if (
479 currentVersion === null ||
480 compareVersions(currentVersion, latestVersion) < 0
481 ) {
482 term.clearLine()
483
484 runningProcess.removeListener('exit', exitListener)
485
486 await new Promise((resolve) => {
487 let exited = false
488 runningProcess.once('exit', () => {
489 exited = true
490 resolve()
491 })
492 runningProcess.kill('SIGTERM')
493 setTimeout(() => {
494 if (!exited) {
495 runningProcess.kill('SIGKILL')
496 // Safety: resolve after giving SIGKILL time to take effect
497 setTimeout(() => resolve(), 1000)
498 }
499 }, 5000)
500 })
501
502 resetTerminal({ exitAlternateScreen: true })
503 console.log(`Update available: ${currentVersion} → ${latestVersion}`)
504
505 await downloadBinary(latestVersion)
506
507 const newChild = spawnInstalledBinary({ detached: false })
508
509 newChild.on('exit', (code, signal) => {
510 resetTerminal({
511 exitAlternateScreen: shouldExitAlternateScreen(code, signal),
512 })
513 printCrashDiagnostics(code, signal)
514 process.exit(signal ? 1 : (code || 0))
515 })
516
517 return new Promise(() => {})
518 }
519 } catch (error) {
520 // Ignore update failures
521 }
522}
523
524function printCrashDiagnostics(code, signal) {
525 // 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