Prat
Prat

Reputation: 105

Upgrading yarn in root directory do not upgrade Workspace dependencies

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?

Upvotes: 2

Views: 5946

Answers (3)

trebor
trebor

Reputation: 634

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 -s workspaces info | 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

Upvotes: 4

eivindml
eivindml

Reputation: 2520

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.

Upvotes: 3

Prat
Prat

Reputation: 105

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

Upvotes: 6

Related Questions