update-yarn.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. # This script is meant to be run on a dev's machine to update the version on
  3. # Yarn used by the monorepo. Its goal is to make sure that every mention of Yarn
  4. # version is updated, and it re-installs the plugins to make sure those are
  5. # up-to-date as well.
  6. set -o pipefail
  7. set -o errexit
  8. set -o nounset
  9. CURRENT_VERSION=$(corepack yarn --version)
  10. LAST_VERSION=$(curl \
  11. -H "Accept: application/vnd.github.v3+json" \
  12. https://api.github.com/repos/yarnpkg/berry/releases?per_page=1 | \
  13. awk '{ if ($1 == "\"tag_name\":") print $2 }' | \
  14. sed 's#^"@yarnpkg/cli/##;s#",$##')
  15. [ "$CURRENT_VERSION" = "$LAST_VERSION" ] && \
  16. echo "Already using latest version." && \
  17. exit 0
  18. echo "Upgrading to Yarn $LAST_VERSION (from Yarn $CURRENT_VERSION)..."
  19. PLUGINS=$(awk '{ if ($1 == "spec:") print $2 }' .yarnrc.yml)
  20. echo "$PLUGINS" | xargs -n1 -t corepack yarn plugin remove
  21. cp package.json .yarn/cache/tmp.package.json
  22. sed "s#\"yarn\": \"$CURRENT_VERSION\"#\"yarn\": \"$LAST_VERSION\"#;s#\"yarn@$CURRENT_VERSION\"#\"yarn@$LAST_VERSION\"#" .yarn/cache/tmp.package.json > package.json
  23. rm .yarn/cache/tmp.package.json
  24. echo "$PLUGINS" | xargs -n1 -t corepack yarn plugin import
  25. corepack yarn
  26. git add package.json yarn.lock
  27. git add .yarn/plugins