| 125 | * @returns Version string from path, or null if not a versioned path |
| 126 | */ |
| 127 | export function getVersionFromPath(installPath: string): string | null { |
| 128 | // Versioned paths have format: .../plugins/cache/marketplace/plugin/version/ |
| 129 | const parts = installPath.split('/').filter(Boolean) |
| 130 | |
| 131 | // Find 'cache' index to determine depth |
| 132 | const cacheIndex = parts.findIndex( |
| 133 | (part, i) => part === 'cache' && parts[i - 1] === 'plugins', |
| 134 | ) |
| 135 | |
| 136 | if (cacheIndex === -1) { |
| 137 | return null |
| 138 | } |
| 139 | |
| 140 | // Versioned path has 3 components after 'cache': marketplace/plugin/version |
| 141 | const componentsAfterCache = parts.slice(cacheIndex + 1) |
| 142 | if (componentsAfterCache.length >= 3) { |
| 143 | return componentsAfterCache[2] || null |
| 144 | } |
| 145 | |
| 146 | return null |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Check if a path is a versioned plugin path. |