yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.44k stars 2.73k forks source link

Add option to change version of all workspaces together #6066

Open alexbrazier opened 6 years ago

alexbrazier commented 6 years ago

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.

brianespinosa commented 6 years ago

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

milesj commented 6 years ago

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

alexindigo commented 6 years ago

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.

dfernandez79 commented 5 years ago

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).

carbonrobot commented 4 years ago

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

nedredmond commented 1 year ago

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.

vlazh commented 9 months ago

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.

FlynnTechTV commented 9 months ago

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!