Skip to content
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

[BUG]: clink 最新版 vfox 切换失效 #408

Closed
ViCrack opened this issue Feb 12, 2025 · 4 comments · Fixed by #410
Closed

[BUG]: clink 最新版 vfox 切换失效 #408

ViCrack opened this issue Feb 12, 2025 · 4 comments · Fixed by #410
Labels
bug Something isn't working

Comments

@ViCrack
Copy link

ViCrack commented Feb 12, 2025

Version
vfox version 0.6.0

OS
Windows

Describe the bug
clink升级到1.7.10.e3c993之后vfox无法切换sdk版本了,只能是全局模式

经过初步排查,可能是clink_vfox.lua文件中的vfox activate clink的没有执行结束的原因

local vfox_task = coroutine.create(function()
os.setenv('__VFOX_PID', os.getpid())
local vfox_activate = io.popen('vfox activate clink')
for line in vfox_activate:lines() do
vfox_setenv(line)
end
vfox_activate:close()
local cleanup = coroutine.create(function()
os.execute('vfox env -c')
end)
coroutine.resume(cleanup)
end)
coroutine.resume(vfox_task)

执行 vfox u nodejs@16 提示这个
Warning: The current shell lacks hook support or configuration. It has switched to global scope automatically.

不知道其他人会不会也一样,可能是clink的bug?

@ViCrack ViCrack added the bug Something isn't working label Feb 12, 2025
@jan-bar
Copy link
Contributor

jan-bar commented Feb 13, 2025

经过测试是 v1.7.8 出现的问题,目前不确定是不是clink的问题,我先排查下,clink的源码不是很了解。

你可以先改成不使用协程的逻辑,我自己也是这样用的,我不在意启动快慢额。

os.setenv('__VFOX_PID', os.getpid())
local vfox_activate = io.popen('vfox activate clink')
for line in vfox_activate:lines() do
    vfox_setenv(line)
end
vfox_activate:close()
os.execute('vfox env -c')

@ViCrack
Copy link
Author

ViCrack commented Feb 13, 2025

我把它写在了clink_vfox.lua末尾的clink.promptcoroutine方法里面了,现在也能用着

@jan-bar
Copy link
Contributor

jan-bar commented Feb 13, 2025

@ViCrack 我找到了clink作者的一份示例 chrisant996/clink#282 (comment) ,启动创建的协程用了clink提供的方法。

Image

然后我试了下面的脚本,在 clink 1.7.7 ~ clink 1.7.10 之间的这些版本都测试通过。请你验证一下额,没问题我再提PR额。

local vfox_task = coroutine.create(function()
    os.setenv('__VFOX_PID', os.getpid())
    os.setenv('__VFOX_CURTMPPATH', nil)
    local vfox_activate = io.popen('vfox activate clink')
    for line in vfox_activate:lines() do
        vfox_setenv(line)
    end
    vfox_activate:close()
    os.execute('vfox env -c')
end)
clink.runcoroutineuntilcomplete(vfox_task)

并且我用 os.clock() 测试上面协程执行时间,对比不用协程也快了很多倍,应该是生效了。

@ViCrack
Copy link
Author

ViCrack commented Feb 13, 2025

@ViCrack 我找到了clink作者的一份示例 chrisant996/clink#282 (comment) ,启动创建的协程用了clink提供的方法。

Image

然后我试了下面的脚本,在 clink 1.7.7 ~ clink 1.7.10 之间的这些版本都测试通过。请你验证一下额,没问题我再提PR额。

local vfox_task = coroutine.create(function()
os.setenv('__VFOX_PID', os.getpid())
os.setenv('__VFOX_CURTMPPATH', nil)
local vfox_activate = io.popen('vfox activate clink')
for line in vfox_activate:lines() do
vfox_setenv(line)
end
vfox_activate:close()
os.execute('vfox env -c')
end)
clink.runcoroutineuntilcomplete(vfox_task)
并且我用 os.clock() 测试上面协程执行时间,对比不用协程也快了很多倍,应该是生效了。

感谢,我已经验证,利用clink.runcoroutineuntilcomplete确认在1.7.10上能用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants