Dependencies
- node.js and npm (obviously)
- jq
- xargs (may needs to be installed manually)
Update all dependencies to their latest version:
cat package.json | \
jq -r '.dependencies | keys[]' | \
xargs -I {} npm i -S {}@latest
Update all devDependencies to their latest version:
cat package.json | \
jq -r '.devDependencies | keys[]' | \
xargs -I {} npm i -S {}@latest
Alias the commands for easier reuse
To reuse the commands without having to remember them just put them into your .bashrc or .bash_profile file. Add this to the end of your bash configuration and restart your shell afterwards:
alias npm-update-all-dependencies="cat package.json | jq -r '.dependencies | keys[]' | xargs -I {} npm i -S {}@latest"
alias npm-update-all-dev-dependencies="cat package.json | jq -r '.devDependencies | keys[]' | xargs -I {} npm i -S {}@latest"
Now you can update all dependencies by running npm-update-all-dependencies
in your project folder. To update all devDependencies run npm-update-all-dev-dependencies
.
Disclaimer
- Don’t use this hack without proper validation. You have been warned!
- This has only been tested with:
- Mac OS 10.14.3 (with xargs included)
- node v10.15.0
- npm 6.4.1
- jq 1.6