CB-10314 avoid fetching plugins when oldId is already fetched This closes #396
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/618eeca9 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/618eeca9 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/618eeca9 Branch: refs/heads/common-1.1.x Commit: 618eeca9583defa81054158ac456674fe5c5b1d0 Parents: 8f15136 Author: Byoungro So <byoungro...@intel.com> Authored: Sat Feb 20 21:48:13 2016 -0800 Committer: Vladimir Kotikov <v-vlk...@microsoft.com> Committed: Sat Mar 5 14:24:40 2016 +0300 ---------------------------------------------------------------------- cordova-lib/src/plugman/fetch.js | 45 ++++++++++++++++++++++----- cordova-lib/src/plugman/install.js | 54 ++++++++++++++------------------- 2 files changed, 60 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/618eeca9/cordova-lib/src/plugman/fetch.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js index 8a48626..a6f5eda 100644 --- a/cordova-lib/src/plugman/fetch.js +++ b/cordova-lib/src/plugman/fetch.js @@ -135,13 +135,33 @@ function fetchPlugin(plugin_src, plugins_dir, options) { var splitVersion = plugin_src.split('@'); var newID = pluginMapperotn[splitVersion[0]]; if(newID) { - events.emit('warn', 'Notice: ' + splitVersion[0] + ' has been automatically converted to ' + newID + ' to be fetched from npm. This is due to our old plugins registry shutting down.'); plugin_src = newID; if (splitVersion[1]) { plugin_src += '@'+splitVersion[1]; } - } - return registry.fetch([plugin_src]) + } + var P, skipCopyingPlugin; + plugin_dir = path.join(plugins_dir, splitVersion[0]); + // if the plugin has already been fetched, use it. + if (fs.existsSync(plugin_dir)) { + P = Q(plugin_dir); + skipCopyingPlugin = true; + } else { + // if the plugin alias has already been fetched, use it. + var alias = pluginMappernto[splitVersion[0]] || newID; + if (alias && fs.existsSync(path.join(plugins_dir, alias))) { + events.emit('warn', 'Found '+alias+' is already fetched. Skipped fetching '+splitVersion[0]); + P = Q(path.join(plugins_dir, alias)); + skipCopyingPlugin = true; + } else { + if (newID) { + events.emit('warn', 'Notice: ' + splitVersion[0] + ' has been automatically converted to ' + newID + ' to be fetched from npm. This is due to our old plugins registry shutting down.'); + } + P = registry.fetch([plugin_src]); + skipCopyingPlugin = false; + } + } + return P .fail(function (error) { var message = 'Failed to fetch plugin ' + plugin_src + ' via registry.' + '\nProbably this is either a connection problem, or plugin spec is incorrect.' + @@ -151,17 +171,23 @@ function fetchPlugin(plugin_src, plugins_dir, options) { }) .then(function(dir) { return { - pinfo: pluginInfoProvider.get(dir), + pinfo: pluginInfoProvider.get(dir), fetchJsonSource: { type: 'registry', id: plugin_src - } + }, + skipCopyingPlugin: skipCopyingPlugin }; }); }).then(function(result) { options.plugin_src_dir = result.pinfo.dir; - return Q.when(copyPlugin(result.pinfo, plugins_dir, options.link && result.fetchJsonSource.type == 'local')) - .then(function(dir) { + var P; + if (result.skipCopyingPlugin) { + P = Q(options.plugin_src_dir); + } else { + P = Q.when(copyPlugin(result.pinfo, plugins_dir, options.link && result.fetchJsonSource.type == 'local')); + } + return P.then(function(dir) { result.dest = dir; return result; }); @@ -182,7 +208,10 @@ function checkID(expectedIdAndVersion, pinfo) { var expectedId = expectedIdAndVersion.split('@')[0]; var expectedVersion = expectedIdAndVersion.split('@')[1]; if (expectedId != pinfo.id) { - throw new Error('Expected plugin to have ID "' + expectedId + '" but got "' + pinfo.id + '".'); + var alias = pluginMappernto[expectedId] || pluginMapperotn[expectedId]; + if (alias !== pinfo.id) { + throw new Error('Expected plugin to have ID "' + expectedId + '" but got "' + pinfo.id + '".'); + } } if (expectedVersion && !semver.satisfies(pinfo.version, expectedVersion)) { throw new Error('Expected plugin ' + pinfo.id + ' to satisfy version "' + expectedVersion + '" but got "' + pinfo.version + '".'); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/618eeca9/cordova-lib/src/plugman/install.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/plugman/install.js b/cordova-lib/src/plugman/install.js index ff02f1c..a7e793f 100644 --- a/cordova-lib/src/plugman/install.js +++ b/cordova-lib/src/plugman/install.js @@ -36,7 +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, + pluginMapper = require('cordova-registry-mapper'), cordovaUtil = require('../cordova/util'); var superspawn = require('cordova-common').superspawn; @@ -79,43 +79,50 @@ module.exports = function installPlugin(platform, project_dir, id, plugins_dir, } var current_stack = new action_stack(); + return possiblyFetch(id, plugins_dir, options) + .then(function(plugin_dir) { + return runInstall(current_stack, platform, project_dir, plugin_dir, plugins_dir, options); + }); +}; +// possible options: subdir, cli_variables, www_dir, git_ref, is_top_level +// Returns a promise. +function possiblyFetch(id, plugins_dir, options) { // 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]]; + var newId = pluginMapper.oldToNew[splitVersion[0]]; if(newId) { - events.emit('warn', '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); - }); -}; - -// possible options: subdir, cli_variables, www_dir, git_ref, is_top_level -// Returns a promise. -function possiblyFetch(id, plugins_dir, options) { - + } // if plugin is a relative path, check if it already exists - var plugin_src_dir = isAbsolutePath(id) ? id : path.join(plugins_dir, id); + var plugin_src_dir = isAbsolutePath(id) ? id : path.join(plugins_dir, splitVersion[0]); // Check that the plugin has already been fetched. if (fs.existsSync(plugin_src_dir)) { return Q(plugin_src_dir); } + var alias = pluginMapper.newToOld[splitVersion[0]] || newId; + // if the plugin alias has already been fetched, use it. + if (alias && fs.existsSync(path.join(plugins_dir, alias))) { + events.emit('warn', 'Found ' + alias + ' is already fetched, so it is installed instead of '+splitVersion[0]); + return Q(path.join(plugins_dir, alias)); + } + + // if plugin doesnt exist, use fetch to get it. + if (newId) { + events.emit('warn', 'Notice: ' + splitVersion[0] + ' has been automatically converted to ' + newId + ' and fetched from npm. This is due to our old plugins registry shutting down.'); + } var opts = underscore.extend({}, options, { client: 'plugman' }); - // if plugin doesnt exist, use fetch to get it. return plugman.raw.fetch(id, plugins_dir, opts); } @@ -291,7 +298,6 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt var pluginInfoProvider = options.pluginInfoProvider; var pluginInfo = pluginInfoProvider.get(plugin_dir); var filtered_variables = {}; - var platformJson = PlatformJson.load(plugins_dir, platform); if (platformJson.isPluginInstalled(pluginInfo.id)) { @@ -432,20 +438,6 @@ 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('warn', '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) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org