You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/11/06 18:36:16 UTC

[cordova-create] branch master updated: Fix isRemoteUri (#52)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d894243  Fix isRemoteUri (#52)
d894243 is described below

commit d89424341df936462977c3ced24bc05e63155510
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Wed Nov 6 19:36:06 2019 +0100

    Fix isRemoteUri (#52)
    
    * Add unit tests for isRemoteUri
    
    Including one failing test for paths that include @
    
    * Fix isRemoteUri using npm-package-arg
    
    Fixes #34
    
    * Rename isRemoteUri to needsToBeFetched after switch to npa
    
    The reason for the rename is, that there are also local specs where we
    need to call fetch. For example tarballs.
---
 index.js            |  8 ++++----
 package-lock.json   |  5 -----
 package.json        |  2 +-
 spec/create.spec.js | 21 +++++++++++++++++++++
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/index.js b/index.js
index 0ce0636..a9f326f 100644
--- a/index.js
+++ b/index.js
@@ -22,7 +22,7 @@ const fs = require('fs-extra');
 var path = require('path');
 
 var tmp = require('tmp');
-var isUrl = require('is-url');
+const npa = require('npm-package-arg');
 var isObject = require('isobject');
 var pathIsInside = require('path-is-inside');
 var requireFresh = require('import-fresh');
@@ -88,7 +88,7 @@ function cordovaCreate (dest, opts = {}) {
             emit('log', 'Creating a new cordova project.');
 
             // Use cordova-fetch to obtain npm or git templates
-            if (isRemoteUri(opts.template)) {
+            if (needsToBeFetched(opts.template)) {
                 var target = opts.template;
                 emit('verbose', 'Using cordova-fetch for ' + target);
                 return fetch(target, getSelfDestructingTempDir(), {});
@@ -167,6 +167,6 @@ function getSelfDestructingTempDir () {
     }).name;
 }
 
-function isRemoteUri (uri) {
-    return isUrl(uri) || uri.includes('@') || !fs.existsSync(uri);
+function needsToBeFetched (uri) {
+    return npa(uri).type !== 'directory';
 }
diff --git a/package-lock.json b/package-lock.json
index c5aeb6b..0ac6974 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1438,11 +1438,6 @@
         "has-symbols": "^1.0.0"
       }
     },
-    "is-url": {
-      "version": "1.2.4",
-      "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz",
-      "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww=="
-    },
     "isarray": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
diff --git a/package.json b/package.json
index 43a98a6..1b9e632 100644
--- a/package.json
+++ b/package.json
@@ -29,8 +29,8 @@
     "cordova-fetch": "^2.0.0",
     "fs-extra": "^8.1.0",
     "import-fresh": "^3.1.0",
-    "is-url": "^1.2.4",
     "isobject": "^4.0.0",
+    "npm-package-arg": "^6.1.1",
     "path-is-inside": "^1.0.2",
     "tmp": "^0.1.0",
     "valid-identifier": "0.0.2"
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 821ed37..96e8fdf 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -18,6 +18,7 @@
 */
 
 const fs = require('fs-extra');
+const rewire = require('rewire');
 
 var path = require('path');
 
@@ -227,3 +228,23 @@ describe('when shit happens', function () {
         );
     });
 });
+
+describe('cordova create needsToBeFetched', () => {
+    let needsToBeFetched;
+
+    beforeEach(() => {
+        needsToBeFetched = rewire('..').__get__('needsToBeFetched');
+    });
+
+    it('should recognize URLs as remote', () => {
+        expect(needsToBeFetched('https://example.com/pkg/foo')).toBe(true);
+    });
+
+    it('should recognize package@version as remote', () => {
+        expect(needsToBeFetched('foo@1')).toBe(true);
+    });
+
+    it('should not detect paths as remote only because they include an @', () => {
+        expect(needsToBeFetched('../foo@1')).toBe(false);
+    });
+});


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