cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TimBarham <...@git.apache.org>
Subject [GitHub] cordova-lib pull request: New plugin version selection implementat...
Date Thu, 18 Feb 2016 11:56:38 GMT
Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/363#discussion_r53304649
  
    --- Diff: cordova-lib/src/cordova/plugin.js ---
    @@ -507,3 +527,117 @@ function versionString(version) {
     
         return null;
     }
    +
    +/**
    + * Gets the version of a plugin that should be fetched for a given project based
    + * on the plugin's engine information from NPM and the platforms/plugins installed
    + * in the project
    + *
    + * @param {string}  projectRoot     The path to the root directory of the project
    + * @param {object}  pluginInfo      The NPM info of the plugin be fetched (e.g. the
    + *                                  result of calling `registry.info()`)
    + * @param {string}  cordovaVersion  The semver version of cordova-lib
    + *
    + * @return {Promise}                A promise that will resolve to either a string
    + *                                  if there is a version of the plugin that this
    + *                                  project satisfies or null if there is not
    + */
    +function getFetchVersion(projectRoot, pluginInfo, cordovaVersion) {
    +    // Figure out the project requirements
    +    if (pluginInfo.engines && pluginInfo.engines.cordovaDependencies) {
    +        var pluginList = getInstalledPlugins(projectRoot);
    +        var pluginMap = {};
    +
    +        for(var i = 0; i < pluginList.length; i++) {
    +            pluginMap[pluginList[i].id] = pluginList[i].version;
    +        }
    +
    +        return cordova_util.getInstalledPlatformsWithVersions(projectRoot)
    +        .then(function(platformVersions) {
    +            return determinePluginVersionToFetch(
    +                pluginInfo.versions,
    +                pluginInfo.engines.cordovaDependencies,
    +                pluginMap,
    +                platformVersions,
    +                cordovaVersion);
    +        });
    +    } else {
    +        // If we have no engine, we want to fall back to the default behavior
    +        return Q.fcall(function() {
    +            return null;
    +        });
    +    }
    +}
    +
    +function determinePluginVersionToFetch(allVersions, engine, pluginMap, platformMap, cordovaVersion)
{
    +    var upperBounds = [];
    +    var versions = [];
    +
    +    for(var version in engine) {
    +        if(version.indexOf('<') === 0 && semver.valid(version.substring(1)))
{
    +            // We only care about upper bounds that our project does not support
    +            if(!satisfiesProjectRequirements(engine[version], pluginMap, platformMap,
cordovaVersion)) {
    +                upperBounds.push(version);
    +            }
    +        } else if(semver.valid(version) && allVersions.indexOf(version) !== -1)
{
    +            versions.push(version);
    +        }
    +    }
    --- End diff --
    
    So do we only support version ranges in the form of `<x.y.z` and specific versions?
I was thinking it might be handy for a plugin dev to specify other ranges. For example, `^1.0.0`
to identify requirements for all 1.x releases. That might actually be very easy to handle
- `semver.maxSatisfying(versions, range)` will take an array of versions (which we have) and
a range, and return the highest version from the list that matches the range. If you do this
to all ranges (including `<x.y.z` type ranges), could you avoid the special case `upperBounds`
handling? Any range could be converted to a single version (the maximum actual version that
matches the range) - could that then be handled like any other entry?


---
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


Mime
View raw message