Updating NPM packages with peer dependencies —made easy

As part of our Open Source Day, I developed a tool that can greatly simplify the updating of NPM packages with peer dependencies. This is particularly useful in connection with Angular updates.

Treppenhaus. Treppensteigen dient als Symbol für die Updates von Version zu Version.

Which Angular developer has not experienced this before? There is a project that is still stuck on an old Angular version. Now you have to update it to the latest version (let’s say from Angular 14 to Angular 17). You work through each major version: you update Angular using the Angular CLI. Then you have to find out which versions of the Angular libraries used in the project (such as ng-translate, ng-bootstrap, Angular Material and the like) are compatible with your current Angular version. Only then can you update the Angular libraries to their latest possible version.

This is an extremely tedious task. You have to look up the CHANGELOG.md file for each package to find out the Angular compatibility. Or maybe you can find this information on the GitHub releases page? And then there are also these packages where you have to go through the package.json files of the individual versions in tedious detective work…

The tool that serves you

Not anymore! I’ve created a tool that can automate this by walking back the versions of a given package and checking the compatibility of its peer dependencies with the packages used in the project.

For example, after updating Angular from 14 to 15, you can determine the latest compatible version of ng-bootstrap by executing the following command from within your project’s directory:

$ npx npm-check-compatible @ng-bootstrap/ng-bootstrap
Searching for a version of @ng-bootstrap/ng-bootstrap whose peer dependencies are satisfied
by the packages installed in the current project:
Checking @ng-bootstrap/ng-bootstrap@16.0.0......
Checking @ng-bootstrap/ng-bootstrap@15.1.2......
Checking @ng-bootstrap/ng-bootstrap@15.1.1......
Checking @ng-bootstrap/ng-bootstrap@15.1.0......
Checking @ng-bootstrap/ng-bootstrap@15.0.1......
Checking @ng-bootstrap/ng-bootstrap@15.0.0......
Checking @ng-bootstrap/ng-bootstrap@14.2.0......
Latest compatible version: @ng-bootstrap/ng-bootstrap@14.2.0

Now you can simply update ng-bootstrap to this version and continue with the next Angular library:

npm install --save @ng-bootstrap/ng-bootstrap@14.2.0

Of course, the tool can also help in contexts other than Angular, where peer dependencies are involved.

The project is published on GitHub as free software, feel free to contribute or comment:
https://github.com/hupf/npm-check-compatible

NPM Package:
https://www.npmjs.com/package/npm-check-compatible

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert