diff --git a/bin/install.js b/bin/install.js index 64a6e03ea..888cd94f9 100755 --- a/bin/install.js +++ b/bin/install.js @@ -543,11 +543,13 @@ function computePathPrefix({ isGlobal, isOpencode, isWindowsHost: _isWindowsHost function normalizeNodePath(execPath) { if (!execPath) return execPath; // Intel Homebrew: /usr/local/Cellar/node//bin/node - if (/^\/usr\/local\/Cellar\/node\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) { + // or /usr/local/Cellar/node@20//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//bin/node - if (/^\/opt\/homebrew\/Cellar\/node\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) { + // or /opt/homebrew/Cellar/node@18//bin/node + if (/^\/opt\/homebrew\/Cellar\/node(@\d+)?\/[^/]+\/bin\/node(\.exe)?$/.test(execPath)) { return '/opt/homebrew/bin/node'; } return execPath; diff --git a/tests/bug-3181-node-cellar-path.test.cjs b/tests/bug-3181-node-cellar-path.test.cjs index 202ce1ccc..a7b092619 100644 --- a/tests/bug-3181-node-cellar-path.test.cjs +++ b/tests/bug-3181-node-cellar-path.test.cjs @@ -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', () => {