Today I’m going to show you how you can upgrade all you package.json dependencies and inflict yourself an unnecessary amount of pain with just 3 simple commands, using a technique that – for this specific purpose – works particularly well with big projects.

Open your console and start by installing npm-check-updates. You need to install this globally, so:

npm install -g npm-check-updates

Now let’s check what you can upgrade to the latest possible stable version. You can do that by just typing ncu, which I did on a relatively not-maintained project and got this:

$ ncuUsing yarn
Checking /home/danielesalatti/workspace/Zerokie/package.json
[====================] 34/34 100%
 chai                         ^4.2.0  →           ^4.3.4
 concurrently                 ^5.3.0  →           ^6.2.1
 mocha                        ^8.2.1  →           ^9.0.3
 nodemon                      ^2.0.6  →          ^2.0.12
 @material-ui/core           ^4.11.1  →          ^4.12.3
 @material-ui/icons           ^4.9.1  →          ^4.11.2
 @material-ui/lab    ^4.0.0-alpha.56  →  ^4.0.0-alpha.60
 @sentry/node                ^5.27.2  →          ^6.11.0
 @sentry/tracing             ^5.27.2  →          ^6.11.0
 bcrypt                       ^5.0.0  →           ^5.0.1
 chalk                        ^4.1.0  →           ^4.1.2
 config                       ^3.3.3  →           ^3.3.6
 create-react-app             ^4.0.1  →           ^4.0.3
 dotenv                       ^8.2.0  →          ^10.0.0
 express-rate-limit           ^5.2.3  →           ^5.3.0
 helmet                       ^4.2.0  →           ^4.6.0
 js-base64                    ^3.5.2  →           ^3.6.1
 knex                       ^0.21.13  →         ^0.21.21
 knex-postgis                ^0.12.0  →          ^0.14.1
 multer                       ^1.4.2  →           ^1.4.3
 pg                           ^8.4.2  →           ^8.7.1
 randomstring                 ^1.1.5  →           ^1.2.1
 react-geolocated             ^3.1.0  →           ^3.2.0
 shopify-api-node             ^3.5.2  →          ^3.6.14
 stripe                      8.129.0  →          8.169.0
Run ncu -u to upgrade package.json

This command was technically not one of the 3 necessary commands for our pain inflicting purposes, but it gives an idea of what is going to happen. Notice that the semantics are kept across upgrades (e.g. ^5.3.0 becomes ^6.2.1, the ^ is retained).

Now let’s have some fun. Type ncu -u:

$ ncu -u
Using yarn
Upgrading /home/danielesalatti/workspace/Zerokie/package.json
[====================] 34/34 100%
 chai                         ^4.2.0  →           ^4.3.4
 concurrently                 ^5.3.0  →           ^6.2.1
 mocha                        ^8.2.1  →           ^9.0.3
 nodemon                      ^2.0.6  →          ^2.0.12
 @material-ui/core           ^4.11.1  →          ^4.12.3
 @material-ui/icons           ^4.9.1  →          ^4.11.2
 @material-ui/lab    ^4.0.0-alpha.56  →  ^4.0.0-alpha.60
 @sentry/node                ^5.27.2  →          ^6.11.0
 @sentry/tracing             ^5.27.2  →          ^6.11.0
 bcrypt                       ^5.0.0  →           ^5.0.1
 chalk                        ^4.1.0  →           ^4.1.2
 config                       ^3.3.3  →           ^3.3.6
 create-react-app             ^4.0.1  →           ^4.0.3
 dotenv                       ^8.2.0  →          ^10.0.0
 express-rate-limit           ^5.2.3  →           ^5.3.0
 helmet                       ^4.2.0  →           ^4.6.0
 js-base64                    ^3.5.2  →           ^3.6.1
 knex                       ^0.21.13  →         ^0.21.21
 knex-postgis                ^0.12.0  →          ^0.14.1
 multer                       ^1.4.2  →           ^1.4.3
 pg                           ^8.4.2  →           ^8.7.1
 randomstring                 ^1.1.5  →           ^1.2.1
 react-geolocated             ^3.1.0  →           ^3.2.0
 shopify-api-node             ^3.5.2  →          ^3.6.14
 stripe                      8.129.0  →          8.169.0
Run yarn install to install new versions.

If you check your package.json now you will see that all your dependencies do actually have the new version numbers.

So, yeah, you are ready. If you had previous changes that you have not committed yet this is probably a good time to do that. All you have to do now is run npm install or yarn install depending on what you use, and have fun. See? 3 commands and just like that, you are done. All your packages are at the latest version.

And don’t thank me. Not that you will want to anyways since likely nothing is going to work because of all the breaking changes you just pulled, but that’s where the self inflicted pain part comes in.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.