(env, plat, lister)
| 67 | * lister (so it's unit-testable without hitting the filesystem). |
| 68 | */ |
| 69 | export function augmentedEnv(env, plat, lister) { |
| 70 | const base = Object.assign({}, env); |
| 71 | if (plat === "win32") return base; // Windows PATH semantics differ; leave as-is. |
| 72 | const ls = lister || ((d) => { try { return readdirSync(d); } catch (e) { return []; } }); |
| 73 | const extra = ["/opt/homebrew/bin", "/opt/homebrew/sbin", "/usr/local/bin", "/usr/local/sbin"]; |
| 74 | if (base.HOME) { |
| 75 | extra.push(base.HOME + "/.sdkman/candidates/java/current/bin"); |
| 76 | extra.push(base.HOME + "/.asdf/shims"); |
| 77 | } |
| 78 | if (base.JAVA_HOME) extra.push(base.JAVA_HOME + "/bin"); |
| 79 | // Keg-only Homebrew JDKs aren't symlinked into .../bin, so enumerate them. |
| 80 | for (const root of ["/opt/homebrew/opt", "/usr/local/opt"]) { |
| 81 | for (const name of ls(root)) { |
| 82 | if (/^openjdk(@\d+)?$/.test(name)) extra.push(root + "/" + name + "/libexec/openjdk.jdk/Contents/Home/bin"); |
| 83 | } |
| 84 | } |
| 85 | const seen = {}; |
| 86 | const prefix = extra.filter((p) => { if (seen[p]) return false; seen[p] = 1; return true; }); |
| 87 | base.PATH = prefix.join(":") + (base.PATH ? ":" + base.PATH : ""); |
| 88 | return base; |
| 89 | } |
| 90 | |
| 91 | /** Build an exec function bound to a specific environment. */ |
| 92 | export function makeExec(env) { |
no outgoing calls
no test coverage detected