MCPcopy
hub / github.com/AutoMaker-Org/automaker / buildEnhancedPath

Function buildEnhancedPath

libs/platform/src/node-finder.ts:338–361  ·  view source on GitHub ↗
(nodePath: string, currentPath: string = '')

Source from the content-addressed store, hash-verified

336 * ```
337 */
338export 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}

Callers 2

startServerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected