Line data Source code
1 : import { compare, valid } from 'semver'
2 :
3 : import type { components } from '@/types/comfyRegistryTypes'
4 : import type { useComfyManagerStore } from '@/platform/customNodes/manager/stores/comfyManagerStore'
5 :
6 : type NodePack = components['schemas']['Node']
7 : type ComfyManagerStore = ReturnType<typeof useComfyManagerStore>
8 :
9 : interface PackUpdateStatus {
10 : isInstalled: boolean
11 : installedVersion: string | undefined
12 : latestVersion: string | undefined
13 : isNightly: boolean
14 : isUpdateAvailable: boolean
15 : }
16 :
17 : /**
18 : * A pack is a nightly build when its installed version is not valid semver
19 : * (a git hash), so it cannot be compared against the latest release version.
20 : */
21 225 : export function isNightlyVersion(version: string | undefined): boolean {
22 225 : return !!version && !valid(version)
23 : }
24 :
25 : /**
26 : * Derives the update status of a pack from its installed version and the
27 : * latest release version advertised by the registry. A nightly build is never
28 : * "outdated" since git hashes cannot be ordered.
29 : */
30 225 : export function getPackUpdateStatus(
31 : pack: NodePack | undefined,
32 : managerStore: ComfyManagerStore
33 : ): PackUpdateStatus {
34 225 : const isInstalled = managerStore.isPackInstalled(pack?.id)
35 225 : const installedVersion = managerStore.getInstalledPackVersion(pack?.id ?? '')
36 225 : const latestVersion = pack?.latest_version?.version
37 225 : const isNightly = isNightlyVersion(installedVersion)
38 :
39 : const isUpdateAvailable =
40 : isInstalled &&
41 : !isNightly &&
42 : !!installedVersion &&
43 : !!latestVersion &&
44 : !!valid(latestVersion) &&
45 : compare(latestVersion, installedVersion) > 0
46 :
47 225 : return {
48 : isInstalled,
49 : installedVersion,
50 : latestVersion,
51 : isNightly,
52 : isUpdateAvailable
53 : }
54 : }
|