diff --git a/docs/configuration.md b/docs/configuration.md index d6c088080..2e61e60f1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -339,13 +339,12 @@ Uses [dotenvy](https://crates.io/crates/dotenvy) under the hood. Set the version for a runtime. For example, `MISE_NODE_VERSION=20` will use regardless of what is set in `.tool-versions`/`.mise.toml`. -### `MISE_USE_TOML=0` +### `MISE_USE_TOML=1` -Set to `1` to default to using `.mise.toml` in `mise local` instead of `.tool-versions` for +Set to `0` to default to using `.tool-verisons` in `mise local` instead of `mise.toml` for configuration. -For now this is not used by `mise use` which will only use `.mise.toml` unless `--path` is -specified. +This is not used by `mise use` which will only use `mise.toml` unless `--path` is specified. ### `MISE_TRUSTED_CONFIG_PATHS` diff --git a/e2e/cli/test_local_toml b/e2e/cli/test_local_toml index 8692788e8..bb541fccd 100644 --- a/e2e/cli/test_local_toml +++ b/e2e/cli/test_local_toml @@ -5,7 +5,7 @@ export MISE_USE_TOML=1 mise i dummy@{1,2} tiny@3 mise local dummy@2 -assert "mise local --path" "$PWD/.mise.toml" +assert "mise local --path" "$PWD/mise.toml" assert "mise local" '[tools] dummy = "2"' assert_contains "mise x -- dummy" "2.0.0" @@ -19,7 +19,7 @@ mkdir subdir ( cd subdir || exit mise local --parent dummy@2 - assert "mise local --parent --path" "$HOME/workdir/.mise.toml" + assert "mise local --parent --path" "$HOME/workdir/mise.toml" assert "mise local --parent" '[tools] dummy = "2"' @@ -29,7 +29,7 @@ dummy = "2"' ( cd subdir || exit mise local tiny@3 - assert "mise local --path" "$PWD/.mise.toml" + assert "mise local --path" "$PWD/mise.toml" assert "mise local" '[tools] tiny = "3"' diff --git a/e2e/cli/test_upgrade b/e2e/cli/test_upgrade index 93410761d..4edc249ae 100644 --- a/e2e/cli/test_upgrade +++ b/e2e/cli/test_upgrade @@ -18,9 +18,9 @@ rm .tool-versions # ensure options are retained mise use "ubi:bazelbuild/buildtools[exe=buildifier,matching=buildifier]@7.1.2" -assert "cat .mise.toml" '[tools] +assert "cat mise.toml" '[tools] "ubi:bazelbuild/buildtools" = { version = "7.1.2", exe = "buildifier", matching = "buildifier" }' bazelbuild_latest=$(mise latest ubi:bazelbuild/buildtools) mise up --bump ubi:bazelbuild/buildtools -assert "cat .mise.toml" "[tools] +assert "cat mise.toml" "[tools] \"ubi:bazelbuild/buildtools\" = { version = \"$bazelbuild_latest\", exe = \"buildifier\", matching = \"buildifier\" }" diff --git a/e2e/cli/test_use b/e2e/cli/test_use index 99012ea52..9444b024d 100644 --- a/e2e/cli/test_use +++ b/e2e/cli/test_use @@ -12,30 +12,34 @@ assert_not_contains "mise use --rm dummy" "dummy" assert "mise current dummy" "" assert_contains "mise use --env local dummy@2" "dummy@2." -assert "cat .mise.local.toml" '[tools] +assert "cat mise.local.toml" '[tools] dummy = "2"' assert "mise current dummy" "2.0.0" -rm .mise.local.toml +rm mise.local.toml mise use dummy@1 dummy@2 assert "mise current dummy" "1.0.0 2.0.0" mise use --pin dummy@1 -assert "cat .mise.toml" '[tools] +assert "cat mise.toml" '[tools] dummy = "1.0.0"' MISE_PIN=1 mise use --fuzzy dummy@1 -assert "cat .mise.toml" '[tools] +assert "cat mise.toml" '[tools] dummy = "1"' -MISE_PIN=1 mise use dummy@1 --path .mise.local.toml -assert "cat .mise.local.toml" '[tools] +MISE_PIN=1 mise use dummy@1 --path mise.local.toml +assert "cat mise.local.toml" '[tools] dummy = "1.0.0"' -mise use --rm dummy --path .mise.local.toml -assert "cat .mise.local.toml" "" +mise use --rm dummy --path mise.local.toml +assert "cat mise.local.toml" "" -rm -f .mise.local.toml .mise.toml +mise use dummy@1 +assert "cat mise.local.toml" '[tools] +dummy = "1"' + +rm -f mise.local.toml mise.toml echo "dummy 1.0.0" >.tool-versions mise use dummy@2 assert "cat .tool-versions" "dummy 2" diff --git a/e2e/config/test_tool_versions_alt b/e2e/config/test_tool_versions_alt index ca6fadd9d..5cf480ede 100644 --- a/e2e/config/test_tool_versions_alt +++ b/e2e/config/test_tool_versions_alt @@ -1,5 +1,6 @@ #!/usr/bin/env bash +export MISE_USE_TOML=0 export MISE_DEFAULT_TOOL_VERSIONS_FILENAME=.alternate-tool-versions export MISE_DEFAULT_CONFIG_FILENAME=.MISSING diff --git a/e2e/lockfile/test_lockfile_exec b/e2e/lockfile/test_lockfile_exec index dbc8a0215..c4fd278f6 100644 --- a/e2e/lockfile/test_lockfile_exec +++ b/e2e/lockfile/test_lockfile_exec @@ -3,7 +3,7 @@ export MISE_LOCKFILE=1 export MISE_EXPERIMENTAL=1 -touch .mise.lock +touch mise.lock mise install tiny@1.0.0 mise use tiny@1 mise install tiny@1.0.1 diff --git a/e2e/lockfile/test_lockfile_install b/e2e/lockfile/test_lockfile_install index e441b0fb6..999bbb1f8 100644 --- a/e2e/lockfile/test_lockfile_install +++ b/e2e/lockfile/test_lockfile_install @@ -3,9 +3,9 @@ export MISE_LOCKFILE=1 export MISE_EXPERIMENTAL=1 -touch .mise.lock +touch mise.lock mise use tiny@1 -cat <.mise.lock +cat <mise.lock [tools] tiny = "1.0.0" EOF diff --git a/e2e/lockfile/test_lockfile_use b/e2e/lockfile/test_lockfile_use index df06b6e15..90ace4c9b 100644 --- a/e2e/lockfile/test_lockfile_use +++ b/e2e/lockfile/test_lockfile_use @@ -3,37 +3,37 @@ export MISE_LOCKFILE=1 export MISE_EXPERIMENTAL=1 -touch .mise.lock +touch mise.lock mise install tiny@1.0.0 mise use tiny@1 mise install tiny@1.0.1 -assert "mise config get -f .mise.toml tools.tiny" "1" +assert "mise config get -f mise.toml tools.tiny" "1" assert "mise where tiny" "$MISE_DATA_DIR/installs/tiny/1.0.0" assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1" assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0" -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "1.0.0"' mise use tiny@1 -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "1.0.1"' assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1" assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.1" mise up tiny -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "1.1.0"' assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1" assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.1.0" mise up tiny --bump -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "3.1.0"' assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "3" assert "mise ls tiny --json --current | jq -r '.[0].version'" "3.1.0" mise use tiny@1 tiny@2 -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = [ "1.0.0", "2.1.0", diff --git a/e2e/plugins/test_tiny b/e2e/plugins/test_tiny index ddab7c563..df8fcb866 100644 --- a/e2e/plugins/test_tiny +++ b/e2e/plugins/test_tiny @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cat >.mise.toml <mise.toml < Result { - let mise_toml = env::current_dir()?.join(MISE_DEFAULT_CONFIG_FILENAME.as_str()); - if *env::MISE_USE_TOML || mise_toml.exists() { + let cwd = env::current_dir()?; + let mise_toml = cwd.join(MISE_DEFAULT_CONFIG_FILENAME.as_str()); + let tool_versions = cwd.join(MISE_DEFAULT_TOOL_VERSIONS_FILENAME.as_str()); + if mise_toml.exists() { + Ok(mise_toml) + } else if tool_versions.exists() { + Ok(tool_versions) + } else if *env::MISE_USE_TOML { Ok(mise_toml) } else { - Ok(env::current_dir()?.join(MISE_DEFAULT_TOOL_VERSIONS_FILENAME.as_str())) + Ok(tool_versions) } } diff --git a/src/cli/use.rs b/src/cli/use.rs index 8709d767b..a7a10ce0e 100644 --- a/src/cli/use.rs +++ b/src/cli/use.rs @@ -10,7 +10,7 @@ use crate::config::{config_file, is_global_config, Config, LOCAL_CONFIG_FILENAME use crate::env::{ MISE_DEFAULT_CONFIG_FILENAME, MISE_DEFAULT_TOOL_VERSIONS_FILENAME, MISE_GLOBAL_CONFIG_FILE, }; -use crate::file::display_path; +use crate::file::{display_path, FindUp}; use crate::toolset::{InstallOptions, ToolRequest, ToolSource, ToolVersion, ToolsetBuilder}; use crate::ui::multi_progress_report::MultiProgressReport; use crate::{env, file, lockfile}; @@ -146,16 +146,27 @@ impl Use { } fn get_config_file(&self) -> Result> { + let cwd = env::current_dir()?; let path = if let Some(env) = &*env::MISE_ENV { - config_file_from_dir(&env::current_dir()?.join(format!(".mise.{}.toml", env))) + config_file_from_dir(&cwd.join(format!("mise.{env}.toml"))) } else if self.global { MISE_GLOBAL_CONFIG_FILE.clone() } else if let Some(env) = &self.env { - config_file_from_dir(&env::current_dir()?.join(format!(".mise.{}.toml", env))) + let p = cwd.join(format!(".mise.{env}.toml")); + if p.exists() { + p + } else { + cwd.join(format!("mise.{env}.toml")) + } } else if let Some(p) = &self.path { - config_file_from_dir(p) + let from_dir = config_file_from_dir(p); + if from_dir.starts_with(&cwd) { + from_dir + } else { + p.clone() + } } else { - config_file_from_dir(&env::current_dir()?) + config_file_from_dir(&cwd) }; config_file::parse_or_init(&path) } @@ -195,25 +206,18 @@ fn config_file_from_dir(p: &Path) -> PathBuf { if !p.is_dir() { return p.to_path_buf(); } - let mise_toml = p.join(&*MISE_DEFAULT_CONFIG_FILENAME); - let tool_versions = p.join(&*MISE_DEFAULT_TOOL_VERSIONS_FILENAME); - if mise_toml.exists() { - return mise_toml; - } else if tool_versions.exists() { - return tool_versions; - } let filenames = LOCAL_CONFIG_FILENAMES .iter() - .rev() - .filter(|f| is_global_config(Path::new(f))) .map(|f| f.to_string()) .collect::>(); - if let Some(p) = file::find_up(p, &filenames) { - return p; + for p in FindUp::new(p, &filenames) { + if !is_global_config(&p) { + return p; + } } match SETTINGS.asdf_compat { - true => tool_versions, - false => mise_toml, + true => p.join(&*MISE_DEFAULT_TOOL_VERSIONS_FILENAME), + false => p.join(&*MISE_DEFAULT_CONFIG_FILENAME), } } diff --git a/src/config/mod.rs b/src/config/mod.rs index ff4d2f441..a6f7c7aaf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -570,7 +570,7 @@ fn load_legacy_files() -> BTreeMap> { } pub static LOCAL_CONFIG_FILENAMES: Lazy> = Lazy::new(|| { - if *env::MISE_DEFAULT_CONFIG_FILENAME == ".mise.toml" { + if *env::MISE_DEFAULT_CONFIG_FILENAME == "mise.toml" { vec![ &*env::MISE_DEFAULT_TOOL_VERSIONS_FILENAME, // .tool-versions ".config/mise/config.toml", @@ -579,8 +579,8 @@ pub static LOCAL_CONFIG_FILENAMES: Lazy> = Lazy::new(|| { "mise/config.toml", ".mise/config.toml", ".rtx.toml", - "mise.toml", - &*env::MISE_DEFAULT_CONFIG_FILENAME, // .mise.toml + &*env::MISE_DEFAULT_CONFIG_FILENAME, // mise.toml + ".mise.toml", ".config/mise/config.local.toml", ".config/mise.local.toml", ".mise/config.local.toml", diff --git a/src/env.rs b/src/env.rs index 1b6fb2c13..ae9359958 100644 --- a/src/env.rs +++ b/src/env.rs @@ -83,7 +83,7 @@ pub static MISE_DEFAULT_TOOL_VERSIONS_FILENAME: Lazy = Lazy::new(|| { var("MISE_DEFAULT_TOOL_VERSIONS_FILENAME").unwrap_or_else(|_| ".tool-versions".into()) }); pub static MISE_DEFAULT_CONFIG_FILENAME: Lazy = - Lazy::new(|| var("MISE_DEFAULT_CONFIG_FILENAME").unwrap_or_else(|_| ".mise.toml".into())); + Lazy::new(|| var("MISE_DEFAULT_CONFIG_FILENAME").unwrap_or_else(|_| "mise.toml".into())); pub static MISE_ENV: Lazy> = Lazy::new(|| environment(&ARGS.read().unwrap())); pub static MISE_SETTINGS_FILE: Lazy = Lazy::new(|| { var_path("MISE_SETTINGS_FILE").unwrap_or_else(|| MISE_CONFIG_DIR.join("settings.toml")) @@ -93,7 +93,7 @@ pub static MISE_GLOBAL_CONFIG_FILE: Lazy = Lazy::new(|| { .or_else(|| var_path("MISE_CONFIG_FILE")) .unwrap_or_else(|| MISE_CONFIG_DIR.join("config.toml")) }); -pub static MISE_USE_TOML: Lazy = Lazy::new(|| var_is_true("MISE_USE_TOML")); +pub static MISE_USE_TOML: Lazy = Lazy::new(|| !var_is_false("MISE_USE_TOML")); pub static MISE_LIST_ALL_VERSIONS: Lazy = Lazy::new(|| var_is_true("MISE_LIST_ALL_VERSIONS")); pub static ARGV0: Lazy = Lazy::new(|| ARGS.read().unwrap()[0].to_string()); pub static MISE_BIN_NAME: Lazy<&str> = Lazy::new(|| filename(&ARGV0));