mirror of
https://github.com/tj/n.git
synced 2024-11-21 18:48:57 +01:00
Make cache directory configurable (#717)
Read the cache directory from the environment, falling back to a location under `N_PREFIX`
This commit is contained in:
parent
8060fba8c5
commit
e1b57955d6
@ -255,6 +255,9 @@ To change the location to say `$HOME/.n`, add lines like the following to your s
|
||||
export N_PREFIX=$HOME/.n
|
||||
export PATH=$N_PREFIX/bin:$PATH
|
||||
|
||||
If you want to store the downloads under a different location, use `N_CACHE_PREFIX`. This does *not* affect the currently active
|
||||
node version.
|
||||
|
||||
`n` defaults to using xz compressed Node.js tarballs for the download if it is likely tar on the system supports xz decompression.
|
||||
You can override the automatic choice by setting an environment variable to zero or non-zero:
|
||||
|
||||
|
6
bin/n
6
bin/n
@ -66,7 +66,11 @@ VERSION="v8.0.3-0"
|
||||
N_PREFIX="${N_PREFIX-/usr/local}"
|
||||
N_PREFIX=${N_PREFIX%/}
|
||||
readonly N_PREFIX
|
||||
readonly CACHE_DIR=$N_PREFIX/n/versions
|
||||
|
||||
N_CACHE_PREFIX="${N_CACHE_PREFIX-${N_PREFIX}}"
|
||||
N_CACHE_PREFIX=${N_CACHE_PREFIX%/}
|
||||
CACHE_DIR="${N_CACHE_PREFIX}/n/versions"
|
||||
readonly N_CACHE_PREFIX CACHE_DIR
|
||||
|
||||
N_NODE_MIRROR=${N_NODE_MIRROR:-${NODE_MIRROR:-https://nodejs.org/dist}}
|
||||
N_NODE_MIRROR=${N_NODE_MIRROR%/}
|
||||
|
@ -42,3 +42,21 @@ function setup() {
|
||||
|
||||
rm -rf "${TMP_PREFIX_DIR}"
|
||||
}
|
||||
|
||||
@test "install: cache prefix" {
|
||||
readonly N_CACHE_PREFIX="$(mktemp -d)"
|
||||
readonly TARGET_VERSION="4.9.1"
|
||||
setup_tmp_prefix
|
||||
export N_CACHE_PREFIX
|
||||
|
||||
[ ! -d "${N_CACHE_PREFIX}/n/versions/node/${TARGET_VERSION}" ]
|
||||
[ ! -d "${N_PREFIX}/n/versions/node/${TARGET_VERSION}" ]
|
||||
|
||||
n ${TARGET_VERSION}
|
||||
|
||||
# Cached version
|
||||
[ -d "${N_CACHE_PREFIX}/n/versions/node/${TARGET_VERSION}" ]
|
||||
[ ! -d "${N_PREFIX}/n/versions/node/${TARGET_VERSION}" ]
|
||||
|
||||
rm -rf "${TMP_PREFIX_DIR}" "${N_CACHE_PREFIX}"
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
function unset_n_env(){
|
||||
unset N_PREFIX
|
||||
unset N_CACHE_PREFIX
|
||||
unset NODE_MIRROR
|
||||
unset N_NODE_MIRROR
|
||||
unset N_NODE_DOWNLOAD_MIRROR
|
||||
|
Loading…
Reference in New Issue
Block a user