(cwd: string, relPath?: string)
| 82 | } |
| 83 | |
| 84 | export function getReadablePath(cwd: string, relPath?: string): string { |
| 85 | // If relPath is undefined, return empty string instead of allowing path.resolve |
| 86 | // to return cwd (which would then show misleading cwd basename in UI) |
| 87 | if (relPath === undefined) { |
| 88 | return "" |
| 89 | } |
| 90 | |
| 91 | // 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 |
| 92 | const absolutePath = path.resolve(cwd, relPath) |
| 93 | if (arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))) { |
| 94 | // 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 |
| 95 | return absolutePath.toPosix() |
| 96 | } |
| 97 | if (arePathsEqual(path.normalize(absolutePath), path.normalize(cwd))) { |
| 98 | return path.basename(absolutePath).toPosix() |
| 99 | } else { |
| 100 | // show the relative path to the cwd |
| 101 | const normalizedRelPath = path.relative(cwd, absolutePath) |
| 102 | if (absolutePath.includes(cwd)) { |
| 103 | return normalizedRelPath.toPosix() |
| 104 | } else { |
| 105 | // we are outside the cwd, so show the absolute path (useful for when cline passes in '../../' for example) |
| 106 | return absolutePath.toPosix() |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | export const toRelativePath = (filePath: string, cwd: string) => { |
| 112 | const relativePath = path.relative(cwd, filePath).toPosix() |
no test coverage detected