Skip to content
Snippets Groups Projects
Unverified Commit 1bd51a37 authored by Étienne Lévesque's avatar Étienne Lévesque Committed by GitHub
Browse files

fix(hex): Preserve minor versions when in bump mode (#8326)


* feat(hex): Preserve minor versions when in bump mode

* Fix linting issue

* Add minor test

Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 9bffbb6e
No related branches found
No related tags found
No related merge requests found
......@@ -128,7 +128,15 @@ describe('lib/versioning/hex', () => {
fromVersion: '1.2.3',
toVersion: '2.0.7',
})
).toEqual('~> 2');
).toEqual('~> 2.0');
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2',
rangeStrategy: 'bump',
fromVersion: '1.2.3',
toVersion: '1.3.1',
})
).toEqual('~> 1.3');
expect(
hexScheme.getNewValue({
currentValue: '~> 1.2.0',
......
......@@ -69,10 +69,16 @@ const getNewValue = ({
toVersion,
});
newSemver = npm2hex(newSemver);
if (/~>\s*(\d+\.\d+)$/.test(currentValue)) {
if (/~>\s*(\d+\.\d+\.\d+)$/.test(currentValue)) {
newSemver = newSemver.replace(
/\^\s*(\d+\.\d+(\.\d)?)/,
(_str, p1: string) => `~> ${p1.slice(0, -2)}`
/[\^~]\s*(\d+\.\d+\.\d+)/,
(_str, p1: string) => `~> ${p1}`
);
} else if (/~>\s*(\d+\.\d+)$/.test(currentValue)) {
newSemver = newSemver.replace(
/\^\s*(\d+\.\d+)/,
(_str, p1: string) =>
`~> ${rangeStrategy !== 'bump' ? p1.slice(0, -2) : p1}`
);
} else {
newSemver = newSemver.replace(/~\s*(\d+\.\d+\.\d)/, '~> $1');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment