Skip to content

Commit

Permalink
Set pnpm env vars rather than reloading .zshrc
Browse files Browse the repository at this point in the history
Reloading .zshrc is a little problematic for a few reasons:
1. user might be running bash or fish or something
2. there might be problematic commands in there, we don't want to take responsibility for running them

So instead we should just set the basic pnpm env vars if necessary and move on
  • Loading branch information
toebeann committed Feb 18, 2024
1 parent c5ba80d commit 4b9ecf8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions gib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@
echo "Preparing pnpm..."
curl -fsSL https://get.pnpm.io/install.sh | sh - >/dev/null

# automatically reload .zshrc if pnpm isn't already in the path
# ensure pnpm env vars are set
if [ -z "$PNPM_HOME" ]; then
export PNPM_HOME="$HOME/Library/pnpm"
fi

# ensure PATH contains pnpm home
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac

# check for pnpm command and ask user to reload terminal if not found
if ! command -v pnpm >/dev/null; then
set +e # ignore errors in the .zshrc, we just need the path to be updated
source ~/.zshrc
set -e # re-enable exit on err

# if pnpm still not in path after reloading .zshrc, exit with error
if ! command -v pnpm >/dev/null; then
echo "pnpm command not found in PATH"
echo "Please reload your terminal, then run this script again"
exit 1
fi
echo "pnpm not found in PATH"
echo "Please reload your terminal, then run this script again"
exit 1
fi

# ensure node v20 is in use
Expand Down

0 comments on commit 4b9ecf8

Please sign in to comment.