From 94f4877a4a3eff020aeef0b108407a1d6c658636 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Mon, 11 Nov 2024 05:15:55 +0000 Subject: [PATCH] Update n to v10.1.0 --- helpers/vendor/n/n | 78 +++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/helpers/vendor/n/n b/helpers/vendor/n/n index 60ad050842..ac2c961d00 100755 --- a/helpers/vendor/n/n +++ b/helpers/vendor/n/n @@ -61,7 +61,7 @@ function n_grep() { # Setup and state # -VERSION="v10.0.0" +VERSION="v10.1.0" N_PREFIX="${N_PREFIX-/usr/local}" N_PREFIX=${N_PREFIX%/} @@ -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 @@ -197,6 +198,10 @@ display_major_version() { echo "${version}" } +display_masked_url() { + echo "$1" | sed -r 's/(https?:\/\/[^:]+):([^@]+)@/\1:****@/' +} + # # Synopsis: update_mirror_settings_for_version version # e.g. means using download mirror and folder is nightly @@ -257,7 +262,7 @@ function update_arch_settings_for_version() { function is_lts_codename() { # https://github.com/nodejs/Release/blob/master/CODENAMES.md # e.g. argon, Boron - [[ "$1" =~ ^([Aa]rgon|[Bb]oron|[Cc]arbon|[Dd]ubnium|[Ee]rbium|[Ff]ermium|[Gg]allium|[Hh]ydrogen|[Ii]ron|[Jj]od)$ ]] + [[ "$1" =~ ^([Aa]rgon|[Bb]oron|[Cc]arbon|[Dd]ubnium|[Ee]rbium|[Ff]ermium|[Gg]allium|[Hh]ydrogen|[Ii]ron|[Jj]od|[Kk]rypton|[Ll]ithium)$ ]] } # @@ -385,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 Download Node.js into cache Options: @@ -392,7 +398,8 @@ Options: -h, --help Display help information -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 + -d, --download Download if necessary. Used with run/exec/which. + --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 @@ -753,6 +760,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 + } # @@ -782,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 @@ -790,10 +805,14 @@ install() { abort "version unavailable offline" fi - log installing "${g_mirror_folder_name}-v$version" + 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' (${url})" + is_ok "${url}" || abort "download preflight failed for '$version' ($(display_masked_url "${url}"))" log mkdir "$dir" mkdir -p "$dir" || abort "sudo required (or change ownership, or define N_PREFIX)" @@ -801,7 +820,7 @@ install() { cd "${dir}" || abort "Failed to cd to ${dir}" - log fetch "$url" + log fetch "$(display_masked_url "${url}")" do_get "${url}" | tar "$tarflag" --strip-components=1 --no-same-owner -f - pipe_results=( "${PIPESTATUS[@]}" ) if [[ "${pipe_results[0]}" -ne 0 ]]; then @@ -1135,6 +1154,8 @@ function get_nvmrc_version() { verbose_log "found" "${filepath}" local version <"${filepath}" read -r version + # remove trailing comment, after # + version="$(echo "${version}" | sed 's/[[:space:]]*#.*//')" verbose_log "read" "${version}" # Translate from nvm aliases case "${version}" in @@ -1241,7 +1262,7 @@ display_remote_index() { do_get_index "${index_url}" | tail -n +2 | cut -f 1,3,10 if [[ "${PIPESTATUS[0]}" -ne 0 ]]; then # Reminder: abort will only exit subshell, but consistent error display - abort "failed to download version index (${index_url})" + abort "failed to download version index ($(display_masked_url "${index_url}"))" fi } @@ -1494,8 +1515,8 @@ function show_diagnostics() { printf "\n\nSETTINGS\n" printf "\nn\n" - echo "node mirror: ${N_NODE_MIRROR}" - echo "node downloads mirror: ${N_NODE_DOWNLOAD_MIRROR}" + echo "node mirror: $(display_masked_url "${N_NODE_MIRROR}")" + echo "node downloads mirror: $(display_masked_url "${N_NODE_DOWNLOAD_MIRROR}")" echo "install destination: ${N_PREFIX}" [[ -n "${N_PREFIX}" ]] && echo "PATH: ${PATH}" echo "ls-remote max matches: ${N_MAX_REMOTE_MATCHES}" @@ -1668,6 +1689,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" ;; @@ -1704,24 +1726,22 @@ 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 ;; + 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 fi