From 321020ab83b715d00b44434f9313c91e66b863dd Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sat, 19 Oct 2024 17:45:30 +0100 Subject: [PATCH] fix: skip major updater if not ready for prod (#4080) --- .../js/src/admin/components/ExtensionCard.tsx | 2 +- .../js/src/admin/components/Updater.tsx | 3 +- .../js/src/admin/models/ExternalExtension.ts | 13 ++------ .../js/src/admin/utils/versions.ts | 32 +++++++++++++++++++ 4 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 extensions/package-manager/js/src/admin/utils/versions.ts diff --git a/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx b/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx index 97f2a13f2..2f5294a68 100644 --- a/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx +++ b/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx @@ -130,7 +130,7 @@ export default class ExtensionCard {
{this.controlItems().toArray()}
{this.availableUpdatesView()} , - core && core.package['latest-major'] ? ( + core && core.package['latest-major'] && isProductionReady(core.package['latest-major']) ? ( ) : null, ]; diff --git a/extensions/package-manager/js/src/admin/models/ExternalExtension.ts b/extensions/package-manager/js/src/admin/models/ExternalExtension.ts index 895b3cf42..fd1692a8a 100644 --- a/extensions/package-manager/js/src/admin/models/ExternalExtension.ts +++ b/extensions/package-manager/js/src/admin/models/ExternalExtension.ts @@ -1,6 +1,7 @@ import Model from 'flarum/common/Model'; import app from 'flarum/admin/app'; import type { Extension } from 'flarum/admin/AdminApplication'; +import { isProductionReady } from '../utils/versions'; export default class ExternalExtension extends Model { extensionId = Model.attribute('extensionId'); @@ -36,16 +37,8 @@ export default class ExternalExtension extends Model { return currentVersion.split('.')[0] === latestCompatibleVersion.split('.')[0]; } - public isStable(): boolean { - const split = this.highestVersion().split('-'); - - if (split.length === 1) { - return true; - } - - const stability = split[1].split('.'); - - return stability[0] === 'stable'; + public isProductionReady(): boolean { + return isProductionReady(this.highestVersion()); } public toLocalExtension(): Extension { diff --git a/extensions/package-manager/js/src/admin/utils/versions.ts b/extensions/package-manager/js/src/admin/utils/versions.ts new file mode 100644 index 000000000..0f291a500 --- /dev/null +++ b/extensions/package-manager/js/src/admin/utils/versions.ts @@ -0,0 +1,32 @@ +export enum VersionStability { + Stable = 'stable', + Alpha = 'alpha', + Beta = 'beta', + RC = 'rc', + Dev = 'dev', +} + +export function isProductionReady(version: string): boolean { + return [VersionStability.Stable, VersionStability.RC].includes(stability(version)); +} + +export function stability(version: string): VersionStability { + const split = version.split('-'); + + if (split.length === 1) { + return VersionStability.Stable; + } + + const stab = split[1].split('.')[0].toLowerCase(); + + switch (stab) { + case 'alpha': + return VersionStability.Alpha; + case 'beta': + return VersionStability.Beta; + case 'rc': + return VersionStability.RC; + default: + return VersionStability.Dev; + } +}