Open alexbrazier opened 6 years ago
@alexbrazier I was just looking for something like this. Thanks for taking the time to write up the proposal.
@alexbrazier Would Lerna work here? https://github.com/lerna/lerna
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.
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).
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
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.
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
.
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!
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
yarn version
only changes current package.json fileWhat is the expected behavior?
yarn version
should have to option to change the version in all workspaces, or aversion
command should be added toyarn 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.