Created
August 15, 2021 10:57
-
-
Save ptm108/494faf153e507bb777115cc66a691458 to your computer and use it in GitHub Desktop.
Manual Node Dependency checker script
This file contains hidden or 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
#!/bin/bash | |
DIRNAME=${1:-.} | |
cd $DIRNAME | |
source ~/.bashrc | |
FILES=$(mktemp) | |
PACKAGES=$(mktemp) | |
find . \ | |
-path ./node_modules -prune -or \ | |
-path ./dist -prune -or \ | |
\( -name "*.tsx" -or -name "*.jsx" -or -name "*.ts" -or -name "*.js" -or -name "*.json" \) -print > $FILES | |
function check { | |
cat package.json \ | |
| jq "{} + .$1 | keys" \ | |
| sed -n 's/.*"\(.*\)".*/\1/p' > $PACKAGES | |
echo "--------------------------" | |
echo "Checking $1..." | |
while read PACKAGE | |
do | |
# echo "Checking ${PACKAGE}..." | |
RES=$(cat $FILES | xargs -I {} egrep -i "(import|require|loader|plugins|${PACKAGE}).*['\"](${PACKAGE}|.?\d+)[\"']" '{}' | wc -l) | |
if [ $RES = 0 ] | |
then | |
echo -e "UNUSED\t\t $PACKAGE" | |
else | |
echo -e "USED ($RES)\t $PACKAGE" | |
fi | |
done < $PACKAGES | |
} | |
check "dependencies" | |
check "devDependencies" | |
check "peerDependencies" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment