I know that I can get a list of my direct dependencies via
npm ls --depth=0 --only=production
which produces something like this
[email protected] /code/my-app
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
... etc ...
Is there an easy way to get the output to look something like this?
[email protected] /code/my-app
├── [email protected] (4 dependencies)
├── [email protected] (28 dependencies)
├── [email protected] (12 dependencies)
├── [email protected] (30 dependencies)
├── [email protected] (21 dependencies)
├── [email protected] (3 dependencies)
├── [email protected] (93 dependencies)
├── [email protected] (1 dependency)
├── [email protected] (7 dependencies)
I don’t think npm provides this natively. Shell script can do something similar:
for path in `npm ls --depth=0 --parseable`
do
package=`basename path`
echo "$package: `npm ls --parseable $package | wc -l` dependencies"
done
Hope this is “easy” enough? Note that some package could be counted multiple time, since transitive dependencies can overlap with each other. It’s also assumed that package names don’t contain spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With