| 104 | })() |
| 105 | |
| 106 | function findBinary(startDir) { |
| 107 | let current = startDir |
| 108 | for (;;) { |
| 109 | const modules = path.join(current, "node_modules") |
| 110 | if (fs.existsSync(modules)) |
| 111 | for (const name of names) { |
| 112 | const candidate = path.join(modules, name, "bin", binary) |
| 113 | if (fs.existsSync(candidate)) return candidate |
| 114 | } |
| 115 | const parent = path.dirname(current) |
| 116 | if (parent === current) return |
| 117 | current = parent |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | const resolved = envPath || (fs.existsSync(cached) ? cached : findBinary(scriptDir)) |
| 122 | if (!resolved) { |