-
-
Save othiym23/4ac31155da23962afd0e to your computer and use it in GitHub Desktop.
#!/bin/sh | |
set -e | |
set -x | |
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3) | |
do | |
npm -g install "$package" | |
done |
#!/bin/sh | |
set -e | |
set -x | |
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f2) | |
do | |
npm -g install "$package" | |
done |
Old issue for adding npm upgrade command: npm/npm#4471
Long standing call-for-PR...
@jsonkarns: if you don't have /bin/sh, you don't have UNIX.
You can run this if you don't feel like downloading it : source <(curl -fsSL https://gist.githubusercontent.com/othiym23/4ac31155da23962afd0e/raw/4ead4c8989c66104a22240819131b99295bc4e37/npm-upgrade.sh)
Add the -bleeding
to the url if you like to live on the edge.
If you prefer to choose which global modules are updated I've added interactive updating to npm-check with support for global
.
It also includes links to the source for each updated package so you can find out what's new.
Behind the scenes npm-check
uses npm install
thanks to the recommendation from @othiym23 in this thread.
# install
npm -g i npm-check
# interactive update of global packages
npm-check -u -g
# interactive update for a project you are working on
npm-check -u
Batch script for Windows is available in gist fork
https://gist.github.com/iki/ec32bfdeeb23930efd15 (cc @othiym23)
@othiym23: I needed to add -q
to npm options to reset the loglevel to warn, so that http level msgs are not in the output ... this is generally good practice, as different people can have different default loglevel set in their .npmrc
Thanks for the npm-check util update!
This caused me a lot of heartburn...hope it helps others who find the thread.
The --parseable
flag changes the order of the output from npm outdated
without the flag.
npm outdated -g --depth=0
produces output according to the header → current | wanted | latest
npm outdated -g --depth=0 --parseable
produces output in a different order → wanted | current | latest
# current
npm outdated <package> -g --depth=0 --parseable | cut -d: -f3
# wanted
npm outdated <package> -g --depth=0 --parseable | cut -d: -f2
# latest
npm outdated <package> -g --depth=0 --parseable | cut -d: -f4
@jsonkarns: if you don't have /bin/sh, you don't have UNIX.
@othiym23 I don't follow. The env isn't to guard against not having sh. It's to ensure that these scripts run against the user's preferred sh executable. For example, running against a homebrew-built sh instead of old system install. Since these scripts are intended to be used directly by the user (and not automated or as part of a utility), then they should be run against the user's chosen executable.
FYI: npm @2.6.1+ does not recursively update dependencies by default anymore.
https://docs.npmjs.com/cli/update
+1 @dylang , thanks bro!!!
+1 @dylang npm-check
for president!
+1 @dylang npm-check
+1 @dylang npm-check
+1 for npm-check
+1 for npm-check
should have emotion for answer in gist, which easy to rise a thumbsub on @dylang's anwser
+1 @dylang npm-check
If you have linked some personal package to global then you should use:
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | grep -v @linked | cut -d: -f2)
do
npm -g install "$package"
done
As this will not try to update your local linked package. Actually this should be the default case since it works even when you don't have linked packages.
I love npm-check
too, but my poor man hardware with low memory hates it. So I have developed a very simple package to list outdated packages, install selected ones and update my package.json rules. It will not check for unused or missing packages like npm-check
does. But will work with global packages too, and my machine likes it... If you want to take a look: atualiza.
This one-liner made the trick for me: npm -gp outdated | cut -d: -f4 | xargs -n1 npm -g install
the one liner updated npm for me :(
+1 @dylan
npm -g i npm-check
+1 @dylang npm-check
npm outdated -g
seems to have stopped working too. Does not print anything at all here though there definitely are outdated packages.
npm outdated -g
was fixed a while back and works with npm version 6.4.1.
Running npm v6.8.0 and seeing this problem again. Global packages won't update beyond "wanted".
> npm outdated --global
Package Current Wanted Latest Location
color-convert 1.9.3 1.9.3 2.0.0
mocha 5.2.0 5.2.0 6.0.0
pdfkit 0.8.3 0.8.3 0.9.0
> npm update --global pdfkit
# does nothing
> npm update --global pdfkit@latest
# does nothing
> npm install --global pdfkit
+ pdfkit@0.9.0
added 8 packages from 41 contributors and updated 22 packages in 9.638s
If you prefer to choose which global modules are updated I've added interactive updating to npm-check with support for
global
.It also includes links to the source for each updated package so you can find out what's new.
Behind the scenes
npm-check
usesnpm install
thanks to the recommendation from @othiym23 in this thread.# install npm -g i npm-check # interactive update of global packages npm-check -u -g # interactive update for a project you are working on npm-check -uSource: github.com/dylang/npm-check
Great, bro! Thanks! :D
The Wanted
version shall be another major version, which is not very favorable, since it can break things.
Here is a way to upgrade only minor versions of global packages:
npm_global_packages=($(npm list -g --depth 0 | awk '/ /{print $2}'))
for val in "${npm_global_packages[@]}"; do
npm i -g --force $(echo $val | tr "." "\n" | head -1)
done
Good part is, that it will not bump npm
to a version that is incompatible with the current node
version, so this will most likely not break.
Suggestion:
#!/usr/bin/env sh
for portability.