* 构造一个 shell 命令前缀,确保 PATH 中包含常用安装目录。 * 用于 `execSync(cmd, { shell: '/bin/bash' })` 这种场景, * 即使 augmentPath() 还没有在父进程设置 PATH 也能生效。
()
| 142 | * 构造一个 shell 命令前缀,确保 PATH 中包含常用安装目录。 |
| 143 | * 用于 `execSync(cmd, { shell: '/bin/bash' })` 这种场景, |
| 144 | * 即使 augmentPath() 还没有在父进程设置 PATH 也能生效。 |
| 145 | */ |
| 146 | function buildShellPathPrefix() { |
| 147 | const home = os.homedir(); |
| 148 | const candidates = process.platform === 'win32' |
| 149 | ? [] |
| 150 | : [ |
| 151 | '/usr/local/bin', |
| 152 | '/opt/homebrew/bin', |
| 153 | path.join(home, '.local', 'bin'), |
| 154 | path.join(home, 'bin'), |
| 155 | path.join(home, '.nvm', 'versions', 'node', 'current', 'bin'), |
| 156 | path.join(home, '.npm-global', 'bin'), |
| 157 | path.join(home, '.openclaw', 'tools', 'node', 'bin'), |
| 158 | ]; |
| 159 | const existing = (process.env.PATH || '').split(path.delimiter).filter(Boolean); |
| 160 | const seen = new Set(); |
| 161 | const merged = []; |
| 162 | for (const dir of [...candidates, ...existing]) { |
| 163 | if (!dir || seen.has(dir)) continue; |
| 164 | seen.add(dir); |
| 165 | merged.push(dir); |
| 166 | } |
| 167 | return `PATH="${merged.join(':')}" `; |
| 168 | } |
no outgoing calls
no test coverage detected