@@ -4,12 +4,12 @@ use biome_diagnostics::{Error, StdError};
44use biome_fs:: normalize_path;
55use biome_package:: node_semver:: Version ;
66use camino:: { Utf8Path , Utf8PathBuf } ;
7+ use reqwest:: blocking:: Client ;
78use self_update:: backends:: github:: Update ;
89use std:: env;
910use std:: fmt;
1011use std:: process:: { Command , Stdio } ;
1112use std:: time:: Duration ;
12- use reqwest:: blocking:: Client ;
1313
1414const BREW_BINARY_NAME : & str = "biome" ;
1515const GITHUB_REPO_OWNER : & str = "biomejs" ;
@@ -39,9 +39,17 @@ pub(crate) fn upgrade(session: CliSession) -> Result<(), CliDiagnostic> {
3939 ) ) ,
4040 InstallSource :: Homebrew => upgrade_with_homebrew ( session) ,
4141 InstallSource :: Standalone => upgrade_standalone ( session) ,
42+ InstallSource :: Unknown => Err ( unknown_install_source_upgrade_error ( ) ) ,
4243 }
4344}
4445
46+ fn unknown_install_source_upgrade_error ( ) -> CliDiagnostic {
47+ CliDiagnostic :: upgrade_error (
48+ "`biome upgrade` couldn't determine how this binary was installed. Upgrade Biome with the same installer or package manager you originally used." ,
49+ None ,
50+ )
51+ }
52+
4553fn ensure_upgrade_supported ( ) -> Result < ( ) , CliDiagnostic > {
4654 if env:: var_os ( "BIOME_BINARY" ) . is_some ( ) {
4755 return Err ( CliDiagnostic :: upgrade_error (
@@ -60,6 +68,7 @@ fn upgrade_with_homebrew(session: CliSession) -> Result<(), CliDiagnostic> {
6068 } ) ;
6169
6270 let status = Command :: new ( "brew" )
71+ . env ( "HOMEBREW_NO_AUTO_UPDATE" , "1" )
6372 . arg ( "upgrade" )
6473 . arg ( BREW_BINARY_NAME )
6574 . stdin ( Stdio :: inherit ( ) )
@@ -211,6 +220,7 @@ enum InstallSource {
211220 Homebrew ,
212221 Npm ,
213222 Standalone ,
223+ Unknown ,
214224}
215225
216226/// Detect the installation source
@@ -219,7 +229,8 @@ enum InstallSource {
219229///
220230/// If the `BIOME_DISTRIBUTION` environment variable is set, it will be used to determine the
221231/// installation source instead of path-based detection. This allows users to override the
222- /// detected installation source if necessary.
232+ /// detected installation source if necessary. Any unrecognized installation source is treated as
233+ /// unknown so `biome upgrade` does not attempt a cross-channel self-update.
223234fn detect_install_source ( current_exe : & Utf8Path ) -> InstallSource {
224235 if let Some ( install_source) = install_source_from_env ( ) {
225236 return install_source;
@@ -234,18 +245,21 @@ fn detect_install_source(current_exe: &Utf8Path) -> InstallSource {
234245 } else if is_homebrew_install ( & canonical) {
235246 InstallSource :: Homebrew
236247 } else {
237- InstallSource :: Standalone
248+ InstallSource :: Unknown
238249 }
239250}
240251
241252/// Detect the installation source from the environment
242253fn install_source_from_env ( ) -> Option < InstallSource > {
243- match env:: var_os ( "BIOME_DISTRIBUTION" ) ?. to_str ( ) ? {
244- "npm" => Some ( InstallSource :: Npm ) ,
245- "homebrew" => Some ( InstallSource :: Homebrew ) ,
246- "standalone" => Some ( InstallSource :: Standalone ) ,
247- _ => None ,
248- }
254+ let install_source = env:: var_os ( "BIOME_DISTRIBUTION" ) ?;
255+ let install_source = match install_source. to_str ( ) {
256+ Some ( "npm" ) => InstallSource :: Npm ,
257+ Some ( "homebrew" ) => InstallSource :: Homebrew ,
258+ Some ( "standalone" ) => InstallSource :: Standalone ,
259+ Some ( _) | None => InstallSource :: Unknown ,
260+ } ;
261+
262+ Some ( install_source)
249263}
250264
251265/// Determines whether Biome was installed using a npm-compatible package manager
@@ -394,13 +408,13 @@ mod tests {
394408 }
395409
396410 #[ test]
397- fn defaults_to_standalone_install ( ) {
411+ fn defaults_to_unknown_install_source ( ) {
398412 let _guard = env_lock ( ) . lock ( ) . unwrap ( ) ;
399413 let _distribution = ScopedEnvVar :: unset ( "BIOME_DISTRIBUTION" ) ;
400414
401415 assert_eq ! (
402416 detect_install_source( Utf8Path :: new( "/usr/local/bin/biome" ) ) ,
403- InstallSource :: Standalone
417+ InstallSource :: Unknown
404418 ) ;
405419 }
406420
@@ -415,6 +429,44 @@ mod tests {
415429 ) ;
416430 }
417431
432+ #[ test]
433+ fn standalone_distribution_env_marks_install_as_standalone ( ) {
434+ let _guard = env_lock ( ) . lock ( ) . unwrap ( ) ;
435+ let _distribution = ScopedEnvVar :: set ( "BIOME_DISTRIBUTION" , "standalone" ) ;
436+
437+ assert_eq ! (
438+ detect_install_source( Utf8Path :: new( "/usr/local/bin/biome" ) ) ,
439+ InstallSource :: Standalone
440+ ) ;
441+ }
442+
443+ #[ test]
444+ fn invalid_distribution_env_marks_install_as_unknown ( ) {
445+ let _guard = env_lock ( ) . lock ( ) . unwrap ( ) ;
446+ let _distribution = ScopedEnvVar :: set ( "BIOME_DISTRIBUTION" , "custom-installer" ) ;
447+
448+ assert_eq ! (
449+ detect_install_source( Utf8Path :: new( "/opt/homebrew/Cellar/biome/2.4.8/bin/biome" ) ) ,
450+ InstallSource :: Unknown
451+ ) ;
452+ }
453+
454+ #[ test]
455+ fn reports_unknown_install_source_upgrade_error ( ) {
456+ let diagnostic = unknown_install_source_upgrade_error ( ) ;
457+
458+ match diagnostic {
459+ CliDiagnostic :: UpgradeError ( diagnostic) => {
460+ assert_eq ! (
461+ PrintDescription ( & diagnostic) . to_string( ) ,
462+ "Upgrade has encountered an error: `biome upgrade` couldn't determine how this binary was installed. Upgrade Biome with the same installer or package manager you originally used." ,
463+ ) ;
464+ assert ! ( diagnostic. source. is_none( ) ) ;
465+ }
466+ other => panic ! ( "expected unknown install source upgrade error, got {other:?}" ) ,
467+ }
468+ }
469+
418470 #[ test]
419471 fn rejects_upgrade_when_biome_binary_is_set ( ) {
420472 let _guard = env_lock ( ) . lock ( ) . unwrap ( ) ;
0 commit comments