(fileUrl: string)
| 104 | * @returns The file path and optional function name |
| 105 | */ |
| 106 | export function parseFileUrl(fileUrl: string): { filePath: string; functionName?: string } { |
| 107 | if (!fileUrl.startsWith('file://')) { |
| 108 | throw new Error('URL must start with file://'); |
| 109 | } |
| 110 | |
| 111 | const urlWithoutProtocol = fileUrl.slice('file://'.length); |
| 112 | const lastColonIndex = urlWithoutProtocol.lastIndexOf(':'); |
| 113 | |
| 114 | if (lastColonIndex > 1) { |
| 115 | const candidateFilePath = urlWithoutProtocol.slice(0, lastColonIndex); |
| 116 | |
| 117 | // Only executable function files support a :functionName suffix. This preserves |
| 118 | // colons that are part of a valid file or directory name on POSIX systems. |
| 119 | if (!isJavascriptFile(candidateFilePath) && !candidateFilePath.endsWith('.py')) { |
| 120 | return { |
| 121 | filePath: normalizeFilePath(urlWithoutProtocol), |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | return { |
| 126 | filePath: normalizeFilePath(candidateFilePath), |
| 127 | functionName: urlWithoutProtocol.slice(lastColonIndex + 1), |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | return { |
| 132 | filePath: normalizeFilePath(urlWithoutProtocol), |
| 133 | }; |
| 134 | } |
no test coverage detected
searching dependent graphs…