(inputPath: string)
| 59 | * // => { valid: false, error: "Path does not exist: /home/user/nonexistent" } |
| 60 | */ |
| 61 | export async function validateProjectPath(inputPath: string): Promise<PathValidationResult> { |
| 62 | // Expand tilde if present |
| 63 | const expandedPath = expandTilde(inputPath); |
| 64 | |
| 65 | // Normalize to resolve any .. or . in the path, then strip trailing slashes |
| 66 | const normalizedPath = stripTrailingSlashes(path.normalize(expandedPath)); |
| 67 | |
| 68 | // Check if path exists |
| 69 | try { |
| 70 | const stats = await fs.stat(normalizedPath); |
| 71 | |
| 72 | // Check if it's a directory |
| 73 | if (!stats.isDirectory()) { |
| 74 | return { |
| 75 | valid: false, |
| 76 | error: `Path is not a directory: ${normalizedPath}`, |
| 77 | }; |
| 78 | } |
| 79 | } catch (err) { |
| 80 | if ((err as NodeJS.ErrnoException).code === "ENOENT") { |
| 81 | return { |
| 82 | valid: false, |
| 83 | error: `Path does not exist: ${normalizedPath}`, |
| 84 | }; |
| 85 | } |
| 86 | throw err; |
| 87 | } |
| 88 | |
| 89 | return { |
| 90 | valid: true, |
| 91 | expandedPath: normalizedPath, |
| 92 | }; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Check if a path is a git repository |
no test coverage detected