Skip to content

Commit

Permalink
smooth the transition to pnpm in post-merge script
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs committed Jan 2, 2024
1 parent fda583c commit 9407635
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions .husky/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
RED='\033[0;31m'
ENDCOLOR='\033[0m'

# Delete old yarn-based stuff while transitioning from yarn to pnpm. It can be
# removed once we're confident that pnpm is working.
if [ -d ".yarn" ]; then
echo "${RED}This application now uses pnpm. Cleaning up old yarn stuff...${ENDCOLOR}"
rm -rf .yarn
rm -rf **/node_modules # belt-and-braces
fi

changedFiles="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"
changedLock="$(echo "$changedFiles" | { grep -E 'pnpm-lock.yaml' || :; })"
changedNode="$(echo "$changedFiles" | { grep '.nvmrc' || :; })"

if [[ ! -z $changedLock ]]
if [[ ! -z $changedNode ]]
then
echo "${RED}This application has new dependencies. Running 'pnpm'... ${ENDCOLOR}"
pnpm install --frozen-lockfile
version="$(cat .nvmrc)"
echo "${RED}This project needs Node "$version". Please run 'nvm use', 'fnm use' or 'asdf install' (or whatever is appropriate) then run 'pnpm install --frozen-lockfile'${ENDCOLOR}"
exit 1
fi

if [[ ! -z $changedNode ]]
if [[ ! -z $changedLock ]]
then
version="$(cat .nvmrc)"
echo "${RED}This project now uses node version "$version". Please use 'nvm use' & run 'pnpm install --frozen-lockfile'${ENDCOLOR}"
echo "${RED}This application has updated dependencies. Installing with pnpm...${ENDCOLOR}"
pnpm install --frozen-lockfile
fi

0 comments on commit 9407635

Please sign in to comment.