Skip to content

Commit e281fc7

Browse files
committed
Add logging to version checker for better observability
- Accept optional logger parameter in checkForUpdates - Log when version check is skipped (npm fetch failed) - Log when plugin is up to date with current versions - Log when an update is available with version details
1 parent 4cf3a47 commit e281fc7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const plugin: Plugin = (async (ctx) => {
147147
})
148148

149149
// Check for updates on launch (fire and forget)
150-
checkForUpdates(ctx.client).catch(() => {})
150+
checkForUpdates(ctx.client, logger).catch(() => {})
151151

152152
return {
153153
/**

lib/version-checker.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,23 @@ export function isOutdated(local: string, remote: string): boolean {
6565
* Checks for updates and shows a toast if outdated.
6666
* Fire-and-forget: does not throw, logs errors silently.
6767
*/
68-
export async function checkForUpdates(client: any): Promise<void> {
68+
export async function checkForUpdates(client: any, logger?: { info: (component: string, message: string, data?: any) => void }): Promise<void> {
6969
try {
7070
const local = getLocalVersion()
7171
const npm = await getNpmVersion()
7272

73-
if (!npm || !isOutdated(local, npm)) {
74-
return // Up to date or couldn't fetch
73+
if (!npm) {
74+
logger?.info("version", "Version check skipped", { reason: "npm fetch failed" })
75+
return
7576
}
7677

78+
if (!isOutdated(local, npm)) {
79+
logger?.info("version", "Up to date", { local, npm })
80+
return
81+
}
82+
83+
logger?.info("version", "Update available", { local, npm })
84+
7785
await client.tui.showToast({
7886
body: {
7987
title: "DCP: Update available",

0 commit comments

Comments
 (0)