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 2015/10/07 07:28:06 UTC
[3/3] cordova-lib git commit: CB-9589 auto convert old plugin ids to
new npm ids
CB-9589 auto convert old plugin ids to new npm ids
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/a7287ce3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/a7287ce3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/a7287ce3
Branch: refs/heads/master
Commit: a7287ce39d310c89d458ba4d4491dddeaeb23e92
Parents: ff0fd6e
Author: Steve Gill <st...@gmail.com>
Authored: Fri Sep 25 12:21:09 2015 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Tue Oct 6 17:40:12 2015 -0700
----------------------------------------------------------------------
cordova-lib/src/plugman/fetch.js | 2 +-
cordova-lib/src/plugman/install.js | 35 ++++++++++++++++++++---
cordova-lib/src/plugman/registry/registry.js | 19 +-----------
cordova-lib/src/plugman/uninstall.js | 29 +++++++++++++++----
4 files changed, 57 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a7287ce3/cordova-lib/src/plugman/fetch.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js
index ad463d7..ad511e4 100644
--- a/cordova-lib/src/plugman/fetch.js
+++ b/cordova-lib/src/plugman/fetch.js
@@ -167,7 +167,6 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
});
}
-
// Helper function for checking expected plugin IDs against reality.
function checkID(expectedIdAndVersion, pinfo) {
if (!expectedIdAndVersion) return;
@@ -181,6 +180,7 @@ function checkID(expectedIdAndVersion, pinfo) {
}
}
+
// Note, there is no cache invalidation logic for local plugins.
// As of this writing loadLocalPlugins() is never called with different
// search paths and such case would not be handled properly.
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a7287ce3/cordova-lib/src/plugman/install.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/install.js b/cordova-lib/src/plugman/install.js
index 67198e5..c8d7e64 100644
--- a/cordova-lib/src/plugman/install.js
+++ b/cordova-lib/src/plugman/install.js
@@ -36,6 +36,7 @@ var path = require('path'),
plugman = require('./plugman'),
HooksRunner = require('../hooks/HooksRunner'),
isWindows = (os.platform().substr(0,3) === 'win'),
+ pluginMapper = require('cordova-registry-mapper').oldToNew,
cordovaUtil = require('../cordova/util');
var superspawn = require('cordova-common').superspawn;
@@ -48,7 +49,8 @@ var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
providing a high-level logic flow overview.
1. module.exports (installPlugin)
a) checks that the platform is supported
- b) invokes possiblyFetch
+ b) converts oldIds into newIds (CPR -> npm)
+ c) invokes possiblyFetch
2. possiblyFetch
a) checks that the plugin is fetched. if so, calls runInstall
b) if not, invokes plugman.fetch, and when done, calls runInstall
@@ -56,7 +58,7 @@ var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
a) checks if the plugin is already installed. if so, calls back (done).
b) if possible, will check the version of the project and make sure it is compatible with the plugin (checks <engine> tags)
c) makes sure that any variables required by the plugin are specified. if they are not specified, plugman will throw or callback with an error.
- d) if dependencies are listed in the plugin, it will recurse for each dependent plugin and call possiblyFetch (2) on each one. When each dependent plugin is successfully installed, it will then proceed to call handleInstall (4)
+ d) if dependencies are listed in the plugin, it will recurse for each dependent plugin, autoconvert IDs to newIDs and call possiblyFetch (2) on each one. When each dependent plugin is successfully installed, it will then proceed to call handleInstall (4)
4. handleInstall
a) queues up actions into a queue (asset, source-file, headers, etc)
b) processes the queue
@@ -68,7 +70,6 @@ var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
module.exports = function installPlugin(platform, project_dir, id, plugins_dir, options) {
project_dir = cordovaUtil.convertToRealPathSafe(project_dir);
plugins_dir = cordovaUtil.convertToRealPathSafe(plugins_dir);
-
options = options || {};
options.is_top_level = true;
plugins_dir = plugins_dir || path.join(project_dir, 'cordova', 'plugins');
@@ -79,6 +80,19 @@ module.exports = function installPlugin(platform, project_dir, id, plugins_dir,
var current_stack = new action_stack();
+ // Split @Version from the plugin id if it exists.
+ var splitVersion = id.split('@');
+ //Check if a mapping exists for the plugin id
+ //if it does, convert id to new name id
+ var newId = pluginMapper[splitVersion[0]];
+ if(newId) {
+ events.emit('log', 'Notice: ' + id + ' has been automatically converted to ' + newId + ' and fetched from npm. This is due to our old plugins registry shutting down.');
+ if(splitVersion[1]) {
+ id = newId +'@'+splitVersion[1];
+ } else {
+ id = newId;
+ }
+ }
return possiblyFetch(id, plugins_dir, options)
.then(function(plugin_dir) {
return runInstall(current_stack, platform, project_dir, plugin_dir, plugins_dir, options);
@@ -404,6 +418,20 @@ function installDependencies(install, dependencies, options) {
return dependencies.reduce(function(soFar, dep) {
return soFar.then(
function() {
+ // Split @Version from the plugin id if it exists.
+ var splitVersion = dep.id.split('@');
+ //Check if a mapping exists for the plugin id
+ //if it does, convert id to new name id
+ var newId = pluginMapper[splitVersion[0]];
+ if(newId) {
+ events.emit('log', 'Notice: ' + dep.id + ' has been automatically converted to ' + newId + ' and fetched from npm. This is due to our old plugins registry shutting down.');
+ if(splitVersion[1]) {
+ dep.id = newId +'@'+splitVersion[1];
+ } else {
+ dep.id = newId;
+ }
+ }
+
dep.git_ref = dep.commit;
if (dep.subdir) {
@@ -528,7 +556,6 @@ function installDependency(dep, install, options) {
var opts;
dep.install_dir = path.join(install.plugins_dir, dep.id);
-
if ( fs.existsSync(dep.install_dir) ) {
events.emit('verbose', 'Dependent plugin "' + dep.id + '" already fetched, using that version.');
opts = underscore.extend({}, options, {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a7287ce3/cordova-lib/src/plugman/registry/registry.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/registry/registry.js b/cordova-lib/src/plugman/registry/registry.js
index cc39f40..5624c4e 100644
--- a/cordova-lib/src/plugman/registry/registry.js
+++ b/cordova-lib/src/plugman/registry/registry.js
@@ -26,7 +26,6 @@ var npm = require('npm'),
rc = require('rc'),
Q = require('q'),
request = require('request'),
- pluginMapper = require('cordova-registry-mapper').oldToNew,
npmhelper = require('../../util/npm-helper'),
home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
events = require('cordova-common').events,
@@ -292,22 +291,6 @@ function isValidCprName(plugin) {
//If matches equals null, plugin is not reverse domain name style
if(matches === null) {
return false;
- } else {
- warnIfIdInMapper(splitVersion[0]);
- }
+ }
return true;
}
-
-/**
- * @param plugin:{Array} - the plugin id or "id@version"
- * @param matches:{Array} - the array containing the RDN style plugin id without @version
- */
-function warnIfIdInMapper(plugin) {
- //Reverse domain name style plugin ID
- //Check if a mapping exists for the plugin id
- //if it does, warn the users to use package-name
- var packageName = pluginMapper[plugin];
- if(packageName) {
- events.emit('log', 'WARNING: ' + plugin + ' has been renamed to ' + packageName + '. You may not be getting the latest version! We suggest you `cordova plugin rm ' + plugin + '` and `cordova plugin add ' + packageName + '`.');
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a7287ce3/cordova-lib/src/plugman/uninstall.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/uninstall.js b/cordova-lib/src/plugman/uninstall.js
index 545a336..3771c1b 100644
--- a/cordova-lib/src/plugman/uninstall.js
+++ b/cordova-lib/src/plugman/uninstall.js
@@ -32,7 +32,8 @@ var path = require('path'),
platform_modules = require('../platforms/platforms'),
promiseutil = require('../util/promise-util'),
HooksRunner = require('../hooks/HooksRunner'),
- cordovaUtil = require('../cordova/util');
+ cordovaUtil = require('../cordova/util'),
+ pluginMapper = require('cordova-registry-mapper').oldToNew;
var superspawn = require('cordova-common').superspawn;
var PlatformJson = require('cordova-common').PlatformJson;
@@ -142,10 +143,19 @@ module.exports.uninstallPlugin = function(id, plugins_dir, options) {
var pluginInfo = pluginInfoProvider.get(depPluginDir);
// TODO: Should remove dependencies in a separate step, since dependencies depend on platform.
var deps = pluginInfo.getDependencies();
+ var deps_path;
deps.forEach(function (d) {
- if (toDelete.indexOf(d.id) === -1) {
- toDelete.push(d.id);
- findDependencies(d.id);
+ var splitVersion = d.id.split('@');
+ deps_path = path.join(plugin_dir, '..', splitVersion[0]);
+ if (!fs.existsSync(deps_path)) {
+ var newId = pluginMapper[splitVersion[0]];
+ if (newId && toDelete.indexOf(newId) === -1) {
+ toDelete.push(newId);
+ findDependencies(newId);
+ }
+ } else if (toDelete.indexOf(d.id) === -1) {
+ toDelete.push(d.id);
+ findDependencies(d.id);
}
});
}
@@ -256,9 +266,18 @@ function runUninstallPlatform(actions, platform, project_dir, plugin_dir, plugin
promise = promiseutil.Q_chainmap(danglers, function(dangler) {
var dependent_path = path.join(plugins_dir, dangler);
+ //try to convert ID if old-id path doesn't exist.
+ if (!fs.existsSync(dependent_path)) {
+ var splitVersion = dangler.split('@');
+ var newId = pluginMapper[splitVersion[0]];
+ if(newId) {
+ dependent_path = path.join(plugins_dir, newId);
+ }
+ }
+
var opts = underscore.extend({}, options, {
is_top_level: depsInfo.top_level_plugins.indexOf(dangler) > -1,
- depsInfo: depsInfo
+ depsInfo: depsInfo
});
return runUninstallPlatform(actions, platform, project_dir, dependent_path, plugins_dir, opts);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org