Skip to content

lerna to publish packages with their current version #1056

Closed

Description

@RinatMullayanov

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:

  1. First I want to manually raise the package version only in git in dialog mode:
    lerna publish --skip-npm
  2. 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

Activity

  1. yairkukielka commented on Oct 10, 2017

    @yairkukielka

    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

  2. evocateur commented on Nov 15, 2017

    @evocateur
    Member

    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.

  3. KingScooty commented on Nov 29, 2017

    @KingScooty

    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?

  4. azu commented on Jan 24, 2018

    @azu
    Contributor

    lerna exec -- npm publish wouldn't work when one or more of the packages are private. lerna publish respects private packages

    I've created can-npm-publish CLI.
    It will help lerna exec npm publish pattern.

    lerna exec --bail=false can-npm-publish && npm publish
    
  5. unregistered commented on Mar 9, 2018

    @unregistered

    @evocateur Is there interest in a PR for this? Conventional commits seems kind of awkward when using lerna in Independent mode.

  6. evocateur commented on Mar 9, 2018

    @evocateur
    Member

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

  7. unregistered commented on Mar 9, 2018

    @unregistered

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

  8. evocateur commented on Mar 9, 2018

    @evocateur
    Member

    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.

  9. evocateur commented on Mar 9, 2018

    @evocateur
    Member

    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?

  10. unregistered commented on Mar 10, 2018

    @unregistered

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

  11. evocateur commented on Mar 10, 2018

    @evocateur
    Member

    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.

  12. penx commented on Mar 19, 2018

    @penx

    lerna exec --no-private -- npm publish

    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
    
  13. morgs32 commented on Mar 19, 2018

    @morgs32

    @penx what about the package from @azu.
    Could that help you?
    #1056 (comment)

  14. azu commented on Jul 22, 2018

    @azu
    Contributor

    Also, I've created @monorepo-utils/publish.
    This script publish packages that are publish-able. (It wrap can-npm-publish.)

    Just replace

    $ lerna exec --bail=false can-npm-publish && npm publish
    

    to

    $ monorepo-utils-publish
    
  15. added a commit that references this issue on Jul 27, 2018
    8b97394
  16. added a commit that references this issue on Dec 18, 2018
    79dd10f
  17. lock commented on Dec 27, 2018

    @lock

    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.

  18. locked as resolved and limited conversation to collaborators on Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions