* Try to resolve a symlinked command file
(filePath: string)
| 100 | * Try to resolve a symlinked command file |
| 101 | */ |
| 102 | async function tryResolveSymlinkedCommand(filePath: string): Promise<string | undefined> { |
| 103 | try { |
| 104 | const lstat = await fs.lstat(filePath) |
| 105 | if (lstat.isSymbolicLink()) { |
| 106 | // Get the symlink target |
| 107 | const linkTarget = await fs.readlink(filePath) |
| 108 | // Resolve the target path (relative to the symlink location) |
| 109 | const resolvedTarget = path.resolve(path.dirname(filePath), linkTarget) |
| 110 | |
| 111 | // Check if the target is a file |
| 112 | const stats = await fs.stat(resolvedTarget) |
| 113 | if (stats.isFile()) { |
| 114 | return resolvedTarget |
| 115 | } |
| 116 | } |
| 117 | } catch { |
| 118 | // Not a symlink or invalid symlink |
| 119 | } |
| 120 | return undefined |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Get all available commands from built-in, global, and project directories |