From 450bea0d8380d19a652aa653e21a82daa817a8e2 Mon Sep 17 00:00:00 2001 From: Mohan Narayana Date: Tue, 16 Nov 2021 16:25:44 -0600 Subject: [PATCH] fix: add package link check Signed-off-by: Mohan Narayana --- bin/package-link | 15 ++++++++++++++- bin/package-unlink | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bin/package-link b/bin/package-link index edecacf083..da4c1d7f67 100755 --- a/bin/package-link +++ b/bin/package-link @@ -10,7 +10,6 @@ set -o pipefail # don't ignore exit codes when piping output set -o posix # more strict failures in subshells # set -x # enable debugging -IFS="$(printf "\n\t")" # ---- End unofficial bash strict mode boilerplate package_name=$1 @@ -19,6 +18,20 @@ yalc_packages_file_name="yalc-packages" container_id="$(docker-compose ps -q web)" container_copied_packages_path="/home/node/copied-packages" +# validate input +IFS='/' +read -a pkgarr <<< "$1" +org_name=${pkgarr[0]} + +#check if the organization name is valid by cross referencing with node_modules +is_package=$(find node_modules -type d -name $org_name) +if [ -z "$is_package" ]; then + echo "$org_name does not exist" + exit 0 +fi + +IFS="$(printf "\n\t")" + if [[ -z "${package_name}" ]]; then if ! [[ -f "$yalc_packages_file_name" ]]; then echo "Yalc packages file doesn't exist. Creating..." diff --git a/bin/package-unlink b/bin/package-unlink index 29fd5267d3..55857d361b 100755 --- a/bin/package-unlink +++ b/bin/package-unlink @@ -10,11 +10,24 @@ set -o pipefail # don't ignore exit codes when piping output set -o posix # more strict failures in subshells # set -x # enable debugging -IFS="$(printf "\n\t")" # ---- End unofficial bash strict mode boilerplate package_name=$1 +# validate input +IFS='/' +read -a pkgarr <<< "$1" +org_name=${pkgarr[0]} + +#check if the organization name is valid by cross referencing with node_modules +is_package=$(find node_modules -type d -name $org_name) +if [ -z "$is_package" ]; then + echo "$org_name does not exist" + exit 0 +fi + +IFS="$(printf "\n\t")" + # Unlink the yalc dependency, remove the package drectory and npm install echo "Unlinking package from Example Storefront..." docker-compose exec web sh -c "cd /usr/local/src/app && yalc remove ${package_name}"