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
diff --git a/index.js b/index.js
index cdc6d4e..3f29dd2 100644
--- a/index.js
+++ b/index.js
@@ -194,15 +194,21 @@
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 @@
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 @@
if (!fs.existsSync(copyDst) && fs.existsSync(copySrc)) {
shell.cp(copySrc, projectDir);
}
- }
\ No newline at end of file
+ }
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 @@
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 @@
// 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.