่ฟ™ๆ˜ฏindexlocๆไพ›็š„ๆœๅŠก๏ผŒไธ่ฆ่พ“ๅ…ฅไปปไฝ•ๅฏ†็ 
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions crates/turborepo-lib/src/shim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -84,13 +88,16 @@ fn run_correct_turbo(
subscriber: &TurboSubscriber,
ui: ColorConfig,
) -> Result<i32, Error> {
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(
Expand All @@ -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(
Expand Down Expand Up @@ -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!(
Expand All @@ -300,6 +310,7 @@ fn try_check_for_updates(
// use default for timeout (800ms)
None,
interval,
package_manager,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
15 changes: 13 additions & 2 deletions crates/turborepo-updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -103,6 +104,7 @@ pub fn display_update_check(
current_version: &str,
timeout: Option<Duration>,
interval: Option<Duration>,
package_manager: &PackageManager,
) -> Result<(), UpdateNotifierError> {
// bail early if the user has disabled update notifications
if should_skip_notification() {
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but this will have to be undone down the road. Adding a package_manager.exec_command() would be preferred to avoid doing an explicit iteration over all supported package managers.

e.g.

fn exec_command(&self) -> &str {
    match self {
        PackageManager::Npm => "npx",
        PackageManager::Yarn | PackageManager::Berry => "yarn dlx",
        PackageManager::Pnpm | PackageManager::Pnpm6 | PackageManager::Pnpm9 => "pnpm dlx"
        PackageManager::Bun =>"bunx",
    }
}

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!(
"
Expand Down
Loading