From d71dd61290cfc077892b4383db918399ff3ab941 Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Sun, 20 Sep 2026 15:27:57 +0300 Subject: [PATCH] docs(readme): document file:// mirrors as a local download source A local directory laid out like nodejs.org already works as a mirror, but only https mirrors were documented. Add an example, mention it in the --mirror description and cover it with a test that lists versions from a local index.json. Closes #193 --- CHANGES | 3 +++ README.rst | 9 ++++++++- tests/nodeenv_test.py | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index eb803d8..dbde23b 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,9 @@ Version [unreleased] `--source` that is what lets a repeated `--force` build reuse the downloaded source tree `#205 `_ +- Documented that `--mirror` takes a `file://` URL, so a local directory can + serve as the download source + `#193 `_ Version 1.3.1 ------------- diff --git a/README.rst b/README.rst index 7bb9380..50cc6ca 100644 --- a/README.rst +++ b/README.rst @@ -141,6 +141,12 @@ Install node.js from a mirror:: $ nodeenv --node=10.19.0 --mirror=https://npm.taobao.org/mirrors/node +A local directory works as a mirror too, if it repeats the layout of +nodejs.org: packages in ``v/`` and, to resolve ``latest``, ``lts`` +or a version range, an ``index.json`` next to them:: + + $ nodeenv --node=22.14.0 --mirror=file:///srv/node-mirror env-22 + Install the highest node.js release matching a version range:: $ nodeenv --node=22 env-22 @@ -307,7 +313,8 @@ Installation options Install node.js from the source (Unix only). ``--mirror=URL`` - Set mirror server of nodejs.org to download from. + Set mirror server of nodejs.org to download from. A ``file://`` URL + points nodeenv at a local directory instead of a server. ``-c, --clean-src`` Remove "src" directory after installation. This is the default. diff --git a/tests/nodeenv_test.py b/tests/nodeenv_test.py index 8fd42cd..7645347 100644 --- a/tests/nodeenv_test.py +++ b/tests/nodeenv_test.py @@ -8,6 +8,7 @@ from shlex import quote as _quote import io import os.path +import pathlib import subprocess import sys import sysconfig @@ -309,6 +310,20 @@ def rewind(_): mock_logger.assert_called() +def test_mirror_option_local_directory(tmpdir): + """A local directory is a valid mirror, see #193""" + tmpdir.join('index.json').write( + '[{"version": "v99.0.0", "date": "2026-01-01", "lts": false,' + ' "files": ["linux-x64", "linux-x64-musl", "linux-riscv64"]}]') + mirror = pathlib.Path(str(tmpdir)).as_uri() + argv = [__file__, '--list', '--mirror=' + mirror] + with mock.patch.object(sys, 'argv', argv), \ + mock.patch.object(nodeenv.logger, 'info') as mock_logger: + nodeenv.src_base_url = None + nodeenv.main() + mock_logger.assert_called_with('99.0.0') + + @pytest.mark.usefixtures('mock_index_json', 'mock_host_platform') def test_get_latest_node_version(): assert nodeenv.get_last_stable_node_version() == '13.5.0'