Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
52b81b7
docs: add a page of scenarios, and say when .nvmrc is read
linghengqian Nov 3, 2026
f93f0f1
docs: say that Node.js 26 entered long-term support as Lithium
linghengqian Nov 3, 2026
fe8ad60
fix(parse_legacy_file): add Lithium (Node.js 26) to the codename table
linghengqian Nov 3, 2026
e4e9bee
fix(parse_legacy_file): read a .nvmrc in UTF-16 or with a byte order …
linghengqian Nov 3, 2026
4548586
fix(parse_legacy_file): make vfox notice a version file after a cd
linghengqian Nov 3, 2026
ec968ae
docs: describe Lithium, UTF-16 files and version files after a cd
linghengqian Nov 3, 2026
7a6fa78
docs: say what a build of vfox with the working directory in its stat…
linghengqian Nov 3, 2026
0898bbb
test: keep the hook tests from removing the state of the shell they r…
linghengqian Nov 3, 2026
8a7a881
docs: keep the vfox patch in the repository, and say what it covers
linghengqian Nov 3, 2026
53c16a1
Merge origin/main into docs/use-case-scenarios
linghengqian Nov 3, 2026
2c02b48
docs: say that a second local run of the e2e suite can be a replay
linghengqian Nov 3, 2026
e104097
test(e2e): wait for the Docker engine before the Windows suite pulls
linghengqian Nov 3, 2026
a4510f6
docs: take the vfox patch out of this pull request, and link the issues
linghengqian Nov 3, 2026
3e88c13
fix(parse_legacy_file): learn the LTS lines from the index instead of…
linghengqian Nov 3, 2026
8144e89
test(e2e): check the file in which the plugin learned the LTS lines
linghengqian Nov 3, 2026
0c69b48
docs: say that the plugin learns the LTS lines from the index
linghengqian Nov 3, 2026
28736b7
test(e2e): run the check of the learned LTS lines on WSL, and say wha…
linghengqian Nov 3, 2026
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
# limitations under the License.

.idea

# What the plugin learns about LTS lines, when a checkout is used as the plugin directory
.lts-cache
.lts-cache.tmp
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ and checks every download against the SHA-256 sums published next to it. Each
release comes with its own npm. On Alpine, OpenWrt and other musl systems it
installs the musl builds. vfox reads `.nvmrc` and `.node-version` through it.

