Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 93749200C2D for ; Sat, 18 Feb 2017 01:46:28 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 920D9160B6D; Sat, 18 Feb 2017 00:46:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DCE5E160B57 for ; Sat, 18 Feb 2017 01:46:27 +0100 (CET) Received: (qmail 91532 invoked by uid 500); 18 Feb 2017 00:46:27 -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 91519 invoked by uid 99); 18 Feb 2017 00:46:26 -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; Sat, 18 Feb 2017 00:46:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 87EECDFBD3; Sat, 18 Feb 2017 00:46:26 +0000 (UTC) From: audreyso To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request #518: CB-12021 : --fetch should use dependency vers... Content-Type: text/plain Message-Id: <20170218004626.87EECDFBD3@git1-us-west.apache.org> Date: Sat, 18 Feb 2017 00:46:26 +0000 (UTC) archived-at: Sat, 18 Feb 2017 00:46:28 -0000 Github user audreyso commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/518#discussion_r101875939 --- Diff: cordova-lib/src/cordova/plugin.js --- @@ -388,26 +384,54 @@ module.exports = function plugin(command, targets, opts) { function determinePluginTarget(projectRoot, cfg, target, fetchOptions) { var parsedSpec = pluginSpec.parse(target); - var id = parsedSpec.package || target; - // CB-10975 We need to resolve relative path to plugin dir from app's root before checking whether if it exists var maybeDir = cordova_util.fixRelativePath(id); if (parsedSpec.version || cordova_util.isUrl(id) || cordova_util.isDirectory(maybeDir)) { return Q(target); } + // Require project pkgJson. + var pkgJsonPath = path.join(projectRoot, 'package.json'); + if(fs.existsSync(pkgJsonPath)) { + delete require.cache[require.resolve(pkgJsonPath)]; + pkgJson = require(pkgJsonPath); + } - // If no version is specified, retrieve the version (or source) from config.xml - events.emit('verbose', 'No version specified for ' + parsedSpec.package + ', retrieving version from config.xml'); - var ver = getVersionFromConfigFile(id, cfg); + // If no parsedSpec.version, use the one from pkg.json or config.xml. + if (!parsedSpec.version) { + // Retrieve from pkg.json. + if(pkgJson && pkgJson.dependencies && pkgJson.dependencies[id]) { + events.emit('verbose', 'No version specified for ' + id + ', retrieving version from package.json'); + parsedSpec.version = pkgJson.dependencies[id]; + } else { + // If no version is specified, retrieve the version (or source) from config.xml. + events.emit('verbose', 'No version specified for ' + id + ', retrieving version from config.xml'); + parsedSpec.version = getVersionFromConfigFile(id, cfg); + } + } + + // If parsedSpec.version satisfies pkgJson version, no writing to pkg.json. Only write when + // it does not satisfy. + if(parsedSpec.version) { + if(pkgJson && pkgJson.dependencies && pkgJson.dependencies[parsedSpec.package]) { + var noSymbolVersion; + if (parsedSpec.version.charAt(0) === '^' || parsedSpec.version.charAt(0) === '~') { + noSymbolVersion = parsedSpec.version.slice(1); + } + if (!semver.satisfies(noSymbolVersion, pkgJson.dependencies[parsedSpec.package])) { --- End diff -- How does this look? ```// If parsedSpec.version satisfies pkgJson version, no writing to pkg.json. Only write when // it does not satisfy. if(parsedSpec.version) { if(pkgJson && pkgJson.dependencies && pkgJson.dependencies[parsedSpec.package]) { var noSymbolVersion = parsedSpec.version; if (parsedSpec.version.charAt(0) === '^' || parsedSpec.version.charAt(0) === '~') { noSymbolVersion = parsedSpec.version.slice(1); } if (pkgJson.dependencies[parsedSpec.package] === parsedSpec.version) { pkgJson.dependencies[parsedSpec.package] = parsedSpec.version; if (fetchOptions.save === true) { fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8'); } } } } if (cordova_util.isUrl(parsedSpec.version) || cordova_util.isDirectory(parsedSpec.version) || pluginSpec.parse(parsedSpec.version).scope) { return Q(parsedSpec.version); }``` --- 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