yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Add option to change version of all workspaces together

Open alexbrazier opened this issue 7 years ago • 8 comments

Do you want to request a feature or report a bug?

Feature

What is the current behavior? yarn version only changes current package.json file

What is the expected behavior? yarn version should have to option to change the version in all workspaces, or a version command should be added to yarn workspaces.

e.g. yarn workspaces version will change the version in all workspaces to the new one.

This will be useful for packages that you always want to stay in sync, and get released together.

alexbrazier avatar Jul 05 '18 15:07 alexbrazier

@alexbrazier I was just looking for something like this. Thanks for taking the time to write up the proposal.

brianespinosa avatar Sep 24 '18 18:09 brianespinosa

@alexbrazier Would Lerna work here? https://github.com/lerna/lerna

milesj avatar Sep 24 '18 19:09 milesj

Also would be useful to have option to change versions simultaneously in all workspaces and in the root package.json, for complex applications we build in corporate world, where we not only publish our workspaces on npm, but use root package.json version for other tooling.

alexindigo avatar Oct 27 '18 00:10 alexindigo

Hi @milesj Lerna resolves the versioning, but in my case it also added other issues with npm-run-all (https://github.com/lerna/lerna/issues/2145).

@alexbrazier @alexindigo because of the issue that I had with Lerna, I decided to create an script to update the versions: https://github.com/dfernandez79/set-versions if you only want to update the versions it may be useful (if you want to do more stuff... take a look to Lerna).

dfernandez79 avatar Jun 29 '19 21:06 dfernandez79

The following currently works:

/packages/A/package.json
"scripts": {
  "prerelease": "yarn version --patch",
  "release": "npm publish", 
}

/packages/B/package.json
"scripts": {
  "prerelease": "yarn version --patch",
  "release": "npm publish", 
}

/package.json
"scripts": {
  "release": "yarn workspaces run release"
}

This does a decent job of keeping the versions in sync as well

carbonrobot avatar Mar 19 '20 00:03 carbonrobot

For anyone that finds themselves here in or after 2022, here's a recipe I'm using to bump versions:

// ./package.json
"scripts": {
  "bump": "yarn version --no-commit-hooks --no-git-tag-version",
  "version": "yarn workspaces run bump-to $npm_package_version",
  "postversion": "...handle tags, commits, pushes, etc. to make one line in git history for incrementing all pkgs"
}

// ./packages/a/package.json
"scripts": {
  "bump-to": "yarn version --no-commit-hooks --no-git-tag-version --new-version",
}

// ./packages/b/package.json
"scripts": {
  "bump-to": "yarn version --no-commit-hooks --no-git-tag-version --new-version",
}

Then I can run yarn bump --patch or --minor or --major or whatever I need, and it's passed directly down to the workspaces.

nedredmond avatar Nov 19 '22 23:11 nedredmond

Looks like the version lifecyrcle scripts is not working anymore with the latest yarn, so I found a solution using npm:

"scripts": {
  "version": "npm version --force --git-tag-version=false --workspaces=true --workspaces-update=false $npm_package_version && git add packages/*/package.json",
  // or with yarn
  "version": "yarn workspaces foreach --all version $npm_package_version && git add packages/*/package.json",
  "newversion": "npm version --force -m 'v%s' --git-tag-version=true",
}

And run yarn newversion patch.

vlazh avatar Jan 18 '24 15:01 vlazh

Managed to get a version of this working with Yarn:

// ./package.json
"scripts": {
    "bump": "yarn version ${0} && yarn bump:workspaces",
    "bump:workspaces": "yarn workspaces foreach -A run bump-to $npm_package_version"
}

// ./packages/a/package.json
"scripts": {
    "bump-to": "yarn version"
}

Run with:

yarn bump <major | minor | patch>

Hope this helps!

FlynnTechTV avatar Jan 23 '24 22:01 FlynnTechTV