(outDir: string, spec: string)
| 245 | |
| 246 | const PATH_TO_SPEC = /[\\/]+/g; |
| 247 | export function pathToSpec(outDir: string, spec: string): string { |
| 248 | const outDirUrl = pathToFileUrl(outDir); |
| 249 | |
| 250 | if ( |
| 251 | spec.startsWith("http:") || spec.startsWith("https:") || |
| 252 | spec.startsWith("jsr:") |
| 253 | ) { |
| 254 | return spec; |
| 255 | } else if (spec.startsWith("file://")) { |
| 256 | const fileUrl = pathToFileUrl(spec); |
| 257 | spec = relativeUrl(outDirUrl, fileUrl); |
| 258 | return maybeDot(spec); |
| 259 | } |
| 260 | |
| 261 | spec = path.normalize(spec); |
| 262 | if (path.isAbsolute(spec)) { |
| 263 | const fileUrl = pathToFileUrl(spec); |
| 264 | spec = relativeUrl(outDirUrl, fileUrl); |
| 265 | return maybeDot(spec); |
| 266 | } |
| 267 | |
| 268 | spec = spec.replaceAll(PATH_TO_SPEC, "/"); |
| 269 | if (spec.startsWith("/")) { |
| 270 | const fileUrl = pathToFileUrl(spec); |
| 271 | spec = relativeUrl(outDirUrl, fileUrl); |
| 272 | return maybeDot(spec); |
| 273 | } |
| 274 | |
| 275 | spec = maybeDot(spec); |
| 276 | return spec; |
| 277 | } |
| 278 | |
| 279 | function maybeDot(spec: string): string { |
| 280 | return spec.startsWith(".") ? spec : `./${spec}`; |
no test coverage detected