Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bump version in all the packages when using yarn workspaces?

When using Yarn Workspaces, we have a project structure like:

- package.json
- packages/
    - package-a/
        - package.json
        - index.js
    - package-b/
        - package.json
        - index.js

If package-b and lots of other packages in this directory are dependent upon package-a and I upgrade the version of package-a after making some changes, How can I upgrade the version package-a in all the dependent packages? Do I have to do it manually or is there a better way?

like image 630
sidoshi Avatar asked Jan 26 '18 13:01

sidoshi


People also ask

How do I set the package version in yarn?

You can specify versions using one of these: yarn add package-name installs the “latest” version of the package. yarn add [email protected] installs a specific version of a package from the registry. yarn add package-name@tag installs a specific “tag” (e.g. beta , next , or latest ).

How do yarn workspaces work?

Yarn Workspaces is a feature that allows users to install dependencies from multiple package. json files in subfolders of a single root package. json file, all in one go. Yarn can also create symlinks between Workspaces that depend on each other, and will ensure the consistency and correctness of all directories.


1 Answers

as i know its not possible for now to manage this with yarn itself. you can use the lerna project https://github.com/lerna/lerna/tree/master/commands/version#readme which supports bumping the version of workspaces

manual (without lerna)

for my existing projects i have done it manually.

attention: this command sets all workspaces to the same version

add postversion in the scripts block of your root ./package.json

{
  "version": "1.0.0",
  ...
  "scripts": {
    "version:package-a": "cd packages/package-a && yarn version --new-version $npm_package_version",
    "version:package-b": "cd packages/package-b && yarn version --new-version $npm_package_version",
    "postversion": "yarn version:package-a && yarn version:package-b"
  }
}
  • now you can run: yarn version --patch
  • this will bump the version of all your workspaces (package-a & package-b) to the same version 1.0.1.

Update 2022-04-08

Solution 1: It's now simpler to bumb all versions with the use of the yarn workspace ... command. In the main package.json you have to put the following:

{
  "version": "1.0.0",
  ...
  "scripts": {
    "version": "yarn workspace package-a version --new-version $npm_package_version && yarn workspace package-b version --new-version $npm_package_version"
  }
}

If you execute now yarn version all the workspace versions are bumped to the same as they inherit from the specified version from the main package.json file

Solution 2: yarn has a solution for this. but it is still in experiment mode. https://yarnpkg.com/features/release-workflow

like image 178
SanQu Avatar answered Sep 21 '22 05:09

SanQu