if [[ $SKIP_HOOKS>0 ]]; then
  echo "[POST-MERGE] skipping hooks ($SKIP_HOOKS)"
  exit 0
fi

# ### run npm install ###
echo "[POST-MERGE] 📦 Checking for changes to dependencies"
# define how to split strings into array elements
IFS=$'\n'
# extract all paths to package-lock.json files
PACKAGE_LOCK_REGEX="(^package-lock\.json)"
echo "[POST-MERGE] running git diff --name-only HEAD^1 HEAD"
PACKAGES=$(git diff --name-only HEAD^1 HEAD | grep -E $PACKAGE_LOCK_REGEX || true)

if [[ ${PACKAGES[@]} ]]; then
  for package in $PACKAGES; do
    echo "📦 $package was changed."
  done
  echo "📦 Running npm install to update your dependencies..."
  npm install
  npm run lint:fix
else
  echo "📦 All packages up-to-date. No need to run npm install."
fi
