From e90d34f848813e206a262b12022d349154fb1589 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Wed, 19 Feb 2020 18:24:42 +0100
Subject: [PATCH] fix(html): allow reverse sorting (#5523)

---
 .../html/__snapshots__/extract.spec.ts.snap   | 20 +++++++++----------
 lib/manager/html/extract.ts                   |  5 +++--
 lib/manager/html/update.ts                    | 13 +++++++-----
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/lib/manager/html/__snapshots__/extract.spec.ts.snap b/lib/manager/html/__snapshots__/extract.spec.ts.snap
index 19a89c4623..f0614586e2 100644
--- a/lib/manager/html/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/html/__snapshots__/extract.spec.ts.snap
@@ -7,100 +7,100 @@ Object {
       "currentValue": "15.6.1",
       "datasource": "cdnjs",
       "depName": "prop-types",
+      "fileReplacePosition": 201,
       "lookupName": "prop-types/prop-types.min.js",
       "managerData": Object {
         "tagLength": 124,
-        "tagPosition": 201,
       },
     },
     Object {
       "currentValue": "16.3.2",
       "datasource": "cdnjs",
       "depName": "react",
+      "fileReplacePosition": 339,
       "lookupName": "react/umd/react.production.min.js",
       "managerData": Object {
         "tagLength": 129,
-        "tagPosition": 339,
       },
     },
     Object {
       "currentValue": "16.3.2",
       "datasource": "cdnjs",
       "depName": "react-dom",
+      "fileReplacePosition": 482,
       "lookupName": "react-dom/umd/react-dom.production.min.js",
       "managerData": Object {
         "tagLength": 137,
-        "tagPosition": 482,
       },
     },
     Object {
       "currentValue": "2.2.1",
       "datasource": "cdnjs",
       "depName": "react-transition-group",
+      "fileReplacePosition": 984,
       "lookupName": "react-transition-group/react-transition-group.min.js",
       "managerData": Object {
         "tagLength": 147,
-        "tagPosition": 984,
       },
     },
     Object {
       "currentValue": "1.14.3",
       "datasource": "cdnjs",
       "depName": "popper.js",
+      "fileReplacePosition": 1145,
       "lookupName": "popper.js/umd/popper.min.js",
       "managerData": Object {
         "tagLength": 123,
-        "tagPosition": 1145,
       },
     },
     Object {
       "currentValue": "0.10.4",
       "datasource": "cdnjs",
       "depName": "react-popper",
+      "fileReplacePosition": 1282,
       "lookupName": "react-popper/umd/react-popper.min.js",
       "managerData": Object {
         "tagLength": 132,
-        "tagPosition": 1282,
       },
     },
     Object {
       "currentValue": "7.1.0",
       "datasource": "cdnjs",
       "depName": "reactstrap",
+      "fileReplacePosition": 1452,
       "lookupName": "reactstrap/reactstrap.min.js",
       "managerData": Object {
         "tagLength": 88,
-        "tagPosition": 1452,
       },
     },
     Object {
       "currentValue": "4.3.1",
       "datasource": "cdnjs",
       "depName": "react-router",
+      "fileReplacePosition": 1554,
       "lookupName": "react-router/react-router.min.js",
       "managerData": Object {
         "tagLength": 93,
-        "tagPosition": 1554,
       },
     },
     Object {
       "currentValue": "4.0.6",
       "datasource": "cdnjs",
       "depName": "react-markdown",
+      "fileReplacePosition": 1663,
       "lookupName": "react-markdown/react-markdown.js",
       "managerData": Object {
         "tagLength": 92,
-        "tagPosition": 1663,
       },
     },
     Object {
       "currentValue": "0.18.0",
       "datasource": "cdnjs",
       "depName": "axios",
+      "fileReplacePosition": 1866,
       "lookupName": "axios/axios.min.js",
       "managerData": Object {
         "tagLength": 179,
-        "tagPosition": 1866,
       },
     },
   ],
diff --git a/lib/manager/html/extract.ts b/lib/manager/html/extract.ts
index 6e179c3102..a11d56d359 100644
--- a/lib/manager/html/extract.ts
+++ b/lib/manager/html/extract.ts
@@ -27,7 +27,7 @@ export function extractPackageFile(content: string): PackageFile {
   while (match) {
     const [tag] = match;
     const tagLength = tag.length;
-    const tagPosition = offset + match.index;
+    const fileReplacePosition = offset + match.index;
 
     offset += match.index + tag.length;
     rest = content.slice(offset);
@@ -37,7 +37,8 @@ export function extractPackageFile(content: string): PackageFile {
     if (dep) {
       deps.push({
         ...dep,
-        managerData: { tagLength, tagPosition },
+        fileReplacePosition,
+        managerData: { tagLength },
       });
     }
   }
diff --git a/lib/manager/html/update.ts b/lib/manager/html/update.ts
index b1a3e240e4..6efbc677c0 100644
--- a/lib/manager/html/update.ts
+++ b/lib/manager/html/update.ts
@@ -41,11 +41,14 @@ export async function updateDependency({
   fileContent,
   upgrade,
 }: UpdateDependencyConfig): Promise<string> {
-  const { currentValue, newValue, managerData } = upgrade;
-  const { tagPosition, tagLength } = managerData;
-  const leftPart = fileContent.slice(0, tagPosition);
-  const tagPart = fileContent.slice(tagPosition, tagPosition + tagLength);
-  const rightPart = fileContent.slice(tagPosition + tagLength);
+  const { currentValue, fileReplacePosition, newValue, managerData } = upgrade;
+  const { tagLength } = managerData;
+  const leftPart = fileContent.slice(0, fileReplacePosition);
+  const tagPart = fileContent.slice(
+    fileReplacePosition,
+    fileReplacePosition + tagLength
+  );
+  const rightPart = fileContent.slice(fileReplacePosition + tagLength);
   const dep = extractDep(tagPart);
   /* istanbul ignore if */
   if (!dep) {
-- 
GitLab