LCOV - code coverage report
Current view: top level - src/platform/customNodes/manager/utils - versionUtil.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 43.8 % 16 7
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { isEmpty, isNil } from 'es-toolkit/compat'
       2              : import { clean, satisfies } from 'semver'
       3              : 
       4              : import config from '@/config'
       5              : import type {
       6              :   ConflictDetail,
       7              :   ConflictType
       8              : } from '@/platform/customNodes/manager/types/conflictDetectionTypes'
       9              : 
      10              : /**
      11              :  * Cleans a version string by removing common prefixes and normalizing format
      12              :  * @param version Raw version string (e.g., "v1.2.3", "1.2.3-alpha")
      13              :  * @returns Cleaned version string or original if cleaning fails
      14              :  */
      15            0 : function cleanVersion(version: string): string {
      16            0 :   return clean(version) || version
      17              : }
      18              : 
      19              : /**
      20              :  * Checks version compatibility and returns conflict details.
      21              :  * Supports all semver ranges including >=, <=, >, <, ~, ^ operators.
      22              :  * @param type Conflict type (e.g., 'comfyui_version', 'frontend_version')
      23              :  * @param currentVersion Current version string
      24              :  * @param supportedVersion Required version range string
      25              :  * @returns ConflictDetail object if incompatible, null if compatible
      26              :  */
      27          446 : export function checkVersionCompatibility(
      28              :   type: ConflictType,
      29              :   currentVersion?: string,
      30              :   supportedVersion?: string
      31              : ): ConflictDetail | null {
      32              :   // If current version is unknown, assume compatible (no conflict)
      33          446 :   if (isNil(currentVersion) || isEmpty(currentVersion)) {
      34          193 :     return null
      35              :   }
      36              : 
      37              :   // If no version requirement specified, assume compatible (no conflict)
      38          446 :   if (isNil(supportedVersion) || isEmpty(supportedVersion.trim())) {
      39          253 :     return null
      40              :   }
      41              : 
      42              :   // Clean and check version compatibility
      43            0 :   const cleanCurrent = cleanVersion(currentVersion)
      44              : 
      45              :   // Check if version satisfies the range
      46            0 :   let isCompatible: boolean
      47            0 :   try {
      48            0 :     isCompatible = satisfies(cleanCurrent, supportedVersion)
      49              :   } catch {
      50              :     // If semver can't parse it, return conflict
      51            0 :     return {
      52              :       type,
      53              :       current_value: currentVersion,
      54              :       required_value: supportedVersion
      55              :     }
      56              :   }
      57              : 
      58            0 :   if (isCompatible) return null
      59              : 
      60            0 :   return {
      61              :     type,
      62              :     current_value: currentVersion,
      63              :     required_value: supportedVersion
      64              :   }
      65              : }
      66              : 
      67              : /**
      68              :  * get frontend version from config.
      69              :  * @returns frontend version string or undefined
      70              :  */
      71          208 : export function getFrontendVersion(): string | undefined {
      72          208 :   return config.app_version || import.meta.env.VITE_APP_VERSION || undefined
      73              : }
        

Generated by: LCOV version 2.0-1