Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM: Update all dependencies with scope

Is there a shortcut for updating all package dependencies that are of a particular scope.

For example is there are in the following package.json is there a quick way to update only those packages with an @example scope?:

…
dependencies: {
  alpha,
  bravo,
  @example/a,
  @example/b,
  @example/c,
  @example/d,
  @example/e,
  @example/f,
}
like image 996
Undistraction Avatar asked Dec 10 '18 12:12

Undistraction


People also ask

How do I update multiple NPM packages?

If you still want to update everything to the latest version, you can use the tool npm-update-all . It's as easy as running this command in your project folder. As you can see, npm-update-all will update all your packages to the latest version.


4 Answers

I wrote small tool for that. Run npx update-by-scope @example for Yarn project and npx update-by-scope @example npm install for Npm project

like image 92
Maxim Valenko Avatar answered Oct 20 '22 03:10

Maxim Valenko


Using yarn:

yarn upgrade --scope @example
like image 24
Undistraction Avatar answered Oct 20 '22 02:10

Undistraction


I update dependencies using the npm-check-updates package -- just install it globally then run ncu. By default it runs in "check" mode against all packages, but you can pass a command-line flag to have it write the newest version of each package to package.json. It supports filtering so you could apply the updates only to a single scope, like ncu '/@angular\/.*/'.

like image 27
Coderer Avatar answered Oct 20 '22 03:10

Coderer


I have the same problem in angular project. I use from the script section in package.json.

I set the custom name (e.g update-scope) as key, and set command(s) as value. follow this:

   "scripts": {
      "ng": "ng",
      "build": "node package-builder",
      "update-scope": "npm update @example/a && npm update @example/b && ..."
   }

then run custom name with this command:

npm run update-scope // `update-scope` is my custom name

finally, all of my packages in my scope was updated.

I hope is useful.

like image 28
AminRostami Avatar answered Oct 20 '22 03:10

AminRostami