DEV Community

Darragh O'Riordan
Darragh O'Riordan

Posted on • Originally published at darraghoriordan.com on

How to also update the package.json version when using yarn update

If you run yarn update on a package, yarn will update the package and your yarn.lock file. This is totally fine.

As long as you check in your lock file, your developers and team will all have the correct versions of libraries when they run yarn install.

However it will not update the package.json with the new semver for the package.

I kind of found this annoying. If only for aesthetic reasons I wanted to quickly see which minimum versions of packages I was using in my package.json.

To have yarn also update the package.json semver there are a couple of options. Essentially you need to add —latest

Using —latest

If you have pass yarn the --latest flag it will update the package.json.

NOTE: this will not respect semver and will update to the latest version. Whatever that might be.

yarn upgrade @graphql-codegen/cli --latest
Enter fullscreen mode Exit fullscreen mode

Using interactive upgrade —latest

If you use the interactive upgrade it will also upgrade the package.json for you

yarn upgrade-interactive --latest
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
arpitprod profile image
arpitprod

yarn upgrade-interactive --latest

This command is not updating all packages.