| 41 | let userPathCapture: Promise<string | undefined> | null = null; |
| 42 | |
| 43 | const captureUserPath = async (): Promise<string | undefined> => { |
| 44 | const shell = process.env.SHELL; |
| 45 | if (!shell) return process.env.PATH; |
| 46 | try { |
| 47 | const { stdout } = await execFileAsync(shell, ["-ilc", 'printf "%s" "$PATH"'], { |
| 48 | encoding: "utf8", |
| 49 | timeout: 5000, |
| 50 | }); |
| 51 | const path = stdout.trim(); |
| 52 | return path.length > 0 ? path : process.env.PATH; |
| 53 | } catch { |
| 54 | return process.env.PATH; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | const memoizedUserPath = (): Promise<string | undefined> => { |
| 59 | userPathCapture ??= captureUserPath(); |