Repository navigation
Description
Lerna needs a separate version command.
Why
Folks who use npm a lot are probably comfortable with the separation between the npm version and npm publish commands. For me, this separation is important because it allows me to double- and triple-check things before publishing. When versioning and publishing a monorepo with dozens of packages, the "publish anxiety" factor is even higher. I've worked through some of that anxiety with various permutations of --skip-git and --skip-npm then git diff, but at some point you have to git reset and just trust that Lerna is going to do the right thing.
The other problem is that Lerna doesn't make it easy (possible?) to just publish all of the packages using the existing package.json versions. AFAICT, it's not possible to skip the increment step, which means that you have to run something like this instead:
lerna exec --bail=false npm publish
...which will output a lot of scary npm publish error messages for any of your packages that haven't been bumped since the last release.
We recently introduced a CI-driven automated publishing workflow in Primer, and to get around this we resorted to running a try-publish script, which would only run npm publish if the version in each module's package.json hadn't already been published. Other teams that want to automate publishing will inevitably run into the same issue, and it would stink if they all ended up having to come up with their own solutions for it.
How
There are a couple of ways to go about this:
-
To maintain backwards compatibility with the current CLI API, the
publishcommand could introduce two new options:- one that does everything but the git and npm steps, e.g.
lerna publish --skip-publish - one that only publishes without touching any
package.jsonfiles, e.g.lerna publish --skip-version
- one that does everything but the git and npm steps, e.g.
-
If you're comfortable breaking the
publishCLI for 2.x users, you could avoid adding any additional options topublishand just move all of the versioning logic over to a newversioncommand.
Activity
danielo515 commentedon Aug 10, 2017
This is also a problem for our company.
There many many times where lerna fails on git operations, or npm operations, and I just want to publish the packages, which is not possible. I would add to the request an option for just publish the packages or to just tag the versions without any version bump.
Regards
evocateur commentedon Aug 23, 2017
I am certainly sympathetic to this request, though I'm not ready to do a breaking change for it...
griest024 commentedon Sep 17, 2017
It would certainly be nice for the CLI to follow
npmas closely as possible, but I would settle for non-breaking changes that implement this.It seems that @shawnbot's proposed
--skip-publishswitch can be accomplished with--skip-npm --skip-gitso all this really needs is a--skip-versionswitch.KingScooty commentedon Nov 29, 2017
+1 for
--skip-version.I've just stumbled across this issue while setting up my CI pipeline to handle publishing.
azu commentedon Jan 23, 2018
I think #1056 is similar to this issue.
Rough summary:
npm versionlerna publish--skip-git/ #961npm publishlerna publish--skip-npm/ #1056lerna publish --conventional-commits--conventional-commitsI think that npm user can get flexibility by running each Task in a sequential order.
By contrast, Lerna can not run each Task in a sequential order.
#956 point out it.
joebowbeer commentedon May 10, 2018
My CI also needs this change.
Given the usual sequence of operations to publish an npm package:
I want lerna to permit a separation of the first two actions from the last.
Related to #653 and #1385
morgs32 commentedon May 10, 2018
I'd like to better understand this issue. @shawnbot you say...
What is the issue exactly? That their process is to publish some packages outside the CI pipeline and some in it? That they get errors in a
try-publishscript because they want that sort of functionality?I must have started watching this issue a while back because I THOUGHT I wanted something similar but came to be perfectly happy with the current API.
shawnbot commentedon May 10, 2018
@morgs32 We've certainly found a workaround, but I predict that many Lerna users will eventually run into a wall with
lerna publish.Stepping back, I think the underlying problem is really just the inability to inspect the state of your packages (in git or otherwise) before you hit the metaphorical "publish" button. When I run☹️
npm version patch, I can check to make sure thatpackage.jsonwas updated to the version I expected and that the corresponding git tag was created. I can't do that with Lerna, and with dozens of packages to manage, that heightens my "publish anxiety".morgs32 commentedon May 10, 2018
Hmm. To me,
lerna publish --skip-npmis the equivalent? Packages get incremented. Git tags created. What am I missing?shawnbot commentedon May 10, 2018
How do you publish after that? IIRC, if you run
lerna publishagain it'll bail because there aren't any changes to trigger version bumps. So you need to runlerna exec npm publish, but that will bail if it hits a package that hasn't changed since the last publish.IMO, it's confusing that there are many Lerna subcommands with presumably equivalent
npmcommands (init,link,ls,publish, andrun) but noversioncommand, and apublishthat behaves so very differently.morgs32 commentedon May 10, 2018
I agree on both counts.
As for wanting to run
lerna publishagain after the--skip-npm, I don't think you should have to. I figured if you were wanting to see the version bumps and git tags you were doing that locally. In which casegit reset --hard HEAD~?If you're in a CI pipeline what's the use for
--skip-npm?shawnbot commentedon May 10, 2018
I guess
lerna publish --skip-npmfeels like a hack in that case. At least in our case (Primer), it would be a lot more straightforward to be able to:lerna versionmanually, e.g. on a release branch, and inspect the resulting version bumps, update the changelog, etc.lerna publishon CI when the release branch merges tomaster.Instead, we a hodgepodge of scripts to simulate that workflow: a
bumpnpm run-script that runslerna publish --skip-nm, areleasescript that runslerna exec -- try-publish, and atry-publishscript that only callsnpm publishif the version of each package isn't already published.And sure, it works, but it's an awful lot of boilerplate for us to have to maintain.
evocateur commentedon May 11, 2018
I agree that the two should be split. I got started on it a couple weeks ago, but then I stalled (pesky day job/infant son): master...evocateur:split-version-from-publish
Historically, I'm fairly certain
lerna publishconflatesnpm versionandnpm publishbecause that's exactly whatyarn publishdoes, andlerna publishwas created by the creator ofyarn. (Again, I disagree with that design decision, it's just ...a big piece of code...)danielo515 commentedon May 11, 2018
Thanks @shawnbot for that piece of gods bless. One of the main problems at our company is publish conflicts. I wish Lerna can handle those, but meanwhile your scripts seems like a good workaround.
shawnbot commentedon May 11, 2018
Whoa @evocateur, congrats! I've got a 7mo and a 3yo... it's a lot.
Anyway, I and my GitHub peeps are more than happy to help out if we can; just give a shout! ✌️
feat: Split `lerna version` from of `lerna publish` (#1522)
shawnbot commentedon Jul 27, 2018
✨ ❤️
feat: Split `lerna version` from of `lerna publish` (lerna#1522)
lock commentedon Dec 27, 2018
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.