update-yarn.sh 996 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. set -o pipefail
  3. set -o errexit
  4. set -o nounset
  5. CURRENT_VERSION=$(corepack yarn --version)
  6. LAST_VERSION=$(curl \
  7. -H "Accept: application/vnd.github.v3+json" \
  8. https://api.github.com/repos/yarnpkg/berry/releases?per_page=1 | \
  9. awk '{ if ($1 == "\"tag_name\":") print $2 }' | \
  10. sed 's#^"@yarnpkg/cli/##;s#",$##')
  11. [ "$CURRENT_VERSION" = "$LAST_VERSION" ] && \
  12. echo "Already using latest version." && \
  13. exit 0
  14. echo "Upgrading to Yarn $LAST_VERSION (from Yarn $CURRENT_VERSION)..."
  15. PLUGINS=$(awk '{ if ($1 == "spec:") print $2 }' .yarnrc.yml)
  16. echo "$PLUGINS" | xargs -n1 -t corepack yarn plugin remove
  17. cp package.json .yarn/cache/tmp.package.json
  18. sed "s#yarn\": \"$CURRENT_VERSION\"#yarn\": \"$LAST_VERSION\"#;s#\"yarn@$CURRENT_VERSION\"#\"yarn@$LAST_VERSION\"#" .yarn/cache/tmp.package.json > package.json
  19. rm .yarn/cache/tmp.package.json
  20. echo "$PLUGINS" | xargs -n1 -t corepack yarn plugin import
  21. corepack yarn
  22. git add package.json yarn.lock
  23. git add .yarn/plugins