MCPcopy Index your code
hub / github.com/microsoft/typescript-go / GetSymlinkCache

Method GetSymlinkCache

internal/compiler/program.go:2022–2069  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2020}
2021
2022func (p *Program) GetSymlinkCache() *symlinks.KnownSymlinks {
2023 return p.knownSymlinks.getValue(func() *symlinks.KnownSymlinks {
2024 knownSymlinks := symlinks.NewKnownSymlink(p.GetCurrentDirectory(), p.UseCaseSensitiveFileNames())
2025
2026 // Resolved modules store realpath information when they're resolved inside node_modules
2027 if len(p.resolvedModules) > 0 || len(p.typeResolutionsInFile) > 0 {
2028 knownSymlinks.SetSymlinksFromResolutions(p.ForEachResolvedModule, p.ForEachResolvedTypeReferenceDirective)
2029 }
2030
2031 // Check other dependencies for symlinks
2032 var seenPackageJsons collections.Set[tspath.Path]
2033 for filePath, meta := range p.sourceFileMetaDatas {
2034 if meta.PackageJsonDirectory == "" ||
2035 !p.SourceFileMayBeEmitted(p.GetSourceFileByPath(filePath), false) ||
2036 !seenPackageJsons.AddIfAbsent(p.toPath(meta.PackageJsonDirectory)) {
2037 continue
2038 }
2039 packageJsonName := tspath.CombinePaths(meta.PackageJsonDirectory, "package.json")
2040 info := p.GetPackageJsonInfo(packageJsonName)
2041 if info.GetContents() == nil {
2042 continue
2043 }
2044
2045 for dep := range info.GetContents().GetRuntimeDependencyNames().Keys() {
2046 // Skip work in common case: we already saved a symlink for this package directory
2047 // in the node_modules adjacent to this package.json
2048 possibleDirectoryPath := p.toPath(tspath.CombinePaths(meta.PackageJsonDirectory, "node_modules", dep))
2049 if knownSymlinks.HasDirectory(possibleDirectoryPath) {
2050 continue
2051 }
2052 if !strings.HasPrefix(dep, "@types") {
2053 possibleTypesDirectoryPath := p.toPath(tspath.CombinePaths(meta.PackageJsonDirectory, "node_modules", module.GetTypesPackageName(dep)))
2054 if knownSymlinks.HasDirectory(possibleTypesDirectoryPath) {
2055 continue
2056 }
2057 }
2058
2059 if packageResolution := p.resolver.ResolvePackageDirectory(dep, packageJsonName, core.ResolutionModeCommonJS, nil); packageResolution.IsResolved() {
2060 knownSymlinks.ProcessResolution(
2061 tspath.CombinePaths(packageResolution.OriginalPath, "package.json"),
2062 tspath.CombinePaths(packageResolution.ResolvedFileName, "package.json"),
2063 )
2064 }
2065 }
2066 }
2067 return knownSymlinks
2068 })
2069}
2070
2071func (p *Program) ResolveModuleName(moduleName string, containingFile string, resolutionMode core.ResolutionMode) *module.ResolvedModule {
2072 resolved, _ := p.resolver.ResolveModuleName(moduleName, containingFile, resolutionMode, nil)

Callers

nothing calls this directly

Calls 15

GetCurrentDirectoryMethod · 0.95
GetSourceFileByPathMethod · 0.95
toPathMethod · 0.95
GetPackageJsonInfoMethod · 0.95
NewKnownSymlinkFunction · 0.92
CombinePathsFunction · 0.92
GetTypesPackageNameFunction · 0.92
lenFunction · 0.85
GetContentsMethod · 0.80

Tested by

no test coverage detected