You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
lerna to publish packages with their current version #1056
How do I tell lerna to publish packages with their current version?
Now lerna is always trying to increase the version of packages ...
I need this because I want to divide the publication process into 2 stages:
First I want to manually raise the package version only in git in dialog mode: lerna publish --skip-npm
Only then with the help of CI I want to publish in npm: lerna publish --skip-git
I do not need to raise the version twice.
My Environment
Executable
Version
lerna --version
2.2.0
npm --version
5.4.2
node --version
v6.11.2
OS
Version
Windows 10 Pro
1703
Reacted by Alex Rybakov, Josh Crowther, Scotty Vernon, Morten A. Bentsen, Nupur Kapoor, Bogdan Plieshka, Alasdair McLeay, Alex Shyba, Michael Cousins, Rhy Moore and 6 more
I want lerna to use the package.json version number to publish without having to bump it since it was already bumped manually by the developer.
In my case, CI doesn't know if it's a breaking change or not, so I expect the developer to do this. So I would use the --yes flag but wouldn't wan't the prompt to ask me what version I want to release. When the branch is merged to master, that's when I expect lerna to just use the version in package.json to publish without new commits.
Something like this would be a nice feature:
package.json: { "name": "mypackage", "version": "0.0.2", }
This command: lerna publish --repo-version-exact
would publish version 0.0.2 without bumping the version
Reacted by Khristinin Nikita, Luca Carangella, Fiona, Scotty Vernon, Maciej Gurban, Helielson, Santosh G, Jakub Strojewski and iamawebgeek
If your CI has ways of indicating when a tag has been created, lerna exec -- npm publish (after bootstrap) would accomplish this. Instead of making lerna publish more complicated, I'd rather focus on making --conventional-commits more useful/robust for the automated publishing in CI use-case.
lerna exec -- npm publish wouldn't work when one or more of the packages are private. lerna publish respects private packages, however npm publish does not and results in an exit 1 error. I have a few "workspaces" that are bootstrapped by Lerna (local symlinked dependencies), but aren't intended to be published to npm.
Ideally, CI would run a lerna publish with some args that would just push to an npm registry without altering version numbers or affecting change logs.
I've scoured the issues section of Lerna, but have really struggled to find a proper answer for cleanly setting up Lerna with a monorepo in CI.
Because Lerna insists on bumping the package.json regardless of what args are passed, it results in a messy CI integration. If you push changes back to git (package.json, changelogs etc), it then triggers a subsequent build.
Ideally Lerna would have a --ci mode or something that just disabled altering any files within the git repo. So it would just push to npm, and push tags back to git?
Anything more triggers further unnecessary builds. The developer can run the changelog part of lerna lerna publish --skip-npm --skip-git --conventional-commits before pushing to github.
Thoughts?
Reacted by Morten A. Bentsen, azu, Alasdair McLeay, mike douges, Matthew Davidson and Jakub Strojewski
@unregistered I was thinking of implementing a from-git value of the --cd-version option, similar to npm version's positional value of the same name. It would throw if the current commit wasn't tagged, of course. Pull out the paths to publish from git show HEAD --name-only --pretty=format:%D -- packages/*/package.json (adding appropriate package location globs as necessary), and jumping straight to the publish loop.
lerna publish --cd-version from-git
btw, --no-private was added in v3.0.0-beta.1, so now lerna exec -- npm publish could skip packages with "private": true set in their package.json.
@evocateur can you clarify what the tag should be for an independently versioned repo? Wouldn't it have to contain the name of the package that's being published?
I think that feature you mentioned might work, just trying to wrap my head around it.
To clarify we publish on every commit we squash to master, but when a commit changes only one package it's wasteful to publish the other 80 packages (and dishonest too, since the patch-level gets bumped but there are no changes).
Edit: I played around with yarn lerna publish --skip-npm --conventional-commits and it works the way I want. It tags packages like @org/[email protected], and when it creates git tags, it only updates versions of packages that change. So that's pretty neat.
You would also need to pass --yes to the command in CI, of course, otherwise it would break due to hanging prompt. Here's some sketches of output and expected response:
# independent mode with valid tags
$ git show HEAD --name-only --pretty=format:%D -- packages/*/package.json
tag: @scope/[email protected], tag: [email protected]
packages/package-1/package.json
packages/package-2/package.json
In independent mode, the tags themselves are valid arguments to npm-package-arg, and we can map the names back to our internal Package objects. Pretty straightforward.
# fixed mode with valid tag
$ git show HEAD --name-only --pretty=format:%D -- packages/*/package.json
tag: v1.8.0
packages/package-1/package.json
packages/package-2/package.json
Fixed mode is a bit more wrinkly, requiring reverse lookups by pkg.manifestLocation of the list of modified package.json files. Not too terribly difficult, really (except maybe windows because windows sucks).
# no tags found, return no-op with appropriate logging
$ git show HEAD --name-only --pretty=format:%D -- packages/*/package.json
# empty string
I figure throwing is not what we want, it should just behave the same as the "no changes found" case, which is just to exit.
To be clear, this would also pretty much require #961, using lerna version instead of the wonky-looking lerna publish --skip-npm.
If it's desired to be completely automated, you'll need to use --conventional-commits. What exactly is "awkward" about that option in a CI context? The changelog generation?
@evocateur It's a bit of a pain to get the auto-generated commit and tags sent back to the master branch, since we have branch protection on, commits only enter master through PRs. Not sure what the recommended pattern for that is, I may just be doing something unusual.
Sounds like you want semantic-release, but with monorepo-awareness. Unfortunately, there isn't great support for that scenario right now. It's something I would definitely like to get to, though.
This sounds like exactly what we need for our project but unfortunately there's still one major issue:
If some packages have been updated but others haven't, this will fail as npm publish will be run on all packages, even those that haven't changed, and throw an error:
You cannot publish over the previously published versions
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.
Activity
yairkukielka commentedon Oct 10, 2017
I want lerna to use the package.json version number to publish without having to bump it since it was already bumped manually by the developer.
In my case, CI doesn't know if it's a breaking change or not, so I expect the developer to do this. So I would use the --yes flag but wouldn't wan't the prompt to ask me what version I want to release. When the branch is merged to master, that's when I expect lerna to just use the version in package.json to publish without new commits.
Something like this would be a nice feature:
package.json:
{ "name": "mypackage", "version": "0.0.2", }This command:
lerna publish --repo-version-exactwould publish version 0.0.2 without bumping the version
evocateur commentedon Nov 15, 2017
If your CI has ways of indicating when a tag has been created,
lerna exec -- npm publish(after bootstrap) would accomplish this. Instead of makinglerna publishmore complicated, I'd rather focus on making--conventional-commitsmore useful/robust for the automated publishing in CI use-case.KingScooty commentedon Nov 29, 2017
lerna exec -- npm publishwouldn't work when one or more of the packages are private.lerna publishrespects private packages, howevernpm publishdoes not and results in an exit 1 error. I have a few "workspaces" that are bootstrapped by Lerna (local symlinked dependencies), but aren't intended to be published to npm.Ideally, CI would run a
lerna publishwith some args that would just push to an npm registry without altering version numbers or affecting change logs.I've scoured the issues section of Lerna, but have really struggled to find a proper answer for cleanly setting up Lerna with a monorepo in CI.
Because Lerna insists on bumping the package.json regardless of what args are passed, it results in a messy CI integration. If you push changes back to git (package.json, changelogs etc), it then triggers a subsequent build.
Ideally Lerna would have a
--cimode or something that just disabled altering any files within the git repo. So it would just push to npm, and push tags back to git?Anything more triggers further unnecessary builds. The developer can run the changelog part of lerna
lerna publish --skip-npm --skip-git --conventional-commitsbefore pushing to github.Thoughts?
azu commentedon Jan 24, 2018
I've created can-npm-publish CLI.
It will help
lerna exec npm publishpattern.unregistered commentedon Mar 9, 2018
@evocateur Is there interest in a PR for this? Conventional commits seems kind of awkward when using lerna in Independent mode.
evocateur commentedon Mar 9, 2018
@unregistered I was thinking of implementing a
from-gitvalue of the--cd-versionoption, similar tonpm version's positional value of the same name. It would throw if the current commit wasn't tagged, of course. Pull out the paths to publish fromgit show HEAD --name-only --pretty=format:%D -- packages/*/package.json(adding appropriate package location globs as necessary), and jumping straight to the publish loop.btw,
--no-privatewas added in v3.0.0-beta.1, so nowlerna exec -- npm publishcould skip packages with"private": trueset in their package.json.unregistered commentedon Mar 9, 2018
@evocateur can you clarify what the tag should be for an independently versioned repo? Wouldn't it have to contain the name of the package that's being published?
I think that feature you mentioned might work, just trying to wrap my head around it.
To clarify we publish on every commit we squash to master, but when a commit changes only one package it's wasteful to publish the other 80 packages (and dishonest too, since the patch-level gets bumped but there are no changes).
Edit: I played around with
yarn lerna publish --skip-npm --conventional-commitsand it works the way I want. It tags packages like@org/[email protected], and when it creates git tags, it only updates versions of packages that change. So that's pretty neat.evocateur commentedon Mar 9, 2018
You would also need to pass
--yesto the command in CI, of course, otherwise it would break due to hanging prompt. Here's some sketches of output and expected response:In independent mode, the tags themselves are valid arguments to
npm-package-arg, and we can map the names back to our internal Package objects. Pretty straightforward.Fixed mode is a bit more wrinkly, requiring reverse lookups by
pkg.manifestLocationof the list of modified package.json files. Not too terribly difficult, really (except maybe windows because windows sucks).I figure throwing is not what we want, it should just behave the same as the "no changes found" case, which is just to exit.
evocateur commentedon Mar 9, 2018
To be clear, this would also pretty much require #961, using
lerna versioninstead of the wonky-lookinglerna publish --skip-npm.If it's desired to be completely automated, you'll need to use
--conventional-commits. What exactly is "awkward" about that option in a CI context? The changelog generation?unregistered commentedon Mar 10, 2018
@evocateur It's a bit of a pain to get the auto-generated commit and tags sent back to the master branch, since we have branch protection on, commits only enter master through PRs. Not sure what the recommended pattern for that is, I may just be doing something unusual.
evocateur commentedon Mar 10, 2018
Sounds like you want
semantic-release, but with monorepo-awareness. Unfortunately, there isn't great support for that scenario right now. It's something I would definitely like to get to, though.penx commentedon Mar 19, 2018
This sounds like exactly what we need for our project but unfortunately there's still one major issue:
If some packages have been updated but others haven't, this will fail as
npm publishwill be run on all packages, even those that haven't changed, and throw an error:morgs32 commentedon Mar 19, 2018
@penx what about the package from @azu.
Could that help you?
#1056 (comment)
azu commentedon Jul 22, 2018
Also, I've created @monorepo-utils/publish.
This script publish packages that are publish-able. (It wrap can-npm-publish.)
Just replace
to
feat: Split `lerna version` from of `lerna publish` (#1522)
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.