From b1d075ae0c059a9321dbb36704ee3f2269fbcfe0 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sat, 31 Jan 2026 11:37:52 -0800 Subject: [PATCH 1/3] Fix dedupe/redirect nondeterminism --- internal/modulespecifiers/util.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/modulespecifiers/util.go b/internal/modulespecifiers/util.go index a6d75afece6..88cbf475508 100644 --- a/internal/modulespecifiers/util.go +++ b/internal/modulespecifiers/util.go @@ -28,7 +28,10 @@ var ( func comparePathsByRedirectAndNumberOfDirectorySeparators(a ModulePath, b ModulePath) int { if a.IsRedirect == b.IsRedirect { - return strings.Count(a.FileName, "/") - strings.Count(b.FileName, "/") + if c := strings.Count(a.FileName, "/") - strings.Count(b.FileName, "/"); c != 0 { + return c + } + return strings.Compare(a.FileName, b.FileName) } if a.IsRedirect { return 1 From b2280d069ad8841895e775f681287699bb58b279 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sat, 31 Jan 2026 11:40:49 -0800 Subject: [PATCH 2/3] Don't stable sort, allFileNames is randomly ordered --- internal/modulespecifiers/specifiers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/modulespecifiers/specifiers.go b/internal/modulespecifiers/specifiers.go index 49838a5ec6f..5d47a436b92 100644 --- a/internal/modulespecifiers/specifiers.go +++ b/internal/modulespecifiers/specifiers.go @@ -220,7 +220,7 @@ func getAllModulePathsWorker( } } if len(pathsInDirectory) > 0 { - slices.SortStableFunc(pathsInDirectory, comparePathsByRedirectAndNumberOfDirectorySeparators) + slices.SortFunc(pathsInDirectory, comparePathsByRedirectAndNumberOfDirectorySeparators) sortedPaths = append(sortedPaths, pathsInDirectory...) } newDirectory := tspath.GetDirectoryPath(directory) @@ -231,7 +231,7 @@ func getAllModulePathsWorker( } if len(allFileNames) > 0 { remainingPaths := slices.Collect(maps.Values(allFileNames)) - slices.SortStableFunc(remainingPaths, comparePathsByRedirectAndNumberOfDirectorySeparators) + slices.SortFunc(remainingPaths, comparePathsByRedirectAndNumberOfDirectorySeparators) sortedPaths = append(sortedPaths, remainingPaths...) } return sortedPaths From 421176c7376e8ba189956a6706b4c5a2f9bc403b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sat, 31 Jan 2026 11:53:19 -0800 Subject: [PATCH 3/3] Use full comparison --- internal/modulespecifiers/specifiers.go | 9 +++++++-- internal/modulespecifiers/util.go | 7 ++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/modulespecifiers/specifiers.go b/internal/modulespecifiers/specifiers.go index 5d47a436b92..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.SortFunc(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.SortFunc(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 88cbf475508..de05c39fd5f 100644 --- a/internal/modulespecifiers/util.go +++ b/internal/modulespecifiers/util.go @@ -26,12 +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 { - if c := strings.Count(a.FileName, "/") - strings.Count(b.FileName, "/"); c != 0 { - return c - } - return strings.Compare(a.FileName, b.FileName) + return tspath.ComparePaths(a.FileName, b.FileName, tspath.ComparePathsOptions{UseCaseSensitiveFileNames: useCaseSensitiveFileNames}) } if a.IsRedirect { return 1