Skip to content

Commit 9da8c7e

Browse files
committed
fix: apply numeric-aware sorting before limit in formatAndCombineResults
The previous implementation removed sorting entirely, which caused version-numbered files to be excluded when directories had 200+ files. This fix applies numeric-aware sorting (using localeCompare with numeric option) before the limit is applied, ensuring proper ordering of version sequences like v3.25, v3.25.1, v3.25.2, etc.
1 parent ab481ea commit 9da8c7e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/services/glob/list-files.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,20 @@ function formatAndCombineResults(files: string[], directories: string[], limit:
601601
const uniquePathsSet = new Set(allPaths)
602602
const uniquePaths = Array.from(uniquePathsSet)
603603

604-
// Note: Sorting is handled by formatFilesList with numeric-aware algorithm
605-
// to properly handle version-numbered files (e.g., v3.25.1, v3.25.2, etc.)
604+
// Apply numeric-aware sorting before limiting results
605+
// This ensures version-numbered files are properly ordered before truncation
606+
uniquePaths.sort((a: string, b: string) => {
607+
const aIsDir = a.endsWith("/")
608+
const bIsDir = b.endsWith("/")
609+
610+
// Directories come first
611+
if (aIsDir && !bIsDir) return -1
612+
if (!aIsDir && bIsDir) return 1
613+
614+
// For same type (both dirs or both files), use numeric-aware comparison
615+
// This properly handles version numbers like v3.25.1, v3.25.2, etc.
616+
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
617+
})
606618

607619
const trimmedPaths = uniquePaths.slice(0, limit)
608620
return [trimmedPaths, trimmedPaths.length >= limit]

0 commit comments

Comments
 (0)