diff --git a/CHANGELOG.md b/CHANGELOG.md index 322eb1808..d67b6017f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,25 @@ - [Rust](https://github.com/moonrepo/rust-plugin/blob/master/CHANGELOG.md) - [TOML schema](https://github.com/moonrepo/schema-plugin/blob/master/CHANGELOG.md) +## Unreleased + +#### 💥 Breaking + +> To ease the migration process, we've added a new migrate command. Simply run `proto migrate v0.24` after upgrading proto! + +- Reworked user configured aliases and default/global version. + - Moved to `~/.proto/config.toml` (user managed) from `~/.proto/tools//manifest.json` (internally managed). + - Are now stored in the `tools` table (object), indexed by tool name. + ```toml + [tools.node] + default-version = "20.10.0" + aliases = { work = "^18" } + ``` + +#### 🚀 Updates + +- Added a `proto migrate v0.24` command for migrating aliases/versions. We'll also log a warning if we detect the old configuration. + ## 0.23.2 #### 🐞 Fixes diff --git a/crates/cli/tests/run_test.rs b/crates/cli/tests/run_test.rs index 72a7e5ebf..ff0430534 100644 --- a/crates/cli/tests/run_test.rs +++ b/crates/cli/tests/run_test.rs @@ -106,10 +106,7 @@ mod run { fs::remove_file(temp.path().join(".prototools")).unwrap(); // Global version - temp.create_file( - "tools/node/manifest.json", - r#"{ "default_version": "19.0.0", "installed_versions": ["19.0.0"] }"#, - ); + temp.create_file("config.toml", "[tools.node]\ndefault-version = \"19.0.0\""); let mut cmd = create_proto_command(temp.path()); let assert = cmd @@ -121,7 +118,7 @@ mod run { assert.stdout(predicate::str::contains("19.0.0")); - fs::remove_file(temp.path().join("tools/node/manifest.json")).unwrap(); + fs::remove_file(temp.path().join("config.toml")).unwrap(); } // This test fails in Windows for some reason, but works fine with `cargo run`... diff --git a/crates/core/src/proto.rs b/crates/core/src/proto.rs index e10f0d47c..8fd727158 100644 --- a/crates/core/src/proto.rs +++ b/crates/core/src/proto.rs @@ -82,11 +82,11 @@ impl ProtoEnvironment { pub fn load_user_config(&self) -> miette::Result<&UserConfig> { self.user_config.get_or_try_init(|| { - if self.test_mode || env::var("PROTO_TEST_USER_CONFIG").is_ok() { - Ok(UserConfig::default()) - } else { - UserConfig::load_from(&self.root) - } + // if self.test_mode || env::var("PROTO_TEST_USER_CONFIG").is_ok() { + // Ok(UserConfig::default()) + // } else { + UserConfig::load_from(&self.root) + // } }) } diff --git a/crates/core/src/tool_manifest.rs b/crates/core/src/tool_manifest.rs index fb017cce8..0019aa995 100644 --- a/crates/core/src/tool_manifest.rs +++ b/crates/core/src/tool_manifest.rs @@ -1,12 +1,13 @@ use crate::helpers::{read_json_file_with_lock, write_json_file_with_lock}; use serde::{Deserialize, Serialize}; +use starbase_styles::color; use std::{ collections::{BTreeMap, HashSet}, env, path::{Path, PathBuf}, time::SystemTime, }; -use tracing::{debug, info}; +use tracing::{debug, info, warn}; use version_spec::*; fn now() -> u128 { @@ -73,6 +74,22 @@ impl ToolManifest { manifest.path = path.to_owned(); + #[allow(deprecated)] + if !manifest.aliases.is_empty() { + warn!( + "Found legacy aliases in tool manifest, please run {} to migrate them", + color::shell("proto migrate v0.24") + ); + } + + #[allow(deprecated)] + if manifest.default_version.is_some() { + warn!( + "Found legacy default version in tool manifest, please run {} to migrate it", + color::shell("proto migrate v0.24") + ); + } + Ok(manifest) } @@ -125,14 +142,7 @@ impl ToolManifest { } pub fn track_used_at(&mut self, version: VersionSpec) { - self.versions - .entry(version) - .and_modify(|v| { - v.last_used_at = Some(now()); - }) - .or_insert(ToolManifestVersion { - last_used_at: Some(now()), - ..ToolManifestVersion::default() - }); + let entry = self.versions.entry(version).or_default(); + entry.last_used_at = Some(now()); } } diff --git a/crates/core/src/version_detector.rs b/crates/core/src/version_detector.rs index 97d41959e..68c16709d 100644 --- a/crates/core/src/version_detector.rs +++ b/crates/core/src/version_detector.rs @@ -126,7 +126,7 @@ pub async fn detect_version( return Ok(candidate); } - // Env var takes highest priorit + // Env var takes highest priority let env_var = format!("{}_VERSION", tool.get_env_var_prefix()); if let Ok(session_version) = env::var(&env_var) { @@ -170,18 +170,22 @@ pub async fn detect_version( // If still no version, load the global version trace!( tool = tool.id.as_str(), - "Attempting to use global version from manifest", + "Attempting to use global version from user config", ); - if let Some(global_version) = &tool.manifest.default_version { - debug!( - tool = tool.id.as_str(), - version = global_version.to_string(), - file = ?tool.manifest.path, - "Detected global version from manifest", - ); + let user_config = tool.proto.load_user_config()?; + + if let Some(tool_user_config) = user_config.tools.get(&tool.id) { + if let Some(global_version) = &tool_user_config.default_version { + debug!( + tool = tool.id.as_str(), + version = global_version.to_string(), + file = ?user_config.path, + "Detected global version from user config", + ); - return Ok(global_version.to_owned()); + return Ok(global_version.to_owned()); + } } // We didn't find anything!