Skip to content

Commit

Permalink
fix: use mise.toml instead of .mise.toml by default in mise use
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 6, 2024
1 parent 48a6f7b commit 6e1b041
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 56 deletions.
7 changes: 3 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> 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`

Expand Down
6 changes: 3 additions & 3 deletions e2e/cli/test_local_toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"'

Expand All @@ -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"'

Expand Down
4 changes: 2 additions & 2 deletions e2e/cli/test_upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -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\" }"
22 changes: 13 additions & 9 deletions e2e/cli/test_use
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions e2e/config/test_tool_versions_alt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion e2e/lockfile/test_lockfile_exec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch .mise.lock
touch mise.lock
mise install [email protected]
mise use tiny@1
mise install [email protected]
Expand Down
4 changes: 2 additions & 2 deletions e2e/lockfile/test_lockfile_install
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch .mise.lock
touch mise.lock
mise use tiny@1
cat <<EOF >.mise.lock
cat <<EOF >mise.lock
[tools]
tiny = "1.0.0"
EOF
Expand Down
14 changes: 7 additions & 7 deletions e2e/lockfile/test_lockfile_use
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch .mise.lock
touch mise.lock
mise install [email protected]
mise use tiny@1
mise install [email protected]
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",
Expand Down
4 changes: 2 additions & 2 deletions e2e/plugins/test_tiny
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

cat >.mise.toml <<EOF
cat >mise.toml <<EOF
[tools]
tiny = {version = "latest", postinstall = "echo 'postinstall'"}
[plugins]
Expand Down Expand Up @@ -29,7 +29,7 @@ rm -rf "$MISE_DATA_DIR/installs/tiny"
mise use tiny@3
mv "$MISE_DATA_DIR/installs/tiny/"{3.1.0,3.0.0}
assert "mise current tiny" "3.0.0"
assert "mise outdated tiny" "tiny 3 3.0.0 3.1.0 ~/workdir/.mise.toml"
assert "mise outdated tiny" "tiny 3 3.0.0 3.1.0 ~/workdir/mise.toml"
mise upgrade tiny
assert "mise current tiny" "3.1.0"
assert "mise outdated tiny" ""
12 changes: 9 additions & 3 deletions src/cli/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ impl Local {
}

fn get_path() -> Result<PathBuf> {
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)
}
}

Expand Down
40 changes: 22 additions & 18 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -146,16 +146,27 @@ impl Use {
}

fn get_config_file(&self) -> Result<Box<dyn ConfigFile>> {
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)
}
Expand Down Expand Up @@ -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::<Vec<_>>();
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),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ fn load_legacy_files() -> BTreeMap<String, Vec<String>> {
}

pub static LOCAL_CONFIG_FILENAMES: Lazy<Vec<&'static str>> = 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",
Expand All @@ -579,8 +579,8 @@ pub static LOCAL_CONFIG_FILENAMES: Lazy<Vec<&'static str>> = 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",
Expand Down
4 changes: 2 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub static MISE_DEFAULT_TOOL_VERSIONS_FILENAME: Lazy<String> = Lazy::new(|| {
var("MISE_DEFAULT_TOOL_VERSIONS_FILENAME").unwrap_or_else(|_| ".tool-versions".into())
});
pub static MISE_DEFAULT_CONFIG_FILENAME: Lazy<String> =
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<Option<String>> = Lazy::new(|| environment(&ARGS.read().unwrap()));
pub static MISE_SETTINGS_FILE: Lazy<PathBuf> = Lazy::new(|| {
var_path("MISE_SETTINGS_FILE").unwrap_or_else(|| MISE_CONFIG_DIR.join("settings.toml"))
Expand All @@ -93,7 +93,7 @@ pub static MISE_GLOBAL_CONFIG_FILE: Lazy<PathBuf> = Lazy::new(|| {
.or_else(|| var_path("MISE_CONFIG_FILE"))
.unwrap_or_else(|| MISE_CONFIG_DIR.join("config.toml"))
});
pub static MISE_USE_TOML: Lazy<bool> = Lazy::new(|| var_is_true("MISE_USE_TOML"));
pub static MISE_USE_TOML: Lazy<bool> = Lazy::new(|| !var_is_false("MISE_USE_TOML"));
pub static MISE_LIST_ALL_VERSIONS: Lazy<bool> = Lazy::new(|| var_is_true("MISE_LIST_ALL_VERSIONS"));
pub static ARGV0: Lazy<String> = Lazy::new(|| ARGS.read().unwrap()[0].to_string());
pub static MISE_BIN_NAME: Lazy<&str> = Lazy::new(|| filename(&ARGV0));
Expand Down

0 comments on commit 6e1b041

Please sign in to comment.