Better `npm outdated` command
Let’s make the npm outdated
command more useful. For example, the original output is something like this:
Package Current Wanted Latest Location Depended by
foo 1.0.0 1.0.0 1.2.0 node_modules/foo my_app
bar 1.0.0 1.0.0 2.0.0 node_modules/bar my_app
So for updating foo
, we have to type:
npm install foo@1.2.0
On the other hand, we can make it print something like that right away, so we can paste it. For example:
npm install foo@1.2.0;# foo@1.0.0
npm install bar@2.0.0;# bar@1.0.0
The comment at the right shows the currently installed
version, which is going to be handy for knowing if there are
expected breaking changes, such as in the bar
package.
Command
Add this NPM script to your package.json
:
"scripts": { "outdated": "npm outdated --parseable | awk -F: '{ printf \"npm i %s ;# %s\\n\", $4, $2 }'" }
…and run it with npm run outdated
How to check outdated NPM dependencies in many projects in parallel?
This script is similar, but it inspects many projects concurrently. For example:
cd $REPO/AppSPA && npm i foo@1.2.0 ;# foo@1.0.0 cd $REPO/AccountSPA && npm i baz@1.9.0 ;# baz@1.1.0
Shell Script
#!/bin/sh apps=" AppSPA AccountSPA ServerSide " npmo() { local pids="" for app in $apps; do cd $REPO/$app npm outdated --parseable |\ awk -v app="$app" -F: \ '{ printf "cd $REPO/%-10s && npm i %-20s ;# %s\n", app, $4, $2 }' & pids="$pids $!" done wait $pids } npmo | sort -k6
Opening the repo’s homepage
Similarly, for seeing the changelogs, for example on a GitHub repository, replace the last line with:
npmo | sort -k6 |\ tee /dev/tty |\ awk '{print $6}' | uniq | xargs npm repo
Open Source
This script is more complete.