| 53 | } |
| 54 | |
| 55 | function isExecutable(path: string, isWindows: boolean): boolean { |
| 56 | try { |
| 57 | if (!existsSync(path)) return false; |
| 58 | // statSync follows symlinks by default — important because wrapper |
| 59 | // scripts and tool-version shims are often symlinks. We want the |
| 60 | // target to be a regular file or directory entry that resolves |
| 61 | // to one, not a broken symlink. |
| 62 | const st = statSync(path); |
| 63 | if (!st.isFile()) return false; |
| 64 | if (isWindows) { |
| 65 | // Windows doesn't have execute permission bits the way POSIX |
| 66 | // does — the .exe/.cmd/.bat extension match is the contract. |
| 67 | return true; |
| 68 | } |
| 69 | // POSIX: check X_OK for the current user/group/other. |
| 70 | accessSync(path, constants.X_OK); |
| 71 | return true; |
| 72 | } catch { |
| 73 | return false; |
| 74 | } |
| 75 | } |