You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2017/05/01 13:06:54 UTC

[1/2] cordova-create git commit: CB-10681: templates will add @latest when fetching from npm when no version is specified. This will ensure an older cahced version of the template is not used

Repository: cordova-create
Updated Branches:
  refs/heads/master 92aa8e796 -> 266217f8f


CB-10681: templates will add @latest when fetching from npm when no version is specified. This will ensure an older cahced version of the template is not used


Project: http://git-wip-us.apache.org/repos/asf/cordova-create/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-create/commit/393118f9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-create/tree/393118f9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-create/diff/393118f9

Branch: refs/heads/master
Commit: 393118f9009c2931a23a528bac73b5e35aab2c52
Parents: 92aa8e7
Author: Steve Gill <st...@gmail.com>
Authored: Mon May 1 12:24:01 2017 +0200
Committer: Steve Gill <st...@gmail.com>
Committed: Mon May 1 12:24:01 2017 +0200

----------------------------------------------------------------------
 index.js            | 15 +++++++++++----
 spec/create.spec.js |  5 ++---
 2 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-create/blob/393118f9/index.js
----------------------------------------------------------------------
diff --git a/index.js b/index.js
index cdc6d4e..3f29dd2 100644
--- a/index.js
+++ b/index.js
@@ -194,15 +194,21 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
 
         events.emit('verbose', 'Copying assets."');
         isGit = cfg.lib.www.template && isUrl(cfg.lib.www.url);
