diff --git a/Cargo.lock b/Cargo.lock index 5d65cf36e3fad..6a2eb39d2568a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6256,6 +6256,7 @@ dependencies = [ "semver 1.0.23", "serde", "thiserror", + "turborepo-repository", "update-informer", ] diff --git a/crates/turborepo-lib/src/shim/mod.rs b/crates/turborepo-lib/src/shim/mod.rs index e7e7136d38c5a..779e79933e250 100644 --- a/crates/turborepo-lib/src/shim/mod.rs +++ b/crates/turborepo-lib/src/shim/mod.rs @@ -16,7 +16,11 @@ use tracing::{debug, warn}; pub use turbo_state::TurboState; use turbo_updater::display_update_check; use turbopath::AbsoluteSystemPathBuf; -use turborepo_repository::inference::{RepoMode, RepoState}; +use turborepo_repository::{ + inference::{RepoMode, RepoState}, + package_manager, + package_manager::PackageManager, +}; use turborepo_ui::ColorConfig; use which::which; @@ -84,13 +88,16 @@ fn run_correct_turbo( subscriber: &TurboSubscriber, ui: ColorConfig, ) -> Result { + let package_manager = repo_state.package_manager.as_ref(); + if let Some(turbo_state) = LocalTurboState::infer(&repo_state.root) { let mut builder = crate::config::TurborepoConfigBuilder::new(&repo_state.root); if let Some(root_turbo_json) = &shim_args.root_turbo_json { builder = builder.with_root_turbo_json_path(Some(root_turbo_json.clone())); } let config = builder.build().unwrap_or_default(); - try_check_for_updates(&shim_args, turbo_state.version(), &config); + + try_check_for_updates(&shim_args, turbo_state.version(), &config, package_manager); if turbo_state.local_is_self() { env::set_var( @@ -115,7 +122,7 @@ fn run_correct_turbo( builder = builder.with_root_turbo_json_path(Some(root_turbo_json.clone())); } let config = builder.build().unwrap_or_default(); - try_check_for_updates(&shim_args, version, &config); + try_check_for_updates(&shim_args, version, &config, package_manager); // cli::run checks for this env var, rather than an arg, so that we can support // calling old versions without passing unknown flags. env::set_var( @@ -275,7 +282,10 @@ fn try_check_for_updates( args: &ShimArgs, current_version: &str, config: &crate::config::ConfigurationOptions, + package_manager: Result<&PackageManager, &package_manager::Error>, ) { + let package_manager = package_manager.unwrap_or(&PackageManager::Npm); + if args.should_check_for_update() && !config.no_update_notifier() { // custom footer for update message let footer = format!( @@ -300,6 +310,7 @@ fn try_check_for_updates( // use default for timeout (800ms) None, interval, + package_manager, ); } } diff --git a/crates/turborepo-updater/Cargo.toml b/crates/turborepo-updater/Cargo.toml index 961c6f094bb81..d71e7b528138c 100644 --- a/crates/turborepo-updater/Cargo.toml +++ b/crates/turborepo-updater/Cargo.toml @@ -22,6 +22,7 @@ reqwest = { workspace = true, features = ["json", "blocking"] } semver = { workspace = true } serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } +turborepo-repository = { path = "../turborepo-repository" } update-informer = { git = "https://github.com/nicholaslyang/update-informer.git", default-features = false, features = [ "reqwest", ] } diff --git a/crates/turborepo-updater/src/lib.rs b/crates/turborepo-updater/src/lib.rs index 09c4b4cbd7fad..881f2954d47ec 100644 --- a/crates/turborepo-updater/src/lib.rs +++ b/crates/turborepo-updater/src/lib.rs @@ -9,6 +9,7 @@ use console::style; use semver::Version as SemVerVersion; use serde::Deserialize; use thiserror::Error as ThisError; +use turborepo_repository::package_manager::PackageManager; use update_informer::{ http_client::{GenericHttpClient, HttpClient}, Check, Package, Registry, Result as UpdateResult, Version, @@ -103,6 +104,7 @@ pub fn display_update_check( current_version: &str, timeout: Option, interval: Option, + package_manager: &PackageManager, ) -> Result<(), UpdateNotifierError> { // bail early if the user has disabled update notifications if should_skip_notification() { @@ -113,8 +115,17 @@ pub fn display_update_check( if let Ok(Some(version)) = version { let latest_version = version.to_string(); - // TODO: make this package manager aware - let update_cmd = style("npx @turbo/codemod@latest update").cyan().bold(); + + let update_cmd = match package_manager { + PackageManager::Npm => style("npx @turbo/codemod@latest update").cyan().bold(), + PackageManager::Yarn | PackageManager::Berry => { + style("yarn dlx @turbo/codemod@latest update").cyan().bold() + } + PackageManager::Pnpm | PackageManager::Pnpm6 | PackageManager::Pnpm9 => { + style("pnpm dlx @turbo/codemod@latest update").cyan().bold() + } + PackageManager::Bun => style("bunx @turbo/codemod@latest update").cyan().bold(), + }; let msg = format!( "