Skip to content

Generic Volta-style shims - #726

Closed
linghengqian wants to merge 1 commit into
version-fox:mainfrom
linghengqian:nodejs-some
Closed

linghengqian wants to merge 1 commit into
version-fox:mainfrom
linghengqian:nodejs-some

Conversation

@linghengqian

@linghengqian linghengqian commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

RFC: generic Volta-style shims for #725 (core stays language-agnostic)

What #725 actually asks for

Two layers, per the original report:

  1. npm install -g rimraf stays on PATH after vfox use switches Node.
  2. It keeps running on the install-time Node (Volta pinning), not the current one.

pnpm add --global only fixes layer 1. Verified in ubuntu:26.04 with vfox 1.0.12:
which playwright-cli stays at ~/.local/share/pnpm/bin/playwright-cli across the
switch, but a probe CLI printing process.version flips from v26.10.0 to v24.21.0.
The shim resolves node from the current PATH, so runtime pinning is still missing.

Why vfox-nodejs alone cannot fix layer 2

Current core behavior (this repo):

  • EnvKeys only puts the currently selected version's bin on PATH
    (internal/sdk/sdk.go EnvKeys/EnvKeysForScope). Switching versions drops the
    old bin, so npm -g binaries disappear.
  • PostInstall runs once at vfox install nodejs@X (internal/sdk/sdk.go).
    It never sees later npm install -g Y, so it can't create per-package shims.
  • PreUse can only return a version string (internal/plugin/model.go). There is no
    post-switch hook, no stable shim dir on PATH, and no generic way to intercept
    global installs.

So a Lua-only fix maxes out at asdf-style default-packages (reinstall on new Node
with the new runtime). That solves "available" but not "pinned to install-time
runtime", and wastes time/bandwidth.

Principle: no Node.js specifics in core

vfox core must not learn npm -g, npm root -g, Node ABI, or JS shim bodies.
nodejs is one plugin among many (pip/cargo/go install/deno/bun would all
want the same). Core owns where shims live, when plugins run, and PATH order.
Plugins own what a shim executes.

What this PR implements (generic)

  1. Stable shim dirs, always on PATH (internal/pathmeta/path_meta.go,
    internal/env/context.go, cmd/commands/env.go, cmd/commands/activate.go):
    ~/.vfox/shims, <project>/.vfox/shims, <session>/shims, merged as
    prefix > shims (Project, Session, Global) > version bins > clean.
    They survive use switches. Core never reads shim contents.
  2. Optional PostUse hook (internal/plugin/plugin.go, model.go,
    lua_plugin.go, internal/sdk/sdk.go):
    PLUGIN:PostUse(ctx) with cwd/scope/version/previousVersion/main/sdkInfo/shimDir,
    fired after scope links update in useInHook, and manually via vfox reshim.
    Old plugins without it keep working (HookFuncMap optional, HasFunction guard).
  3. vfox reshim (cmd/commands/reshim.go): re-links current selections and
    re-fires PostUse. This is the manual sync point for npm -g/pip install
    that happens between two use calls (same role as asdf reshim).

How vfox-nodejs would use it (future, other repo)

function PLUGIN:PostUse(ctx)
    -- scan install-time global bins of ctx.version, write/refresh shims into ctx.shimDir,
    -- each shim execs the recorded Node + package entry (pinning, not current PATH).
    -- use ctx.previousVersion to prune stale shims; use PreUninstall for uninstall cleanup.
end

@linghengqian linghengqian added the enhancement New feature or request label Oct 15, 2026
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.86957% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.97%. Comparing base (9aef814) to head (2c3f76f).

Files with missing lines Patch % Lines
internal/sdk/sdk.go 65.62% 6 Missing and 5 partials ⚠️
cmd/commands/reshim.go 75.67% 5 Missing and 4 partials ⚠️
internal/plugin/lua_plugin.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #726      +/-   ##
==========================================
+ Coverage   34.99%   38.97%   +3.97%     
==========================================
  Files          95       96       +1     
  Lines        6704     6815     +111     
==========================================
+ Hits         2346     2656     +310     
+ Misses       4045     3797     -248     
- Partials      313      362      +49     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@linghengqian
linghengqian marked this pull request as ready for review October 15, 2026 15:42

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aooohan

aooohan commented Oct 17, 2026

Copy link
Copy Markdown
Member

-1

Thanks for working on this. I see what you're trying to solve, but I don't think this is something we should support in vfox.

  1. Global npm packages are part of the Node version they're installed with. Switching versions should keep those environments separate.
  2. With this approach, I could switch to Node 24 and still have some commands running on Node 22. That would make it harder to tell what environment I'm actually using.
  3. Having each plugin handle shim creation, updates, and cleanup also leaves a lot of room for inconsistent behavior.
  4. And users would need to remember when to run reshim, which adds another thing to manage.
    I'd prefer to keep the existing version isolation rather than add a separate runtime binding for global commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants