Skip to content

Commit

Permalink
fix(module): parse apiversions to integer before comparing
Browse files Browse the repository at this point in the history
manifest apiversions and sdk provided apiversions are passed through as strings, apiversions from npm installed modules are provided as integers, by parsing everything to an integer before comparison we ensure we're comparing the same type always
  • Loading branch information
ewanharris committed Jul 2, 2019
1 parent 37e5f90 commit 2974e52
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/timodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ function find(modulesOrParams, platforms, deployType, tiManifest, searchPaths, l
return;
}

if (moduleAPIVersion && moduleAPIVersion[platform] && info.manifest && info.manifest.apiversion && info.manifest.apiversion !== moduleAPIVersion[platform]) {
const platformAPIVersion = moduleAPIVersion && moduleAPIVersion[platform] && parseInt(moduleAPIVersion[platform], 10);
const modAPIVersion = info.manifest && parseInt(info.manifest.apiversion, 10);
if (platformAPIVersion && modAPIVersion && modAPIVersion !== platformAPIVersion) {
if (params.logger) {
params.logger.debug(__('Found incompatible Titanium module id=%s version=%s platform=%s api-version=%s deploy-type=%s', tmp.id.cyan, tmp.version.cyan, tmp.platform.join(',').cyan, String(info.manifest.apiversion).cyan, tmp.deployType.join(',').cyan));
params.logger.debug(__('Module %s has apiversion=%s, but the selected SDK supports module apiversion=%s on platform=%s', tmp.id.cyan, info.manifest.apiversion.cyan, moduleAPIVersion[platform].cyan, platform.cyan));
params.logger.debug(__('Module %s has apiversion=%s, but the selected SDK supports module apiversion=%s on platform=%s', tmp.id.cyan, String(modAPIVersion).cyan, String(platformAPIVersion).cyan, platform.cyan));
}
result.incompatible.push(tmp);
foundIncompatible = true;
Expand Down
18 changes: 18 additions & 0 deletions test/resources/timodule5/modules/android/ti.map/3.1.0/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.1.0
apiversion: 2
architectures: arm64-v8a armeabi-v7a x86
description: External version of Map module
author: Jeff Haynie, Jon Alter, Pedro Enrique, Hans Knöchel, Vijay Singh
license: Apache Public License v2
copyright: Copyright (c) 2013-present by Axway Appcelerator

# these should not be edited
name: map
moduleid: ti.map
guid: fee93b77-8eb3-418c-8f04-013664c4af83
platform: android
minsdk: 6.2.2.GA
19 changes: 19 additions & 0 deletions test/test-timodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,25 @@ describe('timodule', function () {
}
}, true);
});

it('should parse apiversion to an integer before comparing', function (done) {
appc.timodule.find([
{ id: 'ti.map', platform: 'android' }
], [ 'android' ], 'development', { sdkVersion: '6.3.0', moduleAPIVersion: { android: 2 } }, [ path.join(__dirname, 'resources', 'timodule5') ], logger, function (result) {
try {
logger.buffer.stripColors.should.containEql(
'Found Titanium module id=ti.map version=3.1.0 platform=android deploy-type=development'
);

const found = result.found.find(r => r.id === 'ti.map');
assert(found, '"ti.map" module not marked as found');

done();
} catch (e) {
done(e);
}
}, true);
});
});

describe('#detectNodeModules()', () => {
Expand Down

0 comments on commit 2974e52

Please sign in to comment.