|
1 | 1 | import convertPathToPosix from "./convert-path-to-posix.js"; |
2 | | -import path from "path"; |
3 | 2 |
|
4 | 3 | const forwardSlashPattern = /\//g; |
5 | 4 | const protocolPattern = /^(\w{2,}):\/\//i; |
6 | 5 | const jsonPointerSlash = /~1/g; |
7 | 6 | const jsonPointerTilde = /~0/g; |
8 | 7 |
|
9 | | -import { join } from "path"; |
10 | 8 | import { isWindows } from "./is-windows.js"; |
11 | 9 |
|
12 | 10 | const isAbsoluteWin32Path = /^[a-zA-Z]:\\/; |
@@ -399,6 +397,13 @@ export function fromFileSystemPath(path: string) { |
399 | 397 | path.startsWith("file://"); |
400 | 398 |
|
401 | 399 | if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) { |
| 400 | + const join = (a: string, b: string) => { |
| 401 | + if (a.endsWith("/") || a.endsWith("\\")) { |
| 402 | + return a + b; |
| 403 | + } else { |
| 404 | + return a + "/" + b; |
| 405 | + } |
| 406 | + }; |
402 | 407 | path = join(projectDir, path); |
403 | 408 | } |
404 | 409 | path = convertPathToPosix(path); |
@@ -487,15 +492,3 @@ export function safePointerToPath(pointer: string) { |
487 | 492 | return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~"); |
488 | 493 | }); |
489 | 494 | } |
490 | | - |
491 | | -export function relative(from: string, to: string) { |
492 | | - if (!isFileSystemPath(from) || !isFileSystemPath(to)) { |
493 | | - return resolve(from, to); |
494 | | - } |
495 | | - |
496 | | - const fromDir = path.dirname(stripHash(from)); |
497 | | - const toPath = stripHash(to); |
498 | | - |
499 | | - const result = path.relative(fromDir, toPath); |
500 | | - return result + getHash(to); |
501 | | -} |
0 commit comments