Skip to content

Commit 74fd0b2

Browse files
authored
docs(readme): document file:// mirrors as a local download source (#405)
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
1 parent 4b20189 commit 74fd0b2

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Version [unreleased]
2424
`--source` that is what lets a repeated `--force` build reuse the
2525
downloaded source tree
2626
`#205 <https://github.com/ekalinin/nodeenv/issues/205>`_
27+
- Documented that `--mirror` takes a `file://` URL, so a local directory can
28+
serve as the download source
29+
`#193 <https://github.com/ekalinin/nodeenv/issues/193>`_
2730

2831
Version 1.3.1
2932
-------------

README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ Install node.js from a mirror::
141141

142142
$ nodeenv --node=10.19.0 --mirror=https://npm.taobao.org/mirrors/node
143143

144+
A local directory works as a mirror too, if it repeats the layout of
145+
nodejs.org: packages in ``v<version>/`` and, to resolve ``latest``, ``lts``
146+
or a version range, an ``index.json`` next to them::
147+
148+
$ nodeenv --node=22.14.0 --mirror=file:///srv/node-mirror env-22
149+
144150
Install the highest node.js release matching a version range::
145151

146152
$ nodeenv --node=22 env-22
@@ -307,7 +313,8 @@ Installation options
307313
Install node.js from the source (Unix only).
308314

309315
``--mirror=URL``
310-
Set mirror server of nodejs.org to download from.
316+
Set mirror server of nodejs.org to download from. A ``file://`` URL
317+
points nodeenv at a local directory instead of a server.
311318

312319
``-c, --clean-src``
313320
Remove "src" directory after installation. This is the default.

tests/nodeenv_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from shlex import quote as _quote
99
import io
1010
import os.path
11+
import pathlib
1112
import subprocess
1213
import sys
1314
import sysconfig
@@ -309,6 +310,20 @@ def rewind(_):
309310
mock_logger.assert_called()
310311

311312

313+
def test_mirror_option_local_directory(tmpdir):
314+
"""A local directory is a valid mirror, see #193"""
315+
tmpdir.join('index.json').write(
316+
'[{"version": "v99.0.0", "date": "2026-01-01", "lts": false,'
317+
' "files": ["linux-x64", "linux-x64-musl", "linux-riscv64"]}]')
318+
mirror = pathlib.Path(str(tmpdir)).as_uri()
319+
argv = [__file__, '--list', '--mirror=' + mirror]
320+
with mock.patch.object(sys, 'argv', argv), \
321+
mock.patch.object(nodeenv.logger, 'info') as mock_logger:
322+
nodeenv.src_base_url = None
323+
nodeenv.main()
324+
mock_logger.assert_called_with('99.0.0')
325+
326+
312327
@pytest.mark.usefixtures('mock_index_json', 'mock_host_platform')
313328
def test_get_latest_node_version():
314329
assert nodeenv.get_last_stable_node_version() == '13.5.0'

0 commit comments

Comments
 (0)