diff --git a/internal/modulespecifiers/specifiers.go b/internal/modulespecifiers/specifiers.go index 49838a5ec6f..afecbd4f1dc 100644 --- a/internal/modulespecifiers/specifiers.go +++ b/internal/modulespecifiers/specifiers.go @@ -208,6 +208,11 @@ func getAllModulePathsWorker( allFileNames[p.FileName] = p } + useCaseSensitiveFileNames := info.UseCaseSensitiveFileNames + comparePaths := func(a, b ModulePath) int { + return comparePathsByRedirect(a, b, useCaseSensitiveFileNames) + } + // Sort by paths closest to importing file Name directory sortedPaths := make([]ModulePath, 0, len(paths)) for directory := info.SourceDirectory; len(allFileNames) != 0; { @@ -220,7 +225,7 @@ func getAllModulePathsWorker( } } if len(pathsInDirectory) > 0 { - slices.SortStableFunc(pathsInDirectory, comparePathsByRedirectAndNumberOfDirectorySeparators) + slices.SortFunc(pathsInDirectory, comparePaths) sortedPaths = append(sortedPaths, pathsInDirectory...) } newDirectory := tspath.GetDirectoryPath(directory) @@ -231,7 +236,7 @@ func getAllModulePathsWorker( } if len(allFileNames) > 0 { remainingPaths := slices.Collect(maps.Values(allFileNames)) - slices.SortStableFunc(remainingPaths, comparePathsByRedirectAndNumberOfDirectorySeparators) + slices.SortFunc(remainingPaths, comparePaths) sortedPaths = append(sortedPaths, remainingPaths...) } return sortedPaths diff --git a/internal/modulespecifiers/util.go b/internal/modulespecifiers/util.go index a6d75afece6..de05c39fd5f 100644 --- a/internal/modulespecifiers/util.go +++ b/internal/modulespecifiers/util.go @@ -26,9 +26,9 @@ var ( regexPatternCache = make(map[regexPatternCacheKey]*regexp2.Regexp) ) -func comparePathsByRedirectAndNumberOfDirectorySeparators(a ModulePath, b ModulePath) int { +func comparePathsByRedirect(a ModulePath, b ModulePath, useCaseSensitiveFileNames bool) int { if a.IsRedirect == b.IsRedirect { - return strings.Count(a.FileName, "/") - strings.Count(b.FileName, "/") + return tspath.ComparePaths(a.FileName, b.FileName, tspath.ComparePathsOptions{UseCaseSensitiveFileNames: useCaseSensitiveFileNames}) } if a.IsRedirect { return 1