0
0
mirror of https://github.com/tj/n.git synced 2024-11-21 18:48:57 +01:00

Add download command (#821)

This commit is contained in:
John Gee 2024-11-09 11:42:51 +13:00 committed by GitHub
parent eea2a55533
commit cbde6e2b01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 5 deletions

View File

@ -234,6 +234,10 @@ List downloaded versions in cache:
n ls
Download version into cache:
n download 22
Use `n` to access cached versions (already downloaded) without internet available.
n --offline 12

8
bin/n
View File

@ -390,6 +390,7 @@ Commands:
n ls Output downloaded versions
n ls-remote [version] Output matching versions available for download
n uninstall Remove the installed Node.js
n download <version> Download Node.js <version> into cache
Options:
@ -794,6 +795,8 @@ install() {
if [[ ! -e "$dir/n.lock" ]] ; then
if [[ "$DOWNLOAD" == "false" ]] ; then
activate "${g_mirror_folder_name}/${version}"
else
log downloaded "${g_mirror_folder_name}/${version} already in cache"
fi
exit
fi
@ -802,7 +805,11 @@ install() {
abort "version unavailable offline"
fi
if [[ "$DOWNLOAD" == "false" ]]; then
log installing "${g_mirror_folder_name}-v$version"
else
log download "${g_mirror_folder_name}-v$version"
fi
local url="$(tarball_url "$version")"
is_ok "${url}" || abort "download preflight failed for '$version' ($(display_masked_url "${url}"))"
@ -1733,6 +1740,7 @@ else
lsr|ls-remote|list-remote) shift; display_remote_versions "$1"; exit ;;
uninstall) uninstall_installed; exit ;;
i|install) shift; install "$1"; exit ;;
download) shift; DOWNLOAD="true"; install "$1"; exit ;;
N_TEST_DISPLAY_LATEST_RESOLVED_VERSION) shift; get_latest_resolved_version "$1" > /dev/null || exit 2; echo "${g_target_node}"; exit ;;
*) install "$1"; exit ;;
esac

View File

@ -17,9 +17,22 @@ function teardown() {
@test "n --download 4.9.1" {
# deprecated use of --download, replaced by download command
n --download 4.9.1
[ -d "${N_PREFIX}/n/versions/node/4.9.1" ]
# Remember, we installed a dummy node so do have a bin/node
[ ! -f "${N_PREFIX}/bin/node" ]
[ ! -f "${N_PREFIX}/bin/npm" ]
[ ! -d "${N_PREFIX}/include" ]
[ ! -d "${N_PREFIX}/lib" ]
[ ! -d "${N_PREFIX}/shared" ]
}
@test "n download 4.9.1" {
# not an option, but keep with --download so stays in sync
n download 4.9.1
[ -d "${N_PREFIX}/n/versions/node/4.9.1" ]
[ ! -f "${N_PREFIX}/bin/node" ]
[ ! -f "${N_PREFIX}/bin/npm" ]
[ ! -d "${N_PREFIX}/include" ]
[ ! -d "${N_PREFIX}/lib" ]
@ -35,6 +48,14 @@ function teardown() {
}
@test "n --cleanup 4.9.1" {
n install --cleanup 4.9.1
output="$(node --version)"
assert_equal "${output}" "v4.9.1"
[ ! -d "${N_PREFIX}/n/versions/node/4.9.1" ]
}
# mostly --preserve, but also variations with i/install and lts/numeric
@test "--preserve variations # (4 installs)" {
local ARGON_VERSION="v4.9.1"

View File

@ -8,7 +8,7 @@ function setup_file() {
unset_n_env
setup_tmp_prefix
# Note, NOT latest version of 16.
n --download 16.19.0
n download 16.19.0
export N_NODE_MIRROR="https://no.internet.available"
}

View File

@ -9,8 +9,8 @@ function setup_file() {
# fixed directory so can reuse the two installs
tmpdir="${TMPDIR:-/tmp}"
export N_PREFIX="${tmpdir}/n/test/run-which"
n --download 4.9.1
n --download lts
n download 4.9.1
n download lts
# using "latest" for download tests with run and exec
}