jdx / mise

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

`mise hook-env`: PATH is not updated after `mise uninstall` #2876

Closed powerman closed 7 hours ago

powerman commented 4 days ago

Describe the bug If there are some older tool versions installed (which also match version requirement in .mise.toml) and we do mise rm <tool@current_version> then we get broken $PATH and mise i is unable to fix this issue.

To fix this situation we need to do something unusual: either remove all versions of the tool and then mise i will fix it, or install just removed "current_version" back, or leave project's directory and enter again.

To Reproduce Start clean, and ensure mise i won't add new tools to PATH, just in case (so far so good):

$ mkdir mise-rm-path-bug
$ cd mise-rm-path-bug
$ dust --version
zsh: command not found: dust
$ mise ls dust
Tool  Version  Config Source Requested
$ mise i dust@0.8.1 
mise Installed binary into /home/powerman/.local/share/mise/installs/dust/0.8.1/bin/dust
mise ubi:bootandy/dust@0.8.1      ✓ installed
$ mise i dust@0.8.3
mise Installed binary into /home/powerman/.local/share/mise/installs/dust/0.8.3/bin/dust
mise ubi:bootandy/dust@0.8.3      ✓ installed
$ mise ls dust
Tool  Version  Config Source Requested
dust  0.8.1                           
dust  0.8.3                           
$ dust --version
zsh: command not found: dust

Now, start using it and then upgrade, to ensure mise i will update PATH (so far so good too):

$ mise bin-paths | grep dust
$ printf "%s\n" $path | grep dust
$ mise use dust@0.8
mise ~/tmp/mise-rm-path-bug/.mise.toml tools: ubi:bootandy/dust@0.8.3
$ dust --version
Dust 0.8.3
$ mise i dust@0.8.2
mise Installed binary into /home/powerman/.local/share/mise/installs/dust/0.8.2/bin/dust
mise ubi:bootandy/dust@0.8.2      ✓ installed
$ dust --version
Dust 0.8.3
$ mise i dust@0.8.5
mise Installed binary into /home/powerman/.local/share/mise/installs/dust/0.8.5/bin/dust
mise ubi:bootandy/dust@0.8.5      ✓ installed                                                       
$ dust --version
Dust 0.8.5

Then, remove currently used version and get broken PATH:

$ mise ls dust
Tool  Version           Config Source                     Requested
dust  0.8.1                                                        
dust  0.8.2                                                        
dust  0.8.3                                                        
dust  0.8.5 (outdated)  ~/tmp/mise-rm-path-bug/.mise.toml 0.8      
$ mise bin-paths | grep dust
/home/powerman/.local/share/mise/installs/dust/0.8.5/bin
$ printf "%s\n" $path | grep dust
/home/powerman/.local/share/mise/installs/dust/0.8.5/bin
$ mise rm dust@0.8.5
mise ubi:bootandy/dust@0.8.5      ✓ uninstalled
$ mise exec -- dust --version
Dust 0.8.3
$ dust --version
zsh: command not found: dust
$ mise ls dust
Tool  Version           Config Source                     Requested
dust  0.8.1                                                        
dust  0.8.2                                                        
dust  0.8.3 (outdated)  ~/tmp/mise-rm-path-bug/.mise.toml 0.8      
$ mise bin-paths | grep dust
/home/powerman/.local/share/mise/installs/dust/0.8.3/bin
$ printf "%s\n" $path | grep dust
/home/powerman/.local/share/mise/installs/dust/0.8.5/bin

The last line (above) demonstrate the issue: PATH still contain uninstalled/non-existing version, while Mise tools like bin-paths and ls thinks PATH contains another, existing version. As result of this it's even impossible to "fix" this in usual way:

$ cat .mise.toml
[tools]
dust = "0.8"
$ mise i
mise all runtimes are installed
$ dust --version
zsh: command not found: dust

Expected behavior If mise install updates $PATH when installing newer version which matches requirement in config then mise uninstall should do the same when uninstalling currently used version. Or, more precisely, mise hook-env should handle this case.

mise doctor output

version: 2024.10.13 linux-x64 (ee83488 2024-10-28)
activated: yes
shims_on_path: no

build_info:
  Target: x86_64-unknown-linux-gnu
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Mon, 28 Oct 2024 03:25:17 +0000
  Rust Version: rustc 1.81.0 (eeb90cda1 2024-09-04)
  Profile: release

