Skip to content

Commit

Permalink
feat: support composer stability modifiers (#6050)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainweb committed Apr 25, 2020
1 parent 5ea984e commit a7b0520
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/versioning/composer/index.spec.ts
Expand Up @@ -12,6 +12,11 @@ describe('semver.equals(a, b)', () => {
it('should pad really short version', () => {
expect(semver.equals('v1.0.0', '1')).toBe(true);
});
it('should translate stability modifier', () => {
expect(semver.equals('1.0@alpha3', '1.0.0-alpha.3')).toBe(true);
expect(semver.equals('1.0@beta', '1.0.0-beta')).toBe(true);
expect(semver.equals('1.0@rc2', '1.0.0-rc.2')).toBe(true);
});
});
describe('semver.isGreaterThan(a, b)', () => {
it('should pad short version', () => {
Expand Down
11 changes: 11 additions & 0 deletions lib/versioning/composer/index.ts
Expand Up @@ -26,6 +26,15 @@ function removeLeadingV(input: string): string {
return input.replace(/^v/i, '');
}

function composerStability2npm(input: string): string {
const sections = input.split('@');
if (sections.length == 1) {
return input
}
const stability = sections[1].replace(/(?:^|\s)(beta|alpha|rc)([1-9][0-9]*)(?: |$)/gi, '$1.$2');
return sections[0] + '-' + stability;
}

function composer2npm(input: string): string {
const cleanInput = removeLeadingV(input);
if (npm.isVersion(cleanInput)) {
Expand All @@ -39,6 +48,8 @@ function composer2npm(input: string): string {
output = output.replace(/(?:^|\s)~([1-9][0-9]*(?:\.[0-9]*)?)(?: |$)/g, '^$1');
// ~0.4 to >=0.4 <1
output = output.replace(/(?:^|\s)~(0\.[1-9][0-9]*)(?: |$)/g, '>=$1 <1');
// 1.0@beta2 to 1.0-beta.2
output = composerStability2npm(output);
return output;
}

Expand Down

0 comments on commit a7b0520

Please sign in to comment.