* Convert a file:// URI to a filesystem path. Handles URL encoding and * Windows drive letter paths.
(uri: string)
| 46 | * Windows drive letter paths. |
| 47 | */ |
| 48 | function fileUriToPath(uri: string): string { |
| 49 | try { |
| 50 | const url = new URL(uri); |
| 51 | let filePath = decodeURIComponent(url.pathname); |
| 52 | if (process.platform === 'win32' && /^\/[a-zA-Z]:/.test(filePath)) { |
| 53 | filePath = filePath.slice(1); |
| 54 | } |
| 55 | return path.resolve(filePath); |
| 56 | } catch { |
| 57 | return uri.replace(/^file:\/\/\/?/, ''); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** First usable filesystem path from a `roots/list` result, or null. */ |
| 62 | function firstRootPath(result: unknown): string | null { |
no test coverage detected