How can I version bump all my dependencies?

29,414

Solution 1

You can update your packages to the latest version specified in the package.json using yarn upgrade without any args.

This is taken from the docs:

yarn upgrade

This command updates all dependencies to their latest version based on the version range specified in the package.json file. The yarn.lock file will be recreated as well.

This will only update packages that are allowed to be upgraded in the package.json e.g. using ^ (e.g. ^0.13.0 would update to version 0.14.0 if it exists). This will not update your package.json file, but it will update the yarn.lock.

If you want to update dependencies in to the latest version you can use the package npm-check-updates which will update your package.json:

$ yarn global add npm-check-updates
$ npm-check-updates -u
$ yarn upgrade

Solution 2

Upgrade all packages to latest version

yarn upgrade --latest

Solution 3

just run yarn upgrade-interactive --latest and select packages you want to update using space button and press the enter to update.

Solution 4

If your dependencies are using a range version ("^x.x.x", "~x.x.x", etc), your package.json won't be updated if the latest version also match that range, only your yarn.lock.

If you want your package.json to be updated:

  1. Change all your dependencies to a fixed version ("x.x.x")
  2. Run yarn to update the yarn.lock
  3. Run yarn upgrade-interactive and select all dependencies you want to upgrade

Now both your yarn.lock and package.json will reflect the exact latest versions.

Solution 5

Answer for users of Yarn v2 and above.

Import the interactive-tools plugin:

$ yarn plugin import interactive-tools

And run it like this:

$ yarn upgrade-interactive

Note that this will also modify the semvers in your package.json.

Share:
29,414
Drew
Author by

Drew

I am self-taught programmer and designer. I began doing internet-based developments in 1998 with the emergence of Flash and similar technologies. Today I am fully focused on programming web based applications with a broad set of skills, but is on the client side (front-end) where I work more effectively, I can perform tasks side programming server, database administration and systems. As a craftsman, I like to keep things simple and elegant, using different tools with a pragmatic approach. My experience in development teams also found to lead me, so I'm familiar with project management strategies and decision making. I like to make the workspace environment friendly, relaxed, where the communication is seamless, transparent and honest

Updated on July 09, 2022

Comments

  • Drew
    Drew almost 2 years

    Having yarn outdated is quite informative but I'd like to avoid running over package by package doing yarn upgrade.

    From yarn's documentation, just yarn upgrade without arguments is said to upgrade all dependencies but there's no change in my project's package.json and yarn outdated shows the same packages versions than before.

    Is there some command or argument that just bumps all my dependencies?

    If not, is the practice discouraged in some way?

  • Drew
    Drew over 7 years
    Right. Maybe it does. But it's not reflected in my package.json and yarn outdated shows no difference before and after a full run of yarn upgrade. What am I missing?
  • braza
    braza over 7 years
    I realised that yarn upgrade only updates packages to the latest version in the package.json if you are using ^ or ~. If your package is specified as a fixed version this will not change. I have edited my answer to add an option to update your package.json.
  • Kosala Nuwan Perera
    Kosala Nuwan Perera over 4 years
    Have you tried yarn upgrade --latest command? According to the documentation, as I understood, it updates the package.json as well.
  • Fre Timmerman
    Fre Timmerman over 2 years
    this is not official documentation, this is a third party package
  • Prince Sodhi
    Prince Sodhi over 2 years
    ah ok, thank you. Could you please help me to find the official website/documentation?
  • Guilherme Abacherli
    Guilherme Abacherli over 2 years
    Not the official doc (built in functionality), but this worked for me... yarn add --dev yarn-upgrade-all then in the package.json root file I added "up": "yarn-upgrade-all" under "scripts", now execute yarn up in the root project's directory
  • Joshua Pinter
    Joshua Pinter over 2 years
    NOTE: You will need to import the interactive-tools plugin for yarn before using upgrade-interactive, by running this command: yarn plugin import interactive-tools.