Skip to content

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

Closed

Description

@ViCrack

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?

Activity

  1. added
    bug
    on Feb 12, 2025
  2. jan-bar commented on Feb 13, 2025

    @jan-bar
    Contributor

    经过测试是 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')
  3. ViCrack commented on Feb 13, 2025

    @ViCrack
    Author

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

  4. jan-bar commented on Feb 13, 2025

    @jan-bar
    Contributor

    @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() 测试上面协程执行时间,对比不用协程也快了很多倍,应该是生效了。

  5. ViCrack commented on Feb 13, 2025

    @ViCrack
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions