jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
8.03k stars 210 forks source link

MISE_PROJECT_ROOT is unstable (and sometimes unavailable) in script tasks #2336

Open fiadliel opened 5 days ago

fiadliel commented 5 days ago

Describe the bug When running a task defined in {{dir}}/.mise/tasks/my-script, MISE_PROJECT_ROOT is not set if there is no .mise.toml in {{dir}}.

When running a task in {{dir}}/.mise/tasks/my-script, MISE_PROJECT_ROOT is set to the closest .mise.toml in the nested paths to the current working directory.

To Reproduce Create a hierarchy like

Run mise run my-script with the current working dir of test_dir, no path will be printed. Run mise run my-script with the current working dir of test_dir/subdir, the printed path is test_dir/subdir.

Expected behavior When running a script task in {{dir}}/.mise/tasks/my-script:

mise doctor output

version: 2024.6.6 macos-arm64 (2024-06-20)
activated: yes
shims_on_path: no

build_info: 
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS
  Built: Thu, 20 Jun 2024 17:07:53 +0000
  Rust Version: rustc 1.79.0 (129f3b996 2024-06-10) (Homebrew)
  Profile: release

shell: 
  /opt/homebrew/bin/fish
  fish, version 3.7.1

dirs: 
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/Library/Caches/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files: 
  ~/.config/mise/config.toml

backends: 
  cargo
  core
  go
  npm
  pipx
  spm
  ubi

plugins: 
 ...

toolset: 
  ...

env_vars: 
  MISE_ENV=development
  MISE_SHELL=fish

settings: 
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cargo_binstall = true
  color = true
  disable_default_shorthands = false
  disable_tools = []
  experimental = true
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  http_timeout = 30
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  node_compile = false
  not_found_auto_install = true
  paranoid = false
  plugin_autoupdate_last_check_duration = "7d"
  python_default_packages_file = "/Users/xxx/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  raw = false
  trusted_config_paths = []
  quiet = false
  verbose = false
  yes = false
  ci = false
  debug = false
  trace = false
  log_level = "info"
  python_venv_auto_create = true

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false

No warnings found
No problems found

Additional context This looks very similar, and/or the same issue as https://github.com/jdx/mise/issues/2335.

fiadliel commented 5 days ago

Oh - I found that

# mise dir="{{config_root}}"

does work for changing the current working directory (I was sure I'd tried this, but maybe I tried some variant of it, and it's not really documented).

However, this is not sufficient to make up for the issues with MISE_PROJECT_ROOT, as one may want to both refer to the project root, and maintain the current working directory.

jdx commented 5 days ago

Yeah I think there are 3 important concepts: cwd, "project root" and config root (which I think is a better default than cwd). I could see the last 2 being different. There is likely work to ensure these all work everywhere and everything.