Skip to content

Commit

Permalink
Rewrite cordova/requirements to get rid of Q.allSettled
Browse files Browse the repository at this point in the history
Behavior of cordova/requirements should remain unchanged.
  • Loading branch information
raphinesse committed Sep 29, 2018
1 parent eb9aa97 commit af1a1b5
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/cordova/requirements.js
Expand Up @@ -17,10 +17,10 @@
under the License.
*/

var cordova_util = require('./util');
var Q = require('q');
var CordovaError = require('cordova-common').CordovaError;
var knownPlatforms = require('../platforms/platforms');
const { object: zipObject } = require('underscore');
const { preProcessOptions } = require('./util');
const { CordovaError } = require('cordova-common');
const knownPlatforms = require('../platforms/platforms');

/**
* Runs requirements check against platforms specified in 'platfoms' argument
Expand All @@ -32,21 +32,18 @@ var knownPlatforms = require('../platforms/platforms');
* requirements check results for each platform.
*/
module.exports = function check_reqs (platforms) {
return Promise.resolve().then(function () {
var platforms = cordova_util.preProcessOptions(platforms).platforms; // eslint-disable-line no-use-before-define
return Promise.resolve().then(() => {
const normalizedPlatforms = preProcessOptions(platforms).platforms;

This comment has been minimized.

Copy link
@bluetech

bluetech Dec 3, 2018

Contributor

@raphinesse This line causes an error for me, this.isCordova is not a function. The problem is that preProcessOptions assumes it is called as cordova_util.preProcessOptions, it needs its this to be bound to cordova_util. But when called as above the this is bound to global.

This comment has been minimized.

Copy link
@brodybits

brodybits Dec 3, 2018

Contributor

I recall seeing this error on cordova@nightly, would recommend you raise an issue for tracking.

This comment has been minimized.

Copy link
@bluetech

bluetech Dec 3, 2018

Contributor

Sure, I opened #740.

This comment has been minimized.

Copy link
@brodybits

brodybits Dec 3, 2018

Contributor

Thanks!


return Q.allSettled(platforms.map(function (platform) {
return knownPlatforms.getPlatformApi(platform).requirements();
})).then(function (settledChecks) {
var res = {};
settledChecks.reduce(function (result, settledCheck, idx) {
var platformName = platforms[idx];
result[platformName] = settledCheck.state === 'fulfilled' ?
settledCheck.value :
new CordovaError(settledCheck.reason);
return result;
}, res);
return res;
});
return Promise.all(
normalizedPlatforms.map(getPlatformRequirementsOrError)
).then(results => zipObject(normalizedPlatforms, results));
});
};

function getPlatformRequirementsOrError (platform) {
return knownPlatforms
.getPlatformApi(platform)
.requirements()
.catch(err => new CordovaError(err));
}

0 comments on commit af1a1b5

Please sign in to comment.