MCPcopy Create free account
hub / github.com/microsoft/typescript-go / GetAutomaticTypeDirectiveNames

Function GetAutomaticTypeDirectiveNames

internal/module/resolver.go:2082–2127  ·  view source on GitHub ↗
(options *core.CompilerOptions, host ResolutionHost)

Source from the content-addressed store, hash-verified

2080}
2081
2082func GetAutomaticTypeDirectiveNames(options *core.CompilerOptions, host ResolutionHost) []string {
2083 if !options.UsesWildcardTypes() {
2084 if options.Types != nil {
2085 return options.Types
2086 }
2087 return []string{}
2088 }
2089
2090 // Walk the primary type lookup locations
2091 var wildcardMatches []string
2092 typeRoots, _ := options.GetEffectiveTypeRoots(host.GetCurrentDirectory())
2093 for _, root := range typeRoots {
2094 if host.FS().DirectoryExists(root) {
2095 for _, typeDirectivePath := range host.FS().GetAccessibleEntries(root).Directories {
2096 normalized := tspath.NormalizePath(typeDirectivePath)
2097 packageJsonPath := tspath.CombinePaths(root, normalized, "package.json")
2098 isNotNeededPackage := false
2099 if host.FS().FileExists(packageJsonPath) {
2100 contents, _ := host.FS().ReadFile(packageJsonPath)
2101 packageJsonContent, _ := packagejson.Parse([]byte(contents))
2102 // `types-publisher` sometimes creates packages with `"typings": null` for packages that don't provide their own types.
2103 // See `createNotNeededPackageJSON` in the types-publisher` repo.
2104 isNotNeededPackage = packageJsonContent.Typings.Null
2105 }
2106 if !isNotNeededPackage {
2107 baseFileName := tspath.GetBaseFileName(normalized)
2108 if !strings.HasPrefix(baseFileName, ".") {
2109 wildcardMatches = append(wildcardMatches, baseFileName)
2110 }
2111 }
2112 }
2113 }
2114 }
2115
2116 // Order potentially matters in program construction, so substitute
2117 // in the wildcard in the position it was specified in the types array
2118 var result []string
2119 for _, t := range options.Types {
2120 if t == "*" {
2121 result = append(result, wildcardMatches...)
2122 } else {
2123 result = append(result, t)
2124 }
2125 }
2126 return core.Deduplicate(result)
2127}
2128
2129type Ending int
2130

Callers 1

Calls 14

NormalizePathFunction · 0.92
CombinePathsFunction · 0.92
ParseFunction · 0.92
GetBaseFileNameFunction · 0.92
DeduplicateFunction · 0.92
UsesWildcardTypesMethod · 0.80
GetEffectiveTypeRootsMethod · 0.80
GetCurrentDirectoryMethod · 0.65
DirectoryExistsMethod · 0.65
FSMethod · 0.65
GetAccessibleEntriesMethod · 0.65
FileExistsMethod · 0.65

Tested by

no test coverage detected