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/08 14:29:43 UTC
[5/8] cordova-lib git commit: CB-12757 : if there's a plugin
dependency in pkgJson, use that one for config
CB-12757 : if there's a plugin dependency in pkgJson, use that one for config
This closes #552
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/4c497ab4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/4c497ab4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/4c497ab4
Branch: refs/heads/7.0.x
Commit: 4c497ab45847b038eb5f65427d4343745c65c4ed
Parents: 3db0f07
Author: Audrey So <au...@apache.org>
Authored: Thu May 4 10:08:47 2017 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Mon May 8 12:41:00 2017 +0200
----------------------------------------------------------------------
cordova-lib/integration-tests/pkgJson.spec.js | 2 +-
cordova-lib/src/cordova/plugin.js | 53 ++++++++++++----------
2 files changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4c497ab4/cordova-lib/integration-tests/pkgJson.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/integration-tests/pkgJson.spec.js b/cordova-lib/integration-tests/pkgJson.spec.js
index e97372f..9e85d08 100644
--- a/cordova-lib/integration-tests/pkgJson.spec.js
+++ b/cordova-lib/integration-tests/pkgJson.spec.js
@@ -91,7 +91,7 @@ describe('plugin end-to-end', function() {
configPlugins = cfg2.getPluginIdList();
configPlugin = cfg2.getPlugin(configPlugins);
expect(configPlugins.length).toEqual(1);
- expect(configPlugin).toEqual({ name: 'cordova-plugin-device', spec: '~1.1.2', variables: {} });
+ expect(configPlugin).toEqual({ name: 'cordova-plugin-device', spec: '^1.1.2', variables: {} });
}).then(function() {
// And now remove it with --save.
return cordova.raw.plugin('rm', pluginId, {'save':true, 'fetch':true});
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4c497ab4/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 6c59818..e76f479 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -205,8 +205,29 @@ module.exports = function plugin(command, targets, opts) {
.thenResolve(pluginInfo);
})
.then(function(pluginInfo){
+ var pkgJson;
+ var pkgJsonPath = path.join(projectRoot,'package.json');
+
// save to config.xml
if(saveToConfigXmlOn(config_json, opts)){
+ // If statement to see if pkgJsonPath exists in the filesystem
+ if(fs.existsSync(pkgJsonPath)) {
+ // Delete any previous caches of require(package.json)
+ pkgJson = cordova_util.requireNoCache(pkgJsonPath);
+ }
+ // If package.json exists, the plugin object and plugin name
+ // will be added to package.json if not already there.
+ if(pkgJson) {
+ pkgJson.cordova = pkgJson.cordova || {};
+ pkgJson.cordova.plugins = pkgJson.cordova.plugins || {};
+ // Plugin and variables are added.
+ pkgJson.cordova.plugins[pluginInfo.id] = opts.cli_variables;
+ events.emit('log','Adding '+pluginInfo.id+ ' to package.json');
+
+ // Write to package.json
+ fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
+ }
+
var src = parseSource(target, opts);
var attributes = {
name: pluginInfo.id
@@ -218,10 +239,14 @@ module.exports = function plugin(command, targets, opts) {
var ver = '~' + pluginInfo.version;
// Scoped packages need to have the package-spec along with the version
var parsedSpec = pluginSpec.parse(target);
- if (parsedSpec.scope) {
- attributes.spec = parsedSpec.package + '@' + ver;
+ if(pkgJson && pkgJson.dependencies && pkgJson.dependencies[pluginInfo.id]){
+ attributes.spec = pkgJson.dependencies[pluginInfo.id];
} else {
- attributes.spec = ver;
+ if (parsedSpec.scope) {
+ attributes.spec = parsedSpec.package + '@' + ver;
+ } else {
+ attributes.spec = ver;
+ }
}
}
xml = cordova_util.projectConfig(projectRoot);
@@ -231,28 +256,6 @@ module.exports = function plugin(command, targets, opts) {
cfg.write();
events.emit('results', 'Saved plugin info for "' + pluginInfo.id + '" to config.xml');
-
- var pkgJson;
- var pkgJsonPath = path.join(projectRoot,'package.json');
-
- // If statement to see if pkgJsonPath exists in the filesystem
- if(fs.existsSync(pkgJsonPath)) {
- // Delete any previous caches of require(package.json)
- pkgJson = cordova_util.requireNoCache(pkgJsonPath);
- }
-
- // If package.json exists, the plugin object and plugin name
- // will be added to package.json if not already there.
- if (!pkgJson) {
- return;
- }
- pkgJson.cordova = pkgJson.cordova || {};
- pkgJson.cordova.plugins = pkgJson.cordova.plugins || {};
- // Plugin and variables are added.
- pkgJson.cordova.plugins[pluginInfo.id] = opts.cli_variables;
- events.emit('log','Adding '+pluginInfo.id+ ' to package.json');
- // Write to package.json
- fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
}
});
}, Q());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org