Last active
January 29, 2020 10:00
-
-
Save termosa/aa13c4a03eec25807dec84b415af08ae to your computer and use it in GitHub Desktop.
Measure size of NPM package
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
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