|
1
|
#!/bin/bash |
|
2
|
|
|
3
|
if [ $# -lt 2 ]; then |
|
4
|
echo "Usage: ./update-dependency-versions.sh <package-name> <new-version>" |
|
5
|
echo "Example: ./update-dependency-versions.sh typescript ^5.6.2" |
|
6
|
exit 1 |
|
7
|
fi |
|
8
|
|
|
9
|
PACKAGE_NAME=$1 |
|
10
|
NEW_VERSION=$2 |
|
11
|
|
|
12
|
echo "=== Updating $PACKAGE_NAME to $NEW_VERSION across all packages ===\n" |
|
13
|
|
|
14
|
# Find all package.json files (excluding node_modules) |
|
15
|
find packages -name "package.json" -not -path "*/node_modules/*" | while read -r pkgfile; do |
|
16
|
# Check if package exists in dependencies or devDependencies |
|
17
|
if grep -q "\"$PACKAGE_NAME\":" "$pkgfile"; then |
|
18
|
echo "📝 Updating $pkgfile" |
|
19
|
|
|
20
|
# Use sed to update the version (works on both macOS and Linux) |
|
21
|
# Using | as delimiter to avoid conflicts with / in package names like @types/react |
|
22
|
if [[ "$OSTYPE" == "darwin"* ]]; then |
|
23
|
# macOS |
|
24
|
sed -i '' "s|\"$PACKAGE_NAME\": \"[^\"]*\"|\"$PACKAGE_NAME\": \"$NEW_VERSION\"|" "$pkgfile" |
|
25
|
else |
|
26
|
# Linux |
|
27
|
sed -i "s|\"$PACKAGE_NAME\": \"[^\"]*\"|\"$PACKAGE_NAME\": \"$NEW_VERSION\"|" "$pkgfile" |
|
28
|
fi |
|
29
|
fi |
|
30
|
done |
|
31
|
|
|
32
|
echo "\n✅ Update complete!" |
|
33
|
echo "Next steps:" |
|
34
|
echo " 1. Review changes: git diff" |
|
35
|
echo " 2. Install dependencies: yarn install" |
|
36
|
echo " 3. Test the build: yarn build" |