From 4ccbc20bc1dd5787dae215ae457dc1f532644bbc Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sat, 16 Jun 2018 09:28:11 +0200
Subject: [PATCH] fix: match current version (#2135)

fix: match current version
---
 lib/util/package-rules.js                 | 18 ++++++++++++++----
 lib/workers/repository/updates/flatten.js |  4 ++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/util/package-rules.js b/lib/util/package-rules.js
index 4dd2dfa856..ec95b5edd3 100644
--- a/lib/util/package-rules.js
+++ b/lib/util/package-rules.js
@@ -9,7 +9,14 @@ module.exports = {
 
 function applyPackageRules(inputConfig) {
   let config = { ...inputConfig };
-  const { versionScheme, packageFile, depType, depName, fromVersion } = config;
+  const {
+    versionScheme,
+    packageFile,
+    depType,
+    depName,
+    currentValue,
+    fromVersion,
+  } = config;
   const packageRules = config.packageRules || [];
   logger.trace(
     { depName, packageRules },
@@ -94,9 +101,12 @@ function applyPackageRules(inputConfig) {
       positiveMatch = positiveMatch || !isMatch;
     }
     if (matchCurrentVersion) {
-      if (fromVersion) {
-        const { matches } = versioning(versionScheme);
-        const isMatch = matches(fromVersion, matchCurrentVersion);
+      const { matches, isVersion } = versioning(versionScheme);
+      const compareVersion = isVersion(currentValue)
+        ? currentValue // it's a version so we can match against it
+        : fromVersion; // need to match against this fromVersion, if available
+      if (compareVersion) {
+        const isMatch = matches(compareVersion, matchCurrentVersion);
         positiveMatch = positiveMatch || isMatch;
         negativeMatch = negativeMatch || !isMatch;
       } else {
diff --git a/lib/workers/repository/updates/flatten.js b/lib/workers/repository/updates/flatten.js
index 8257aa8526..ad56fed416 100644
--- a/lib/workers/repository/updates/flatten.js
+++ b/lib/workers/repository/updates/flatten.js
@@ -18,12 +18,12 @@ function flattenUpdates(config, packageFiles) {
       const packageFileConfig = mergeChildConfig(managerConfig, packageFile);
       for (const dep of packageFile.deps) {
         if (dep.updates.length) {
-          let depConfig = mergeChildConfig(packageFileConfig, dep);
+          const depConfig = mergeChildConfig(packageFileConfig, dep);
           delete depConfig.deps;
-          depConfig = applyPackageRules(depConfig);
           for (const update of dep.updates) {
             let updateConfig = mergeChildConfig(depConfig, update);
             delete updateConfig.updates;
+            updateConfig = applyPackageRules(updateConfig);
             // apply major/minor/patch/pin/digest
             updateConfig = mergeChildConfig(
               updateConfig,
-- 
GitLab