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
fix(version): Resolve prerelease for version without bump #2041
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect https://github.com/lerna/lerna/blob/master/commands/version/__tests__/version-bump-prerelease.test.js to be somewhere that this sort of TDD could be established before making changes to the command implementation.
|
||
const getExistingPreId = version => (semver.prerelease(version) || []).shift(); | ||
const resolvePrereleaseId = existingPreid => preid || (isPrerelease && existingPreid) || "alpha"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is certainly distressing that removing this inline conditional doesn't break any tests. The prompting is very poorly tested, I'll be the first to admit.
I would expect a modification to makePromptVersion
's arguments to be necessary to establish the correct preid
in the dialog, at the very least. I think the best way to write the tests is to do them first, before changing this code, just so we can establish what fails in the current context. Without that, I really can't say if this is the right approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll revert locally and poke around with the tests to try to find the use case that relies on the isPrerelease
conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been looking at this a bit and I think that the isPrerelease
condition is a no-op.
The result of resolvePrereleaseId
function is the identifier passed as the third argument to semver.inc
. The identifier is only used when the second argument is a pre___
type; for major
, minor
, and patch
releases, the identifier is ignored.
If the condition is removed, a failing test would happen when isPrerelease
is false and existingPreid
is not undefined
; the third argument to semver.inc
would be existingPreid
instead of alpha
. However, since the value returned by resolvePrereleaseId
is never used if isPrerelease
is false, the value doesn't actually matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, of course. Thanks for taking the time to explain it in detail. I verified it locally with this change:
--- a/commands/version/__tests__/version-bump-prerelease.test.js
+++ b/commands/version/__tests__/version-bump-prerelease.test.js
@@ -152,8 +152,8 @@ test("independent version prerelease does not bump on every unrelated change", a
// simulate choices for pkg-a then pkg-b
prompt.mockChoices("patch", "PRERELEASE");
prompt.input.mockImplementationOnce((msg, cfg) =>
- // a convoluted way of entering "bumps" at the prompt
- Promise.resolve(cfg.filter("bumps"))
+ // the _existing_ "bumps" prerelease ID should be preserved
+ Promise.resolve(cfg.filter())
);
await lernaVersion(cwd)();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the test once this is merged. Thanks again!
Fixes #2025
Description
This PR modifies the
resolvePrereleaseId
function to use the package's prerelease identifier as the default identifier when it exists, not only when when thebump
CLI arg is an increment keyword.Motivation and Context
Currently, the existing prerelease identifier is only used when
lerna version
is provided an increment bump. This means that if the current version is1.0.0-beta.2
, the "Custom Prerelease" prompt's default value isalpha
.How Has This Been Tested?
I ran the existing tests, but haven't added any new ones yet. I was looking at the tests in
prompt-version.test.js
, but those use a customresolvePrereleaseId
function. I'd be happy to add a test, but I'm not sure what the best way to test theresolvePrereleaseId
function created ingetVersionsForUpdates
is.I'm not actually sure why the
isPrerelease
check exists, so I'm not sure if removing it will break anything. I didn't have any luck tracing the code's history (it was introduced in #1522) to see why it was originally added.Types of changes
Checklist: