@@ -83,6 +83,43 @@ export function clearUpdateCache(toolName: string): boolean {
8383 return false ;
8484}
8585
86+ /**
87+ * Write a cache entry that suppresses the update notification.
88+ *
89+ * After a CLI `update` command installs a new version, the currently running
90+ * binary still reports the OLD version via getPackageJson(__dirname). If we
91+ * merely clear the cache, the next command will fetch the latest from npm and
92+ * compare it against the stale pkgVersion, producing a false-positive
93+ * "Update available" message.
94+ *
95+ * By writing the current binary's version as `latestVersion`, the next
96+ * checkForUpdates call sees latestVersion === pkgVersion and returns
97+ * hasUpdate: false. Once the cache expires (24 h by default), a fresh check
98+ * runs against the (by then correct) new binary version.
99+ *
100+ * @param toolName - Tool name used for appstash directory (e.g., 'pgpm')
101+ * @param currentVersion - The version of the currently running binary
102+ * @returns true if the cache was written successfully
103+ */
104+ export function suppressUpdateCheck ( toolName : string , currentVersion : string ) : boolean {
105+ try {
106+ const dirs = appstash ( toolName ) ;
107+ const cacheFile = path . join ( dirs . cache , CACHE_FILENAME ) ;
108+ if ( ! fs . existsSync ( dirs . cache ) ) {
109+ fs . mkdirSync ( dirs . cache , { recursive : true } ) ;
110+ }
111+ fs . writeFileSync ( cacheFile , JSON . stringify ( {
112+ latestVersion : currentVersion ,
113+ timestamp : Date . now ( )
114+ } ) ) ;
115+ return true ;
116+ } catch {
117+ // If writing fails, fall back to clearing the old cache
118+ clearUpdateCache ( toolName ) ;
119+ return false ;
120+ }
121+ }
122+
86123function isNewerVersion ( latest : string , current : string ) : boolean {
87124 if ( semver . valid ( latest ) && semver . valid ( current ) ) {
88125 return semver . gt ( latest , current ) ;
0 commit comments