mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 10:10:20 +00:00
fix(daemon): handle versioned node@XX Homebrew formulas in Cellar resolution
Address review feedback: versioned Homebrew formulas (node@22, node@20) use keg-only paths where the stable symlink is at <prefix>/opt/<formula>/bin/node, not <prefix>/bin/node. Updated resolveStableNodePath to: 1. Try <prefix>/opt/<formula>/bin/node first (works for both default + versioned) 2. Fall back to <prefix>/bin/node for the default "node" formula 3. Return the original Cellar path if neither stable path exists Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
8950c59581
commit
163f5184b3
@@ -156,21 +156,39 @@ export function renderSystemNodeWarning(
|
||||
/**
|
||||
* Homebrew Cellar paths (e.g. /opt/homebrew/Cellar/node/25.7.0/bin/node)
|
||||
* break when Homebrew upgrades Node and removes the old version directory.
|
||||
* Resolve these to the stable Homebrew symlink path (/opt/homebrew/bin/node)
|
||||
* which Homebrew updates automatically during upgrades.
|
||||
* Resolve these to a stable Homebrew-managed path that survives upgrades:
|
||||
* - Default formula "node": <prefix>/opt/node/bin/node or <prefix>/bin/node
|
||||
* - Versioned formula "node@22": <prefix>/opt/node@22/bin/node (keg-only)
|
||||
*/
|
||||
export async function resolveStableNodePath(nodePath: string): Promise<string> {
|
||||
const cellarMatch = nodePath.match(/^(.+?)\/Cellar\/[^/]+\/[^/]+\/bin\/node$/);
|
||||
const cellarMatch = nodePath.match(/^(.+?)\/Cellar\/([^/]+)\/[^/]+\/bin\/node$/);
|
||||
if (!cellarMatch) {
|
||||
return nodePath;
|
||||
}
|
||||
const stablePath = `${cellarMatch[1]}/bin/node`;
|
||||
const prefix = cellarMatch[1]; // e.g. /opt/homebrew
|
||||
const formula = cellarMatch[2]; // e.g. "node" or "node@22"
|
||||
|
||||
// Try the Homebrew opt symlink first — works for both default and versioned formulas.
|
||||
const optPath = `${prefix}/opt/${formula}/bin/node`;
|
||||
try {
|
||||
await fs.access(stablePath);
|
||||
return stablePath;
|
||||
await fs.access(optPath);
|
||||
return optPath;
|
||||
} catch {
|
||||
return nodePath;
|
||||
// fall through
|
||||
}
|
||||
|
||||
// For the default "node" formula, also try the direct bin symlink.
|
||||
if (formula === "node") {
|
||||
const binPath = `${prefix}/bin/node`;
|
||||
try {
|
||||
await fs.access(binPath);
|
||||
return binPath;
|
||||
} catch {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
return nodePath;
|
||||
}
|
||||
|
||||
export async function resolvePreferredNodePath(params: {
|
||||
|
||||
Reference in New Issue
Block a user