Skip to content
Snippets Groups Projects
Unverified Commit 6bf18be2 authored by Sergio Zharinov's avatar Sergio Zharinov Committed by GitHub
Browse files

fix: Don't modify git-tags datasource results (#5251)


Co-authored-by: default avatarJared Kauppila <Jared@Kauppi.la>
parent 1d9a9873
Branches
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ export async function getPkgReleases({ ...@@ -36,7 +36,7 @@ export async function getPkgReleases({
const result: ReleaseResult = { const result: ReleaseResult = {
sourceUrl, sourceUrl,
releases: tags.map(tag => ({ releases: tags.map(tag => ({
version: semver.isValid(tag), version: tag,
gitRef: tag, gitRef: tag,
})), })),
}; };
......
...@@ -12,13 +12,14 @@ function padZeroes(input: string): string { ...@@ -12,13 +12,14 @@ function padZeroes(input: string): string {
} }
function composer2npm(input: string): string { function composer2npm(input: string): string {
if (npm.isVersion(input)) { const cleanInput = input.replace(/^v/, '');
return input; if (npm.isVersion(cleanInput)) {
return cleanInput;
} }
if (npm.isVersion(padZeroes(input))) { if (npm.isVersion(padZeroes(cleanInput))) {
return padZeroes(input); return padZeroes(cleanInput);
} }
let output = input; let output = cleanInput;
// ~4 to ^4 and ~4.1 to ^4.1 // ~4 to ^4 and ~4.1 to ^4.1
output = output.replace(/(?:^|\s)~([1-9][0-9]*(?:\.[0-9]*)?)(?: |$)/g, '^$1'); output = output.replace(/(?:^|\s)~([1-9][0-9]*(?:\.[0-9]*)?)(?: |$)/g, '^$1');
// ~0.4 to >=0.4 <1 // ~0.4 to >=0.4 <1
......
...@@ -24,9 +24,15 @@ export const isValid = (input: string): boolean => ...@@ -24,9 +24,15 @@ export const isValid = (input: string): boolean =>
!!valid(input) || !!validRange(toSemverRange(input)); !!valid(input) || !!validRange(toSemverRange(input));
export const isVersion = (input: string): boolean => !!valid(input); export const isVersion = (input: string): boolean => !!valid(input);
const maxSatisfyingVersion = (versions: string[], range: string): string => const maxSatisfyingVersion = (versions: string[], range: string): string =>
maxSatisfying(versions, toSemverRange(range)); maxSatisfying(
versions.map(v => v.replace(/^v/, '')),
toSemverRange(range)
);
const minSatisfyingVersion = (versions: string[], range: string): string => const minSatisfyingVersion = (versions: string[], range: string): string =>
minSatisfying(versions, toSemverRange(range)); minSatisfying(
versions.map(v => v.replace(/^v/, '')),
toSemverRange(range)
);
const isLessThanRange = (version: string, range: string): boolean => const isLessThanRange = (version: string, range: string): boolean =>
ltr(version, toSemverRange(range)); ltr(version, toSemverRange(range));
const matches = (version: string, range: string): boolean => const matches = (version: string, range: string): boolean =>
......
...@@ -36,7 +36,7 @@ function toSemverRange(range: string): string { ...@@ -36,7 +36,7 @@ function toSemverRange(range: string): string {
function getNewValue({ currentValue, toVersion }: NewValueConfig): string { function getNewValue({ currentValue, toVersion }: NewValueConfig): string {
if (fromParam.test(currentValue)) { if (fromParam.test(currentValue)) {
return toVersion; return toVersion.replace(/^v/, '');
} }
if (fromRange.test(currentValue)) { if (fromRange.test(currentValue)) {
const [, version] = currentValue.match(fromRange); const [, version] = currentValue.match(fromRange);
......
...@@ -41,7 +41,7 @@ describe('datasource/git-tags', () => { ...@@ -41,7 +41,7 @@ describe('datasource/git-tags', () => {
lookupName, lookupName,
}); });
const result = versions.releases.map(x => x.version).sort(); const result = versions.releases.map(x => x.version).sort();
expect(result).toEqual(['0.0.1', '0.0.2']); expect(result).toEqual(['0.0.1', 'v0.0.2']);
}); });
}); });
}); });
...@@ -75,6 +75,12 @@ describe('semver.maxSatisfyingVersion()', () => { ...@@ -75,6 +75,12 @@ describe('semver.maxSatisfyingVersion()', () => {
'~4' '~4'
) )
).toBe('4.2.0'); ).toBe('4.2.0');
expect(
semver.maxSatisfyingVersion(
['v0.4.0', 'v0.5.0', 'v4.0.0', 'v4.2.0', 'v5.0.0'],
'~4'
)
).toBe('4.2.0');
expect( expect(
semver.maxSatisfyingVersion( semver.maxSatisfyingVersion(
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'], ['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
...@@ -91,6 +97,12 @@ describe('semver.minSatisfyingVersion()', () => { ...@@ -91,6 +97,12 @@ describe('semver.minSatisfyingVersion()', () => {
'~4' '~4'
) )
).toBe('4.0.0'); ).toBe('4.0.0');
expect(
semver.minSatisfyingVersion(
['v0.4.0', 'v0.5.0', 'v4.0.0', 'v4.2.0', 'v5.0.0'],
'~4'
)
).toBe('4.0.0');
expect( expect(
semver.minSatisfyingVersion( semver.minSatisfyingVersion(
['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'], ['0.4.0', '0.5.0', '4.0.0', '4.2.0', '5.0.0'],
......
...@@ -38,6 +38,7 @@ describe('isValid(input)', () => { ...@@ -38,6 +38,7 @@ describe('isValid(input)', () => {
}); });
it('should support simple semver', () => { it('should support simple semver', () => {
expect(isValid('1.2.3')).toBe(true); expect(isValid('1.2.3')).toBe(true);
expect(isValid('v1.2.3')).toBe(true);
}); });
it('should support semver with dash', () => { it('should support semver with dash', () => {
expect(isValid('1.2.3-foo')).toBe(true); expect(isValid('1.2.3-foo')).toBe(true);
...@@ -58,22 +59,34 @@ describe('isValid(input)', () => { ...@@ -58,22 +59,34 @@ describe('isValid(input)', () => {
expect( expect(
minSatisfyingVersion(['1.2.3', '1.2.4', '1.2.5'], '..<"1.2.4"') minSatisfyingVersion(['1.2.3', '1.2.4', '1.2.5'], '..<"1.2.4"')
).toBe('1.2.3'); ).toBe('1.2.3');
expect(
minSatisfyingVersion(['v1.2.3', 'v1.2.4', 'v1.2.5'], '..<"1.2.4"')
).toBe('1.2.3');
expect( expect(
maxSatisfyingVersion(['1.2.3', '1.2.4', '1.2.5'], '..<"1.2.4"') maxSatisfyingVersion(['1.2.3', '1.2.4', '1.2.5'], '..<"1.2.4"')
).toBe('1.2.3'); ).toBe('1.2.3');
expect(
maxSatisfyingVersion(['v1.2.3', 'v1.2.4', 'v1.2.5'], '..<"1.2.4"')
).toBe('1.2.3');
expect( expect(
maxSatisfyingVersion(['1.2.3', '1.2.4', '1.2.5'], '..."1.2.4"') maxSatisfyingVersion(['1.2.3', '1.2.4', '1.2.5'], '..."1.2.4"')
).toBe('1.2.4'); ).toBe('1.2.4');
expect(isLessThanRange('1.2.3', '..."1.2.4"')).toBe(false); expect(isLessThanRange('1.2.3', '..."1.2.4"')).toBe(false);
expect(isLessThanRange('v1.2.3', '..."1.2.4"')).toBe(false);
expect(isLessThanRange('1.2.3', '"1.2.4"...')).toBe(true); expect(isLessThanRange('1.2.3', '"1.2.4"...')).toBe(true);
expect(isLessThanRange('v1.2.3', '"1.2.4"...')).toBe(true);
expect(matches('1.2.4', '..."1.2.4"')).toBe(true); expect(matches('1.2.4', '..."1.2.4"')).toBe(true);
expect(matches('v1.2.4', '..."1.2.4"')).toBe(true);
expect(matches('1.2.4', '..."1.2.3"')).toBe(false); expect(matches('1.2.4', '..."1.2.3"')).toBe(false);
expect(matches('v1.2.4', '..."1.2.3"')).toBe(false);
}); });
}); });
describe('getNewValue()', () => { describe('getNewValue()', () => {
it('supports range update', () => { it('supports range update', () => {
[ [
['1.2.3', 'auto', '1.2.3', '1.2.4', '1.2.3'], ['1.2.3', 'auto', '1.2.3', '1.2.4', '1.2.3'],
['v1.2.3', 'auto', 'v1.2.3', 'v1.2.4', 'v1.2.3'],
['from: "1.2.3"', 'auto', '1.2.3', '1.2.4', '1.2.4'], ['from: "1.2.3"', 'auto', '1.2.3', '1.2.4', '1.2.4'],
['"1.2.3"...', 'auto', '1.2.3', '1.2.4', '"1.2.4"...'], ['"1.2.3"...', 'auto', '1.2.3', '1.2.4', '"1.2.4"...'],
['"1.2.3"..."1.2.4"', 'auto', '1.2.3', '1.2.5', '"1.2.3"..."1.2.5"'], ['"1.2.3"..."1.2.4"', 'auto', '1.2.3', '1.2.5', '"1.2.3"..."1.2.5"'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment