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

Cannot spot the changed packages correctly when a custom version provided as command parameter #845

Open
5 tasks done
afshin-hoseini opened this issue Apr 18, 2024 · 1 comment

Comments

@afshin-hoseini
Copy link

Describe the bug

Lerna cannot detect changed packages when publishing with a custom version, provided as publish command's parameter. But can figure out when providing the same custom version using prompt.

Expectation

It should spot the changes the same way in either ways.

Reproduction

  • I got two packages ( pkg-a and pkg-b ), where pkg-b depends on pkg-a.
  • I published both of them with 10.3.0-ticket-1234-1 as version.
  • I apply some changes on pkg-b and commit it.
  • When I run npx lerna publish and then select the custom version option from the prompt, and input the next version as 10.3.0-ticket-1234-2, it identifies pkg-b as the only changed package, which is correct.
  • However, if I provide the version along with the command like npx lerna publish 10.3.0-ticket-1234-2, it cannot identify the changed packages correctly and wanna publish both pkg-a and pkg-b.

Lerna config and logs

lerna.json

{
  "$schema": "node_modules/lerna/schemas/lerna-schema.json",
  "version": "10.3.0-ticket-1234-1",
  "packages": [
    "packages/*"
  ]
}

Environment Info

  System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Pro
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.20 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Utilities:
    Git: 2.39.3 - /usr/bin/git
  npmPackages:
    lerna: 8.1.2 => 8.1.2 

Used Package Manager

npm

Validations

@ghiscoding
Copy link
Member

ghiscoding commented Apr 18, 2024

I think that is the default behavior of Lerna and it was added by the original author of Lerna

When providing a version, it's defined as a global version and I'm assuming it's for probably all packages (so I'm guessing it's falling under either line 438 or 441) and it seems to be using semver.inc for all packages. However when using prompt, as you mentioned, it will skip unchanged packages. So when comes the time to publish, the global version has more packages to publish.

These are all just assumptions, you should troubleshoot it yourself. I saw you've opened the same ticket on Lerna's project, we'll see if they ever reply.

if (repoVersion) {
predicate = makeGlobalVersionPredicate(applyBuildMetadata(repoVersion, this.options.buildMetadata));
} else if (increment && independentVersions) {
// compute potential prerelease ID for each independent update
predicate = (node: { version: string; prereleaseId: string }) =>
applyBuildMetadata(
semver.inc(node.version, increment, resolvePrereleaseId(node.prereleaseId)),
this.options.buildMetadata
);
} else if (increment) {
// compute potential prerelease ID once for all fixed updates
const prereleaseId = prereleaseIdFromVersion(this.project.version);
const nextVersion = applyBuildMetadata(
semver.inc(this.project.version, increment, resolvePrereleaseId(prereleaseId)),
this.options.buildMetadata
);
predicate = makeGlobalVersionPredicate(nextVersion as string);
} else if (conventionalCommits) {
// it's a bit weird to have a return here, true
return this.recommendVersions(resolvePrereleaseId);
} else if (independentVersions) {
// prompt for each independent update with potential prerelease ID
predicate = makePromptVersion(resolvePrereleaseId, this.options.buildMetadata);
} else {
// prompt once with potential prerelease ID
const prereleaseId = prereleaseIdFromVersion(this.project.version);
const node = { version: this.project.version, prereleaseId };
predicate = makePromptVersion(resolvePrereleaseId, this.options.buildMetadata);
predicate = predicate(node).then(makeGlobalVersionPredicate);
}
return Promise.resolve(predicate).then((getVersion: (s: PackageGraphNode) => string) => this.reduceVersions(getVersion));

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

No branches or pull requests

2 participants