Skip to content

Instantly share code, notes, and snippets.

@bushong1
Last active August 29, 2015 14:14
Show Gist options
  • Save bushong1/10dd6458f26987231738 to your computer and use it in GitHub Desktop.
Save bushong1/10dd6458f26987231738 to your computer and use it in GitHub Desktop.
Determine full npm dependencies of a node.js package.
#Add to .bashrc
#Usage: npmdeps <package>[@<version>]
function npmdeps {
regex="^[- |]*$"
regex_space="^ *$"
regex_github="github\.com"
if [[ "$1" =~ $regex ]]; then
return
else
DEPS=`npm info $1 dependencies|perl -0777 -pe 's/^.*{//gs'|perl -0777 -pe 's/}.*$//gs'| sed "s/[\{\}' ]//g" | sed 's/, \?/\n/g' | sed "s/:/@/g"`
echo "`echo "$2"|sed 's/-/ /g'|sed 's/ $/-/'`$1"
if ! [[ $(echo " $3" | grep $1) ]]; then
while read -r line; do
if [[ "$line" =~ $regex_github ]]; then
#Github dependency in npm package? Shame on you.
echo "`echo "$2| "|sed 's/-/ /g'|sed 's/ $/-/'`$line"
else
npmdeps "$line" "$2| " "'$3;$1'"
fi
done <<< "$DEPS"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment