8c91d411f37a.github/scripts/bump-package-dep.sh+75 -0.github/workflows/upgrade-vite-rolldown.yml+3 -398c91d411f37a.github/scripts/bump-package-dep.sh+75 -0.github/workflows/upgrade-vite-rolldown.yml+3 -39| 1 | + | #!/usr/bin/env bash | |
| 2 | + | # Update the version of a dependency across every package.json in the repo. | |
| 3 | + | # | |
| 4 | + | # Usage: bump-package-dep.sh <dep-name> <new-version> | |
| 5 | + | # | |
| 6 | + | # Updates <dep-name> and any package in the matching scope (`@<dep-name>/*`, | |
| 7 | + | # e.g. `@vitest/ui` when bumping `vitest`) across: | |
| 8 | + | # - dependencies, devDependencies, peerDependencies, optionalDependencies | |
| 9 | + | # - pnpm.overrides | |
| 10 | + | # Preserves a leading `^` range prefix if present. | |
| 11 | + | # | |
| 12 | + | # Unlike a global `sed` replace, this only rewrites the version string for the | |
| 13 | + | # named package(s) — so an unrelated dep that happens to share a version | |
| 14 | + | # (e.g. `npm-run-all@^4.1.5` while bumping `vitest@4.1.5`) is left untouched. | |
| 15 | + | | |
| 16 | + | set -euo pipefail | |
| 17 | + | | |
| 18 | + | if [ "$#" -ne 2 ]; then | |
| 19 | + | echo "Usage: $0 <dep-name> <new-version>" >&2 | |
| 20 | + | exit 2 | |
| 21 | + | fi | |
| 22 | + | | |
| 23 | + | NAME="$1" | |
| 24 | + | NEW="$2" | |
| 25 | + | | |
| 26 | + | echo "Bumping $NAME (and @$NAME/*) → $NEW in all package.json files..." | |
| 27 | + | | |
| 28 | + | find . -name 'package.json' -not -path '*/node_modules/*' -print0 \ | |
| 29 | + | | while IFS= read -r -d '' file; do | |
| 30 | + | present=$(jq --arg name "$NAME" ' | |
| 31 | + | def tail_pkg: split(">") | last | sub("@[^@]*$"; ""); | |
| 32 | + | def matches($n; key): key == $n or (key | startswith("@" + $n + "/")); | |
| 33 | + | [ | |
| 34 | + | ((.dependencies // {}) | keys[] | select(matches($name; .))), | |
| 35 | + | ((.devDependencies // {}) | keys[] | select(matches($name; .))), | |
| 36 | + | ((.peerDependencies // {}) | keys[] | select(matches($name; .))), | |
| 37 | + | ((.optionalDependencies // {}) | keys[] | select(matches($name; .))), | |
| 38 | + | ((.pnpm.overrides // {}) | keys[] | select(matches($name; tail_pkg))) | |
| 39 | + | ] | length > 0 | |
| 40 | + | ' "$file") | |
| 41 | + | | |
| 42 | + | if [ "$present" != "true" ]; then | |
| 43 | + | continue | |
| 44 | + | fi | |
| 45 | + | | |
| 46 | + | jq --arg name "$NAME" --arg new "$NEW" --indent 2 ' | |
| 47 | + | # Last package segment of a pnpm.overrides key: "parent>child" → "child", | |
| 48 | + | # "parent@1>child" → "child", plain "child" → "child". | |
| 49 | + | def tail_pkg: split(">") | last | sub("@[^@]*$"; ""); | |
| 50 | + | def matches($n; key): key == $n or (key | startswith("@" + $n + "/")); | |
| 51 | + | def updname($n; $v): | |
| 52 | + | to_entries | map( | |
| 53 | + | if matches($n; .key) and (.value | type) == "string" | |
| 54 | + | then .value = (if (.value | startswith("^")) then "^" + $v else $v end) | |
| 55 | + | else . end | |
| 56 | + | ) | from_entries; | |
| 57 | + | def updoverrides($n; $v): | |
| 58 | + | to_entries | map( | |
| 59 | + | if matches($n; (.key | tail_pkg)) and (.value | type) == "string" | |
| 60 | + | then .value = (if (.value | startswith("^")) then "^" + $v else $v end) | |
| 61 | + | else . end | |
| 62 | + | ) | from_entries; | |
| 63 | + | | |
| 64 | + | (if has("dependencies") then .dependencies |= updname($name; $new) else . end) | |
| 65 | + | | (if has("devDependencies") then .devDependencies |= updname($name; $new) else . end) | |
| 66 | + | | (if has("peerDependencies") then .peerDependencies |= updname($name; $new) else . end) | |
| 67 | + | | (if has("optionalDependencies") then .optionalDependencies |= updname($name; $new) else . end) | |
| 68 | + | | (if (.pnpm? != null) and (.pnpm | has("overrides")) | |
| 69 | + | then .pnpm.overrides |= updoverrides($name; $new) else . end) | |
| 70 | + | ' "$file" > "$file.tmp" | |
| 71 | + | mv "$file.tmp" "$file" | |
| 72 | + | echo " Updated: $file" | |
| 73 | + | done | |
| 74 | + | | |
| 75 | + | echo "Done." |
| 184 | 184 | | |
| 185 | 185 | - name: Replace Vite version in all package.json files | |
| 186 | 186 | if: steps.pr.outputs.exists == 'false' && steps.check.outputs.needed == 'true' && steps.check.outputs.vite_changed == 'true' | |
| 187 | - | run: | | |
| 188 | - | OLD="${{ steps.current.outputs.vite }}" | |
| 189 | - | NEW="${{ steps.latest.outputs.vite }}" | |
| 190 | - | echo "Replacing Vite $OLD → $NEW in all package.json files..." | |
| 191 | - | | |
| 192 | - | find . -name 'package.json' -not -path '*/node_modules/*' | while read -r file; do | |
| 193 | - | if grep -q "\"$OLD\"" "$file"; then | |
| 194 | - | echo " Updating: $file" | |
| 195 | - | sed -i "s|\"$OLD\"|\"$NEW\"|g" "$file" | |
| 196 | - | fi | |
| 197 | - | done | |
| 198 | - | | |
| 199 | - | echo "Done replacing Vite versions." | |
| 187 | + | run: bash .github/scripts/bump-package-dep.sh vite "${{ steps.latest.outputs.vite }}" | |
| 200 | 188 | | |
| 201 | 189 | - name: Replace Rolldown version in all package.json files | |
| 202 | 190 | if: steps.pr.outputs.exists == 'false' && steps.check.outputs.needed == 'true' && steps.check.outputs.rolldown_changed == 'true' | |
| 203 | - | run: | | |
| 204 | - | OLD="${{ steps.current.outputs.rolldown }}" | |
| 205 | - | NEW="${{ steps.latest.outputs.rolldown }}" | |
| 206 | - | echo "Replacing Rolldown $OLD → $NEW in all package.json files..." | |
| 207 | - | | |
| 208 | - | find . -name 'package.json' -not -path '*/node_modules/*' | while read -r file; do | |
| 209 | - | if grep -q "\"$OLD\"" "$file"; then | |
| 210 | - | echo " Updating: $file" | |
| 211 | - | sed -i "s|\"$OLD\"|\"$NEW\"|g" "$file" | |
| 212 | - | fi | |
| 213 | - | done | |
| 214 | - | | |
| 215 | - | echo "Done replacing Rolldown versions." | |
| 191 | + | run: bash .github/scripts/bump-package-dep.sh rolldown "${{ steps.latest.outputs.rolldown }}" | |
| 216 | 192 | | |
| 217 | 193 | - name: Replace Vitest version in all package.json files | |
| 218 | 194 | if: steps.pr.outputs.exists == 'false' && steps.check.outputs.needed == 'true' && steps.check.outputs.vitest_changed == 'true' | |
| 219 | - | run: | | |
| 220 | - | OLD="${{ steps.current.outputs.vitest }}" | |
| 221 | - | NEW="${{ steps.latest.outputs.vitest }}" | |
| 222 | - | echo "Replacing Vitest $OLD → $NEW in all package.json files..." | |
| 223 | - | | |
| 224 | - | find . -name 'package.json' -not -path '*/node_modules/*' | while read -r file; do | |
| 225 | - | if grep -q "$OLD" "$file"; then | |
| 226 | - | echo " Updating: $file" | |
| 227 | - | sed -i "s|$OLD|$NEW|g" "$file" | |
| 228 | - | fi | |
| 229 | - | done | |
| 230 | - | | |
| 231 | - | echo "Done replacing Vitest versions." | |
| 195 | + | run: bash .github/scripts/bump-package-dep.sh vitest "${{ steps.latest.outputs.vitest }}" | |
| 232 | 196 | | |
| 233 | 197 | - name: Install deps | |
| 234 | 198 | if: steps.pr.outputs.exists == 'false' && steps.check.outputs.needed == 'true' |