mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-03 04:31:58 +00:00
## Summary - Replace custom `compareVersions()` with `semver.compare()` - Replace custom `isSemVer()` with `semver.valid()` - Remove deprecated version comparison functions from `formatUtil.ts` - Update all version comparison logic across components and stores - Fix tests to use semver mocking instead of formatUtil mocking ## Benefits - **Industry standard**: Uses well-maintained, battle-tested `semver` package - **Better reliability**: Handles edge cases more robustly than custom implementation - **Consistent behavior**: All version comparisons now use the same underlying logic - **Type safety**: Better TypeScript support with proper semver types Fixes #4787 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5653-refactor-Replace-manual-semantic-version-utilities-functions-with-semver-package-2736d73d365081fb8498ee11cbcc10e2) by [Unito](https://www.unito.io) --------- Co-authored-by: DrJKL <DrJKL@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { compare, valid } from 'semver'
|
|
import { computed } from 'vue'
|
|
|
|
import type { components } from '@/types/comfyRegistryTypes'
|
|
import { useComfyManagerStore } from '@/workbench/extensions/manager/stores/comfyManagerStore'
|
|
|
|
export const usePackUpdateStatus = (
|
|
nodePack: components['schemas']['Node']
|
|
) => {
|
|
const { isPackInstalled, getInstalledPackVersion } = useComfyManagerStore()
|
|
|
|
const isInstalled = computed(() => isPackInstalled(nodePack?.id))
|
|
const installedVersion = computed(() =>
|
|
getInstalledPackVersion(nodePack.id ?? '')
|
|
)
|
|
const latestVersion = computed(() => nodePack.latest_version?.version)
|
|
|
|
const isNightlyPack = computed(
|
|
() => !!installedVersion.value && !valid(installedVersion.value)
|
|
)
|
|
|
|
const isUpdateAvailable = computed(() => {
|
|
if (!isInstalled.value || isNightlyPack.value || !latestVersion.value) {
|
|
return false
|
|
}
|
|
return compare(latestVersion.value, installedVersion.value) > 0
|
|
})
|
|
|
|
return {
|
|
isUpdateAvailable,
|
|
isNightlyPack,
|
|
installedVersion,
|
|
latestVersion
|
|
}
|
|
}
|