fix(install): normalize Homebrew node@NN Cellar paths

This commit is contained in:
Tom Boucher
2026-05-06 21:33:07 -04:00
parent 69aa7ec04e
commit 739b95ef80
2 changed files with 14 additions and 2 deletions

View File

@@ -543,11 +543,13 @@ function computePathPrefix({ isGlobal, isOpencode, isWindowsHost: _isWindowsHost
function normalizeNodePath(execPath) {
if (!execPath) return execPath;
// Intel Homebrew: /usr/local/Cellar/node/<version>/bin/node
if (/^\/usr\/local\/Cellar\/node\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) {
// or /usr/local/Cellar/node@20/<version>/bin/node
if (/^\/usr\/local\/Cellar\/node(@\d+)?\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) {
return '/usr/local/bin/node';
}
// Apple Silicon Homebrew: /opt/homebrew/Cellar/node/<version>/bin/node
if (/^\/opt\/homebrew\/Cellar\/node\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) {
// or /opt/homebrew/Cellar/node@18/<version>/bin/node
if (/^\/opt\/homebrew\/Cellar\/node(@\d+)?\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) {
return '/opt/homebrew/bin/node';
}
return execPath;

View File

@@ -50,6 +50,11 @@ describe('Bug #3181: normalizeNodePath — Intel Homebrew Cellar paths → /usr/
const result = normalizeNodePath('/usr/local/Cellar/node/22.0.0-rc.1/bin/node');
assert.equal(result, '/usr/local/bin/node');
});
test('Intel versioned formula Cellar path (node@20) maps to stable symlink', () => {
const result = normalizeNodePath('/usr/local/Cellar/node@20/20.11.0/bin/node');
assert.equal(result, '/usr/local/bin/node');
});
});
describe('Bug #3181: normalizeNodePath — Apple Silicon Homebrew Cellar paths → /opt/homebrew/bin/node', () => {
@@ -62,6 +67,11 @@ describe('Bug #3181: normalizeNodePath — Apple Silicon Homebrew Cellar paths
const result = normalizeNodePath('/opt/homebrew/Cellar/node/18.20.4/bin/node');
assert.equal(result, '/opt/homebrew/bin/node');
});
test('Apple Silicon versioned formula Cellar path (node@18) maps to stable symlink', () => {
const result = normalizeNodePath('/opt/homebrew/Cellar/node@18/18.20.4/bin/node');
assert.equal(result, '/opt/homebrew/bin/node');
});
});
describe('Bug #3181: normalizeNodePath — non-Homebrew paths are returned unchanged', () => {