* Convert a file:// URI to a filesystem path. Handles URL encoding and * Windows drive letter paths.
(uri: string)
| 112 | * Windows drive letter paths. |
| 113 | */ |
| 114 | function fileUriToPath(uri: string): string { |
| 115 | try { |
| 116 | const url = new URL(uri); |
| 117 | let filePath = decodeURIComponent(url.pathname); |
| 118 | if (process.platform === 'win32' && /^\/[a-zA-Z]:/.test(filePath)) { |
| 119 | filePath = filePath.slice(1); |
| 120 | } |
| 121 | return path.resolve(filePath); |
| 122 | } catch { |
| 123 | return uri.replace(/^file:\/\/\/?/, ''); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** First usable filesystem path from a `roots/list` result, or null. */ |
| 128 | function firstRootPath(result: unknown): string | null { |
no test coverage detected