Skip to content

Instantly share code, notes, and snippets.

@iki
Forked from othiym23/npm-upgrade-bleeding.sh
Last active December 12, 2021 08:50
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save iki/ec32bfdeeb23930efd15 to your computer and use it in GitHub Desktop.
Save iki/ec32bfdeeb23930efd15 to your computer and use it in GitHub Desktop.
Update global top level npm packages

Update global top level npm packages

Problem

npm update -g updates all global packages and their dependencies, see npm/npm#6247.

Solution

  1. Either use the shell script or windows batch here instead.

    The shell script is forked from https://gist.github.com/othiym23/4ac31155da23962afd0e. See the discussion there.

  2. Or use https://github.com/dylang/npm-check to interactively select which global/local packages to update

    # 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
    

Sample using npm-check -u

@echo off
setlocal enableextensions enabledelayedexpansion
set packages=
for /f "usebackq delims=: tokens=3" %%f in (`npm -g outdated --parseable --depth=0 -q`) do set packages=!packages! %%f
:: Note: on windows, the first : separates drive in package path.
call npm install -g%packages%
exit /b %errorlevel%
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 -q | cut -d: -f2)
do
npm -g install "$package"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment