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

Merge branch 'develop' of github.com:tj/n into develop

This commit is contained in:
John Gee 2024-10-20 11:12:02 +13:00
commit 2914fe3ed5
2 changed files with 39 additions and 21 deletions

View File

@ -60,7 +60,7 @@ To take ownership of the system directories (option 1):
If `npm` is not yet available, one way to bootstrap an install is to download and run `n` directly. To install the `lts` version of Node.js:
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s lts
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s install lts
# If you want n installed, you can use npm now.
npm install -g n
@ -237,6 +237,18 @@ Use `n` to access cached versions (already downloaded) without internet availabl
n --offline 12
Remove the cache version after installing using `--cleanup`. This is particularly useful for a one-shot install, like in a docker container.
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s install --cleanup lts
The `--download` option can be used in two ways, to download a version into cache but not make active:
n --download lts
or to download a possibly missing version for `n run`, `n exec`, and `n which`:
n --download run 18.3 my-script.js
Display diagnostics to help resolve problems:
n doctor

46
bin/n
View File

@ -133,6 +133,7 @@ g_active_node=
g_target_node=
DOWNLOAD=false # set to opt-out of activate (install), and opt-in to download (run, exec)
CLEANUP=false # remove cached download after install
ARCH=
SHOW_VERBOSE_LOG="true"
OFFLINE=false
@ -397,6 +398,7 @@ Options:
-p, --preserve Preserve npm and npx during install of Node.js
-q, --quiet Disable curl output. Disable log messages processing "auto" and "engine" labels.
-d, --download Download if necessary, and don't make active
--cleanup Remove cached version after install
-a, --arch Override system architecture
--offline Resolve target version against cached downloads instead of internet lookup
--all ls-remote displays all matches instead of last 20
@ -757,6 +759,12 @@ activate() {
printf 'If "node --version" shows the old version then start a new shell, or reset the location hash with:\nhash -r (for bash, zsh, ash, dash, and ksh)\nrehash (for csh and tcsh)\n'
fi
fi
if [[ "$CLEANUP" == "true" ]]; then
log "cleanup" "removing cached $version"
remove_versions "$version"
fi
}
#
@ -1672,6 +1680,7 @@ while [[ $# -ne 0 ]]; do
-h|--help|help) display_help; exit ;;
-q|--quiet) set_quiet ;;
-d|--download) DOWNLOAD="true" ;;
--cleanup) CLEANUP="true" ;;
--offline) OFFLINE="true" ;;
--insecure) set_insecure ;;
-p|--preserve) N_PRESERVE_NPM="true" N_PRESERVE_COREPACK="true" ;;
@ -1708,24 +1717,21 @@ if test $# -eq 0; then
test -z "$(display_versions_paths)" && err_no_installed_print_help
menu_select_cache_versions
else
while test $# -ne 0; do
case "$1" in
bin|which) display_bin_path_for_version "$2"; exit ;;
run|as|use) shift; run_with_version "$@"; exit ;;
exec) shift; exec_with_version "$@"; exit ;;
doctor) show_diagnostics; exit ;;
rm|-) shift; remove_versions "$@"; exit ;;
prune) prune_cache; exit ;;
latest) install latest; exit ;;
stable) install stable; exit ;;
lts) install lts; exit ;;
ls|list) display_versions_paths; exit ;;
lsr|ls-remote|list-remote) shift; display_remote_versions "$1"; exit ;;
uninstall) uninstall_installed; exit ;;
i|install) shift; 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
shift
done
case "$1" in
bin|which) display_bin_path_for_version "$2"; exit ;;
run|as|use) shift; run_with_version "$@"; exit ;;
exec) shift; exec_with_version "$@"; exit ;;
doctor) show_diagnostics; exit ;;
rm|-) shift; remove_versions "$@"; exit ;;
prune) prune_cache; exit ;;
latest) install latest; exit ;;
stable) install stable; exit ;;
lts) install lts; exit ;;
ls|list) display_versions_paths; exit ;;
lsr|ls-remote|list-remote) shift; display_remote_versions "$1"; exit ;;
uninstall) uninstall_installed; exit ;;
i|install) shift; 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
fi