Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Comparing the symbolic link solution with the environment variable solution #141

Closed
jan-bar opened this issue Mar 23, 2024 · 5 comments
Labels
question Further information is requested

Comments

@jan-bar
Copy link
Contributor

jan-bar commented Mar 23, 2024

方案参考:https://github.com/Schniz/fnm

如下图所示,只需要在打开终端时设置一次环境变量。其中有个临时目录设置到环境变量PATH中。

image

实际上设置到PATH中的值也只是个目录软链接,重点就是后续切换环境,只需要修改该软连接的目标目录,轻松实现版本切换

image

上图是指向 alias 别名为 default 的版本,下图是直接指向固定版本的情况。这种方案允许为指定版本创建别名,使用时也可以不用记住指定版本,记住别名也能轻松切换版本。这种方案我感觉很灵活。

image

当前vfox的版本切换我看了,每次切换版本都需要设置PATH环境变量。我也是window的cmder用户,同样遇到 #129 的困扰。但我在用fnm时没遇到该问题(fnm支持cmd.exe且也有cmder设置教程),所以是否可以将vfox切换版本的方案改成fnm那种呢?

@jan-bar jan-bar added the enhancement New feature or request label Mar 23, 2024
@jan-bar
Copy link
Contributor Author

jan-bar commented Mar 23, 2024

fnm没有使用终端的hook功能,切换版本时仅仅修改目录链接目标地址,方法简单速度快。

@aooohan
Copy link
Member

aooohan commented Mar 25, 2024

首先, 非常感谢如此详细的说明.

我在之前的#84 (comment), 提到过这个问题.

简单来说, 对于Nodejs, 这种方案是没有任何问题的, 但是对于vfox作为一个通用SDK版本管理器而言,不能保证其他SDK不需要设置除了PATH之外的环境变量. 举个例子如JDK, 可能就需要配置JAVA_HOME. 因为有些中间件会默认查找当前环境变量来定位JDK的位置.

当前, 这个issue暂时不打算关闭. 有些功能未来还是可以借鉴的.

@jan-bar
Copy link
Contributor Author

jan-bar commented Mar 25, 2024

@aooohan 切换时需要设置额外环境变量确实需要终端的hook功能。不过习惯win下cmd使用 clink方案的用户也有很多,比如我使用cmderr。我前两天尝试编写lua脚本实现hook,遇到一些问题,例如lua执行cmd命令的io.popen不会将环境变量传递给子进程,导致vfox env -s xxx不能正确输出。我觉得可以试试在这个 #129 议题中增强cmd终端的支持额。

@jan-bar
Copy link
Contributor Author

jan-bar commented Mar 25, 2024

我想起在使用过程中遇到一个问题,我在vfox挂载指令后面继续设置PATH。

eval "$(vfox activate bash)"
export PATH=$HOME/bin:$PATH

结果就是vfox切换版本读取__VFOX_ORIG_PATH环境变量是我设置PATH之前的值,这时$HOME/bin在PATH环境变量中被丢掉了。

如果将方案改为最开始设置临时目录,然后使用软连接切换版本就不会出现这种问题。

目前我不得不将eval "$(vfox activate bash)"放到最后设置PATH指令后面执行。

@aooohan
Copy link
Member

aooohan commented Mar 25, 2024

结果就是vfox切换版本读取__VFOX_ORIG_PATH环境变量是我设置PATH之前的值,这时$HOME/bin在PATH环境变量中被丢掉了。

上周Discord上也有用户反馈过. 下个版本修复吧.

@aooohan aooohan changed the title [Feature]: 可否换一种切换版本的方案 [Question]: Comparing the symbolic link solution with the environment variable solution Mar 25, 2024
@aooohan aooohan added question Further information is requested and removed enhancement New feature or request labels Mar 25, 2024
@version-fox version-fox locked and limited conversation to collaborators Apr 10, 2024
@aooohan aooohan converted this issue into discussion #191 Apr 10, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants