* Convert a file:// URI to a filesystem path. Handles URL encoding and * Windows drive letter paths.
(uri: string)
| 153 | * Windows drive letter paths. |
| 154 | */ |
| 155 | function fileUriToPath(uri: string): string { |
| 156 | try { |
| 157 | const url = new URL(uri); |
| 158 | let filePath = decodeURIComponent(url.pathname); |
| 159 | if (process.platform === 'win32' && /^\/[a-zA-Z]:/.test(filePath)) { |
| 160 | filePath = filePath.slice(1); |
| 161 | } |
| 162 | return path.resolve(filePath); |
| 163 | } catch { |
| 164 | return uri.replace(/^file:\/\/\/?/, ''); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /** First usable filesystem path from a `roots/list` result, or null. */ |
| 169 | function firstRootPath(result: unknown): string | null { |
no test coverage detected