Created
October 17, 2024 13:55
-
-
Save tluyben/f0e4efcfa8fc4f34d974fb6229542a74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
find . -name "package.json" -type f | while read -r file; do | |
# Backup the original file | |
cp "$file" "${file}.bak" | |
# Process dependencies and devDependencies | |
for key in dependencies devDependencies; do | |
jq --arg key "$key" ' | |
if has($key) then | |
.[$key] = (.[$key] | to_entries | map(.value |= sub("^[~^]"; "")) | from_entries) | |
else | |
. | |
end | |
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file" | |
done | |
echo "Processed: $file" | |
done | |
echo "All package.json files have been updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment