Skip to content

Commit

Permalink
fix(relative): handle different windows drive letters (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 10, 2024
1 parent 2fa8aaa commit faa2b11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ export const relative: typeof path.relative = function (from, to) {
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");

// Different windows drive letters
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
return _to.join("/");
}

const _fromCopy = [..._from];
for (const segment of _fromCopy) {
if (_to[0] !== segment) {
Expand Down
1 change: 1 addition & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ runTest("relative", relative, [
["C:\\orandea\\test\\aaa", "c:\\orandea\\impl\\bbb", "../../impl/bbb"],
["C:\\", "C:\\foo\\bar", "foo/bar"],
["C:\\foo", "C:\\", ".."],
["C:\\foo", "d:\\bar", "D:/bar"],
[
() => process.cwd().replace(/\\/g, "/"),
"./dist/client/b-scroll.d.ts",
Expand Down

0 comments on commit faa2b11

Please sign in to comment.