-        isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url)));
+        isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url))) && !isGit;
 
         //Always use cordova fetch to obtain the npm or git template
         if (isGit || isNPM) {
             //Saved to .Cordova folder (ToDo: Delete installed template after using)
             //ToDo: @carynbear properly label errors from fetch as such
             var tempDest = global_config_path;
-            events.emit('log', 'Using cordova-fetch for '+ cfg.lib.www.url);
-            return fetch(cfg.lib.www.url, tempDest, {})
+            var target = cfg.lib.www.url;
+            //add latest to npm module if no version is specified
+            //this prevents create using an older cached version of the template
+            if(isNPM && target.indexOf('@') === -1) {
+                target = cfg.lib.www.url + '@latest';
+            }
+            events.emit('verbose', 'Using cordova-fetch for '+ target);
+            return fetch(target, tempDest, {})
             .fail(function(err){
                 events.emit('error', '\033[1m \033[31m Error from Cordova Fetch: ' + err.message);
                 if (options.verbose) {
@@ -286,6 +292,7 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
         var pkgjsonPath = path.join(dir, 'package.json');
         // Update package.json name and version fields
         if (fs.existsSync(pkgjsonPath)) {
+            delete require.cache[require.resolve(pkgjsonPath)];
             var pkgjson = require(pkgjsonPath);
 
             // Pkjson.displayName should equal config's name.
@@ -483,4 +490,4 @@ function writeToConfigJson(project_root, opts, autoPersist) {
     if (!fs.existsSync(copyDst) && fs.existsSync(copySrc)) {
         shell.cp(copySrc, projectDir);
     }
- }
\ No newline at end of file
+ }

http://git-wip-us.apache.org/repos/asf/cordova-create/blob/393118f9/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
index ddbc64b..78ca432 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -171,8 +171,7 @@ describe('create end-to-end', function() {
         var configXml = new ConfigParser(path.join(project, 'config.xml'));
         expect(configXml.packageName()).toEqual(appId);
         expect(configXml.version()).toEqual('1.0.0');
-
-
+        delete require.cache[require.resolve(path.join(project, 'package.json'))];
         // Check that we got package.json (the correct one)
         var pkjson = require(path.join(project, 'package.json'));
         // Pkjson.displayName should equal config's name.
@@ -416,7 +415,7 @@ describe('create end-to-end', function() {
                     
                     // Check that we got the right config.xml
                     expect(configXml.description()).toEqual('this is the correct config.xml');
-
+                    delete require.cache[require.resolve(path.join(project, 'package.json'))];
                     // Check that we got package.json (the correct one) and it was changed
                     var pkjson = require(path.join(project, 'package.json'));
                     // Pkjson.name should equal config's id.


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


[2/2] cordova-create git commit: CB-10681: added test to confirm we aren't using cached template

Posted by st...@apache.org.
CB-10681: added test to confirm we aren't using cached template


Project: http://git-wip-us.apache.org/repos/asf/cordova-create/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-create/commit/266217f8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-create/tree/266217f8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-create/diff/266217f8

Branch: refs/heads/master
Commit: 266217f8f35cf6df998a753f5fc48286370fc976
Parents: 393118f
Author: Steve Gill <st...@gmail.com>
Authored: Mon May 1 13:37:47 2017 +0200
Committer: Steve Gill <st...@gmail.com>
Committed: Mon May 1 14:37:58 2017 +0200

----------------------------------------------------------------------
 index.js            |  1 -
 package.json        |  3 ++-
 spec/create.spec.js | 63 +++++++++++++++++++++++++++++++++---------------
 3 files changed, 46 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-create/blob/266217f8/index.js
----------------------------------------------------------------------
diff --git a/index.js b/index.js
index 3f29dd2..d29b8a4 100644
--- a/index.js
+++ b/index.js
@@ -195,7 +195,6 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) {
         events.emit('verbose', 'Copying assets."');
         isGit = cfg.lib.www.template && isUrl(cfg.lib.www.url);
         isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url))) && !isGit;
-
         //Always use cordova fetch to obtain the npm or git template
         if (isGit || isNPM) {
             //Saved to .Cordova folder (ToDo: Delete installed template after using)

http://git-wip-us.apache.org/repos/asf/cordova-create/blob/266217f8/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 4f05f69..371e798 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,8 @@
   },
   "devDependencies": {
     "jasmine": "^2.4.1",
-    "jshint": "2.5.8"
+    "jshint": "2.5.8",
+    "semver": "^5.3.0"
   },
   "scripts": {
     "test": "npm run jshint && npm run jasmine",

http://git-wip-us.apache.org/repos/asf/cordova-create/blob/266217f8/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 78ca432..407ee46 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -24,6 +24,7 @@ var helpers = require('./helpers'),
     ConfigParser = require('cordova-common').ConfigParser,
     create = require('../index'),
     fs = require('fs'),
+    semver = require('semver'),
     CordovaLogger = require('cordova-common').CordovaLogger.get().setLevel('error');
 
 var tmpDir = helpers.tmpDir('create_test');
@@ -31,6 +32,13 @@ var appName = 'TestBase';
 var appId = 'org.testing';
 var project = path.join(tmpDir, appName);
 
+// Global configuration paths
+var global_config_path = process.env.CORDOVA_HOME;
+if (!global_config_path) {
+    var HOME = process.env[(process.platform.slice(0, 3) == 'win') ? 'USERPROFILE' : 'HOME'];
+    global_config_path = path.join(HOME, '.cordova');
+}
+
 var configSubDirPkgJson = {
     lib: {
         www: {
@@ -61,11 +69,21 @@ var configGit = {
     }
 };
 
+var configNPMold = {
+    lib: {
+        www: {
+            template: true,
+            url: 'phonegap-template-vue-f7-tabs@1.0.0',
+            version: ''
+        }
+    }
+};
+
 var configNPM = {
     lib: {
         www: {
             template: true,
-            url: 'cordova-app-hello-world',
+            url: 'phonegap-template-vue-f7-tabs',
             version: ''
         }
     }
@@ -197,18 +215,29 @@ describe('create end-to-end', function() {
         .fin(done);
     }, 60000);
 
-    // it('should successfully run with NPM package', function(done) {
-    //     // Call cordova create with no args, should return help.
-  
-    //     // Create a real project
-    //     return create(project, appId, appName, configNPM)
-    //     .then(checkProject)
-    //     .fail(function(err) {
-    //         console.log(err && err.stack);
-    //         expect(err).toBeUndefined();
-    //     })
-    //     .fin(done);
-    // }, 60000);
+    it('should successfully run with NPM package and not use old cache of template on second create', function(done) {
+        var templatePkgJsonPath = path.join(global_config_path, 'node_modules', 'phonegap-template-vue-f7-tabs', 'package.json');
+        // Call cordova create with no args, should return help.
+        // Create a real project
+        //uses phonegap-template-vue-f7-tabs
+        return create(project, appId, appName, configNPMold)
+        .then(checkProject)
+        .then(function() {
+            shell.rm('-rf', project);
+            delete require.cache[require.resolve(templatePkgJsonPath)];
+            var pkgJson = require(templatePkgJsonPath);
+            expect(pkgJson.version).toBe('1.0.0');
+            return create(project, appId, appName, configNPM);
+        }).then(function() {
+            delete require.cache[require.resolve(templatePkgJsonPath)];
+            var pkgJson = require(templatePkgJsonPath);
+            expect(semver.gt(pkgJson.version, '1.0.0')).toBeTruthy();
+        }).fail(function(err) {
+            console.log(err && err.stack);
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    }, 60000);
     
     it('should successfully run with template not having a package.json at toplevel', function(done) {
         // Call cordova create with no args, should return help.
@@ -415,6 +444,7 @@ describe('create end-to-end', function() {
                     
                     // Check that we got the right config.xml
                     expect(configXml.description()).toEqual('this is the correct config.xml');
+                    
                     delete require.cache[require.resolve(path.join(project, 'package.json'))];
                     // Check that we got package.json (the correct one) and it was changed
                     var pkjson = require(path.join(project, 'package.json'));
@@ -498,10 +528,5 @@ describe('create end-to-end', function() {
                     .fin(done);
             }, 60000);
 
-        });
-
-    
-
-
-                
+        });     
 });


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