Skip to content

Instantly share code, notes, and snippets.

@muuvmuuv
Created June 13, 2025 09:17
Show Gist options
  • Save muuvmuuv/e966c713a237d20f50dd7c015408fe89 to your computer and use it in GitHub Desktop.
Save muuvmuuv/e966c713a237d20f50dd7c015408fe89 to your computer and use it in GitHub Desktop.
Bulk re-order json file contents like dependencies in package.json or paths in tsconfig.json. It uses `jq` and can be expanded to re-order other paths as well!
#!/usr/bin/env sh
tsconfig_files=$(
find . -type d \( -path "*/node_modules" -o -path "*/dist" -o -path "*/tmp" -o -path '*/.*' \) -prune \
-o -not -name '.*' \
-type f -name "tsconfig*.json" \
-print
)
for tsconfig_file in $tsconfig_files; do
echo "Reordering paths in $tsconfig_file"
(
jq '
if .compilerOptions.paths != null then
.compilerOptions.paths|=(to_entries|sort_by(.key)|from_entries)
end |
if .references != null then
.references|=sort_by(.path)
end
' $tsconfig_file >$tsconfig_file.tmp
mv $tsconfig_file.tmp $tsconfig_file
prettier --write --log-level=silent $tsconfig_file
) &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment