From a3f51482f7335b21a6d9c8025435ae1cf3466d48 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 22 Jan 2021 16:41:38 -0300 Subject: [PATCH 1/3] feature: add a check to only reshim on installs cmdline also add the same hook as postinstall on postuninstall --- bin/postinstall | 17 +++++++++++++---- npm-hooks/postuninstall | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100755 npm-hooks/postuninstall diff --git a/bin/postinstall b/bin/postinstall index bad88ba..b90bd23 100755 --- a/bin/postinstall +++ b/bin/postinstall @@ -3,8 +3,17 @@ # shellcheck source=../lib/utils.sh source "$(dirname "$0")/../lib/utils.sh" -if [ "$ASDF_SKIP_RESHIM" == "1" ]; then - echo "Run 'asdf reshim $(plugin_name) ${ASDF_INSTALL_VERSION:-$npm_config_node_version}' after installing the packages to reshim" -else - asdf reshim "$(plugin_name)" "${ASDF_INSTALL_VERSION:-$npm_config_node_version}" +# If the command contains this package it should be the last +# Or one of multiples packages being installed/removed +# There's no problem executing it more than once +if grep -qw "$npm_package_name" <<< "$npm_config_argv" ; then + plgn_name="$(plugin_name)" + current_version="$(asdf current $plgn_name)" + + if [ "$ASDF_SKIP_RESHIM" == "1" ]; then + echo "Run 'asdf reshim $plgn_name $current_version' after installing the packages to reshim" + else + echo "Reshiming npm packages..." + asdf reshim "$plgn_name" "$current_version" + fi fi diff --git a/npm-hooks/postuninstall b/npm-hooks/postuninstall new file mode 100755 index 0000000..1fb339d --- /dev/null +++ b/npm-hooks/postuninstall @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +asdf_nodejs_installs_path=$(dirname $(dirname $(dirname $NODE))) +asdf_nodejs_plugin_path=${asdf_nodejs_installs_path/installs/plugins} +bash ${asdf_nodejs_plugin_path}/bin/postinstall From 1dfc7e661d349388157773bb5c037e59aecb2ee9 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 22 Jan 2021 17:15:06 -0300 Subject: [PATCH 2/3] fix: fix current_version getting a complex string --- bin/postinstall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/postinstall b/bin/postinstall index b90bd23..10fc0ad 100755 --- a/bin/postinstall +++ b/bin/postinstall @@ -8,7 +8,7 @@ source "$(dirname "$0")/../lib/utils.sh" # There's no problem executing it more than once if grep -qw "$npm_package_name" <<< "$npm_config_argv" ; then plgn_name="$(plugin_name)" - current_version="$(asdf current $plgn_name)" + current_version="$(asdf current $plgn_name | awk '{ print $2 }')" if [ "$ASDF_SKIP_RESHIM" == "1" ]; then echo "Run 'asdf reshim $plgn_name $current_version' after installing the packages to reshim" From 7bf454057b5f7837566681c47eb26a2f5ee5a621 Mon Sep 17 00:00:00 2001 From: Augusto Moura Date: Fri, 22 Jan 2021 18:39:37 -0300 Subject: [PATCH 3/3] feature: enhance package finding --- bin/postinstall | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/postinstall b/bin/postinstall index 10fc0ad..0e0b458 100755 --- a/bin/postinstall +++ b/bin/postinstall @@ -6,9 +6,9 @@ source "$(dirname "$0")/../lib/utils.sh" # If the command contains this package it should be the last # Or one of multiples packages being installed/removed # There's no problem executing it more than once -if grep -qw "$npm_package_name" <<< "$npm_config_argv" ; then +if grep -qFw "\"$npm_package_name\"" <<< "$npm_config_argv"; then plgn_name="$(plugin_name)" - current_version="$(asdf current $plgn_name | awk '{ print $2 }')" + current_version="${ASDF_INSTALL_VERSION:-$(asdf current "$plgn_name" | awk '{ print $2 }')}" if [ "$ASDF_SKIP_RESHIM" == "1" ]; then echo "Run 'asdf reshim $plgn_name $current_version' after installing the packages to reshim"