Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(plugins): offer the final release over an installed prerelease

Yudhi Armyndharisb0bb74717a92
diff --git a/src/modules/plugins/catalog.spec.ts b/src/modules/plugins/catalog.spec.ts
index f223e2192..89be156c2 100644
--- a/src/modules/plugins/catalog.spec.ts
+++ b/src/modules/plugins/catalog.spec.ts
@@ -46,4 +46,19 @@ describe('annotateCatalog', () => {
const out = annotateCatalog(entries, [{ id: 'faq-bot', version: '2.0.0' }]);
expect(out.find(e => e.id === 'faq-bot')!.updateAvailable).toBe(false);
});
+
+ it('flags the final release as an update over its own installed prerelease', () => {
+ const rc = annotateCatalog(entries, [{ id: 'faq-bot', version: '1.0.0-rc.1' }]);
+ expect(rc.find(e => e.id === 'faq-bot')!.updateAvailable).toBe(true);
+ const prerelease = annotateCatalog(
+ [{ id: 'faq-bot', name: 'FAQ', version: '1.0.0-rc.2' }],
+ [{ id: 'faq-bot', version: '1.0.0' }],
+ );
+ expect(prerelease[0].updateAvailable).toBe(false);
+ const rcToRc = annotateCatalog(
+ [{ id: 'faq-bot', name: 'FAQ', version: '1.0.0-rc.2' }],
+ [{ id: 'faq-bot', version: '1.0.0-rc.1' }],
+ );
+ expect(rcToRc[0].updateAvailable).toBe(false);
+ });
});
diff --git a/src/modules/plugins/catalog.ts b/src/modules/plugins/catalog.ts
index 945bff9e4..59465265f 100644
--- a/src/modules/plugins/catalog.ts
+++ b/src/modules/plugins/catalog.ts
@@ -46,7 +46,9 @@ export function compareSemver(a: string, b: string): number {
/**
* Annotate catalog entries with install state, given the plugins currently loaded by this instance.
- * `updateAvailable` is true when an entry is installed and the catalog version is strictly newer.
+ * `updateAvailable` is true when an entry is installed and the catalog version is strictly newer. A final
+ * release counts as newer than an installed prerelease of the same version, which compareSemver alone
+ * would call equal.
*/
export function annotateCatalog(
entries: CatalogEntry[],
@@ -55,11 +57,14 @@ export function annotateCatalog(
const byId = new Map(installed.map(p => [p.id, p.version]));
return entries.map(entry => {
const installedVersion = byId.get(entry.id) ?? null;
+ const cmp = installedVersion === null ? 0 : compareSemver(entry.version, installedVersion);
return {
...entry,
installed: installedVersion !== null,
installedVersion,
- updateAvailable: installedVersion !== null && compareSemver(entry.version, installedVersion) > 0,
+ updateAvailable:
+ installedVersion !== null &&
+ (cmp > 0 || (cmp === 0 && installedVersion.includes('-') && !String(entry.version).includes('-'))),
};
});
}