mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
Co-authored-by: Roo Code <roomote@roocode.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com> Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com>
35 lines
1 KiB
TypeScript
35 lines
1 KiB
TypeScript
import * as path from "path"
|
|
|
|
/**
|
|
* Normalize a path by removing trailing slashes and converting separators.
|
|
* This handles cross-platform path comparison issues.
|
|
*/
|
|
export function normalizePath(p: string): string {
|
|
// Remove trailing slashes
|
|
let normalized = p.replace(/[/\\]+$/, "")
|
|
// Convert to consistent separators using path.normalize
|
|
normalized = path.normalize(normalized)
|
|
return normalized
|
|
}
|
|
|
|
/**
|
|
* Compare two paths for equality, handling:
|
|
* - Trailing slashes
|
|
* - Path separator differences
|
|
* - Case sensitivity (case-insensitive on Windows/macOS)
|
|
*/
|
|
export function arePathsEqual(path1?: string, path2?: string): boolean {
|
|
if (!path1 || !path2) {
|
|
return false
|
|
}
|
|
|
|
const normalizedPath1 = normalizePath(path1)
|
|
const normalizedPath2 = normalizePath(path2)
|
|
|
|
// On Windows and macOS, file paths are case-insensitive
|
|
if (process.platform === "win32" || process.platform === "darwin") {
|
|
return normalizedPath1.toLowerCase() === normalizedPath2.toLowerCase()
|
|
}
|
|
|
|
return normalizedPath1 === normalizedPath2
|
|
}
|