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

Function normalizePathForCJSResolution

internal/module/resolver.go:2048–2056  ·  view source on GitHub ↗

If you import from "." inside a containing directory "/foo", the result of `tspath.NormalizePath` would be "/foo", but this loses the information that `foo` is a directory and we intended to look inside of it. The Node CommonJS resolution algorithm doesn't call this out (https://nodejs.org/api/modul

(containingDirectory string, moduleName string)

Source from the content-addressed store, hash-verified

2046// (https://nodejs.org/api/modules.html#all-together), but it seems that module paths ending
2047// in `.` are actually normalized to `./` before proceeding with the resolution algorithm.
2048func normalizePathForCJSResolution(containingDirectory string, moduleName string) string {
2049 combined := tspath.CombinePaths(containingDirectory, moduleName)
2050 parts := tspath.GetPathComponents(combined, "")
2051 lastPart := parts[len(parts)-1]
2052 if lastPart == "." || lastPart == ".." {
2053 return tspath.EnsureTrailingDirectorySeparator(tspath.NormalizePath(combined))
2054 }
2055 return tspath.NormalizePath(combined)
2056}
2057
2058func matchesPatternWithTrailer(target string, name string) bool {
2059 if strings.HasSuffix(target, "*") {

Callers 2

resolveNodeLikeWorkerMethod · 0.85

Calls 5

CombinePathsFunction · 0.92
GetPathComponentsFunction · 0.92
NormalizePathFunction · 0.92
lenFunction · 0.85

Tested by

no test coverage detected