Skip to content
Open
Show file tree
Hide file tree
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
60 changes: 42 additions & 18 deletions tsc/internal/compiler/projectreferencedtsfakinghost.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,36 +200,60 @@ func (fs *projectReferenceDtsFakingVfs) fileOrDirectoryExistsUsingSource(
if packageRoot != "" {
fs.handleDirectoryCouldBeSymlink(packageRoot)
}
knownDirectoryLinks := fs.knownSymlinks.Directories()
if knownDirectoryLinks.Size() == 0 {
if !fs.knownSymlinks.HasAnyDirectory() {
return false
}
knownDirectoryLinks := fs.knownSymlinks.Directories()
if onFileExists != nil {
_, ok := fs.knownSymlinks.Files().Load(fileOrDirectoryPath)
if ok {
return true
}
}

// If it contains node_modules check if its one of the symlinked path we know of
var exists bool
knownDirectoryLinks.Range(func(directoryPath tspath.PathKey, knownDirectoryLink *symlinks.KnownDirectoryLink) bool {
if directoryPath == fileOrDirectoryPath || !directoryPath.ContainsPath(fileOrDirectoryPath) {
// If a directory link was stored with an uppercase non-dynamic root on a case-sensitive host,
// fall back to ContainsPath which compares path roots case-insensitively.
if fs.knownSymlinks.HasUppercaseRoot() {
var exists bool
knownDirectoryLinks.Range(func(directoryPath tspath.PathKey, knownDirectoryLink *symlinks.KnownDirectoryLink) bool {
if knownDirectoryLink == nil || directoryPath == fileOrDirectoryPath || !directoryPath.ContainsPath(fileOrDirectoryPath) {
return true
}
realFileOrDirectory, ok := knownDirectoryLink.ResolveFilePath(tspath.RootedFilePathFromPath(fileOrDirectory), fs.CaseSensitivity())
if !ok {
panic("canonical symlink path did not match its presentation path")
}
if exists = existsUsingSource(tspath.RootedPath(realFileOrDirectory)).IsTrue(); exists {
if onFileExists != nil {
onFileExists(realFileOrDirectory)
}
return false
}
return true
}
realFileOrDirectory, ok := knownDirectoryLink.ResolveFilePath(tspath.RootedFilePathFromPath(fileOrDirectory), fs.CaseSensitivity())
if !ok {
panic("canonical symlink path did not match its presentation path")
}
if exists = existsUsingSource(tspath.RootedPath(realFileOrDirectory)).IsTrue(); exists {
if onFileExists != nil {
onFileExists(realFileOrDirectory)
})
return exists
}
// If it contains node_modules check if any ancestor directory is a known symlink
for dir := fileOrDirectoryPath.Parent(); ; {
if knownDirectoryLink, ok := knownDirectoryLinks.Load(dir); ok && knownDirectoryLink != nil {
realFileOrDirectory, ok := knownDirectoryLink.ResolveFilePath(tspath.RootedFilePathFromPath(fileOrDirectory), fs.CaseSensitivity())
if !ok {
panic("canonical symlink path did not match its presentation path")
}
if existsUsingSource(tspath.RootedPath(realFileOrDirectory)).IsTrue() {
if onFileExists != nil {
onFileExists(realFileOrDirectory)
}
return true
}
return false
}
return true
})
return exists
parent := dir.Parent()
if parent == dir {
break
}
dir = parent
}
return false
}

func (fs *projectReferenceDtsFakingVfs) fileExistsIfProjectReferenceDts(file tspath.RootedFilePath) core.Tristate {
Expand Down
31 changes: 31 additions & 0 deletions tsc/internal/symlinks/knownsymlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package symlinks

import (
"strings"
"sync/atomic"

"github.com/microsoft/TypeScript/tsc/internal/ast"
"github.com/microsoft/TypeScript/tsc/internal/collections"
Expand All @@ -26,6 +27,30 @@ type KnownSymlinks struct {
files collections.SyncMap[tspath.PathKey, tspath.RootedFilePath]
filesByRealpath collections.SyncMap[tspath.PathKey, *collections.SyncSet[tspath.RootedFilePath]]
caseSensitivity tspath.CaseSensitivity
hasDirectories atomic.Bool
hasUppercaseRoot atomic.Bool
}

func (cache *KnownSymlinks) HasAnyDirectory() bool {
return cache.hasDirectories.Load()
}

func (cache *KnownSymlinks) HasUppercaseRoot() bool {
return cache.hasUppercaseRoot.Load()
}

func hasNonDynamicUppercaseRoot(p tspath.PathKey) bool {
s := string(p)
if tspath.IsEncodedDynamicFileName(s) {
return false
}
root := s[:tspath.GetRootLength(s)]
for i := range len(root) {
if 'A' <= root[i] && root[i] <= 'Z' {
return true
}
}
return false
}

func (cache *KnownSymlinks) HasDirectory(symlinkPath tspath.PathKey) bool {
Expand Down Expand Up @@ -62,6 +87,12 @@ func (cache *KnownSymlinks) SetDirectory(symlink tspath.RootedDirectoryPath, sym
set.Add(symlink)
}
}
if realDirectory != nil {
if hasNonDynamicUppercaseRoot(symlinkPath) {
cache.hasUppercaseRoot.Store(true)
}
cache.hasDirectories.Store(true)
}
cache.directories.Store(symlinkPath, realDirectory)
}

Expand Down
Loading