feat: support semver equals (=)

Adds support for upgrading equals values, e.g. from `=1.0.0` to `=1.0.1`.
This commit is contained in:
Rhys Arkins 2018-06-03 21:16:57 +02:00
parent 549b12529f
commit 24e341b5b4
4 changed files with 22 additions and 5 deletions

View file

@ -111,8 +111,7 @@ async function extractDependencies(content, packageFile, config) {
depName, depName,
versionScheme: 'semver', versionScheme: 'semver',
}; };
// TODO: do we need to remove the equals? dep.currentVersion = version.trim();
dep.currentVersion = version.trim().replace(/^=/, '');
if (depType === 'engines') { if (depType === 'engines') {
if (depName === 'node') { if (depName === 'node') {
dep.purl = 'pkg:github/nodejs/node?clean=true'; dep.purl = 'pkg:github/nodejs/node?clean=true';

View file

@ -49,6 +49,9 @@ function rangify(config, currentVersion, fromVersion, toVersion) {
if (element.operator === '~') { if (element.operator === '~') {
return `~${toVersion}`; return `~${toVersion}`;
} }
if (element.operator === '=') {
return `=${toVersion}`;
}
if (element.operator === '>=') { if (element.operator === '>=') {
return currentVersion.includes('>= ') return currentVersion.includes('>= ')
? `>= ${toVersion}` ? `>= ${toVersion}`
@ -75,6 +78,9 @@ function rangify(config, currentVersion, fromVersion, toVersion) {
} }
return `^${major(toVersion)}.0.0`; return `^${major(toVersion)}.0.0`;
} }
if (element.operator === '=') {
return `=${toVersion}`;
}
if (element.operator === '~') { if (element.operator === '~') {
return `~${major(toVersion)}.${minor(toVersion)}.0`; return `~${major(toVersion)}.${minor(toVersion)}.0`;
} }

View file

@ -122,7 +122,7 @@ Object {
"versionScheme": "semver", "versionScheme": "semver",
}, },
Object { Object {
"currentVersion": "0.22.0", "currentVersion": "=0.22.0",
"depName": "cheerio", "depName": "cheerio",
"depType": "dependencies", "depType": "dependencies",
"purl": "pkg:npm/cheerio", "purl": "pkg:npm/cheerio",
@ -231,7 +231,7 @@ Object {
"versionScheme": "semver", "versionScheme": "semver",
}, },
Object { Object {
"currentVersion": "0.22.0", "currentVersion": "=0.22.0",
"depName": "cheerio", "depName": "cheerio",
"depType": "dependencies", "depType": "dependencies",
"purl": "pkg:npm/cheerio", "purl": "pkg:npm/cheerio",
@ -320,7 +320,7 @@ Object {
"versionScheme": "semver", "versionScheme": "semver",
}, },
Object { Object {
"currentVersion": "0.22.0", "currentVersion": "=0.22.0",
"depName": "cheerio", "depName": "cheerio",
"depType": "dependencies", "depType": "dependencies",
"purl": "pkg:npm/cheerio", "purl": "pkg:npm/cheerio",

View file

@ -37,3 +37,15 @@ describe('semver.isRange(input)', () => {
expect(!!semver.isRange('^1.2.3')).toBe(true); expect(!!semver.isRange('^1.2.3')).toBe(true);
}); });
}); });
describe('semver.rangify()', () => {
it('bumps equals', () => {
expect(
semver.rangify({ rangeStrategy: 'bump' }, '=1.0.0', '1.0.0', '1.1.0')
).toEqual('=1.1.0');
});
it('replaces equals', () => {
expect(
semver.rangify({ rangeStrategy: 'replace' }, '=1.0.0', '1.0.0', '1.1.0')
).toEqual('=1.1.0');
});
});