version-fox / vfox

A cross-platform and extendable version manager with support for Java, Node.js, Flutter, .Net & more
https://vfox.lhan.me
Apache License 2.0
2.46k stars 83 forks source link

[BUG]: .tool-versions behavior #228

Open NamPNQ opened 1 month ago

NamPNQ commented 1 month ago

Describe the bug The behavior of asdf will keep search up until reach / https://github.com/asdf-vm/asdf/blob/ccdd47df9b73d0a22235eb06ad4c48eb57360832/lib/utils.bash#L212

While vfox just use config from current directory

aooohan commented 1 month ago

https://vfox.lhan.me/guides/quick-start.html#_5-switch-runtime

vfox use config from three places:

  1. $HOME/.version-fox/.tool-versions
  2. $PWD/.tool-versions
  3. $HOME/.version-fox/tmp/<shell-pid>/.tool-versions

The behavior of asdf will keep search up until reach /

To be honest, I don't like this strategy.

NamPNQ commented 1 month ago

Just imagine you're in project, config .tool-versions is stay in project/.tool-versions. Then you go to child dir on your project, what you expected? You want use the right tools you already configured or any another version?

aooohan commented 1 month ago

Then you go to child dir on your project, what you expected? You want use the right tools you already configured or any another version?

The current vfox strategy is that if you have a .tool-version in your project (project/.tool-versions), that version will be used in the current shell, regardless of whether you switch directories or not, the version is not changed until the next .tool-versions file is encountered, or vfox use command is executed manually.

NamPNQ commented 1 month ago

Maybe we don't understand each other Here is simple to reproduce what I mean

$ cd `mktemp -d`
$ mkdir -p proj/child
$ node -v # 20 for example
$ echo "nodejs 16.20.2" > proj/.tool-versions
$ vfox install nodejs@16.20.2
$ cd proj
$ node -v # 16 => its ok
$ cd child
$ node -v # 20 => its not ok => and this is unexpected behavior since another tools (asdf, nvmrc, pyenv...) always look at parent folder
aooohan commented 1 month ago
$ cd `mktemp -d`
$ mkdir -p proj/child
$ node -v # 20 for example
$ echo "nodejs 16.20.2" > proj/.tool-versions
$ vfox install nodejs@16.20.2
$ cd proj
$ node -v # 16 => its ok
$ cd child
$ node -v # 20 => its not ok => and this is unexpected behavior since another tools (asdf, nvmrc, pyenv...) always look at parent folder

Okay, it can indeed be reproduced.

NamPNQ commented 1 month ago

@aooohan Your fix is not works if we go directly to child folder

aooohan commented 1 month ago

@aooohan Your fix is not works if we go directly to child folder

I'm aware of this, and for this issue, I need to make sure that the behavior I described earlier is correct.

As I said earlier, I really don't like the strategy of keeping search up until reach /.

Also, as for the situation you mentioned, I can't think of a case where it would go directly to a child folder of the project instead of the project root first.

NamPNQ commented 1 month ago

I think navigate to child directory is a common practice, particularly in monorepo projects. Additionally, several other approaches exist, such as launch a new shell from the child directory