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

            Line data    Source code
       1              : import { mapKeys } from 'es-toolkit/compat'
       2              : 
       3              : /**
       4              :  * Normalizes a pack ID by removing the version suffix.
       5              :  *
       6              :  * ComfyUI-Manager returns pack IDs in different formats:
       7              :  * - Enabled packs: "packname" (without version)
       8              :  * - Disabled packs: "packname@1_0_3" (with version suffix)
       9              :  * - Latest versions from registry: "packname" (without version)
      10              :  *
      11              :  * Since the pack object itself contains the version info (ver field),
      12              :  * we normalize all pack IDs to just the base name for consistent access.
      13              :  * This ensures we can always find a pack by its base name (nodePack.id)
      14              :  * regardless of its enabled/disabled state.
      15              :  *
      16              :  * @param packId - The pack ID that may contain a version suffix
      17              :  * @returns The normalized pack ID without version suffix
      18              :  */
      19           33 : export function normalizePackId(packId: string): string {
      20           33 :   return packId.split('@')[0]
      21              : }
      22              : 
      23              : /**
      24              :  * Normalizes all keys in a pack record by removing version suffixes.
      25              :  * This is used when receiving pack data from the server to ensure
      26              :  * consistent key format across the application.
      27              :  *
      28              :  * @param packs - Record of packs with potentially versioned keys
      29              :  * @returns Record with normalized keys
      30              :  */
      31           16 : export function normalizePackKeys<T>(
      32              :   packs: Record<string, T>
      33              : ): Record<string, T> {
      34           16 :   return mapKeys(packs, (_value, key) => normalizePackId(key))
      35              : }
      36              : 
      37              : /** Returns the normalized pack id from a `custom_nodes.<pack>` Python module path, or null for any other module. */
      38            1 : export function extractCustomNodeName(
      39              :   pythonModule: string | undefined
      40              : ): string | null {
      41            1 :   const modules = pythonModule?.split('.') || []
      42            1 :   if (modules.length >= 2 && modules[0] === 'custom_nodes') {
      43            1 :     return normalizePackId(modules[1])
      44              :   }
      45            0 :   return null
      46              : }
        

Generated by: LCOV version 2.0-1