It does for vfox what [nvm-sh/nvm](https://github.com/nvm-sh/nvm) does for POSIX
shells: several releases side by side, one chosen per shell, per project or as
the default, and `.nvmrc` read. nvm-sh/nvm is written for POSIX shells and does
not run in PowerShell. vfox does, so Windows PowerShell 5.1 gets the same work.
[docs/scenarios.md](docs/scenarios.md) shows it in concrete cases, with the
commands side by side.

## Install

After installing [vfox](https://github.com/version-fox/vfox), install the plugin by running:
Expand Down Expand Up @@ -74,6 +81,13 @@ calls `libstdc++` the `libstdcpp` package). musl builds exist for x64 and arm64
only. musl details (OpenWrt, tarball matrix, mirror fallback, which releases
have a build): see [docs/musl.md](docs/musl.md).

## Scenarios

See [docs/scenarios.md](docs/scenarios.md) for concrete cases: the nvm-sh/nvm
commands next to vfox's, Windows PowerShell 5.1 from scratch, one Node.js for a
whole team, several projects in one shell, running a command on a given release,
mirrors and editors.

## Versions and names

A version is a release number: `24.21.0`, or the start of one, `24.21` and `24`,
Expand Down Expand Up @@ -107,10 +121,16 @@ details and for mirrors that were checked.

## `.nvmrc` and `.node-version`

vfox reads these files when you enter a directory, and selects the release they
name if it is installed. What a file can say depends on vfox's
vfox reads these files at every prompt in a directory that has one, and selects
the release they name if it is installed, so a `cd` into the directory switches.
Unreleased: release 0.5.3 reads them when a shell starts in the directory, not
after a `cd` from a running shell. Neither switches back when you `cd` into a
directory with no config at all; a `.vfox.toml`, which `vfox use --project`
writes, does. What a file can say depends on vfox's
`legacyVersionFile.strategy`: with the default, `specified`, only a full release
number selects something. See [docs/nvmrc.md](docs/nvmrc.md) for details.
number selects something. A file in UTF-16 or with a byte order mark, which
Windows PowerShell 5.1 writes, is read too (Unreleased). See
[docs/nvmrc.md](docs/nvmrc.md) for details.

## LTS

Expand Down
8 changes: 7 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

它安装 [nodejs.org](https://nodejs.org/dist/) 或其[镜像](docs/zh-CN/mirror.md)上发布的 Node.js 版本压缩包,并对照一同发布的 SHA-256 校验和检查每次下载。每个版本都自带自己的 npm。在 Alpine、OpenWrt 和其他 musl 系统上,安装的是 musl 构建。vfox 通过它读取 `.nvmrc` 和 `.node-version`。

它为 vfox 做的,正是 [nvm-sh/nvm](https://github.com/nvm-sh/nvm) 为 POSIX Shell 做的事:多个版本并存,可以按 Shell、按项目选定其中一个,或者设为默认,并读取 `.nvmrc`。nvm-sh/nvm 是为 POSIX Shell 写的,不能在 PowerShell 里运行;vfox 可以,所以 Windows PowerShell 5.1 也能做同样的事。[docs/zh-CN/scenarios.md](docs/zh-CN/scenarios.md) 用具体的场景展示这一点,并把两边的命令并排列出。

## 安装

先安装 [vfox](https://github.com/version-fox/vfox),然后执行下面的命令安装插件:
Expand Down Expand Up @@ -56,6 +58,10 @@ vfox use --global nodejs@24

Node.js 的 musl 构建需要 `libstdc++`,26.8.0 及以后的构建还需要 `libatomic`。原版 Alpine 镜像两者都没有,而插件不会安装系统库。安装会中止,并给出一条提示,写明缺少哪个包以及安装它的命令(`apk add libatomic`;OpenWrt 把 `libstdc++` 称为 `libstdcpp` 包)。musl 构建只提供 x64 和 arm64。musl 的详细情况(OpenWrt、压缩包对照表、镜像回退、哪些版本有构建)见 [docs/zh-CN/musl.md](docs/zh-CN/musl.md)。

## 使用场景

具体的场景见 [docs/zh-CN/scenarios.md](docs/zh-CN/scenarios.md):nvm-sh/nvm 与 vfox 的命令对照、从零开始使用 Windows PowerShell 5.1、全团队使用同一个 Node.js、一个 Shell 里的多个项目、用指定版本运行一条命令、镜像,以及编辑器。

## 版本与命名

版本就是版本号:`24.21.0`,也可以只写开头的部分,如 `24.21` 和 `24`,它们安装对应版本线的最新版本。`latest` 是所有版本线中最新的版本,不论是否属于 LTS。这里没有 `lts` 别名,请写明版本线(`nodejs@24`)。安装后的版本名就是版本号 `24.21.0`,`vfox uninstall` 需要写完整。`vfox use` 和 `vfox search` 怎样处理这些写法,详见 [docs/zh-CN/versions.md](docs/zh-CN/versions.md)。
Expand All @@ -74,7 +80,7 @@ Node.js 为 Linux(x64、arm64、ppc64le、s390x)、macOS(x64 和 arm64)

## `.nvmrc` 和 `.node-version`

进入目录时,vfox 会读取这些文件,并选中其中指定的版本(前提是已经安装)。文件里能写什么取决于 vfox 的 `legacyVersionFile.strategy`:默认值 `specified` 下,只有完整的版本号才能选中某个版本。详见 [docs/zh-CN/nvmrc.md](docs/zh-CN/nvmrc.md)。
每个提示符出现在带有这些文件的目录里时,vfox 都会读取它们,并选中其中指定的版本(前提是已经安装),所以 `cd` 进这个目录就会切换。未发布:0.5.3 在 Shell 于该目录里启动时读取,已经在运行的 Shell 里 `cd` 进来则不读取。两者在 `cd` 到完全没有配置的目录时都不会切换回来;`vfox use --project` 写出的 `.vfox.toml` 则会。文件里能写什么取决于 vfox 的 `legacyVersionFile.strategy`:默认值 `specified` 下,只有完整的版本号才能选中某个版本。UTF-16 的文件或带字节顺序标记的文件(Windows PowerShell 5.1 会写出这样的文件)也能读取(未发布)。详见 [docs/zh-CN/nvmrc.md](docs/zh-CN/nvmrc.md)。

## LTS

Expand Down
32 changes: 32 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ ahead of it by everything under "Unreleased".
requests, `vfox/1.0.13 vfox-nodejs/0.5.3` under vfox 1.0.13, and all of the
mirrors of [mirror.md](mirror.md#mirrors-that-work) install 24.21.0. China
Telecom Cloud, `https://mirrors.ctyun.cn/nodejs-release`, is in that list now.
- The plugin learns the LTS lines from the version index, so a line that
Node.js promotes later needs no release of the plugin. It keeps what it
learned in `.lts-cache` next to the plugin. It writes the file when
`vfox search`, or an install of `latest` or of a major, reads the index, and
when an install of an exact release finds the file missing or a day old. It
reads it for `lts/<codename>`, `lts` and `lts/*` under `specified` and
`latest_installed`, without any request. Before it has learned anything, or
where it cannot write the file, it uses a table of the codenames, which now
ends at Lithium (26): Node.js 26 entered long-term support on 2026-10-28.
Release 0.5.3 has the table only, and it ends at Krypton (24), so there
`lts/lithium` selects nothing under `latest_installed`, and `lts` and `lts/*`
select a 24.x. See [lts.md](lts.md#what-this-plugin-understands).
- A `.nvmrc` or `.node-version` in UTF-16, or in UTF-8 with a byte order mark,
is read. Windows PowerShell 5.1 writes the first with `>` and `Out-File`, and
the second with `-Encoding UTF8`. Release 0.5.3 reads the bytes as they are,
so no release matches the text and vfox says nothing. See
[nvmrc.md](nvmrc.md#what-the-file-may-hold).
- `.nvmrc` and `.node-version` are read at every prompt in their directory, so a
`cd` into it switches, and a change of the file takes effect at the next
prompt. Release 0.5.3 reads them when a shell starts in the directory and not
after a `cd`, because vfox 1.0.13 keeps the first result it worked out for the
shell and does not track version files. The plugin now removes that result
whenever vfox asks it to read such a file. A `cd` out of the directory into
one with no config at all does not switch back yet, and a `.vfox.toml` always
did. See [nvmrc.md](nvmrc.md#when-the-file-is-read). The cache is vfox's, and
vfox has been asked to fix it
([version-fox/vfox#745](https://github.com/version-fox/vfox/issues/745),
tracked here as [#46](https://github.com/version-fox/vfox-nodejs/issues/46)).
- The documentation has a page of scenarios: the nvm-sh/nvm commands next to
vfox's, Windows PowerShell 5.1 from scratch, one Node.js for a whole team,
several projects in one shell, `vfox exec`, mirrors and editors. See
[scenarios.md](scenarios.md).

## 0.5.3 (2026-10-20)

Expand Down
117 changes: 96 additions & 21 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ hooks/post_install.lua musl: fail when node cannot run, such as without
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/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
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
.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
Injection.lua type hints for what vfox injects, never loaded
Expand Down Expand Up @@ -123,12 +124,24 @@ check that cannot work never blocks an install. See

## Legacy files

`ParseLegacyFile` reads the file, removes all whitespace, and gives the text to
`ParseLegacyFile` first removes `env-state.json` from the session directory
(`util.forget_env_state`). vfox keeps the result of `vfox env` there and does
not track version files, so without this a `cd` into a directory that only has
one is not noticed. vfox calls the hook before it loads that file, which is what
makes the workaround work, and it is why the hook cannot help on the way out of
the directory: it is not called where there is nothing to read. See
[nvmrc.md](nvmrc.md#when-the-file-is-read).

It then reads the file and decodes it (`util.decode_text` turns UTF-16 with a
byte order mark into UTF-8, and drops the UTF-8 mark, because Windows PowerShell
5.1 writes both). It removes all whitespace, and gives the text to
`resolve_version(query, strategy)`: it drops a leading `v`, lowers the case,
turns `lts-x` into `lts/x`, and maps `lts/<codename>` to a major, `lts` and
`lts/*` to the highest major in `nodejs_codenames`. Under `latest_available` the
codename comes from the index first (`discover_lts`), and the table is the
fallback when that finds nothing or the request fails.
`lts/*` to the newest major of an LTS line. Under `latest_available` the
codename comes from the index first (`discover_lts`). Everywhere else, and when
that finds nothing or the request fails, `util.known_lts_lines` answers without
a request: what the plugin learned from the index over the built-in
`util.LtsLines`, see [below](#what-the-plugin-learns-about-lts-lines).

`resolve_legacy_version(strategy, query)` then reads the query with
`util.version_prefix`: `22` is `{ 22 }`, `22.23` is `{ 22, 23 }`, and `22.x`,
Expand All @@ -145,21 +158,64 @@ fallback when that finds nothing or the request fails.
`vfox` then selects the answer if it is installed. User-facing rules and
examples are in [nvmrc.md](nvmrc.md) and [lts.md](lts.md).

## What the plugin learns about LTS lines

`ParseLegacyFile` runs at every prompt in a directory with a version file, so it
cannot fetch `index.json` to find out what `lts/*` is. The plugin learns it when
it has the index in hand anyway, and keeps it in `.lts-cache`, a text file next
to the plugin:

```text
# What vfox-nodejs learned from index.json about LTS lines. Safe to delete.
updated 1793000000
newest 26
line argon 4
...
line lithium 26
```

- `Available` calls `util.remember_lts` with the index it has decoded.
`util.lts_summary` finds the major of each named line and the newest major
that is LTS at all (a release whose `lts` is `true`, a line without a name,
counts for the newest only). It runs when vfox's own cache of the answer has
run out.
- `PreInstall` calls `util.refresh_lts_cache` once the install has its checksum,
so an install that fails early, such as the one for an architecture without a
package, fetches nothing. vfox installs an exact release without asking
`Available`, so this is where such an install learns. It calls `Available`
when the file is missing or older than a day, and only if the file can be
written, so that a plugin directory that is read-only does not cost an index
at every install.
- `ParseLegacyFile` reads the file through `util.known_lts_lines`, which puts
what was learned over the built-in `util.LtsLines` and takes the newest major
of the two for `lts` and `lts/*`. It never fetches.
- vfox gives a plugin no path of its own, so `util.plugin_dir` finds the
directory where `package.path` has `hooks/?.lua` and `lib/?.lua`. The new
file is written beside the old one and renamed over it. Every failure, no
directory, nothing writable, a damaged file, leaves the plugin with the table.
- In the checkout `package.path` starts with `./lib/?.lua`, so the directory
would be the repository. The hook tests point `util.lts_cache_path` at a file
of their own.

## When Node.js promotes a line to LTS

Each October an even-numbered line gets a codename, see
[lts.md](lts.md#when-nodejs-promotes-a-line). To teach the plugin the new one:

1. Add `<codename> = <major>` to `nodejs_codenames` in
`hooks/parse_legacy_file.lua`.
2. Add a case next to `legacy lts krypton maps to its major` in
`tests/hooks_test.lua`.
3. Add a row to the table in [lts.md](lts.md#what-this-plugin-understands), and
change the "24 at the time of writing" sentences in [lts.md](lts.md) and
[nvmrc.md](nvmrc.md).
4. `DefaultLTSVersion` in `tests/e2e/common/common.go` may stay: it only has to
[lts.md](lts.md#when-nodejs-promotes-a-line). The plugin learns the line from
the index and needs no release for it. This is housekeeping, so that a plugin
that has learned nothing yet knows it too, and that the documents are right:

1. Add `<codename> = <major>` to `UTIL.LtsLines` in `lib/util.lua`.
2. Add a case next to `legacy lts lithium maps to its major` in
`tests/hooks_test.lua`, and change the major that `legacy bare lts is the
newest line of the table` expects.
3. Add the codename to `LTSCodenames` in `tests/e2e/common/common.go`, and a
case to `TestLTSCodename`. The e2e suites compare that table with the file
the plugin wrote from the live index.
4. Add a row to the table in [lts.md](lts.md#what-this-plugin-understands), and
change the "26 at the time of writing" sentences in [lts.md](lts.md) and
[nvmrc.md](nvmrc.md), and the examples of [lts.md](lts.md#examples).
5. `DefaultLTSVersion` in `tests/e2e/common/common.go` may stay: it only has to
stay inside the table.
5. Release.

## Tests

Expand All @@ -176,12 +232,18 @@ itself (`package.preload`), sets `RUNTIME` per case, and answers requests from
It covers `Available` and its failures, the package name per platform and the
errors of a failed checksum request, musl and `PostInstall` (with `util.capture`,
`util.file_exists` and `util.has_libstdcxx` stubbed through `with_util`),
`ParseLegacyFile` under each strategy, `PreUse` with the shadowing `node`, and
the helpers of `lib/util.lua`. Add the case a change needs there.
`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.

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
`pcall` has to keep it in a table field.
`pcall` has to keep it in a table field. It also ends in a Go "nil pointer
dereference" at `if file == nil` after `local file = path ~= nil and
io.open(path, "r") or nil`: test `path` and open the file in two statements.
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
Expand Down Expand Up @@ -244,10 +306,23 @@ have no package. For the musl table run the same program against
- The e2e Alpine image gets `libatomic` through `go`, which depends on `gcc`, so
the suite does not cover a stock Alpine without it. The hook tests do.
- `.nvmrc` aliases (`node`, `stable`, `lts/-1`), ranges and comments are not
understood, and `lts` follows a hand-made table, see
[nvmrc.md](nvmrc.md#not-understood).
understood, see [nvmrc.md](nvmrc.md#not-understood).
- A plugin directory that cannot be written, or a plugin that has not had the
index in hand since it was installed, leaves `specified` and
`latest_installed` with the built-in table, which ends at Lithium.
- A `cd` out of a directory with a version file into one with no config at all
does not switch back. vfox does not track version files and keeps the result
of its last calculation, and the plugin is not called where there is no file
to read, so `util.forget_env_state` only covers the way in. A fix belongs in
vfox: [version-fox/vfox#745](https://github.com/version-fox/vfox/issues/745),
tracked here as [#46](https://github.com/version-fox/vfox-nodejs/issues/46).
Drop `util.forget_env_state` when vfox tracks version files.
- Every prompt in a directory with a version file calculates the environment
again, because of `util.forget_env_state`. It took about a millisecond with
one SDK installed.
- `latest_available` downloads `index.json` at every prompt in a directory with a
legacy file.
- UTF-32, and UTF-16 without a byte order mark, are not decoded.
- The unofficial site is not covered by `VFOX_NODEJS_MIRROR`.
- macOS has no e2e job.

Expand Down
Loading
Loading