( source: MarketplaceSource, )
| 233 | * @returns The hostname string, or null if extraction fails or source type not supported |
| 234 | */ |
| 235 | export function extractHostFromSource( |
| 236 | source: MarketplaceSource, |
| 237 | ): string | null { |
| 238 | switch (source.source) { |
| 239 | case 'github': |
| 240 | // GitHub shorthand always means github.com |
| 241 | return 'github.com' |
| 242 | |
| 243 | case 'git': { |
| 244 | // SSH format: user@HOST:path (e.g., git@github.com:owner/repo.git) |
| 245 | const sshMatch = source.url.match(/^[^@]+@([^:]+):/) |
| 246 | if (sshMatch?.[1]) { |
| 247 | return sshMatch[1] |
| 248 | } |
| 249 | // HTTPS format: extract hostname from URL |
| 250 | try { |
| 251 | return new URL(source.url).hostname |
| 252 | } catch { |
| 253 | return null |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | case 'url': |
| 258 | try { |
| 259 | return new URL(source.url).hostname |
| 260 | } catch { |
| 261 | return null |
| 262 | } |
| 263 | |
| 264 | // npm, file, directory, hostPattern, pathPattern sources are not supported for hostPattern matching |
| 265 | default: |
| 266 | return null |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Check if a source matches a hostPattern entry. |
no outgoing calls
no test coverage detected