Upgrading yarn in root directory do not upgrade Workspace dependencies

Viewed 2699

On running yarn upgrade in root directory, it is upgrading only root directory's package.json and yarn.lock, but I need to upgrade workspace dependencied.

Is there a way to do so, other than using yarn upgrade-interactive?

3 Answers

I found an alternative

yarn workspace (workspace name) add (package name) (type of dependancy)

for all the packages you need to upgrade.

Then

yarn install

This is handled much better in yarn version 2. There you can do

yarn up react react-dom

And it will be aware of workspaces, or add -i for interactive mode, where it will ask you what to do for each dependency upgrade in each workspace.

Option a) Chain two commands

You can chain two commands together:

yarn upgrade -W && yarn workspace <workspace> upgrade

or to upgrade a specific package:

yarn upgrade <package> -W && yarn workspace <workspace> upgrade <package>

Option b) Create a function

Act on the root and each workspace in one command.

For many workspaces, or if you don't want to write the package name twice, you can automate this with a function.

Requirements: You will need jq installed.

Enter this line once per shell session:

yarn_all() { yarn -W $@ && for w in $(yarn workspaces info -s | sed '1d;$d' | jq -r 'keys[]'); do yarn workspace $w $@; done; }

Usage: yarn_all <command> [<package>]

Examples:

yarn_all upgrade
yarn_all upgrade my-package
yarn_all upgrade my-package --registry http://localhost:4873

It can be used with other commands as well, such as remove.

Tested with yarn v1.22.4 and jq v1.6

Related