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

Function GetEachFileNameOfModule

internal/modulespecifiers/specifiers.go:260–357  ·  view source on GitHub ↗

GetEachFileNameOfModule returns all possible file paths for a module, including symlink alternatives. This function handles symlink resolution and provides multiple path options for module resolution.

(
	importingFileName string,
	importedFileName string,
	host ModuleSpecifierGenerationHost,
	preferSymlinks bool,
)

Source from the content-addressed store, hash-verified

258// GetEachFileNameOfModule returns all possible file paths for a module, including symlink alternatives.
259// This function handles symlink resolution and provides multiple path options for module resolution.
260func GetEachFileNameOfModule(
261 importingFileName string,
262 importedFileName string,
263 host ModuleSpecifierGenerationHost,
264 preferSymlinks bool,
265) []ModulePath {
266 cwd := host.GetCurrentDirectory()
267 importedPath := tspath.ToPath(importedFileName, cwd, host.UseCaseSensitiveFileNames())
268 var referenceRedirect string
269 outputAndReference := host.GetProjectReferenceFromSource(importedPath)
270 if outputAndReference != nil && outputAndReference.OutputDts != "" {
271 referenceRedirect = outputAndReference.OutputDts
272 }
273
274 redirects := host.GetRedirectTargets(importedPath)
275 importedFileNames := make([]string, 0, 2+len(redirects))
276 if len(referenceRedirect) > 0 {
277 importedFileNames = append(importedFileNames, referenceRedirect)
278 }
279 importedFileNames = append(importedFileNames, importedFileName)
280 importedFileNames = append(importedFileNames, redirects...)
281 targets := core.Map(importedFileNames, func(f string) string { return tspath.GetNormalizedAbsolutePath(f, cwd) })
282 shouldFilterIgnoredPaths := !core.Every(targets, containsIgnoredPath)
283
284 results := make([]ModulePath, 0, 2)
285 if !preferSymlinks {
286 for _, p := range targets {
287 if !(shouldFilterIgnoredPaths && containsIgnoredPath(p)) {
288 results = append(results, ModulePath{
289 FileName: p,
290 IsInNodeModules: ContainsNodeModules(p),
291 IsRedirect: referenceRedirect == p,
292 })
293 }
294 }
295 }
296
297 symlinkCache := host.GetSymlinkCache()
298 fullImportedFileName := tspath.GetNormalizedAbsolutePath(importedFileName, cwd)
299 if symlinkCache != nil {
300 tspath.ForEachAncestorDirectoryStoppingAtGlobalCache(
301 host.GetGlobalTypingsCacheLocation(),
302 tspath.GetDirectoryPath(fullImportedFileName),
303 func(realPathDirectory string) (bool, bool) {
304 symlinkSet, ok := symlinkCache.DirectoriesByRealpath().Load(tspath.ToPath(realPathDirectory, cwd, host.UseCaseSensitiveFileNames()).EnsureTrailingDirectorySeparator())
305 if !ok {
306 return false, false
307 } // Continue to ancestor directory
308
309 // Don't want to a package to globally import from itself (importNameCodeFix_symlink_own_package.ts)
310 if tspath.StartsWithDirectory(importingFileName, realPathDirectory, host.UseCaseSensitiveFileNames()) {
311 return false, true // Stop search, each ancestor directory will also hit this condition
312 }
313
314 for _, target := range targets {
315 if !tspath.StartsWithDirectory(target, realPathDirectory, host.UseCaseSensitiveFileNames()) {
316 continue
317 }

Calls 15

ToPathFunction · 0.92
MapFunction · 0.92
EveryFunction · 0.92
GetDirectoryPathFunction · 0.92
StartsWithDirectoryFunction · 0.92
ResolvePathFunction · 0.92
lenFunction · 0.85
containsIgnoredPathFunction · 0.85
ContainsNodeModulesFunction · 0.85