resolveFromTypeRoot tries to resolve a module name from the configured typeRoots. This is used as a fallback after node_modules resolution fails, for declaration file lookups. Returns nil if typeRoots is not configured or if no matching module is found in any typeRoot directory.
()
| 468 | // This is used as a fallback after node_modules resolution fails, for declaration file lookups. |
| 469 | // Returns nil if typeRoots is not configured or if no matching module is found in any typeRoot directory. |
| 470 | func (r *resolutionState) resolveFromTypeRoot() *resolved { |
| 471 | if r.compilerOptions.TypeRoots == nil { |
| 472 | return nil |
| 473 | } |
| 474 | for _, typeRoot := range r.compilerOptions.TypeRoots { |
| 475 | candidate := r.getCandidateFromTypeRoot(typeRoot) |
| 476 | directoryExists := r.resolver.host.FS().DirectoryExists(typeRoot) |
| 477 | if !directoryExists { |
| 478 | if r.tracer != nil { |
| 479 | r.tracer.write(diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, typeRoot) |
| 480 | } |
| 481 | continue |
| 482 | } |
| 483 | if resolvedFromFile := r.loadModuleFromFile(extensionsDeclaration, candidate); !resolvedFromFile.shouldContinueSearching() { |
| 484 | packageDirectory := ParseNodeModuleFromPath(resolvedFromFile.path, false) |
| 485 | if packageDirectory != "" { |
| 486 | resolvedFromFile.packageId = r.getPackageId(resolvedFromFile.path, r.getPackageJsonInfo(packageDirectory)) |
| 487 | } |
| 488 | return resolvedFromFile |
| 489 | } |
| 490 | if resolved := r.loadNodeModuleFromDirectory(extensionsDeclaration, candidate, true /*considerPackageJson*/); !resolved.shouldContinueSearching() { |
| 491 | return resolved |
| 492 | } |
| 493 | } |
| 494 | return nil |
| 495 | } |
| 496 | |
| 497 | func (r *resolutionState) getPackageScopeForPath(directory string) *packagejson.InfoCacheEntry { |
| 498 | result := tspath.ForEachAncestorDirectoryStoppingAtGlobalCache( |
no test coverage detected