Skip to content

Instantly share code, notes, and snippets.

@geoffreygarrett
Created June 22, 2024 10:36
Show Gist options
  • Save geoffreygarrett/8e00508120003a35555565ac620e9ae1 to your computer and use it in GitHub Desktop.
Save geoffreygarrett/8e00508120003a35555565ac620e9ae1 to your computer and use it in GitHub Desktop.
This Gawk script parses the output from 'deno info', extracts dependencies along with their sizes, converts all sizes to megabytes (MB), aggregates sizes by unique paths, and lists the top 10 largest dependencies sorted by size in descending order.
#!/usr/bin/env gawk -f
# deno_dependency_analyzer.sh
#
# Description:
# This Gawk script parses the output from 'deno info', extracts dependencies along with their sizes,
# converts all sizes to megabytes (MB), aggregates sizes by unique paths, and lists the top 10 largest
# dependencies sorted by size in descending order.
# Execute 'deno info' with provided import map and script, and process the output with gawk
deno info --import-map "$IMPORT_MAP" "$DENO_SCRIPT" | gawk '
{
# Remove ANSI escape sequences for cleaner parsing
gsub(/\x1B\[[0-9;]*[mK]/, "");
# Match lines with sizes at the end, after a URL or path
if (match($0, /(\S+)\s+\(([0-9]+\.[0-9]+)(KB|MB)\)/, arr)) {
path = arr[1]; # Capture the dependency path
size = arr[2]; # Capture the numeric size
unit = arr[3]; # Capture the unit (KB or MB)
if (unit == "KB") {
size /= 1024; # Convert KB to MB
}
# Print the size in MB and the path
printf("%.2f MB\t%s\n", size, path);
}
}' | sort -k1,1nr | head -10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment