cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-12021) --fetch should use dependency version saved in package.json before default cordova version when adding/restoring
Date Sat, 18 Feb 2017 00:23:44 GMT

    [ https://issues.apache.org/jira/browse/CB-12021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15872792#comment-15872792
] 

ASF GitHub Bot commented on CB-12021:
-------------------------------------

Github user stevengill commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/518#discussion_r101870795
  
    --- 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 --
    
    `noSymbolVersion` doesn't have a value if `parsedSpec.version` doesn't have a `^` or `~`.
 I'd fix that by giving `noSymbolVersion` a default value of `parsedSpec.version`. Like:
    
    ```
    var noSymbolVersion = parsedSpec.version
    ```
    
    So the purpose of this code is to replace the plugin dependency version in `package.json`
if the user passes in a specific one that doesn't satisfy what is already in `package.json`.
    
    I believe `parsedSpec.version` can be:
    
    * a version number (possibly with ^ or ~)
    * a url
    * a local path
    
    I think semver.satisfies would fail if `parsedSpec.version` was url or path. 
    
    Maybe we do checks similar to line 428 to see if `parsedSpec.version` is a URL or directory.
If it is, don't do th satisfies check, instead do a equivalence check (pkgJson.dependencies[parsedSpec.package]
=== parsedSpec.version)
    
    We also don't check if fetchOptions.save is true. We don't want to write to package.json
unless that is true.
    
    
     


> --fetch should use dependency version saved in package.json before default cordova version
when adding/restoring
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-12021
>                 URL: https://issues.apache.org/jira/browse/CB-12021
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-fetch, CordovaLib
>            Reporter: Steve Gill
>            Assignee: Audrey So
>              Labels: cordova-7.0.0
>             Fix For: 7.0.0
>
>
> cordova platform add android --save --fetch should use the version of cordova-android
already saved in package.json instead of the version from platformsConfig.json



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message