(nodePath: string, currentPath: string = '')
| 336 | * ``` |
| 337 | */ |
| 338 | export function buildEnhancedPath(nodePath: string, currentPath: string = ''): string { |
| 339 | // If using fallback 'node', don't modify PATH |
| 340 | if (nodePath === 'node') { |
| 341 | return currentPath; |
| 342 | } |
| 343 | |
| 344 | const nodeDir = path.dirname(nodePath); |
| 345 | |
| 346 | // Don't add if already present or if it's just '.' |
| 347 | // Use path segment matching to avoid false positives (e.g., /opt/node vs /opt/node-v18) |
| 348 | // Normalize paths for comparison to handle mixed separators on Windows |
| 349 | const normalizedNodeDir = path.normalize(nodeDir); |
| 350 | const pathSegments = currentPath.split(path.delimiter).map((s) => path.normalize(s)); |
| 351 | if (normalizedNodeDir === '.' || pathSegments.includes(normalizedNodeDir)) { |
| 352 | return currentPath; |
| 353 | } |
| 354 | |
| 355 | // Use platform-appropriate path separator |
| 356 | // Handle empty currentPath without adding trailing delimiter |
| 357 | if (!currentPath) { |
| 358 | return nodeDir; |
| 359 | } |
| 360 | return `${nodeDir}${path.delimiter}${currentPath}`; |
| 361 | } |
no outgoing calls
no test coverage detected