You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by no...@apache.org on 2020/04/01 03:43:46 UTC

[cordova-android] branch master updated: fix: GH-935 replaced compare-func with native sort method (#937)

This is an automated email from the ASF dual-hosted git repository.

normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ab1dbc  fix: GH-935 replaced compare-func with native sort method (#937)
8ab1dbc is described below

commit 8ab1dbc373eefd55e912e29d6bfb2a9c67e95b6e
Author: Norman Breau <no...@normanbreau.com>
AuthorDate: Wed Apr 1 00:43:36 2020 -0300

    fix: GH-935 replaced compare-func with native sort method (#937)
---
 .../cordova/lib/builders/ProjectBuilder.js         | 39 ++++++++++++++++------
 package.json                                       |  1 -
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/bin/templates/cordova/lib/builders/ProjectBuilder.js b/bin/templates/cordova/lib/builders/ProjectBuilder.js
index 28e3a28..9bf95ca 100644
--- a/bin/templates/cordova/lib/builders/ProjectBuilder.js
+++ b/bin/templates/cordova/lib/builders/ProjectBuilder.js
@@ -24,7 +24,6 @@ var events = require('cordova-common').events;
 var CordovaError = require('cordova-common').CordovaError;
 var check_reqs = require('../check_reqs');
 var PackageType = require('../PackageType');
-const compareFunc = require('compare-func');
 const { createEditor } = require('properties-parser');
 
 const MARKER = 'YOUR CHANGES WILL BE ERASED!';
@@ -33,19 +32,37 @@ const TEMPLATE =
     '# This file is automatically generated.\n' +
     '# Do not modify this file -- ' + MARKER + '\n';
 
-const fileSorter = compareFunc([
-    // Sort arch specific builds after generic ones
-    filePath => /-x86|-arm/.test(filePath),
+const archSpecificRegex = /-x86|-arm/;
+const unsignedBuildRegex = /-unsigned/;
 
-    // Sort unsigned builds after signed ones
-    filePath => /-unsigned/.test(filePath),
+const fileSorter = (filePathA, filePathB) => {
+    const archSpecificA = archSpecificRegex.test(filePathA);
+    const archSpecificB = archSpecificRegex.test(filePathB);
 
-    // Sort by file modification time, latest first
-    filePath => -fs.statSync(filePath).mtime.getTime(),
+    // If they are not equal, then sort by specific archs after generic ones
+    if (archSpecificA !== archSpecificB) {
+        return archSpecificA < archSpecificB ? -1 : 1;
+    }
+
+    // Otherwise, move onto the next sort item, which is by sorting unsigned bulds after signed ones
+    const unsignedA = unsignedBuildRegex.test(filePathA);
+    const unsignedB = unsignedBuildRegex.test(filePathB);
+
+    if (unsignedA !== unsignedB) {
+        return unsignedA < unsignedB ? -1 : 1;
+    }
+
+    // Then, sort by modification time, latest first
+    const modTimeA = fs.statSync(filePathA).mtime.getTime();
+    const modTimeB = fs.statSync(filePathB).mtime.getTime();
+
+    if (modTimeA !== modTimeB) {
+        return modTimeA < modTimeB ? 1 : -1;
+    }
 
-    // Sort by file name length, ascending
-    'length'
-]);
+    // Finally, if all above is the same, sort by file name length, ascending
+    return filePathB.length < filePathA.length ? -1 : 1;
+};
 
 /**
  * If the provided directory does not exist or extension is missing, return an empty array.
diff --git a/package.json b/package.json
index 77d4f28..a3f9ba5 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,6 @@
   "license": "Apache-2.0",
   "dependencies": {
     "android-versions": "^1.4.0",
-    "compare-func": "^1.3.2",
     "cordova-common": "^3.2.0",
     "execa": "^3.2.0",
     "fs-extra": "^8.1.0",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org