mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-20 06:44:32 +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>
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { compare, valid } from 'semver'
|
|
import { computed, onMounted } from 'vue'
|
|
|
|
import { useInstalledPacks } from '@/composables/nodePack/useInstalledPacks'
|
|
import type { components } from '@/types/comfyRegistryTypes'
|
|
import { useComfyManagerStore } from '@/workbench/extensions/manager/stores/comfyManagerStore'
|
|
|
|
/**
|
|
* Composable to find NodePacks that have updates available
|
|
* Uses the same filtering approach as ManagerDialogContent.vue
|
|
* Automatically fetches installed pack data when initialized
|
|
*/
|
|
export const useUpdateAvailableNodes = () => {
|
|
const comfyManagerStore = useComfyManagerStore()
|
|
const { installedPacks, isLoading, error, startFetchInstalled } =
|
|
useInstalledPacks()
|
|
|
|
// Check if a pack has updates available (same logic as usePackUpdateStatus)
|
|
const isOutdatedPack = (pack: components['schemas']['Node']) => {
|
|
const isInstalled = comfyManagerStore.isPackInstalled(pack?.id)
|
|
if (!isInstalled) return false
|
|
|
|
const installedVersion = comfyManagerStore.getInstalledPackVersion(
|
|
pack.id ?? ''
|
|
)
|
|
const latestVersion = pack.latest_version?.version
|
|
|
|
const isNightlyPack = !!installedVersion && !valid(installedVersion)
|
|
|
|
if (isNightlyPack || !latestVersion) {
|
|
return false
|
|
}
|
|
|
|
return compare(latestVersion, installedVersion) > 0
|
|
}
|
|
|
|
// Same filtering logic as ManagerDialogContent.vue
|
|
const filterOutdatedPacks = (packs: components['schemas']['Node'][]) =>
|
|
packs.filter(isOutdatedPack)
|
|
|
|
// Filter only outdated packs from installed packs
|
|
const updateAvailableNodePacks = computed(() => {
|
|
if (!installedPacks.value.length) return []
|
|
return filterOutdatedPacks(installedPacks.value)
|
|
})
|
|
|
|
// Filter only enabled outdated packs
|
|
const enabledUpdateAvailableNodePacks = computed(() => {
|
|
return updateAvailableNodePacks.value.filter((pack) =>
|
|
comfyManagerStore.isPackEnabled(pack.id)
|
|
)
|
|
})
|
|
|
|
// Check if there are any enabled outdated packs
|
|
const hasUpdateAvailable = computed(() => {
|
|
return enabledUpdateAvailableNodePacks.value.length > 0
|
|
})
|
|
|
|
// Check if there are disabled packs with updates
|
|
const hasDisabledUpdatePacks = computed(() => {
|
|
return (
|
|
updateAvailableNodePacks.value.length >
|
|
enabledUpdateAvailableNodePacks.value.length
|
|
)
|
|
})
|
|
|
|
// Automatically fetch installed pack data when composable is used
|
|
onMounted(async () => {
|
|
if (!installedPacks.value.length && !isLoading.value) {
|
|
await startFetchInstalled()
|
|
}
|
|
})
|
|
|
|
return {
|
|
updateAvailableNodePacks,
|
|
enabledUpdateAvailableNodePacks,
|
|
hasUpdateAvailable,
|
|
hasDisabledUpdatePacks,
|
|
isLoading,
|
|
error
|
|
}
|
|
}
|