()
| 16 | * Create a clean environment without local node_modules/.bin in PATH |
| 17 | */ |
| 18 | export function getCleanEnv(): NodeJS.ProcessEnv { |
| 19 | const env = { ...process.env } |
| 20 | const cwd = process.cwd() |
| 21 | const pathSep = process.platform === 'win32' ? ';' : ':' |
| 22 | const pathKey = process.platform === 'win32' ? 'Path' : 'PATH' |
| 23 | const actualPathKey = Object.keys(env).find(k => k.toLowerCase() === 'path') || pathKey |
| 24 | |
| 25 | if (env[actualPathKey]) { |
| 26 | const cleanPath = env[actualPathKey]! |
| 27 | .split(pathSep) |
| 28 | .filter(p => { |
| 29 | const normalizedP = p.replace(/\\/g, '/').toLowerCase() |
| 30 | const normalizedCwd = cwd.replace(/\\/g, '/').toLowerCase() |
| 31 | return !normalizedP.startsWith(normalizedCwd) |
| 32 | }) |
| 33 | .join(pathSep) |
| 34 | env[actualPathKey] = cleanPath |
| 35 | } |
| 36 | |
| 37 | return env |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Try to find globally installed Claude CLI |
no outgoing calls
no test coverage detected