Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: YarnPnP resolve drive letter correctly #3664

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions internal/fs/fs_zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"
"sync"
"syscall"
"unicode"
)

type zipFS struct {
Expand Down Expand Up @@ -330,6 +331,10 @@ func (fs *zipFS) WatchData() WatchData {
return fs.inner.WatchData()
}

func HasDriveLetter(path string) bool {
return len(path) >= 2 && unicode.IsLetter(rune(path[0])) && path[1] == ':'
}

func ParseYarnPnPVirtualPath(path string) (string, string, bool) {
i := 0

Expand All @@ -356,7 +361,7 @@ func ParseYarnPnPVirtualPath(path string) (string, string, bool) {
// Find the range of the count
if slash := strings.IndexAny(path[j:], "/\\"); slash != -1 {
count = path[j : j+slash]
suffix = path[j+slash:]
suffix = path[j+slash+1:]
} else {
count = path[j:]
}
Expand All @@ -369,6 +374,9 @@ func ParseYarnPnPVirtualPath(path string) (string, string, bool) {
for n > 0 && (strings.HasSuffix(prefix, "/") || strings.HasSuffix(prefix, "\\")) {
slash := strings.LastIndexAny(prefix[:len(prefix)-1], "/\\")
if slash == -1 {
if HasDriveLetter(prefix) {
prefix = ""
}
break
}
prefix = prefix[:slash+1]
Expand All @@ -378,8 +386,8 @@ func ParseYarnPnPVirtualPath(path string) (string, string, bool) {
// Make sure the prefix and suffix work well when joined together
if suffix == "" && strings.IndexAny(prefix, "/\\") != strings.LastIndexAny(prefix, "/\\") {
prefix = prefix[:len(prefix)-1]
} else if prefix == "" {
prefix = "."
} else if prefix == "" && !HasDriveLetter(suffix) {
prefix = "./"
} else if strings.HasPrefix(suffix, "/") || strings.HasPrefix(suffix, "\\") {
suffix = suffix[1:]
}
Expand Down