Browse Source

fix(auto-update): preserve channel in dist-tag fallback

Alvin Unreal 2 months ago
parent
commit
f3236700bc

+ 25 - 0
src/hooks/auto-update-checker/checker.test.ts

@@ -387,5 +387,30 @@ describe('auto-update-checker/checker', () => {
 
 
       globalThis.fetch = originalFetch;
       globalThis.fetch = originalFetch;
     });
     });
+
+    test('fallback dist-tags never return stable latest for prerelease channel', async () => {
+      const originalFetch = globalThis.fetch;
+      globalThis.fetch = mock(async (url: string) => {
+        if (url.includes('/-/package/')) {
+          return Response.json({ latest: '1.5.0' });
+        }
+
+        return new Response(null, { status: 503 });
+      }) as never;
+
+      const { getLatestCompatibleVersion } = await import(
+        `./checker?test=${importCounter++}`
+      );
+
+      const result = await getLatestCompatibleVersion('1.4.0-beta.1', 'beta');
+
+      expect(result).toEqual({
+        latestVersion: null,
+        latestMajorVersion: null,
+        blockedByMajor: false,
+      });
+
+      globalThis.fetch = originalFetch;
+    });
   });
   });
 });
 });

+ 5 - 1
src/hooks/auto-update-checker/checker.ts

@@ -478,7 +478,11 @@ async function getCompatibleFromDistTags(
   const blockedByMajor = latestMajorVersion !== null;
   const blockedByMajor = latestMajorVersion !== null;
   const parsedLatest = latestVersion ? parseVersion(latestVersion) : null;
   const parsedLatest = latestVersion ? parseVersion(latestVersion) : null;
   const compatibleLatestVersion =
   const compatibleLatestVersion =
-    parsedLatest?.major === current.major ? latestVersion : null;
+    parsedLatest?.major === current.major &&
+    latestVersion &&
+    isVersionInChannel(latestVersion, channel)
+      ? latestVersion
+      : null;
 
 
   return {
   return {
     latestVersion: compatibleLatestVersion,
     latestVersion: compatibleLatestVersion,