Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ node -v
`vfox search nodejs` lists every release, with the npm that comes with it and a
mark on the ones of an LTS line. In an interactive terminal it lets you pick one.

Behavior that only exists on `main` and not in the latest release is marked
"Unreleased" in the pages below. [docs/changes.md](docs/changes.md) lists it, and
[docs/source-build.md](docs/source-build.md) gets you `main`.

### Example: Ubuntu 26.04

```bash
Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ node -v

`vfox search nodejs` 会列出每个版本及其自带的 npm,属于 LTS 版本线的版本带有标记。在交互式终端里可以从中选一个。

只存在于 `main`、还没进入最新发布版的行为,在下面各页里标有“未发布”。[docs/zh-CN/changes.md](docs/zh-CN/changes.md) 里列出了这些行为,想直接用上 `main`,见 [docs/zh-CN/source-build.md](docs/zh-CN/source-build.md)。

### 示例:Ubuntu 26.04

```bash
Expand Down
24 changes: 23 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,29 @@

What changed in each release, as a user notices it. GitHub's
[release pages](https://github.com/version-fox/vfox-nodejs/releases) list the
pull requests.
pull requests. The newest release at the time of writing is 0.5.4, and `main` is
ahead of it by everything under "Unreleased".
[source-build.md](source-build.md) gets you those changes now.

## Unreleased

- On vfox 1.1.0 and later a `node` that shadows vfox's is reported by vfox
itself with the plugin's hint, instead of the plugin's `Note:`. Release
0.5.4 prints `Note: <shadowing node> comes before vfox in PATH, ...` from
`PreUse` on every vfox, so with the new vfox the same shadowing prints
both the core warning and the plugin note. The plugin now declares
`PLUGIN.shadowHints` for pnpm, mise, asdf, nvm, Homebrew and winget (each
with its handoff command and a link to `docs/pnpm.md` or the new
`docs/managers.md`) and keeps its own `Note:` for vfox before 1.1.0
only, which ignores the new metadata field. See [pnpm.md](pnpm.md),
[managers.md](managers.md) and
[troubleshooting.md](troubleshooting.md).
- `vfox link --detect nodejs` links the Node.js already on the machine
instead of downloading another copy: the nvm, mise, asdf and Homebrew
Cellar directories with a working `node` in them, and the winget
directory on Windows, each under the plain release number the binary
reports. Shims, pnpm's global runtime and copies without a versioned
home are skipped. See [managers.md](managers.md).

## 0.5.4 (2026-11-04)

Expand Down
20 changes: 14 additions & 6 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
## Layout

```text
metadata.lua plugin name, version, and .node-version and .nvmrc as legacy files
metadata.lua plugin name, version, .node-version and .nvmrc as legacy files, and shadowHints for a shadowing node
hooks/available.lua vfox search: the version index
hooks/pre_install.lua vfox install: choose the package, its URL and its checksum
hooks/post_install.lua musl: fail when node cannot run, such as without libstdc++ or libatomic
hooks/env_keys.lua PATH: bin on Linux and macOS, the install directory on Windows
hooks/pre_use.lua vfox use: map 24 or 24.21 to an installed release, note a shadowing node
hooks/pre_use.lua vfox use: map 24 or 24.21 to an installed release (and, on vfox before 1.1.0, note a shadowing node)
hooks/parse_legacy_file.lua .nvmrc and .node-version
lib/util.lua mirror URL and download headers, musl detection and missing libraries, running a command, version comparison and matching, shorthands, PATH probe, the LTS lines the plugin learned
hooks/detect.lua vfox link --detect: the nvm, mise, asdf, Homebrew and winget installs on this machine
lib/util.lua mirror URL and download headers, musl detection and missing libraries, running a command, version comparison and matching, shorthands, PATH probe, vfox version check, the LTS lines the plugin learned
.lts-cache not in the repository: what the plugin learned about LTS lines, written next to it
tests/hooks_test.lua offline hook tests
tests/e2e/ container tests, see e2e.md
Expand All @@ -37,6 +38,7 @@ loaded with `require("util")`.
| `vfox use nodejs@24` | `PreUse` returns the installed release to select. `EnvKeys` provides `PATH` |
| a shell hook, `cd` into a directory with `.nvmrc` | `ParseLegacyFile`, then `EnvKeys` |
| `vfox uninstall nodejs@24.21.0` | none, the name has to be exact |
| `vfox link --detect nodejs` | `Detect` |

A few contracts that cost time to find:

Expand Down Expand Up @@ -235,8 +237,12 @@ errors of a failed checksum request, musl and `PostInstall` (with `util.capture`
`ParseLegacyFile` under each strategy, in UTF-16 and with a byte order mark, and
with the removal of `env-state.json` (`os.getenv` and `os.remove` stubbed), what
the plugin learns about LTS lines (the file is a temporary one, and every case
starts with a fresh one that knows no line), `PreUse` with the shadowing `node`,
and the helpers of `lib/util.lua`. Add the case a change needs there.
starts with a fresh one that knows no line), `PreUse` with and without the
shadowing `node` on old and new vfox (`RUNTIME.version` before and from
1.1.0), `PLUGIN.shadowHints` in `metadata.lua`, `Detect` over stubbed
install roots, listings and `node --version` outputs (`os.getenv`,
`list_dir`, `file_exists` and `capture` stubbed), and the helpers of
`lib/util.lua`. Add the case a change needs there.

gopher-lua 1.1.1 loses a `local x = nil` that a closure assigns: the outer scope
still reads `nil`. A test that collects a value from inside `with_util` or
Expand All @@ -247,14 +253,16 @@ Check new code under `glua`, not only with LuaLS.

To call one hook against the real servers, vfox 1.0.13 and later has
`vfox plugin run`. It does not register the plugin, `--os` and `--arch` answer
for another platform, `--offline` rejects HTTP, and `VFOX_NODEJS_MIRROR` applies:
for another platform, `--offline` rejects HTTP, and `VFOX_NODEJS_MIRROR` applies
(`Detect` needs vfox 1.1.0 or later, which knows the hook):

```bash
vfox plugin run . Available --json
vfox plugin run . PreInstall --input '{"version":"24"}' --os windows --arch arm64 --json
vfox plugin run . PreUse --input '{"version":"22","installedSdks":{"22.23.3":{"version":"22.23.3"}}}' --json
vfox plugin run . ParseLegacyFile --input '{"filename":".nvmrc","filepath":"/tmp/p/.nvmrc","strategy":"latest_installed","installedVersions":["24.21.0"]}' --json
vfox plugin run . EnvKeys --input '{"path":"C:\\vfox\\nodejs-24.21.0"}' --os windows --arch amd64 --json
vfox plugin run . Detect --json
```

`vfox --debug <command>` shows what vfox does with a hook, which is how to find
Expand Down
208 changes: 208 additions & 0 deletions docs/managers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# Other Node.js managers

[中文](zh-CN/managers.md) | [English](managers.md)

pnpm has its own page ([pnpm.md](pnpm.md)): `pnpm runtime set node -g`
puts a second `node` into `$PNPM_HOME/bin`. This page is for the same
problem from the other managers people commonly have next to vfox:
mise, asdf, nvm, Homebrew and winget (or the official installer, which
puts `node` in the same place as winget).

The symptom is always the same: `vfox use nodejs@<version>` prints
`Now using`, `vfox current nodejs` agrees, but `node --version` prints
the other manager's version, because its `node` comes before vfox's in
`PATH` (`type -a node` lists it first). On vfox 1.1.0 and later vfox
warns itself and appends the plugin's hint for the manager it
recognizes; on older vfox the plugin prints its own `Note:`. Unreleased:
release 0.5.4 prints the `Note:`; on vfox 1.1.0 and later the warning
comes from vfox itself with the plugin's hint.

Pick at most one manager for `node` in a shell. The fastest way out is
`vfox link --detect nodejs` (needs vfox 1.1.0 or later, which has
`vfox link`): it asks the plugin for the real installs on this machine
and links what you pick. Nothing is downloaded or copied:

```sh
vfox link --detect nodejs
vfox use nodejs@22.14.0
```

It finds the nvm, mise, asdf and Homebrew Cellar directories with a
working `node` in them (including Intel's `/usr/local/Cellar/node`),
and the winget directory on Windows, each under the plain release
number the binary reports, so `vfox use 22` keeps working. A release
found twice links once, and what vfox installed already is skipped. It
never reports shims, pnpm's global runtime or copies without a
versioned home (a manual `/usr/local/bin/node`): link those by hand,
or hand `PATH` to vfox as below.

There are two roads per manager below. Road A, the default, hands
`PATH` to vfox without removing the other manager itself: its `node`
stops shadowing, and vfox installs and selects its own releases. Road B
keeps the files where they are and registers one of them with vfox:

```sh
vfox link nodejs@<name> <dir>
vfox use nodejs@<name>
```

`<dir>` is the SDK directory the plugin expects: the directory holding
`bin/` with `bin/node` in it on Linux and macOS, the directory holding
`node.exe` itself on Windows. `vfox link` checks that and refuses
anything else. Link the real install, never a shims directory
(`mise/shims`, `.asdf/shims`, `$PNPM_HOME/bin`): a shim is a
version-switching proxy, and pnpm's shim additionally ships no npm, so
a linked shim selects nothing stable. A linked version stays its
owner's: the other manager may upgrade or prune it underneath vfox
(`brew upgrade` replaces the Cellar directory, mise/asdf prune
installs), vfox only reports that, `vfox install --reinstall` does not
apply to it, and `vfox uninstall` removes the link only. Name a linked
install after the plain release number the binary reports (`22.14.0`),
so `vfox use 22` keeps selecting it; if vfox installed that release
already, just `vfox use` it instead of linking. A name may use letters,
digits, `.`, `_`, `+` and `-`, and must not be `latest`.

## mise

mise keeps shims in `~/.local/share/mise/shims/` (`%LOCALAPPDATA%\mise\shims\`
on Windows, e.g. `...\mise\shims\node.exe`) and the real installs in
`~/.local/share/mise/installs/node/<version>/`. `mise activate` puts the
shims first in `PATH`, so its `node` wins.

To let vfox own `node` (road A), drop the request and delete the
installs:

```sh
mise unuse -g node
mise uninstall --all node
```

In a project directory, `mise unuse node` edits that project's config
instead of the global one. Official reference:
[uninstall](https://mise.jdx.dev/cli/uninstall.html) and
[unuse](https://mise.jdx.dev/cli/unuse.html).

Or link one real install (road B); never the shims directory.
`vfox link --detect nodejs` finds these itself:

```sh
mise ls node
vfox link nodejs@22.0.0 ~/.local/share/mise/installs/node/22.0.0
vfox use nodejs@22.0.0
```

## asdf

asdf keeps shims in `~/.asdf/shims/` (`$ASDF_DATA_DIR/shims` when that
is set), e.g. `~/.asdf/shims/node`, and the real installs in
`~/.asdf/installs/nodejs/<version>/`. The shims directory is prepended
to `PATH`, so its `node` wins.

To let vfox own `node` (road A), uninstall the versions and drop the
pin:

```sh
asdf uninstall nodejs <version>
```

Then delete the `nodejs ...` line from `./.tool-versions` and
`~/.tool-versions` (or `asdf unset nodejs` on asdf 0.16+), and run
`asdf reshim nodejs` if a stale shim stays. Official reference:
[versions](https://asdf-vm.com/manage/versions.html) (uninstall and
shims on one page).

Or link one real install (road B); never the shims directory.
`vfox link --detect nodejs` finds these itself:

```sh
asdf list nodejs
asdf where nodejs 22.13.0
vfox link nodejs@22.13.0 ~/.asdf/installs/nodejs/22.13.0
vfox use nodejs@22.13.0
```

## nvm

nvm (nvm-sh) keeps versions in `~/.nvm/versions/node/v<version>/`, e.g.
`~/.nvm/versions/node/v22.14.0/bin/node`, and `nvm use` prepends that
`bin/` to `PATH`, so its `node` wins. Check with `nvm which current`.

To hand the current shell to vfox without deleting anything (road A),
run:

```sh
nvm deactivate
```

The installs stay for a later `nvm use`. `nvm unload` is stronger: it
also unloads the `nvm` function itself, so prefer `deactivate` for a
handoff. Official reference:
[restoring PATH](https://github.com/nvm-sh/nvm#restoring-path).

Or link one installed version (road B).
`vfox link --detect nodejs` finds these itself:

```sh
nvm which 22
vfox link nodejs@22.14.0 ~/.nvm/versions/node/v22.14.0
vfox use nodejs@22.14.0
```

## Homebrew

Homebrew links `node` into its prefix: `/opt/homebrew/bin/node` on Apple
silicon, `/usr/local/bin/node` on Intel Macs,
`/home/linuxbrew/.linuxbrew/bin/node` on Linux. Whichever `node` is first
in `PATH` wins (`which -a node`).

To let vfox own `node` while keeping the keg around (road A), run:

```sh
brew unlink node
```

`brew link node` brings it back. To remove it fully, `brew uninstall
node`. The Intel prefix `/usr/local/bin/node` does not contain
`homebrew`, so there vfox warns without the Homebrew hint; the fix is
the same. Official reference:
[manpage](https://docs.brew.sh/Manpage) (`unlink`, `uninstall`).

Or link the Cellar directory (road B); a later `brew upgrade` replaces
it, so the link can dangle and need relinking.
`vfox link --detect nodejs` finds these itself:

```sh
ls $(brew --cellar node)
vfox link nodejs@24.5.0 /opt/homebrew/Cellar/node/24.5.0
vfox use nodejs@24.5.0
```

## winget and the official installer

winget runs the official MSI, which installs machine-wide to
`C:\Program Files\nodejs\`, e.g. `C:\Program Files\nodejs\node.exe`,
and appends that directory to the system `PATH`. The LTS line uses the
`OpenJS.NodeJS.LTS` package id instead of `OpenJS.NodeJS`.

To let vfox own `node` (road A), uninstall it (Add/Remove Programs runs
the same uninstaller):

```powershell
winget list --name Node.js
winget uninstall -e --id OpenJS.NodeJS
```

If the LTS line is installed, replace the id with
`OpenJS.NodeJS.LTS`. Open a new terminal afterwards so the stale `PATH`
entry is gone. Official download page:
[nodejs.org](https://nodejs.org/en/download).

Or link the directory (road B); an MSI upgrade replaces the files
underneath, which vfox only reports.
`vfox link --detect nodejs` finds it itself; by hand:

```powershell
& "C:\Program Files\nodejs\node.exe" --version
vfox link nodejs@22.14.0 "C:\Program Files\nodejs"
vfox use nodejs@22.14.0
```
18 changes: 16 additions & 2 deletions docs/pnpm.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,27 @@ Observed with pnpm 12.14.0 and vfox 1.0.12 in bash on Ubuntu.
pnpm's `globalShims` setting and `PNPM_SHIM_BYPASS=1` only turn off the
project lookup; `node` still runs pnpm's global Node.js, not vfox's.

`vfox use nodejs@<version>` prints a note when a `node` sits ahead of vfox
this way, whichever tool put it there:
`vfox use nodejs@<version>` warns when a `node` sits ahead of vfox
this way, whichever tool put it there. Unreleased: release 0.5.4 prints
the `Note:` below from the plugin; on vfox 1.1.0 and later the warning
comes from vfox itself with the plugin's hint.

On vfox 1.1.0 and later:

```text
node runs /home/user/.local/share/pnpm/bin/node instead of nodejs@24.21.0: its directory comes before vfox in PATH.
pnpm installed its own node. Run `pnpm remove -g node` so vfox's node runs. See https://github.com/version-fox/vfox-nodejs/blob/main/docs/pnpm.md
```

On older vfox, the plugin prints:

```text
Note: /home/user/.local/share/pnpm/bin/node comes before vfox in PATH, so `node` will not run nodejs@24.21.0. See https://github.com/version-fox/vfox-nodejs/blob/main/docs/pnpm.md
```

For the same problem from mise, asdf, nvm, Homebrew or winget, see
[managers.md](managers.md).

## Keeping vfox in charge of `node`

Remove the Node.js that pnpm installed globally. pnpm keeps working, since
Expand Down
11 changes: 10 additions & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ These are not errors.
| `Note: Node.js versions below 16 do not support Apple Silicon (arm64), using x64 architecture with Rosetta 2` | macOS arm64 and a release before 16.0.0, see [platforms.md](platforms.md#macos) |
| `Note: musl libc detected, installed node-v22.23.3-linux-x64-musl.tar.gz. See ...` | the plugin took the musl package, see [musl.md](musl.md) |
| `Note: node-v18.20.8-linux-x64-musl.tar.gz is not listed in https://nodejs.org/dist/v18.20.8/, using unofficial musl build` | nodejs.org has no such musl package and the plugin takes it from unofficial-builds.nodejs.org |
| ``Note: /home/me/.local/share/pnpm/bin/node comes before vfox in PATH, so `node` will not run nodejs@24.21.0. See ...`` | another `node` shadows vfox's, see [pnpm.md](pnpm.md) |
| ``Note: /home/me/.local/share/pnpm/bin/node comes before vfox in PATH, so `node` will not run nodejs@24.21.0. See ...`` | another `node` shadows vfox's on vfox before 1.1.0, see [pnpm.md](pnpm.md) for pnpm and [managers.md](managers.md) for mise, asdf, nvm, Homebrew and winget. Unreleased: release 0.5.4 prints this; on vfox 1.1.0 and later vfox warns itself (`node runs ... instead of nodejs@...`) and appends the plugin's hint |

### Warnings from vfox itself

Unreleased: vfox 1.1.0 and later reports a shadowing `node` with the
plugin's hint; release 0.5.4 prints the `Note:` above from the plugin.

| Warning | Meaning |
| --- | --- |
| ``node runs /home/me/.local/share/pnpm/bin/node instead of nodejs@24.21.0: its directory comes before vfox in PATH. pnpm installed its own node. Run `pnpm remove -g node` so vfox's node runs. See ...`` | another `node` shadows vfox's, see [pnpm.md](pnpm.md) for pnpm and [managers.md](managers.md) for mise, asdf, nvm, Homebrew and winget |

### Errors from Node.js itself

Expand Down
7 changes: 6 additions & 1 deletion docs/zh-CN/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

[中文](changes.md) | [English](../changes.md)

按发布版本列出用户能感受到的变化。GitHub 的 [Release 页面](https://github.com/version-fox/vfox-nodejs/releases)列出了对应的 PR。
按发布版本列出用户能感受到的变化。GitHub 的 [Release 页面](https://github.com/version-fox/vfox-nodejs/releases)列出了对应的 PR。写这篇文档时最新的发布版是 0.5.4,`main` 比它多出“未发布”下面的所有内容。想现在就用上这些变化,见 [source-build.md](source-build.md)。

## 未发布

- 在 vfox 1.1.0 及以后的版本里,遮蔽 vfox 的 `node` 由 vfox 自己报告,并附带插件的提示,不再由插件打印 `Note:`。0.5.4 会在所有 vfox 上从 `PreUse` 打印 `Note: <shadowing node> comes before vfox in PATH, ...`,所以在新 vfox 上,同一个遮蔽会同时打印核心警告和插件的提示。插件现在为 pnpm、mise、asdf、nvm、Homebrew 和 winget 声明 `PLUGIN.shadowHints`(各自的交接命令,以及指向 `docs/pnpm.md` 或新建 `docs/managers.md` 的链接),只在 1.1.0 之前的 vfox 上保留自己的 `Note:`,老 vfox 会忽略这个新的元数据字段。见 [pnpm.md](pnpm.md)、[managers.md](managers.md)和 [troubleshooting.md](troubleshooting.md)。
- `vfox link --detect nodejs` 会把本机已有的 Node.js 链进来,不用再下载一份:装着可用 `node` 的 nvm、mise、asdf 和 Homebrew Cellar 目录,Windows 上还有 winget 目录,每个都用二进制自己报出的纯版本号命名。shim、pnpm 的全局运行时和没有版本化家目录的复制会被跳过。见 [managers.md](managers.md)。

## 0.5.4(2026-11-04)

Expand Down
Loading
Loading