* Convert a file:// URI to a filesystem path. Handles URL encoding and * Windows drive letter paths.
(uri: string)
| 68 | * Windows drive letter paths. |
| 69 | */ |
| 70 | function fileUriToPath(uri: string): string { |
| 71 | try { |
| 72 | const url = new URL(uri); |
| 73 | let filePath = decodeURIComponent(url.pathname); |
| 74 | if (process.platform === 'win32' && /^\/[a-zA-Z]:/.test(filePath)) { |
| 75 | filePath = filePath.slice(1); |
| 76 | } |
| 77 | return path.resolve(filePath); |
| 78 | } catch { |
| 79 | return uri.replace(/^file:\/\/\/?/, ''); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** First usable filesystem path from a `roots/list` result, or null. */ |
| 84 | function firstRootPath(result: unknown): string | null { |
no test coverage detected