Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lerna updates all packages with every publish #2487

Closed
0livare opened this issue Mar 9, 2020 · 12 comments · Fixed by #2488
Closed

Lerna updates all packages with every publish #2487

0livare opened this issue Mar 9, 2020 · 12 comments · Fixed by #2488

Comments

@0livare
Copy link
Contributor

0livare commented Mar 9, 2020

Expected Behavior

Lerna should only update packages that have changed. From the README:

When you run lerna publish, if a module has been updated since the last time a release was made, it will be updated to the new version you're releasing. This means that you only publish a new version of a package when you need to.

Current Behavior

Instead of only updating packages that have changed, lerna updates every package with every change.

Both lerna updated and lerna changed return the correct result. Changing only a single package only displays changes from that package and packages that depend on that package.

Steps to Reproduce (for bugs)

  1. Clone this repository: https://github.com/zposten/lerna-all-update
  2. On the master branch, run lerna updated or lerna changed. Notice that only two @test/checkbox and the one package that depends on checkbox are shown to be updated (this is correct behavior).
  3. Now run lerna publish, choose "patch", and see that it lists every package in the repository as changed, when only two packages should have changed:
Changes:
 - demo: 0.0.19 => 0.0.20 (private)
 - @test/button: 0.0.19 => 0.0.20
 - @test/card: 0.0.19 => 0.0.20
 - @test/checkbox: 0.0.19 => 0.0.20
 - @test/components-web: 0.0.19 => 0.0.20
 - @test/date-picker: 0.0.19 => 0.0.20
 - @test/form-field: 0.0.19 => 0.0.20
 - @test/global: 0.0.19 => 0.0.20
lerna.json

{
  "version": "0.0.19",
  "packages": [
    "packages/*"
  ],
  "npmClient": "yarn",
  "useWorkspaces": true
}

Context

Your Environment

Executable Version
lerna --version 3.20.2
npm --version 6.4.1
yarn --version 1.17.3
node --version v10.15.3
OS Version
macOS Mojave 10.14.6
@revelt
Copy link
Contributor

revelt commented Mar 9, 2020

Looking at your lerna.json:

{
"version": "0.0.19",
"packages": [
"packages/*"
],
"npmClient": "yarn",
"useWorkspaces": true
}

I noticed there are no ignoreChanges field. For example, myself, I use:

{
  "command": {
    "publish": {
      "conventionalCommits": true,
      "message": "[skip ci] chore: release"
    }
  },
  "ignoreChanges": [
    "**/CHANGELOG.md",
    "**/node_modules/**",
    "**/package.json",
    "**/*.md",
    "**/perf/**"
  ],
  "lifecycle": {
    "version": "npm run build && git add ."
  },
  "packages": [
    "packages/*"
  ],
  "version": "independent"
}

Please try to add copious ignoreChanges (add package.json and changelog and anything else you can imagine, anything that could theoretically mutate during publishing) and let us know how it went.

I'd rule out ignoreChanges first.

@0livare
Copy link
Contributor Author

0livare commented Mar 10, 2020

Great idea! I didn't know that this field existed. It doesn't seem to solve the problem however.

In my example repo, I added a file to the @test/button package. Again, both lerna updated and lerna changed show that only @test/button, and the one package that depends directly on that package have changed, which makes sense. (Both the "ignoreChanges" and this new file are both now reflected in the master branch)

However, when I try to publish, lerna still insists that I publish every package. I don't even have a build (or any source files) in this project that I think could possibly be mutating to create a confusing diff.

@revelt
Copy link
Contributor

revelt commented Mar 10, 2020

Can it be that versioning is not set to be independent? The "version": "independent" I use instructs Lerna to bump only "affected" packages, not all, see https://github.com/lerna/lerna#fixedlocked-mode-default

@0livare
Copy link
Contributor Author

0livare commented Mar 10, 2020

A teammate brought up that same point to me. But my understanding from the documentation is that even in fixed version mode, only the packages that have changed should be updated.

From, the Fixed/Locked mode section of the README:

When you run lerna publish, if a module has been updated since the last time a release was made, it will be updated to the new version you're releasing. This means that you only publish a new version of a package when you need to.

I don't want every package to be published every time (that's just a waste of space on the package server), but what I do want is all packages that are updated to get the same new version number, even if that version number skips because that package hasn't been updated in awhile.

@revelt
Copy link
Contributor

revelt commented Mar 10, 2020

That's basically a mix of two systems... But that's not possible. Because in that case, if, in theory some "untouched" packages would be left on an old versions, the versioning would diverge — it would become "Independent" mode. The idea of "Fixed" is that all packages in monorepo have the same version, no matter what.

@0livare
Copy link
Contributor Author

0livare commented Mar 10, 2020

So are you saying that the README section I quoted above is incorrect?

@revelt
Copy link
Contributor

revelt commented Mar 10, 2020

I was wrong. You're right. It's something else then.

A quick shot, can it be that in semver, in pre-v1, all versions count as breaking? Hypothesis being that if demo repo versions were at least v1 minor/patch bumps would not breaking and would not bump all? I can't find a reference quickly...

@0livare
Copy link
Contributor Author

0livare commented Mar 10, 2020

Huh! That seems to work in my example repo. Interesting, I had never heard of such a convention, thank you for pointing it out!

If you don't mind, I would like a little time to test this in an actual repository to see if I can get the same result.

@0livare
Copy link
Contributor Author

0livare commented Mar 10, 2020

That totally worked! Wow that's a relief. Thank you again.

Do you think it would be worth adding a note to that fixed/locked section of the README to warn people about that?

@revelt
Copy link
Contributor

revelt commented Mar 10, 2020

Yeah, are you happy to raise an MR?

@0livare
Copy link
Contributor Author

0livare commented Mar 10, 2020

Absolutely!

@livingrockrises
Copy link

Hey all, the way "version": "independent" works is I believe, it creates tag for every package and pushes it on github (if below flags are not used --no-git-tag-version --no-push)

so in order for this to work and only bump up updated packages I need to remove flag -no-git-tag-version which creates a big problem by pushing lot of tags every time on github for all packages.

What we want is bump up the version of only changed packages and create a release tag (for example r1) for that particular publish cycle. so using lerna version only for appropriate bumping of package versioning and changelog.

How can this be done in the best way?
Appreciate your advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants