From 44cff5c4b0d52a296ca24a6e97bd7927bf8e1cc1 Mon Sep 17 00:00:00 2001 From: Ben Limmer Date: Sat, 14 Nov 2020 14:13:22 -0700 Subject: [PATCH 01/27] Suggest updating plugin upon failure --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index 0654da3..8b1e78e 100755 --- a/bin/install +++ b/bin/install @@ -192,7 +192,7 @@ download_and_verify_checksums() { if ! $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then # Try default keyring if ! $gnugp_verify_command_name --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then - echo "Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting." >&2 + echo "Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. Also, make sure the plugin is up-to-date by running \`asdf plugin update nodejs\`. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting." >&2 exit 1 fi fi From f0cc64c799c77d41043c8885836266f1015ec7eb Mon Sep 17 00:00:00 2001 From: Ben Limmer Date: Fri, 9 Apr 2021 10:18:04 -0600 Subject: [PATCH 02/27] Update bin/install Co-authored-by: Augusto Borges de Moura --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index 8b1e78e..26f5d47 100755 --- a/bin/install +++ b/bin/install @@ -192,7 +192,7 @@ download_and_verify_checksums() { if ! $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then # Try default keyring if ! $gnugp_verify_command_name --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then - echo "Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. Also, make sure the plugin is up-to-date by running \`asdf plugin update nodejs\`. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting." >&2 + echo "Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. Also, make sure the plugin is up-to-date by running \`asdf plugin update $(plugin_name)\`. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting." >&2 exit 1 fi fi From cc7c7d20ae003d9817798f05240f7270b143f7fe Mon Sep 17 00:00:00 2001 From: Nicolas Caille Date: Sun, 22 Nov 2020 22:47:30 +0100 Subject: [PATCH 03/27] add 'amd64' in install script function get_nodejs_machine_hardware_name for FreeBSD --- bin/install | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install b/bin/install index 26f5d47..2b5dec9 100755 --- a/bin/install +++ b/bin/install @@ -86,6 +86,7 @@ get_nodejs_machine_hardware_name() { case "$machine_hardware_name" in 'x86_64') local cpu_type="x64";; + 'amd64') local cpu_type="x64";; 'i686') local cpu_type="x86";; 'aarch64') local cpu_type="arm64";; *) local cpu_type="$machine_hardware_name";; From adb47b8bc9a686b3d05e6d30aa8bea855226b7e8 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Mon, 23 Nov 2020 08:48:26 -0500 Subject: [PATCH 04/27] Add comment on individual `uname -m` clause --- bin/install | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install b/bin/install index 2b5dec9..6ebd9f4 100755 --- a/bin/install +++ b/bin/install @@ -86,6 +86,7 @@ get_nodejs_machine_hardware_name() { case "$machine_hardware_name" in 'x86_64') local cpu_type="x64";; + # For FreeBSD 'amd64') local cpu_type="x64";; 'i686') local cpu_type="x86";; 'aarch64') local cpu_type="arm64";; From 3bff0719af5d7342655d583193b9dd686857d47f Mon Sep 17 00:00:00 2001 From: Brian van Burken Date: Sun, 2 Aug 2020 20:27:53 +0200 Subject: [PATCH 05/27] Support non-default default-npm-packages location. --- README.md | 2 ++ bin/install | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 17b4769..1d1d989 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ request express ``` +You can specify a non-default location of this file by setting a `ASDF_NPM_DEFAULT_PACKAGES_FILE` variable. + ## Temporarily disable reshimming To avoid a slowdown when installing large packages (see https://github.com/asdf-vm/asdf-nodejs/issues/46), you can `ASDF_SKIP_RESHIM=1 npm i -g ` and reshim after installing all packages using `asdf reshim nodejs`. diff --git a/bin/install b/bin/install index 6ebd9f4..7dd3c81 100755 --- a/bin/install +++ b/bin/install @@ -267,7 +267,7 @@ verlte() { } install_default_npm_packages() { - local default_npm_packages="${HOME}/.default-npm-packages" + local default_npm_packages="${ASDF_NPM_DEFAULT_PACKAGES_FILE:=$HOME/.default-npm-packages}" if [ ! -f "$default_npm_packages" ]; then return; fi From 2abce68edc7e2f3f48880187ec34cfda3ead1677 Mon Sep 17 00:00:00 2001 From: Adam Hawkins Date: Fri, 21 Aug 2020 09:37:06 -1000 Subject: [PATCH 06/27] fix(bin): close #165 This file may already exist. It's unclear why this happens though. --- bin/install | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install b/bin/install index 7dd3c81..8b10d12 100755 --- a/bin/install +++ b/bin/install @@ -200,6 +200,7 @@ download_and_verify_checksums() { fi ## Mitigates: https://github.com/nodejs/node/issues/6821 local authentic_checksum_file="$tmp_download_dir/authentic_SHASUMS256.txt" + rm -f $authentic_checksum_file $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null || $gnugp_verify_command_name --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null ) From 6cd8bc40b2b5ff994679a2c7af721f5345f30b7c Mon Sep 17 00:00:00 2001 From: Adam Hawkins Date: Fri, 21 Aug 2020 10:15:33 -1000 Subject: [PATCH 07/27] fix(bin): add --yes to confirm GPG overwrite --- bin/install | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/install b/bin/install index 8b10d12..739e41d 100755 --- a/bin/install +++ b/bin/install @@ -200,9 +200,8 @@ download_and_verify_checksums() { fi ## Mitigates: https://github.com/nodejs/node/issues/6821 local authentic_checksum_file="$tmp_download_dir/authentic_SHASUMS256.txt" - rm -f $authentic_checksum_file - $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null || - $gnugp_verify_command_name --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null + $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --yes --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null || + $gnugp_verify_command_name --yes --output "${authentic_checksum_file}" --decrypt "$signed_checksum_file" 2>/dev/null ) elif [ "${NODEJS_CHECK_SIGNATURES}" == "strict" ]; then echo "$version did not provide signed checksums or support for them has not been implemented and NODEJS_CHECK_SIGNATURES=strict is set. Exiting." >&2 From e832fd0f120678aef6f455d7ca0beed78a7c38c9 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Thu, 14 Jan 2021 21:07:56 +0000 Subject: [PATCH 08/27] Sync NodeJS gpg keys --- bin/import-previous-release-team-keyring | 3 ++- bin/import-release-team-keyring | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/import-previous-release-team-keyring b/bin/import-previous-release-team-keyring index 8012494..489454e 100755 --- a/bin/import-previous-release-team-keyring +++ b/bin/import-previous-release-team-keyring @@ -10,7 +10,8 @@ KEYS="9554F04D7259F04124DE6B476D5A82AC7E37093B \ 56730D5401028683275BD23C23EFEFE93C4CFFFE \ FD3A5288F042B6850C66B31F09FE44734EB7990E \ 114F43EE0176B71C7BC219DD50A3051F888C628D \ - 7937DFD2AB06298B2293C3187D33FF9D0246406D" + 7937DFD2AB06298B2293C3187D33FF9D0246406D \ + 1C050899334244A8AF75E53792EF661D867B9DFA" SERVERS="ha.pool.sks-keyservers.net p80.pool.sks-keyservers.net:80 \ diff --git a/bin/import-release-team-keyring b/bin/import-release-team-keyring index 18a8138..95182a9 100755 --- a/bin/import-release-team-keyring +++ b/bin/import-release-team-keyring @@ -7,7 +7,7 @@ source "$(dirname "$0")/../lib/utils.sh" ## Keys from https://github.com/nodejs/node/#release-keys KEYS="4ED778F539E3634C779C87C6D7062848A1AB005C \ 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - 1C050899334244A8AF75E53792EF661D867B9DFA \ + 74F12602B6F1C4E913FAA37AD3A89613643B6201 \ 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ From d5d2ea6ce99325fd491f9da53b27100852c79401 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Wed, 23 Sep 2020 20:33:03 -0300 Subject: [PATCH 09/27] refactor list all to use the official index.tab also add support for lts aliases, giving it's trivial to implement after processing the tab also get better error messages for missing versions --- README.md | 2 ++ bin/install | 36 ++++++++++++++++++---------- bin/list-all | 8 +++++-- lib/utils.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1d1d989..5f2b157 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Node.js plugin for [asdf](https://github.com/asdf-vm/asdf) version manager ### MacOS * [GNU Core Utils](http://www.gnu.org/software/coreutils/coreutils.html) - `brew install coreutils` * [GnuPG](http://www.gnupg.org) - `brew install gpg` +* awk - any posix compliant implementation (tested on gawk `brew install gawk`) ### Linux (Debian) @@ -19,6 +20,7 @@ Node.js plugin for [asdf](https://github.com/asdf-vm/asdf) version manager dirmngr` * [GnuPG](http://www.gnupg.org) - `apt-get install gpg` * [curl](https://curl.haxx.se) - `apt-get install curl` +* awk - any posix compliant implementation (tested on gawk `apt-get install gawk`) ## Install diff --git a/bin/install b/bin/install index 739e41d..e7b08a6 100755 --- a/bin/install +++ b/bin/install @@ -7,26 +7,20 @@ source "$(dirname "$0")/../lib/utils.sh" NODEJS_CHECK_SIGNATURES="${NODEJS_CHECK_SIGNATURES:-strict}" -# When in China, set $NODEJS_ORG_MIRROR: -# export NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/ -NODEJS_ORG_MIRROR="${NODEJS_ORG_MIRROR:-https://nodejs.org/dist/}" -if [ ${NODEJS_ORG_MIRROR: -1} != / ] -then - NODEJS_ORG_MIRROR=$NODEJS_ORG_MIRROR/ -fi - install_nodejs() { local install_type="$1" - local version="$2" + local version_query="$2" local install_path="$3" local tmp_download_dir="$4" + local version="$(resolve_version_query "$version_query")" ## Do this first as it is fast but could fail. download_and_verify_checksums "$install_type" "$version" "$tmp_download_dir" local archive_path archive_path="${tmp_download_dir}/$(get_archive_file_name "$install_type" "$version")" - download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" + download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ + || die "Binary not found for version $version" verify_archive "$tmp_download_dir" @@ -59,6 +53,21 @@ install_nodejs() { ) } +resolve_version_query() { + local version_query="$1" + local aliased="$( + print_index_tab \ + | filter_version_candidates \ + | awk -F'\t' -v "al=$version_query" '$1 == al { print $2; exit }' + )" + + if ! [ -z "$aliased" ]; then + >&2 echo "Installing alias $version_query as $aliased" + echo "$aliased" + else + echo "$version_query" + fi +} construct_configure_options() { local install_path="$1" @@ -104,8 +113,7 @@ download_file() { STATUSCODE=$(curl --write-out "%{http_code}" -Lo "$download_path" -C - "$download_url") if test $STATUSCODE -eq 404; then - echo "Binaries were not found. Full version must be specified, not just major version." - exit 1 + return 1 fi } @@ -177,7 +185,9 @@ download_and_verify_checksums() { return 0 fi fi - download_file "${signed_checksum_download_url}" "$signed_checksum_file" + + download_file "${signed_checksum_download_url}" "$signed_checksum_file" \ + || die "Checksum not found for version $version" local gnugp_verify_command_name gnugp_verify_command_name="$(command -v gpg gpg2 | head -n 1 || :)" diff --git a/bin/list-all b/bin/list-all index a0d5fbd..ff3e0e2 100755 --- a/bin/list-all +++ b/bin/list-all @@ -1,6 +1,10 @@ #!/usr/bin/env bash +set -o nounset -o pipefail -o errexit + +# shellcheck source=../lib/utils.sh +source "$(dirname "$0")/../lib/utils.sh" + echo $( - curl --silent https://semver.io/node/versions \ - | grep -E -v '^0\.([0-9])\.' + print_index_tab | filter_candidates_versions | awk -F'\t' '{ print $1 }' | tac ) diff --git a/lib/utils.sh b/lib/utils.sh index 6c1d22a..5566789 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -1,9 +1,77 @@ # Helper functions +# When in China, set $NODEJS_ORG_MIRROR: +# export NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/ +NODEJS_ORG_MIRROR="${NODEJS_ORG_MIRROR:-https://nodejs.org/dist/}" +if [ ${NODEJS_ORG_MIRROR: -1} != / ] +then + NODEJS_ORG_MIRROR=$NODEJS_ORG_MIRROR/ +fi + # TODO: Replace with an asdf variable once asdf starts providing the plugin name # as a variable plugin_name() { basename "$(dirname "$(dirname "$0")")" } +die() { + >&2 echo "$@" + exit 1 +} + ASDF_NODEJS_KEYRING=asdf-nodejs.gpg + +# TODO: implement a cache for the tab. The api supports If-None-Match and +# If-Modified-Since HTTP headers +print_index_tab() { + curl --silent "${NODEJS_ORG_MIRROR}index.tab" +} + +# Print all alias and correspondent versions in the format "$alias\t$version" +# Also prints versions as a alias of itself. Eg: "v10.0.0 v10.0.0" +filter_version_candidates() { + awk -F'\t' ' + # First line is the headers for the columns + NR == 1 { + for (i = 1; i <= NF; i++) { + cols[cols_size++] = $i + } + + # Skip first line because we got all the information already + next + } + + # Add a global variable `record` with the current line version + # using the headers as fields + { + for (i = 1; i < NF; i++) { + record[cols[i - 1]] = $i + } + } + + { + # Version without the `v` prefix + vers = substr(record["version"], 2) + + # We need to check if the lts alias is in a variable because multiple versions + # have the same alias, we want to print only the most recent + if (record["lts"] != "-") { + + # Check if lts is already printed, if not print it as version candidate and + # put it at the aliases map + if (!("lts" in aliases)) { + aliases["lts"] = vers + print "lts\t" vers + } + + lts_alias = "lts/" tolower(record["lts"]) + if (!(lts_alias in aliases)) { + aliases[lts_alias] = vers + print lts_alias "\t" vers + } + } + + print vers "\t" vers + } + ' +} From 465cff44aacf61ad4c773ac501b1875e5c7576b2 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Wed, 23 Sep 2020 20:50:37 -0300 Subject: [PATCH 10/27] fix typo in the filter versions function I forgot to commit the change in name on the list_all script --- bin/list-all | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/list-all b/bin/list-all index ff3e0e2..82397c1 100755 --- a/bin/list-all +++ b/bin/list-all @@ -5,6 +5,7 @@ set -o nounset -o pipefail -o errexit # shellcheck source=../lib/utils.sh source "$(dirname "$0")/../lib/utils.sh" +# Print echo $( - print_index_tab | filter_candidates_versions | awk -F'\t' '{ print $1 }' | tac + print_index_tab | filter_version_candidates | awk -F'\t' '{ print $1 }' | tac ) From 753b4a7b263e8c74d0a255e97692eed8759d0390 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Wed, 23 Sep 2020 21:09:50 -0300 Subject: [PATCH 11/27] add better formatting and commentaries --- bin/install | 5 ++++- bin/list-all | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/install b/bin/install index e7b08a6..df7cb41 100755 --- a/bin/install +++ b/bin/install @@ -53,12 +53,14 @@ install_nodejs() { ) } + resolve_version_query() { local version_query="$1" local aliased="$( + # Find the first candidate which the alias match, then print it version print_index_tab \ | filter_version_candidates \ - | awk -F'\t' -v "al=$version_query" '$1 == al { print $2; exit }' + | awk -F'\t' -v "alias=$version_query" '$1 == alias { print $2; exit }' )" if ! [ -z "$aliased" ]; then @@ -69,6 +71,7 @@ resolve_version_query() { fi } + construct_configure_options() { local install_path="$1" diff --git a/bin/list-all b/bin/list-all index 82397c1..e8399d0 100755 --- a/bin/list-all +++ b/bin/list-all @@ -7,5 +7,6 @@ source "$(dirname "$0")/../lib/utils.sh" # Print echo $( + # Only print the first column of candidates print_index_tab | filter_version_candidates | awk -F'\t' '{ print $1 }' | tac ) From f46bfa8a170e415e4a652c03fac73f69473ef971 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 2 Oct 2020 11:11:40 -0300 Subject: [PATCH 12/27] fix lts/ breaking asdf dir versioning --- lib/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.sh b/lib/utils.sh index 5566789..9e96efa 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -64,7 +64,7 @@ filter_version_candidates() { print "lts\t" vers } - lts_alias = "lts/" tolower(record["lts"]) + lts_alias = "lts-" tolower(record["lts"]) if (!(lts_alias in aliases)) { aliases[lts_alias] = vers print lts_alias "\t" vers From 6b287904e4fdca8c375bf0916c21a07da5481862 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 2 Oct 2020 12:33:24 -0300 Subject: [PATCH 13/27] install alias as symlinks to real versions --- bin/install | 86 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/bin/install b/bin/install index df7cb41..b9a73d2 100755 --- a/bin/install +++ b/bin/install @@ -7,6 +7,8 @@ source "$(dirname "$0")/../lib/utils.sh" NODEJS_CHECK_SIGNATURES="${NODEJS_CHECK_SIGNATURES:-strict}" +ASDF_PLUGIN_NAME=nodejs + install_nodejs() { local install_type="$1" local version_query="$2" @@ -14,43 +16,60 @@ install_nodejs() { local tmp_download_dir="$4" local version="$(resolve_version_query "$version_query")" - ## Do this first as it is fast but could fail. - download_and_verify_checksums "$install_type" "$version" "$tmp_download_dir" + if [ "$version" != "$version_query" ]; then + # install the true version and only symlink it to the alias + + >&2 echo "Installing alias $version_query as $version" + asdf install "$ASDF_PLUGIN_NAME" "$version" \ + || die "Could not install version $version" - local archive_path - archive_path="${tmp_download_dir}/$(get_archive_file_name "$install_type" "$version")" - download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ - || die "Binary not found for version $version" - - verify_archive "$tmp_download_dir" - - # running this in a subshell - # we don't want to disturb current working dir - ( - if [ "$install_type" != "version" ]; then - tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 - cd "$install_path" || exit 1 - - local configure_options - configure_options="$(construct_configure_options "$install_path")" - - # shellcheck disable=SC2086 - ./configure $configure_options || exit 1 - make - make install - - if [ $? -ne 0 ]; then - rm -rf "$install_path" - exit 1 - fi + if [ -L "$install_path" ]; then + rm "$install_path" else - tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 + rmdir "$install_path" fi - mkdir -p "$install_path/.npm/lib/node_modules/.hooks" - cp "$(dirname "$(dirname "$0")")"/npm-hooks/* "$install_path/.npm/lib/node_modules/.hooks/" - chmod +x "$install_path"/.npm/lib/node_modules/.hooks/* - ) + >&2 echo "Linking \"$version_query\" to \"$version\"" + ln -s "$(asdf where "$ASDF_PLUGIN_NAME" "$version")" "$install_path" + else + ## Do this first as it is fast but could fail. + download_and_verify_checksums "$install_type" "$version" "$tmp_download_dir" + + local archive_path + archive_path="${tmp_download_dir}/$(get_archive_file_name "$install_type" "$version")" + download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ + || die "Binary not found for version $version" + + verify_archive "$tmp_download_dir" + + # running this in a subshell + # we don't want to disturb current working dir + ( + if [ "$install_type" != "version" ]; then + tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 + cd "$install_path" || exit 1 + + local configure_options + configure_options="$(construct_configure_options "$install_path")" + + # shellcheck disable=SC2086 + ./configure $configure_options || exit 1 + make + make install + + if [ $? -ne 0 ]; then + rm -rf "$install_path" + exit 1 + fi + else + tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 + fi + + mkdir -p "$install_path/.npm/lib/node_modules/.hooks" + cp "$(dirname "$(dirname "$0")")"/npm-hooks/* "$install_path/.npm/lib/node_modules/.hooks/" + chmod +x "$install_path"/.npm/lib/node_modules/.hooks/* + ) + fi } @@ -64,7 +83,6 @@ resolve_version_query() { )" if ! [ -z "$aliased" ]; then - >&2 echo "Installing alias $version_query as $aliased" echo "$aliased" else echo "$version_query" From e6ace0fca5be187ab40e03374543ef42900327f5 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 2 Oct 2020 13:11:26 -0300 Subject: [PATCH 14/27] separate install functions between alias and canon --- bin/install | 123 +++++++++++++++++++++++++++++---------------------- lib/utils.sh | 4 +- 2 files changed, 73 insertions(+), 54 deletions(-) diff --git a/bin/install b/bin/install index b9a73d2..738855d 100755 --- a/bin/install +++ b/bin/install @@ -7,85 +7,104 @@ source "$(dirname "$0")/../lib/utils.sh" NODEJS_CHECK_SIGNATURES="${NODEJS_CHECK_SIGNATURES:-strict}" -ASDF_PLUGIN_NAME=nodejs install_nodejs() { local install_type="$1" local version_query="$2" local install_path="$3" local tmp_download_dir="$4" + local version="$(resolve_version_query "$version_query")" if [ "$version" != "$version_query" ]; then - # install the true version and only symlink it to the alias - - >&2 echo "Installing alias $version_query as $version" - asdf install "$ASDF_PLUGIN_NAME" "$version" \ - || die "Could not install version $version" + install_aliased_version "$version" "$version_query" "$install_path" + else + install_canon_version "$1" "$version" "$3" "$4" + fi +} - if [ -L "$install_path" ]; then - rm "$install_path" + +install_canon_version() { + local install_type="$1" + local version="$2" + local install_path="$3" + local tmp_download_dir="$4" + + ## Do this first as it is fast but could fail. + download_and_verify_checksums "$install_type" "$version" "$tmp_download_dir" + + local archive_path + archive_path="${tmp_download_dir}/$(get_archive_file_name "$install_type" "$version")" + download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ + || die "Binary not found for version $version" + + verify_archive "$tmp_download_dir" + + # running this in a subshell + # we don't want to disturb current working dir + ( + if [ "$install_type" != "version" ]; then + tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 + cd "$install_path" || exit 1 + + local configure_options + configure_options="$(construct_configure_options "$install_path")" + + # shellcheck disable=SC2086 + ./configure $configure_options || exit 1 + make + make install + + if [ $? -ne 0 ]; then + rm -rf "$install_path" + exit 1 + fi else - rmdir "$install_path" + tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 fi - >&2 echo "Linking \"$version_query\" to \"$version\"" - ln -s "$(asdf where "$ASDF_PLUGIN_NAME" "$version")" "$install_path" + mkdir -p "$install_path/.npm/lib/node_modules/.hooks" + cp "$(dirname "$(dirname "$0")")"/npm-hooks/* "$install_path/.npm/lib/node_modules/.hooks/" + chmod +x "$install_path"/.npm/lib/node_modules/.hooks/* + ) +} + + +install_aliased_version() { + local version=$1 + local version_query=$2 + local install_path=$3 + + # install the true version and only symlink it to the alias + >&2 echo "Installing alias $version_query as $version" + asdf install "$(plugin_name)" "$version" \ + || die "Could not install version $version" + + if [ -L "$install_path" ]; then + rm "$install_path" else - ## Do this first as it is fast but could fail. - download_and_verify_checksums "$install_type" "$version" "$tmp_download_dir" - - local archive_path - archive_path="${tmp_download_dir}/$(get_archive_file_name "$install_type" "$version")" - download_file "$(get_download_url "$install_type" "$version")" "${archive_path}" \ - || die "Binary not found for version $version" - - verify_archive "$tmp_download_dir" - - # running this in a subshell - # we don't want to disturb current working dir - ( - if [ "$install_type" != "version" ]; then - tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 - cd "$install_path" || exit 1 - - local configure_options - configure_options="$(construct_configure_options "$install_path")" - - # shellcheck disable=SC2086 - ./configure $configure_options || exit 1 - make - make install - - if [ $? -ne 0 ]; then - rm -rf "$install_path" - exit 1 - fi - else - tar zxf "$archive_path" -C "$install_path" --strip-components=1 || exit 1 - fi - - mkdir -p "$install_path/.npm/lib/node_modules/.hooks" - cp "$(dirname "$(dirname "$0")")"/npm-hooks/* "$install_path/.npm/lib/node_modules/.hooks/" - chmod +x "$install_path"/.npm/lib/node_modules/.hooks/* - ) + rmdir "$install_path" fi + + >&2 echo "Linking \"$version_query\" to \"$version\"" + ln -s "$(asdf where "$(plugin_name)" "$version")" "$install_path" } resolve_version_query() { local version_query="$1" - local aliased="$( + + local canon_version="$( # Find the first candidate which the alias match, then print it version print_index_tab \ | filter_version_candidates \ | awk -F'\t' -v "alias=$version_query" '$1 == alias { print $2; exit }' )" - if ! [ -z "$aliased" ]; then - echo "$aliased" - else + if [ -z "$canon_version" ]; then echo "$version_query" + else + echo "$canon_version" fi } diff --git a/lib/utils.sh b/lib/utils.sh index 9e96efa..94cbcaa 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -8,6 +8,8 @@ then NODEJS_ORG_MIRROR=$NODEJS_ORG_MIRROR/ fi +ASDF_NODEJS_KEYRING=asdf-nodejs.gpg + # TODO: Replace with an asdf variable once asdf starts providing the plugin name # as a variable plugin_name() { @@ -19,8 +21,6 @@ die() { exit 1 } -ASDF_NODEJS_KEYRING=asdf-nodejs.gpg - # TODO: implement a cache for the tab. The api supports If-None-Match and # If-Modified-Since HTTP headers print_index_tab() { From a82ac52b0500ffc0d27ed065a76624ac66bfa58f Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Thu, 21 Jan 2021 17:37:23 -0300 Subject: [PATCH 15/27] use pure bash to filter version candidates instead of awk --- bin/list-all | 2 +- lib/utils.sh | 68 ++++++++++++++++++++++------------------------------ 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/bin/list-all b/bin/list-all index e8399d0..fccf0af 100755 --- a/bin/list-all +++ b/bin/list-all @@ -8,5 +8,5 @@ source "$(dirname "$0")/../lib/utils.sh" # Print echo $( # Only print the first column of candidates - print_index_tab | filter_version_candidates | awk -F'\t' '{ print $1 }' | tac + print_index_tab | filter_version_candidates | cut -f1 | tac ) diff --git a/lib/utils.sh b/lib/utils.sh index 94cbcaa..3dd3791 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -1,3 +1,4 @@ +#! /usr/bin/env bash # Helper functions # When in China, set $NODEJS_ORG_MIRROR: @@ -27,51 +28,40 @@ print_index_tab() { curl --silent "${NODEJS_ORG_MIRROR}index.tab" } +# Tab file needs to be piped as stdin # Print all alias and correspondent versions in the format "$alias\t$version" -# Also prints versions as a alias of itself. Eg: "v10.0.0 v10.0.0" +# Also prints versions as a alias of itself. Eg: "v10.0.0\tv10.0.0" filter_version_candidates() { - awk -F'\t' ' - # First line is the headers for the columns - NR == 1 { - for (i = 1; i <= NF; i++) { - cols[cols_size++] = $i - } + local curr_line="" + local -A aliases - # Skip first line because we got all the information already - next - } + # Skip headers + IFS= read -r curr_line - # Add a global variable `record` with the current line version - # using the headers as fields - { - for (i = 1; i < NF; i++) { - record[cols[i - 1]] = $i - } - } + while IFS= read -r curr_line; do + # Just expanding the string should work because tabs are considered array separators + local -a fields=($curr_line) - { - # Version without the `v` prefix - vers = substr(record["version"], 2) + # Version without `v` prefix + local version="${fields[0]#v}" + # Lowercase lts codename, `-` if not a lts version + local lts="${fields[9],,}" - # We need to check if the lts alias is in a variable because multiple versions - # have the same alias, we want to print only the most recent - if (record["lts"] != "-") { + if [ "$lts" != - ]; then + # No lts read yet, so this must be the more recent + if [ -z "${aliases[lts]:-}" ]; then + printf "lts\t%s\n" "$version" + aliases[lts]="$version" + fi - # Check if lts is already printed, if not print it as version candidate and - # put it at the aliases map - if (!("lts" in aliases)) { - aliases["lts"] = vers - print "lts\t" vers - } + # No lts read for this codename yet, so this must be the more recent + if [ -z "${aliases[$lts]:-}" ]; then + printf "lts-$lts\t%s\n" "$version" + aliases[$lts]="$version" + fi + fi - lts_alias = "lts-" tolower(record["lts"]) - if (!(lts_alias in aliases)) { - aliases[lts_alias] = vers - print lts_alias "\t" vers - } - } - - print vers "\t" vers - } - ' + printf "%s\t%s\n" "$version" "$version" + done } + From c3c219ab9d55b7cf83dff354b2704285114fbec7 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 22 Jan 2021 17:18:56 -0300 Subject: [PATCH 16/27] fix: remove hashbang front utils --- lib/utils.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/utils.sh b/lib/utils.sh index 3dd3791..4a6b5d5 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -1,4 +1,3 @@ -#! /usr/bin/env bash # Helper functions # When in China, set $NODEJS_ORG_MIRROR: From 260927f62af5ff004b71fbc7fd68f7d66ca0a265 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Tue, 2 Feb 2021 13:43:11 -0300 Subject: [PATCH 17/27] remove dependency on bash 4 associative arrays --- lib/utils.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/utils.sh b/lib/utils.sh index 4a6b5d5..eb2af17 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -31,8 +31,7 @@ print_index_tab() { # Print all alias and correspondent versions in the format "$alias\t$version" # Also prints versions as a alias of itself. Eg: "v10.0.0\tv10.0.0" filter_version_candidates() { - local curr_line="" - local -A aliases + local curr_line="" aliases="" # Skip headers IFS= read -r curr_line @@ -44,19 +43,19 @@ filter_version_candidates() { # Version without `v` prefix local version="${fields[0]#v}" # Lowercase lts codename, `-` if not a lts version - local lts="${fields[9],,}" + local lts_codename="${fields[9],,}" - if [ "$lts" != - ]; then + if [ "$lts_codename" != - ]; then # No lts read yet, so this must be the more recent - if [ -z "${aliases[lts]:-}" ]; then + if ! grep -q "^lts:" <<< "$aliases"; then printf "lts\t%s\n" "$version" - aliases[lts]="$version" + aliases="$aliases"$'\n'"lts:$version" fi # No lts read for this codename yet, so this must be the more recent - if [ -z "${aliases[$lts]:-}" ]; then - printf "lts-$lts\t%s\n" "$version" - aliases[$lts]="$version" + if ! grep -q "^$lts_codename:" <<< "$aliases"; then + printf "lts-$lts_codename\t%s\n" "$version" + aliases="$aliases"$'\n'"$lts_codename:$version" fi fi From b1dfaa2eb75b696e2756f773de99a9e03e79be6c Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sat, 6 Mar 2021 22:43:35 -0800 Subject: [PATCH 18/27] replace Bash 4+ lowercase logic with POSIX alternative using 'tr' --- lib/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.sh b/lib/utils.sh index eb2af17..0c1aa22 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -43,7 +43,7 @@ filter_version_candidates() { # Version without `v` prefix local version="${fields[0]#v}" # Lowercase lts codename, `-` if not a lts version - local lts_codename="${fields[9],,}" + local lts_codename=$(echo "${fields[9]}" | tr '[:upper:]' '[:lower:]') if [ "$lts_codename" != - ]; then # No lts read yet, so this must be the more recent From addbaaa75187030dd48f4e187687fc2c97113de7 Mon Sep 17 00:00:00 2001 From: Dave Ashby Date: Fri, 5 Mar 2021 08:43:37 -0500 Subject: [PATCH 19/27] Add check to see if key already exists locally before querying keyservers --- bin/import-release-team-keyring | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/import-release-team-keyring b/bin/import-release-team-keyring index 95182a9..8f88ec3 100755 --- a/bin/import-release-team-keyring +++ b/bin/import-release-team-keyring @@ -39,7 +39,9 @@ if [ -z "${gnugp_verify_command_name}" ]; then fi for key in $KEYS; do - for server in $SERVERS; do - $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} --no-tty --keyserver "hkp://$server" $OPTIONS --display-charset utf-8 --recv-keys "$key" && break - done + for server in $SERVERS; do + $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} -k $key -with-colons > /dev/null 2>&1 || \ + $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} --no-tty --keyserver "hkp://$server" $OPTIONS --display-charset utf-8 --recv-keys "$key" && break + done +# fi done From e0f170fc52b4fd1e168a44cdb819ec754804a84e Mon Sep 17 00:00:00 2001 From: Dave Ashby Date: Tue, 9 Mar 2021 11:45:33 -0500 Subject: [PATCH 20/27] tweak gpg check and add automatic key installation --- bin/import-release-team-keyring | 2 +- bin/install | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/import-release-team-keyring b/bin/import-release-team-keyring index 8f88ec3..041d1ec 100755 --- a/bin/import-release-team-keyring +++ b/bin/import-release-team-keyring @@ -40,7 +40,7 @@ fi for key in $KEYS; do for server in $SERVERS; do - $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} -k $key -with-colons > /dev/null 2>&1 || \ + $gnugp_verify_command_name --with-colons --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} -k $key > /dev/null 2>&1 || \ $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} --no-tty --keyserver "hkp://$server" $OPTIONS --display-charset utf-8 --recv-keys "$key" && break done # fi diff --git a/bin/install b/bin/install index 738855d..8b4b8fa 100755 --- a/bin/install +++ b/bin/install @@ -241,6 +241,9 @@ download_and_verify_checksums() { export GNUPGHOME="${ASDF_DIR:-$HOME/.asdf}/keyrings/nodejs" fi + # Automatically add needed PGP keys + source "$(dirname "$0")/import-release-team-keyring" + if ! $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then # Try default keyring if ! $gnugp_verify_command_name --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then From c87a52c5c2485a5fb9ac514cda99333e6818bc92 Mon Sep 17 00:00:00 2001 From: Dave Ashby Date: Tue, 9 Mar 2021 12:27:10 -0500 Subject: [PATCH 21/27] Update README to reflect automatic import of keys --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 5f2b157..426e226 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,7 @@ Install the plugin: asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git ``` -Import the Node.js release team's OpenPGP keys to main keyring: - -```bash -bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring' -``` - -If you are trying to install a previous release and facing any issue about verification, import the Node.js previous release team's OpenPGP keys to main keyring: +The plugin now automatically imports the NodeJS release team's OpenPGP keys. If you are trying to install a previous release and facing any issue about verification, import the Node.js previous release team's OpenPGP keys to main keyring: ```bash bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-previous-release-team-keyring' From 9a093d4be587f546420dfce4b875be7dd5066d4f Mon Sep 17 00:00:00 2001 From: Dave Ashby Date: Wed, 10 Mar 2021 10:45:41 -0500 Subject: [PATCH 22/27] tweak automatic key import --- bin/import-release-team-keyring | 1 - bin/install | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/import-release-team-keyring b/bin/import-release-team-keyring index 041d1ec..09fe3f6 100755 --- a/bin/import-release-team-keyring +++ b/bin/import-release-team-keyring @@ -43,5 +43,4 @@ for key in $KEYS; do $gnugp_verify_command_name --with-colons --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} -k $key > /dev/null 2>&1 || \ $gnugp_verify_command_name --no-default-keyring --keyring ${ASDF_NODEJS_KEYRING} --no-tty --keyserver "hkp://$server" $OPTIONS --display-charset utf-8 --recv-keys "$key" && break done -# fi done diff --git a/bin/install b/bin/install index 8b4b8fa..4be38be 100755 --- a/bin/install +++ b/bin/install @@ -242,7 +242,7 @@ download_and_verify_checksums() { fi # Automatically add needed PGP keys - source "$(dirname "$0")/import-release-team-keyring" + "$(dirname "$0")/import-release-team-keyring" if ! $gnugp_verify_command_name --no-default-keyring --keyring "${ASDF_NODEJS_KEYRING}" --display-charset utf-8 --verify "$signed_checksum_file" 2>/dev/null; then # Try default keyring From 6778954108811cc61b5dae3663b7c88d8bf57fb5 Mon Sep 17 00:00:00 2001 From: "john r. durand" Date: Sat, 6 Mar 2021 08:28:38 -0800 Subject: [PATCH 23/27] Fix use of tac on macOS. --- bin/list-all | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/list-all b/bin/list-all index fccf0af..82ba299 100755 --- a/bin/list-all +++ b/bin/list-all @@ -1,5 +1,12 @@ #!/usr/bin/env bash +# simulate tac on macOS +if [[ $(uname -s) = Darwin ]]; then + tac() { + tail -r "$@" + } +fi + set -o nounset -o pipefail -o errexit # shellcheck source=../lib/utils.sh From 96989eb1278e1579fd8a3e474c4f496159a7a00d Mon Sep 17 00:00:00 2001 From: "john r. durand" Date: Fri, 12 Mar 2021 11:05:39 -0800 Subject: [PATCH 24/27] Remove delcared coreutils dependency, correct macOS. --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 426e226..dc22261 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,7 @@ Node.js plugin for [asdf](https://github.com/asdf-vm/asdf) version manager ## Requirements -### MacOS -* [GNU Core Utils](http://www.gnu.org/software/coreutils/coreutils.html) - `brew install coreutils` +### macOS * [GnuPG](http://www.gnupg.org) - `brew install gpg` * awk - any posix compliant implementation (tested on gawk `brew install gawk`) From b87aca1b9a4b65d9feb0a003acc44263989e4507 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogov Date: Wed, 24 Mar 2021 15:52:33 +0300 Subject: [PATCH 25/27] Fix tac on OSX if coreutils are linked in path (#216) * Fix tac on osx if coreutils are linked in path * Change fallback condition for `tac`. Provide space-safe implementation --- bin/list-all | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/list-all b/bin/list-all index 82ba299..886f571 100755 --- a/bin/list-all +++ b/bin/list-all @@ -1,9 +1,9 @@ #!/usr/bin/env bash # simulate tac on macOS -if [[ $(uname -s) = Darwin ]]; then +if ! command -v tac &>/dev/null; then tac() { - tail -r "$@" + cat -n "$@" | sort -nrk1 | cut -f2- } fi From e0f49386c9a29b0c53c95153f72f6c9da9011044 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogov Date: Wed, 7 Apr 2021 17:56:03 +0300 Subject: [PATCH 26/27] feat: Implement index tab cache (#219) * feat: Implement index tab cache * feat: Switch to etag-based caching * Update lib/utils.sh Co-authored-by: Augusto Borges de Moura Co-authored-by: Trevor Brown --- bin/install | 3 +-- bin/list-all | 2 +- lib/utils.sh | 30 ++++++++++++++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bin/install b/bin/install index 4be38be..5901c92 100755 --- a/bin/install +++ b/bin/install @@ -87,7 +87,7 @@ install_aliased_version() { fi >&2 echo "Linking \"$version_query\" to \"$version\"" - ln -s "$(asdf where "$(plugin_name)" "$version")" "$install_path" + ln -s "$(asdf where "$(plugin_name)" "$version")" "$install_path" } @@ -97,7 +97,6 @@ resolve_version_query() { local canon_version="$( # Find the first candidate which the alias match, then print it version print_index_tab \ - | filter_version_candidates \ | awk -F'\t' -v "alias=$version_query" '$1 == alias { print $2; exit }' )" diff --git a/bin/list-all b/bin/list-all index 886f571..7915513 100755 --- a/bin/list-all +++ b/bin/list-all @@ -15,5 +15,5 @@ source "$(dirname "$0")/../lib/utils.sh" # Print echo $( # Only print the first column of candidates - print_index_tab | filter_version_candidates | cut -f1 | tac + print_index_tab | cut -f1 | tac ) diff --git a/lib/utils.sh b/lib/utils.sh index 0c1aa22..fde8efc 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -21,12 +21,6 @@ die() { exit 1 } -# TODO: implement a cache for the tab. The api supports If-None-Match and -# If-Modified-Since HTTP headers -print_index_tab() { - curl --silent "${NODEJS_ORG_MIRROR}index.tab" -} - # Tab file needs to be piped as stdin # Print all alias and correspondent versions in the format "$alias\t$version" # Also prints versions as a alias of itself. Eg: "v10.0.0\tv10.0.0" @@ -63,3 +57,27 @@ filter_version_candidates() { done } +versions_cache_dir="${ASDF_DATA_DIR:-${ASDF_HOME:-$HOME/.asdf}}/tmp/$(plugin_name)/cache" +mkdir -p "$versions_cache_dir" + +etag_file="$versions_cache_dir/etag" +index_file="$versions_cache_dir/index" +touch "$etag_file" "$index_file" + +print_index_tab(){ + local temp_headers_file="$(mktemp)" + + if [ -f "$etag_file" ]; then + etag_flag='--header If-None-Match:'"$(cat "$etag_file")" + fi + + index="$(curl --fail --silent --dump-header "$temp_headers_file" $etag_flag "${NODEJS_ORG_MIRROR}index.tab")" + if [ -z "$index" ]; then + cat "$index_file" + else + cat "$temp_headers_file" | awk 'tolower($1) == "etag:" { print $2 }' > "$etag_file" + echo "$index" | filter_version_candidates | tee "$index_file" + fi + + rm "$temp_headers_file" +} From 33be6867165e4068c2884d7c76d84ea0bcc29d33 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Thu, 8 Apr 2021 22:05:57 +0900 Subject: [PATCH 27/27] Fix path priority for global npm (#212) * Fix path priority for global npm Signed-off-by: Sora Morimoto * Remove bin/exec-path Signed-off-by: Sora Morimoto --- bin/exec-path | 15 --------------- bin/list-bin-paths | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100755 bin/exec-path diff --git a/bin/exec-path b/bin/exec-path deleted file mode 100755 index b244c51..0000000 --- a/bin/exec-path +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -install_path=$1 -cmd=$2 -executable_path=$3 - -if [[ "$cmd" == "npm" ]] || [[ "$cmd" == "npx" ]]; then - npm_bin_cmd=".npm/bin/$cmd" - - if [[ -f "$install_path/$npm_bin_cmd" ]]; then - executable_path="$npm_bin_cmd" - fi -fi - -echo "$executable_path" diff --git a/bin/list-bin-paths b/bin/list-bin-paths index ab48934..67865ae 100755 --- a/bin/list-bin-paths +++ b/bin/list-bin-paths @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "bin .npm/bin" +echo ".npm/bin bin"