Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created October 17, 2024 13:55
Show Gist options
  • Save tluyben/f0e4efcfa8fc4f34d974fb6229542a74 to your computer and use it in GitHub Desktop.
Save tluyben/f0e4efcfa8fc4f34d974fb6229542a74 to your computer and use it in GitHub Desktop.
#!/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