Skip to content

Commit cbde6e2

Browse files
authored
Add download command (#821)
1 parent eea2a55 commit cbde6e2

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ List downloaded versions in cache:
234234

235235
n ls
236236

237+
Download version into cache:
238+
239+
n download 22
240+
237241
Use `n` to access cached versions (already downloaded) without internet available.
238242

239243
n --offline 12

bin/n

+9-1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ Commands:
390390
n ls Output downloaded versions
391391
n ls-remote [version] Output matching versions available for download
392392
n uninstall Remove the installed Node.js
393+
n download <version> Download Node.js <version> into cache
393394
394395
Options:
395396
@@ -794,6 +795,8 @@ install() {
794795
if [[ ! -e "$dir/n.lock" ]] ; then
795796
if [[ "$DOWNLOAD" == "false" ]] ; then
796797
activate "${g_mirror_folder_name}/${version}"
798+
else
799+
log downloaded "${g_mirror_folder_name}/${version} already in cache"
797800
fi
798801
exit
799802
fi
@@ -802,7 +805,11 @@ install() {
802805
abort "version unavailable offline"
803806
fi
804807

805-
log installing "${g_mirror_folder_name}-v$version"
808+
if [[ "$DOWNLOAD" == "false" ]]; then
809+
log installing "${g_mirror_folder_name}-v$version"
810+
else
811+
log download "${g_mirror_folder_name}-v$version"
812+
fi
806813

807814
local url="$(tarball_url "$version")"
808815
is_ok "${url}" || abort "download preflight failed for '$version' ($(display_masked_url "${url}"))"
@@ -1733,6 +1740,7 @@ else
17331740
lsr|ls-remote|list-remote) shift; display_remote_versions "$1"; exit ;;
17341741
uninstall) uninstall_installed; exit ;;
17351742
i|install) shift; install "$1"; exit ;;
1743+
download) shift; DOWNLOAD="true"; install "$1"; exit ;;
17361744
N_TEST_DISPLAY_LATEST_RESOLVED_VERSION) shift; get_latest_resolved_version "$1" > /dev/null || exit 2; echo "${g_target_node}"; exit ;;
17371745
*) install "$1"; exit ;;
17381746
esac

test/tests/install-options.bats

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@ function teardown() {
1717

1818

1919
@test "n --download 4.9.1" {
20+
# deprecated use of --download, replaced by download command
2021
n --download 4.9.1
2122
[ -d "${N_PREFIX}/n/versions/node/4.9.1" ]
22-
# Remember, we installed a dummy node so do have a bin/node
23+
[ ! -f "${N_PREFIX}/bin/node" ]
24+
[ ! -f "${N_PREFIX}/bin/npm" ]
25+
[ ! -d "${N_PREFIX}/include" ]
26+
[ ! -d "${N_PREFIX}/lib" ]
27+
[ ! -d "${N_PREFIX}/shared" ]
28+
}
29+
30+
31+
@test "n download 4.9.1" {
32+
# not an option, but keep with --download so stays in sync
33+
n download 4.9.1
34+
[ -d "${N_PREFIX}/n/versions/node/4.9.1" ]
35+
[ ! -f "${N_PREFIX}/bin/node" ]
2336
[ ! -f "${N_PREFIX}/bin/npm" ]
2437
[ ! -d "${N_PREFIX}/include" ]
2538
[ ! -d "${N_PREFIX}/lib" ]
@@ -35,6 +48,14 @@ function teardown() {
3548
}
3649

3750

51+
@test "n --cleanup 4.9.1" {
52+
n install --cleanup 4.9.1
53+
output="$(node --version)"
54+
assert_equal "${output}" "v4.9.1"
55+
[ ! -d "${N_PREFIX}/n/versions/node/4.9.1" ]
56+
}
57+
58+
3859
# mostly --preserve, but also variations with i/install and lts/numeric
3960
@test "--preserve variations # (4 installs)" {
4061
local ARGON_VERSION="v4.9.1"

test/tests/offline.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function setup_file() {
88
unset_n_env
99
setup_tmp_prefix
1010
# Note, NOT latest version of 16.
11-
n --download 16.19.0
11+
n download 16.19.0
1212
export N_NODE_MIRROR="https://no.internet.available"
1313
}
1414

test/tests/run-which.bats

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function setup_file() {
99
# fixed directory so can reuse the two installs
1010
tmpdir="${TMPDIR:-/tmp}"
1111
export N_PREFIX="${tmpdir}/n/test/run-which"
12-
n --download 4.9.1
13-
n --download lts
12+
n download 4.9.1
13+
n download lts
1414
# using "latest" for download tests with run and exec
1515
}
1616

0 commit comments

Comments
 (0)