mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-22 13:21:07 -05:00
Refactor util functions out of claude dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as path from "path"
|
||||
import os from "os"
|
||||
|
||||
/*
|
||||
The Node.js 'path' module resolves and normalizes paths differently depending on the platform:
|
||||
@@ -76,3 +77,25 @@ function normalizePath(p: string): string {
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
export function getReadablePath(cwd: string, relPath?: string): string {
|
||||
relPath = relPath || ""
|
||||
// path.resolve is flexible in that it will resolve relative paths like '../../' to the cwd and even ignore the cwd if the relPath is actually an absolute path
|
||||
const absolutePath = path.resolve(cwd, relPath)
|
||||
if (arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))) {
|
||||
// User opened vscode without a workspace, so cwd is the Desktop. Show the full absolute path to keep the user aware of where files are being created
|
||||
return absolutePath.toPosix()
|
||||
}
|
||||
if (arePathsEqual(path.normalize(absolutePath), path.normalize(cwd))) {
|
||||
return path.basename(absolutePath).toPosix()
|
||||
} else {
|
||||
// show the relative path to the cwd
|
||||
const normalizedRelPath = path.relative(cwd, absolutePath)
|
||||
if (absolutePath.includes(cwd)) {
|
||||
return normalizedRelPath.toPosix()
|
||||
} else {
|
||||
// we are outside the cwd, so show the absolute path (useful for when claude passes in '../../' for example)
|
||||
return absolutePath.toPosix()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user