You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ka...@apache.org on 2015/03/27 16:50:22 UTC
cordova-lib git commit: CB-8741 Make plugin --save work more like npm
install
Repository: cordova-lib
Updated Branches:
refs/heads/master b9d02cbd7 -> 4d081771e
CB-8741 Make plugin --save work more like npm install
1. 'plugin add --save' now always saves version (in the form '^x.y.z')
2. 'plugin add --save' now always overwrites an existing entry.
3. 'plugin add' now honors an existing version specified in config.xml when a
plugin is added without a specific version, even if the '--save' flag is
specified.
I also fixed a bug in isUrl() in util.js - url.protocol includes the colon, so
the protocol for a windows path is something like "c:" - 2 characters, not
one.
GitHub: close #198
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/4d081771
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/4d081771
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/4d081771
Branch: refs/heads/master
Commit: 4d081771e90c0d971751ba78da37a980d057337f
Parents: b9d02cb
Author: Tim Barham <ti...@microsoft.com>
Authored: Fri Mar 27 23:22:20 2015 +1000
Committer: Mark Koudritsky <ka...@gmail.com>
Committed: Fri Mar 27 11:47:10 2015 -0400
----------------------------------------------------------------------
cordova-lib/src/cordova/plugin.js | 67 ++++++++++++----------------------
cordova-lib/src/cordova/util.js | 8 ++--
2 files changed, 28 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4d081771/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 8bdeb6a..d9b5d18 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -122,12 +122,12 @@ module.exports = function plugin(command, targets, opts) {
var id = parts[0];
var version = parts[1];
- // If no version is specified, retrieve the version from config.xml
- if(!saveToConfigXmlOn(config_json,opts) && !version && !cordova_util.isUrl(id) && !cordova_util.isDirectory(id)){
+ // If no version is specified, retrieve the version (or source) from config.xml
+ if (!version && !cordova_util.isUrl(id) && !cordova_util.isDirectory(id)) {
events.emit('verbose', 'no version specified, retrieving version from config.xml');
var ver = getVersionFromConfigFile(id, cfg);
- if( cordova_util.isUrl(ver) || cordova_util.isDirectory(ver) ){
+ if (cordova_util.isUrl(ver) || cordova_util.isDirectory(ver)) {
target = ver;
} else {
target = ver ? (id + '@' + ver) : target;
@@ -145,42 +145,33 @@ module.exports = function plugin(command, targets, opts) {
// save to config.xml
if(saveToConfigXmlOn(config_json,opts)){
var pluginInfo = pluginInfoProvider.get(dir);
- var existingPluginEntry = cfg.getPlugin(pluginInfo.id);
- if(!existingPluginEntry){
- var attributes = {};
- attributes.name = pluginInfo.id;
- var pluginVersion = versionFromTargetString(target);
- if(!pluginVersion && opts.shrinkwrap){
- pluginVersion = pluginInfo.version;
- }
- if(pluginVersion){
- attributes.version = pluginVersion;
- }
- var url = require('url');
- var uri = url.parse(target);
- if ( uri.protocol && uri.protocol != 'file:' && uri.protocol[1] != ':' && !target.match(/^\w+:\\/)) {
+ var attributes = {};
+ attributes.name = pluginInfo.id;
+ attributes.version = '^' + pluginInfo.version;
+
+ var url = require('url');
+ var uri = url.parse(target);
+ if (uri.protocol && uri.protocol != 'file:' && uri.protocol[1] != ':' && !target.match(/^\w+:\\/)) {
+ attributes.src = target;
+ } else {
+ var plugin_dir = cordova_util.fixRelativePath(path.join(target, (opts.subdir || '.')));
+ if (fs.existsSync(plugin_dir)) {
attributes.src = target;
- }else{
- var plugin_dir = cordova_util.fixRelativePath(path.join(target, (opts.subdir || '.') ));
- if (fs.existsSync(plugin_dir)) {
- attributes.src = target;
- }
}
- var variables = [];
- if(opts.cli_variables){
- for(var varname in opts.cli_variables){
- if(opts.cli_variables.hasOwnProperty(varname)){
- variables.push({name:varname, value:opts.cli_variables[varname]});
- }
+ }
+ var variables = [];
+ if (opts.cli_variables) {
+ for (var varname in opts.cli_variables) {
+ if (opts.cli_variables.hasOwnProperty(varname)) {
+ variables.push({name: varname, value: opts.cli_variables[varname]});
}
}
- cfg.addPlugin(attributes,variables);
- cfg.write();
- events.emit('results', 'Saved plugin info for "'+pluginInfo.id+'" to config.xml');
- }else{
- events.emit('results', 'Plugin info for "'+pluginInfo.id+'" already exists in config.xml');
}
+ cfg.removePlugin(pluginInfo.id);
+ cfg.addPlugin(attributes, variables);
+ cfg.write();
+ events.emit('results', 'Saved plugin info for "' + pluginInfo.id + '" to config.xml');
}
return dir;
})
@@ -449,13 +440,3 @@ function saveToConfigXmlOn(config_json, options){
var autosave = config_json.auto_save_plugins || false;
return autosave || options.save;
}
-
-function versionFromTargetString(target){
- if (target[target.length - 1] == path.sep) {
- target = target.substring(0, target.length - 1);
- }
- var parts = target.split('@');
- if(!cordova_util.isUrl(parts[0]) && !cordova_util.isDirectory(parts[0])){
- return parts[1];
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4d081771/cordova-lib/src/cordova/util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js
index e661c9e..d6e768e 100644
--- a/cordova-lib/src/cordova/util.js
+++ b/cordova-lib/src/cordova/util.js
@@ -58,7 +58,7 @@ exports.isUrl = isUrl;
function isUrl(value) {
var u = value && url.parse(value);
- return !!(u && u.protocol && u.protocol.length > 1); // Account for windows c:/ paths
+ return !!(u && u.protocol && u.protocol.length > 2); // Account for windows c:/ paths
}
function isRootDir(dir) {
@@ -238,9 +238,9 @@ function preProcessOptions (inputOptions) {
function isDirectory(dir) {
try {
- return fs.lstatSync(dir).isDirectory();
- } catch(e) {
- return false;
+ return fs.lstatSync(dir).isDirectory();
+ } catch (e) {
+ return false;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org