@@ -12,6 +12,8 @@ const UPDATE_CHECK_CACHE_FILE = 'update-check.json';
1212
1313type UpdateCheckCache = {
1414 checkedAt ?: string ;
15+ /** The dist-tag `latestVersion` was read from; a cache from before channels means `latest`. */
16+ distTag ?: string ;
1517 latestVersion ?: string ;
1618 prompted ?: boolean ;
1719} ;
@@ -50,7 +52,7 @@ export function maybeRunUpgradeNotifier(options: UpgradeNotifierOptions): void {
5052 } ) ;
5153 }
5254
53- if ( shouldStartBackgroundCheck ( cache , now ) ) {
55+ if ( shouldStartBackgroundCheck ( cache , options . currentVersion , now ) ) {
5456 spawnBackgroundUpdateCheck ( cachePath , options . currentVersion ) ;
5557 }
5658}
@@ -59,16 +61,17 @@ export async function runUpdateCheckWorker(options: UpdateCheckWorkerOptions): P
5961 const now = Date . now ( ) ;
6062 const cache = readUpdateCheckCache ( options . cachePath ) ;
6163
64+ const distTag = distTagFor ( options . currentVersion ) ;
6265 try {
63- const latestVersion =
64- ( await fetchLatestPackageVersion ( distTagFor ( options . currentVersion ) ) ) ?? undefined ;
66+ const latestVersion = ( await fetchLatestPackageVersion ( distTag ) ) ?? undefined ;
6567 if ( ! latestVersion || compareVersions ( latestVersion , options . currentVersion ) <= 0 ) {
66- writeUpdateCheckCache ( options . cachePath , { checkedAt : new Date ( now ) . toISOString ( ) } ) ;
68+ writeUpdateCheckCache ( options . cachePath , { checkedAt : new Date ( now ) . toISOString ( ) , distTag } ) ;
6769 return ;
6870 }
6971
7072 writeUpdateCheckCache ( options . cachePath , {
7173 checkedAt : new Date ( now ) . toISOString ( ) ,
74+ distTag,
7275 latestVersion,
7376 prompted : cache . latestVersion === latestVersion ? cache . prompted === true : false ,
7477 } ) ;
@@ -92,11 +95,17 @@ function shouldEnableUpgradeNotifier(options: UpgradeNotifierOptions): boolean {
9295
9396function shouldShowUpgradeNotice ( cache : UpdateCheckCache , currentVersion : string ) : boolean {
9497 if ( ! cache . latestVersion ) return false ;
98+ if ( cachedDistTag ( cache ) !== distTagFor ( currentVersion ) ) return false ;
9599 if ( compareVersions ( cache . latestVersion , currentVersion ) <= 0 ) return false ;
96100 return cache . prompted !== true ;
97101}
98102
99- function shouldStartBackgroundCheck ( cache : UpdateCheckCache , now : number ) : boolean {
103+ function shouldStartBackgroundCheck (
104+ cache : UpdateCheckCache ,
105+ currentVersion : string ,
106+ now : number ,
107+ ) : boolean {
108+ if ( cachedDistTag ( cache ) !== distTagFor ( currentVersion ) ) return true ;
100109 const checkedAt = parseTimestamp ( cache . checkedAt ) ;
101110 return checkedAt === undefined || now - checkedAt >= UPDATE_CHECK_INTERVAL_MS ;
102111}
@@ -106,6 +115,7 @@ function readUpdateCheckCache(cachePath: string): UpdateCheckCache {
106115 const raw = JSON . parse ( fs . readFileSync ( cachePath , 'utf8' ) ) as UpdateCheckCache ;
107116 return {
108117 checkedAt : typeof raw . checkedAt === 'string' ? raw . checkedAt : undefined ,
118+ distTag : typeof raw . distTag === 'string' ? raw . distTag : undefined ,
109119 latestVersion : typeof raw . latestVersion === 'string' ? raw . latestVersion : undefined ,
110120 prompted : raw . prompted === true ,
111121 } ;
@@ -151,6 +161,10 @@ function spawnBackgroundUpdateCheck(cachePath: string, currentVersion: string):
151161 ] ) ;
152162}
153163
164+ function cachedDistTag ( cache : UpdateCheckCache ) : string {
165+ return cache . distTag ?? 'latest' ;
166+ }
167+
154168/** A nightly build follows the `nightly` dist-tag; every other build follows `latest`. */
155169function distTagFor ( version : string ) : 'latest' | 'nightly' {
156170 return version . includes ( '-nightly.' ) ? 'nightly' : 'latest' ;
0 commit comments