Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 392C4185FF for ; Thu, 18 Feb 2016 11:08:35 +0000 (UTC) Received: (qmail 39184 invoked by uid 500); 18 Feb 2016 11:08:30 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 39143 invoked by uid 500); 18 Feb 2016 11:08:29 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 39132 invoked by uid 99); 18 Feb 2016 11:08:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Feb 2016 11:08:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9601BDFF67; Thu, 18 Feb 2016 11:08:29 +0000 (UTC) From: TimBarham To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request: New plugin version selection implementat... Content-Type: text/plain Message-Id: <20160218110829.9601BDFF67@git1-us-west.apache.org> Date: Thu, 18 Feb 2016 11:08:29 +0000 (UTC) Github user TimBarham commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/363#discussion_r53300134 --- Diff: cordova-lib/src/cordova/plugin.js --- @@ -154,6 +135,38 @@ module.exports = function plugin(command, targets, opts) { is_top_level: true }; + // 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)) { + target = ver; + } else if (ver) { + // If version exists in config.xml, use that + target = ver ? (id + '@' + ver) : target; + } else { + // If no version is given at all, We need to decide what version to + // fetch based on the current project + return registry.info([id]) + .then(function(pluginInfo) { + return getFetchVersion(projectRoot, pluginInfo, pkgJson.version); + }) + .then(function(fetchVersion) { + // Fallback to pinned version if available + fetchVersion = fetchVersion ? fetchVersion : pkgJson.cordovaPlugins[id]; + target = fetchVersion ? (id + '@' + fetchVersion) : target; + + events.emit('verbose', 'Calling plugman.fetch on plugin "' + target + '"'); + return plugman.raw.fetch(target, pluginPath, fetchOptions); + }) + .then(function (directory) { + return pluginInfoProvider.get(directory); + }); --- End diff -- We don't want this code duplicating the code below. It's only a couple of lines now, but it leaves us open to problems later on if changes are made to what we do here. Instead, I'd suggest moving this whole `if` block (that is, `if (!version && !cordova_util.isUrl(id) && !cordova_util.isDirectory(id)) { ... }`) to a separate method that returns a promise for a version. Then you can have a single `plugman.raw.fetch()` and `pluginInfoProvider.get()` regardless of whether the operation to determine the version is sync or async. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org