shell:
  /bin/zsh
  zsh 5.9 (x86_64-pc-linux-gnu)

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

config_files:
  ~/.config/mise/config.toml
  ~/mise.toml
  ~/tmp/mise-rm-path-bug/.mise.toml

backends:
  cargo
  core
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins:

toolset:
  ubi:bootandy/dust@0.8.3
  ubi:jdx/usage@1.0.0
  ubi:aquaproj/aqua@2.36.2
  ubi:go-task/task@3.39.2
  go:github.com/oklog/ulid/v2/cmd/ulid@2.1.0
  ubi:santhosh-tekuri/jsonschema@6.0.1
  ubi:bronze1man/yaml2json@1.3.3
  ubi:mikefarah/yq@4.44.3
  ubi:fullstorydev/grpcui@1.4.1
  ubi:fullstorydev/grpcurl@1.9.1
  ubi:ktr0731/evans@0.10.11
  pipx:a13xp0p0v/kernel-hardening-checker@latest
  go:golang.org/x/review/git-codereview@1.12.0
  ubi:ankitpokhrel/jira-cli@1.5.2
  ubi:noahgorstein/jqp@0.7.0
  ubi:cespare/reflex@0.3.1
  ubi:jondot/goweight@1.0.5
  ubi:kubernetes-sigs/kind@0.24.0
  ubi:kubernetes/minikube@1.34.0
  go:github.com/bernardo-bruning/ollama-copilot@0.2.0
  ubi:plandex-ai/plandex@cli/v1.1.1
  npm:rag-crawler@1.5.0
  ubi:magefile/mage@1.15.0
  go:github.com/erning/gorun@latest
  ubi:myitcv/gobin@0.0.14
  ubi:traefik/yaegi@0.16.1
  ubi:x-motemen/gore@0.5.7
  go:golang.org/x/pkgsite/cmd/pkgsite@latest
  go:golang.org/x/tools/cmd/godoc@0.26.0
  go:golang.org/x/tools/cmd/gonew@0.26.0
  go:github.com/rogpeppe/gohack@1.0.2
  ubi:oligot/go-mod-upgrade@0.10.0
  ubi:psampaz/go-mod-outdated@0.9.0
  ubi:uber-go/gopatch@0.4.0
  go:golang.org/x/tools/cmd/eg@0.26.0
  go:rsc.io/rf@latest
  go:github.com/quasilyte/gogrep/cmd/gogrep@0.5.0
  go:golang.org/x/tools/cmd/go-contrib-init@0.26.0
  go:github.com/josharian/impl@1.4.0
  go:github.com/koron/iferr@latest
  go:github.com/fatih/gomodifytags@1.17.0
  go:github.com/davidrjenni/reftools/cmd/fillswitch@latest
  go:github.com/davidrjenni/reftools/cmd/fillstruct@latest
  go:github.com/maruel/panicparse/v2/cmd/pp@2.3.1
  go:github.com/smartystreets/goconvey@1.8.1
  go:golang.org/x/perf/cmd/benchstat@latest
  go:github.com/vugu/vgrun@latest

env_vars:
  MISE_SHELL=zsh

settings:
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cache_prune_age = "30d"
  ci = false
  color = true
  debug = false
  disable_backends = []
  disable_default_registry = false
  disable_hints = []
  disable_tools = []
  experimental = true
  fetch_remote_versions_cache = "1h"
  fetch_remote_versions_timeout = "10s"
  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 = "30s"
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  libgit2 = true
  lockfile = false
  log_level = "info"
  not_found_auto_install = true
  paranoid = false
  pin = false
  plugin_autoupdate_last_check_duration = "7d"
  quiet = false
  raw = false
  trace = false
  trusted_config_paths = []
  use_versions_host = true
  verbose = false
  yes = false

  [cargo]
  binstall = true

  [node]

  [pipx]
  uvx = true

  [python]
  default_packages_file = "~/.default-python-packages"
  pyenv_repo = "https://github.com/pyenv/pyenv.git"
  venv_auto_create = false
  venv_stdlib = false

  [ruby]
  default_packages_file = "~/.default-gems"
  ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
  ruby_install = false
  ruby_install_repo = "https://github.com/postmodern/ruby-install.git"

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false
No warnings found
No problems found