mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-27 18:24:11 +00:00
Manager Conflict Nofitication (#4443)
Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: bymyself <cbyrne@comfy.org> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
66
src/utils/conflictMessageUtil.ts
Normal file
66
src/utils/conflictMessageUtil.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { ConflictDetail } from '@/types/conflictDetectionTypes'
|
||||
|
||||
/**
|
||||
* Generates a localized conflict message for a given conflict detail.
|
||||
* This function should be used anywhere conflict messages need to be displayed.
|
||||
*
|
||||
* @param conflict The conflict detail object
|
||||
* @param t The i18n translation function
|
||||
* @returns A localized conflict message string
|
||||
*/
|
||||
export function getConflictMessage(
|
||||
conflict: ConflictDetail,
|
||||
t: (key: string, params?: Record<string, any>) => string
|
||||
): string {
|
||||
const messageKey = `manager.conflicts.conflictMessages.${conflict.type}`
|
||||
|
||||
// For version and compatibility conflicts, use interpolated message
|
||||
if (
|
||||
conflict.type === 'comfyui_version' ||
|
||||
conflict.type === 'frontend_version' ||
|
||||
conflict.type === 'python_version' ||
|
||||
conflict.type === 'os' ||
|
||||
conflict.type === 'accelerator'
|
||||
) {
|
||||
return t(messageKey, {
|
||||
current: conflict.current_value,
|
||||
required: conflict.required_value
|
||||
})
|
||||
}
|
||||
|
||||
// For dependency conflicts, show the missing dependency
|
||||
if (conflict.type === 'python_dependency') {
|
||||
return t(messageKey, {
|
||||
required: conflict.required_value
|
||||
})
|
||||
}
|
||||
|
||||
// For banned and security_pending, use simple message
|
||||
if (conflict.type === 'banned' || conflict.type === 'security_pending') {
|
||||
return t(messageKey)
|
||||
}
|
||||
|
||||
// Fallback to generic message with interpolation
|
||||
return t('manager.conflicts.conflictMessages.generic', {
|
||||
current: conflict.current_value,
|
||||
required: conflict.required_value
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates conflict messages for multiple conflicts and joins them.
|
||||
*
|
||||
* @param conflicts Array of conflict details
|
||||
* @param t The i18n translation function
|
||||
* @param separator The separator to use when joining messages (default: '; ')
|
||||
* @returns A single string with all conflict messages joined
|
||||
*/
|
||||
export function getJoinedConflictMessages(
|
||||
conflicts: ConflictDetail[],
|
||||
t: (key: string, params?: Record<string, any>) => string,
|
||||
separator = '; '
|
||||
): string {
|
||||
return conflicts
|
||||
.map((conflict) => getConflictMessage(conflict, t))
|
||||
.join(separator)
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import * as semver from 'semver'
|
||||
|
||||
import type {
|
||||
ConflictDetail,
|
||||
ConflictType
|
||||
} from '@/types/conflictDetectionTypes'
|
||||
|
||||
/**
|
||||
* Cleans a version string by removing common prefixes and normalizing format
|
||||
* @param version Raw version string (e.g., "v1.2.3", "1.2.3-alpha")
|
||||
@@ -53,28 +58,54 @@ export function isValidVersion(version: string): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a human-readable description of a version range
|
||||
* @param range Version range string
|
||||
* @returns Description of what the range means
|
||||
* Checks version compatibility and returns conflict details.
|
||||
* Supports all semver ranges including >=, <=, >, <, ~, ^ operators.
|
||||
* @param type Conflict type (e.g., 'comfyui_version', 'frontend_version')
|
||||
* @param currentVersion Current version string
|
||||
* @param supportedVersion Required version range string
|
||||
* @returns ConflictDetail object if incompatible, null if compatible
|
||||
*/
|
||||
export function describeVersionRange(range: string): string {
|
||||
if (range.startsWith('>=')) {
|
||||
return `version ${range.substring(2)} or higher`
|
||||
} else if (range.startsWith('>')) {
|
||||
return `version higher than ${range.substring(1)}`
|
||||
} else if (range.startsWith('<=')) {
|
||||
return `version ${range.substring(2)} or lower`
|
||||
} else if (range.startsWith('<')) {
|
||||
return `version lower than ${range.substring(1)}`
|
||||
} else if (range.startsWith('^')) {
|
||||
return `compatible with version ${range.substring(1)}`
|
||||
} else if (range.startsWith('~')) {
|
||||
return `approximately version ${range.substring(1)}`
|
||||
} else if (range.includes(' - ')) {
|
||||
const [min, max] = range.split(' - ')
|
||||
return `version between ${min} and ${max}`
|
||||
} else if (range.includes('||')) {
|
||||
return `one of multiple version ranges: ${range}`
|
||||
export function checkVersionCompatibility(
|
||||
type: ConflictType,
|
||||
currentVersion: string,
|
||||
supportedVersion: string
|
||||
): ConflictDetail | null {
|
||||
// If current version is unknown, assume compatible (no conflict)
|
||||
if (!currentVersion || currentVersion === 'unknown') {
|
||||
return null
|
||||
}
|
||||
return `version ${range}`
|
||||
}
|
||||
|
||||
// If no version requirement specified, assume compatible (no conflict)
|
||||
if (!supportedVersion || supportedVersion.trim() === '') {
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
// Clean the current version using semver utilities
|
||||
const cleanCurrent = cleanVersion(currentVersion)
|
||||
|
||||
// Check version compatibility using semver library
|
||||
const isCompatible = satisfiesVersion(cleanCurrent, supportedVersion)
|
||||
|
||||
if (!isCompatible) {
|
||||
return {
|
||||
type,
|
||||
current_value: currentVersion,
|
||||
required_value: supportedVersion
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`[VersionUtil] Failed to parse version requirement: ${supportedVersion}`,
|
||||
error
|
||||
)
|
||||
// On error, assume incompatible to be safe
|
||||
return {
|
||||
type,
|
||||
current_value: currentVersion,
|
||||
required_value: supportedVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user