diff options
| author | Gal Zahavi <[email protected]> | 2025-07-28 17:56:52 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-29 00:56:52 +0000 |
| commit | 871e0dfab811192f67cd80bc270580ad784ffdc8 (patch) | |
| tree | bcb8de6af3a2e52a7d7597e5b28465c35b87f60a /packages/cli/src/ui/utils/updateCheck.ts | |
| parent | 83c4dddb7ee7ba34d7dec09d00819972d2e1ff5f (diff) | |
feat: Add auto update functionality (#4686)
Diffstat (limited to 'packages/cli/src/ui/utils/updateCheck.ts')
| -rw-r--r-- | packages/cli/src/ui/utils/updateCheck.ts | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/packages/cli/src/ui/utils/updateCheck.ts b/packages/cli/src/ui/utils/updateCheck.ts index 904a9890..b0a0de1b 100644 --- a/packages/cli/src/ui/utils/updateCheck.ts +++ b/packages/cli/src/ui/utils/updateCheck.ts @@ -4,11 +4,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -import updateNotifier from 'update-notifier'; +import updateNotifier, { UpdateInfo } from 'update-notifier'; import semver from 'semver'; import { getPackageJson } from '../../utils/package.js'; -export async function checkForUpdates(): Promise<string | null> { +export interface UpdateObject { + message: string; + update: UpdateInfo; +} + +export async function checkForUpdates(): Promise<UpdateObject | null> { try { // Skip update check when running from source (development mode) if (process.env.DEV === 'true') { @@ -30,11 +35,13 @@ export async function checkForUpdates(): Promise<string | null> { shouldNotifyInNpmScript: true, }); - if ( - notifier.update && - semver.gt(notifier.update.latest, notifier.update.current) - ) { - return `Gemini CLI update available! ${notifier.update.current} → ${notifier.update.latest}\nRun npm install -g ${packageJson.name} to update`; + const updateInfo = await notifier.fetchInfo(); + + if (updateInfo && semver.gt(updateInfo.latest, updateInfo.current)) { + return { + message: `Gemini CLI update available! ${updateInfo.current} → ${updateInfo.latest}`, + update: updateInfo, + }; } return null; |
