Skip to content

Instantly share code, notes, and snippets.

@termosa
Last active January 29, 2020 10:00
Show Gist options
  • Save termosa/aa13c4a03eec25807dec84b415af08ae to your computer and use it in GitHub Desktop.
Save termosa/aa13c4a03eec25807dec84b415af08ae to your computer and use it in GitHub Desktop.
Measure size of NPM package
npmsize() {
if [ $1 ]
then
PACKAGE_NAME=$1
CURRENT_DIR="$(pwd)"
LC_ALL=C
RANDOM_NAME="$(tr -dc 'a-z' </dev/urandom | head -c 32)"
TEMP_DIR="$HOME/.$RANDOM_NAME"
mkdir $TEMP_DIR
cd $TEMP_DIR
echo $'{\"name\":\"'$RANDOM_NAME$'\"}' > package.json
npm install --silent $PACKAGE_NAME
cd node_modules
for f in $(ls); do du -sh $(echo $f); done
cd ..
echo "$(du -sh node_modules)\t <-- TOTAL"
cd $CURRENT_DIR
rm -rf $TEMP_DIR
else
echo "Usage: npmsize <package_name>"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment