( currentPath: string | undefined, loginShellPath: string, )
| 90 | * commands from arbitrary workspace directories. |
| 91 | */ |
| 92 | export function mergeLoginShellPath( |
| 93 | currentPath: string | undefined, |
| 94 | loginShellPath: string, |
| 95 | ): string { |
| 96 | const current = currentPath ?? ''; |
| 97 | const seen = new Set(current.split(':').filter((entry) => entry.length > 0)); |
| 98 | const additions: string[] = []; |
| 99 | for (const entry of loginShellPath.split(':')) { |
| 100 | // The probe only runs on POSIX (win32 bails before merging), so a |
| 101 | // leading slash is a sufficient absoluteness test. Empty components |
| 102 | // fail it too. |
| 103 | if (!entry.startsWith('/') || seen.has(entry)) continue; |
| 104 | seen.add(entry); |
| 105 | additions.push(entry); |
| 106 | } |
| 107 | if (additions.length === 0) return current; |
| 108 | // `undefined` means "no PATH at all", so the additions stand alone; '' |
| 109 | // is a real (cwd-only) PATH whose empty component must survive as a |
| 110 | // leading colon. |
| 111 | if (currentPath === undefined) return additions.join(':'); |
| 112 | return `${current}:${additions.join(':')}`; |
| 113 | } |
| 114 | |
| 115 | /** Probe the login shell and merge its PATH into `deps.env['PATH']`. */ |
| 116 | export async function applyLoginShellPath(deps: LoginShellPathDeps): Promise<void> { |
no test coverage detected