cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [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
Date Mon, 01 May 2017 13:06:54 GMT
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 <stevengill97@gmail.com>
Authored: Mon May 1 12:24:01 2017 +0200
Committer: Steve Gill <stevengill97@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


Mime
View raw message