()
| 2020 | } |
| 2021 | |
| 2022 | func (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 | |
| 2071 | func (p *Program) ResolveModuleName(moduleName string, containingFile string, resolutionMode core.ResolutionMode) *module.ResolvedModule { |
| 2072 | resolved, _ := p.resolver.ResolveModuleName(moduleName, containingFile, resolutionMode, nil) |
nothing calls this directly
no test coverage detected