Split out from #193, which asked for two things: -p not redownloading node (done in #403) and a way to install from a local copy (--mirror=file://..., documented in #405). What neither covers is a cache shared between environments.
Current behaviour
Every environment downloads its own copy. The archive is never stored: _download_node_file() keeps it in a BytesIO and download_node_src() extracts it straight into <env>/src. That directory is then removed after the install by default since #404, and --no-clean-src keeps only the unpacked tree, inside that one environment.
So creating 10 environments with the same node version means 10 downloads of the same ~50 MB archive, even though nothing about it is environment specific.
Proposal
An opt-in cache directory for downloaded archives:
$ nodeenv --cache-dir=~/.cache/nodeenv env1
$ nodeenv --cache-dir=~/.cache/nodeenv env2 # no download
- a
cache_dir key in ~/.nodeenvrc, like mirror has, so it can be set once
- the cached file is keyed by the archive name, e.g.
node-v22.14.0-linux-x64.tar.gz, which already contains version, platform and arch
- a cache hit skips the download and extracts from the cached file; a miss downloads and then stores it
- off by default, so nothing is written outside the environment unless asked
Touchpoints are download_node_src() and install_node_wrapped(). install_npm_win() downloads a separate npm zip and could reuse the same directory later, but the node archive is where the size is.
Open questions
- flag only, or also an env var (
NODEENV_CACHE) for CI?
- should a default location such as
~/.cache/nodeenv be used when the flag is given without a value?
- any pruning at all, or leave the directory to the user?
Split out from #193, which asked for two things:
-pnot redownloading node (done in #403) and a way to install from a local copy (--mirror=file://..., documented in #405). What neither covers is a cache shared between environments.Current behaviour
Every environment downloads its own copy. The archive is never stored:
_download_node_file()keeps it in aBytesIOanddownload_node_src()extracts it straight into<env>/src. That directory is then removed after the install by default since #404, and--no-clean-srckeeps only the unpacked tree, inside that one environment.So creating 10 environments with the same node version means 10 downloads of the same ~50 MB archive, even though nothing about it is environment specific.
Proposal
An opt-in cache directory for downloaded archives:
cache_dirkey in~/.nodeenvrc, likemirrorhas, so it can be set oncenode-v22.14.0-linux-x64.tar.gz, which already contains version, platform and archTouchpoints are
download_node_src()andinstall_node_wrapped().install_npm_win()downloads a separate npm zip and could reuse the same directory later, but the node archive is where the size is.Open questions
NODEENV_CACHE) for CI?~/.cache/nodeenvbe used when the flag is given without a value?