1- import { execSync } from 'child_process' ;
2- import { mkdirSync , readFileSync , writeFileSync } from 'fs' ;
1+ import { mkdirSync , readFileSync , realpathSync , writeFileSync } from 'fs' ;
32import https from 'https' ;
43import { homedir } from 'os' ;
54import { join } from 'path' ;
@@ -96,8 +95,8 @@ export function isNewerVersion(current: string, latest: string): boolean {
9695function isHomebrewInstall ( ) : boolean {
9796 if ( process . platform === 'win32' ) return false ;
9897 try {
99- execSync ( 'brew list tigris' , { stdio : 'ignore' } ) ;
100- return true ;
98+ const resolved = realpathSync ( process . execPath ) ;
99+ return resolved . includes ( '/Cellar/' ) || resolved . includes ( '/Caskroom/' ) ;
101100 } catch {
102101 return false ;
103102 }
@@ -109,15 +108,23 @@ function isHomebrewInstall(): boolean {
109108export function getUpdateCommand ( ) : string {
110109 const isBinary =
111110 ( globalThis as { __TIGRIS_BINARY ?: boolean } ) . __TIGRIS_BINARY === true ;
112- const isWindows = process . platform === 'win32' ;
113111
112+ // npm install — process.execPath is Node, not our binary.
113+ // Must come before isHomebrewInstall() to avoid false positives
114+ // when Node itself was installed via Homebrew.
114115 if ( ! isBinary ) {
115116 return 'npm install -g @tigrisdata/cli' ;
116- } else if ( isHomebrewInstall ( ) ) {
117+ }
118+ // Standalone binary installed via Homebrew (execPath resolves to /Cellar/ or /Caskroom/)
119+ else if ( isHomebrewInstall ( ) ) {
117120 return 'brew upgrade tigris' ;
118- } else if ( isWindows ) {
121+ }
122+ // Standalone binary on Windows
123+ else if ( process . platform === 'win32' ) {
119124 return 'irm https://github.com/tigrisdata/cli/releases/latest/download/install.ps1 | iex' ;
120- } else {
125+ }
126+ // Standalone binary on macOS/Linux (installed via curl)
127+ else {
121128 return 'curl -fsSL https://github.com/tigrisdata/cli/releases/latest/download/install.sh | sh' ;
122129 }
123130}
0 commit comments