From 24e341b5b4495c279172d0f40f4de418a140ce93 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Sun, 3 Jun 2018 21:16:57 +0200 Subject: [PATCH] feat: support semver equals (=) Adds support for upgrading equals values, e.g. from `=1.0.0` to `=1.0.1`. --- lib/manager/npm/extract/index.js | 3 +-- lib/versioning/semver/range.js | 6 ++++++ .../npm/extract/__snapshots__/index.spec.js.snap | 6 +++--- test/versioning/semver.spec.js | 12 ++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/manager/npm/extract/index.js b/lib/manager/npm/extract/index.js index 396f73beea..7130e5133a 100644 --- a/lib/manager/npm/extract/index.js +++ b/lib/manager/npm/extract/index.js @@ -111,8 +111,7 @@ async function extractDependencies(content, packageFile, config) { depName, versionScheme: 'semver', }; - // TODO: do we need to remove the equals? - dep.currentVersion = version.trim().replace(/^=/, ''); + dep.currentVersion = version.trim(); if (depType === 'engines') { if (depName === 'node') { dep.purl = 'pkg:github/nodejs/node?clean=true'; diff --git a/lib/versioning/semver/range.js b/lib/versioning/semver/range.js index 1f20b4465f..48b0b50c65 100644 --- a/lib/versioning/semver/range.js +++ b/lib/versioning/semver/range.js @@ -49,6 +49,9 @@ function rangify(config, currentVersion, fromVersion, toVersion) { if (element.operator === '~') { return `~${toVersion}`; } + if (element.operator === '=') { + return `=${toVersion}`; + } if (element.operator === '>=') { return currentVersion.includes('>= ') ? `>= ${toVersion}` @@ -75,6 +78,9 @@ function rangify(config, currentVersion, fromVersion, toVersion) { } return `^${major(toVersion)}.0.0`; } + if (element.operator === '=') { + return `=${toVersion}`; + } if (element.operator === '~') { return `~${major(toVersion)}.${minor(toVersion)}.0`; } diff --git a/test/manager/npm/extract/__snapshots__/index.spec.js.snap b/test/manager/npm/extract/__snapshots__/index.spec.js.snap index 535b6737e0..8555d4089a 100644 --- a/test/manager/npm/extract/__snapshots__/index.spec.js.snap +++ b/test/manager/npm/extract/__snapshots__/index.spec.js.snap @@ -122,7 +122,7 @@ Object { "versionScheme": "semver", }, Object { - "currentVersion": "0.22.0", + "currentVersion": "=0.22.0", "depName": "cheerio", "depType": "dependencies", "purl": "pkg:npm/cheerio", @@ -231,7 +231,7 @@ Object { "versionScheme": "semver", }, Object { - "currentVersion": "0.22.0", + "currentVersion": "=0.22.0", "depName": "cheerio", "depType": "dependencies", "purl": "pkg:npm/cheerio", @@ -320,7 +320,7 @@ Object { "versionScheme": "semver", }, Object { - "currentVersion": "0.22.0", + "currentVersion": "=0.22.0", "depName": "cheerio", "depType": "dependencies", "purl": "pkg:npm/cheerio", diff --git a/test/versioning/semver.spec.js b/test/versioning/semver.spec.js index 6a6d76ce58..f45cf7f739 100644 --- a/test/versioning/semver.spec.js +++ b/test/versioning/semver.spec.js @@ -37,3 +37,15 @@ describe('semver.isRange(input)', () => { 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'); + }); +});