From 5a4d5035c3deffca5384366e15c3f4d14b55a551 Mon Sep 17 00:00:00 2001 From: Bartosz Wojtkowiak Date: Wed, 26 Apr 2017 20:43:39 +0200 Subject: [PATCH] Implement CORDOVA_COMPATIBILITY_VERSION_IOS/ANDROID and EXCLUDE (#8581) * Implement CORDOVA_COMPATIBILITY_VERSION_EXCLUDE and CORDOVA_COMPATIBILITY_VERSION_IOS/ANDROID CORDOVA_COMPATIBILITY_VERSION_IOS or CORDOVA_COMPATIBILITY_VERSION_ANDROID allows to override compatibility version for a specified platform. CORDOVA_COMPATIBILITY_VERSION_EXCLUDE provides a way of excluding a certain plugin from compatibility version calculation. You can pass several plugin names with ';'. For example: `CORDOVA_COMPATIBILITY_VERSION_EXCLUDE='cordova-plugin-crosswalk-webview;cordova-plugin-device'` * Changes after review --- tools/isobuild/bundler.js | 17 +++++++++++--- tools/tests/cordova-hcp.js | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index 3bbc8cacb4..87add438ad 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -1522,11 +1522,22 @@ class ClientTarget extends Target { if (this.arch === 'web.cordova') { const { WebAppHashing } = loadIsopacket('cordova-support')['webapp-hashing']; + const cordovaCompatibilityVersions = _.object(_.map(CORDOVA_PLATFORM_VERSIONS, (version, platform) => { - const hash = WebAppHashing.calculateCordovaCompatibilityHash( - version, - this.cordovaDependencies); + + const pluginsExcludedFromCompatibilityHash = (process.env.METEOR_CORDOVA_COMPAT_VERSION_EXCLUDE || '') + .split(','); + + const cordovaDependencies = Object.assign( + Object.create(null), + _.omit(this.cordovaDependencies, pluginsExcludedFromCompatibilityHash) + ); + + const hash = process.env[`METEOR_CORDOVA_COMPAT_VERSION_${platform.toUpperCase()}`] || + WebAppHashing.calculateCordovaCompatibilityHash( + version, + cordovaDependencies); return [platform, hash]; })); program.cordovaCompatibilityVersions = cordovaCompatibilityVersions; diff --git a/tools/tests/cordova-hcp.js b/tools/tests/cordova-hcp.js index 1a15ec88b8..efd7be0e55 100644 --- a/tools/tests/cordova-hcp.js +++ b/tools/tests/cordova-hcp.js @@ -39,3 +39,50 @@ selftest.define( run.stop(); }); + +selftest.define( + "cordova METEOR_CORDOVA_COMPAT_VERSION_* works", ["cordova", "slow"], function () { + var s = new Sandbox(); + var run; + + var androidCompatibilityVersion = '2.0'; + + // Override the compatibility version for android with METEOR_CORDOVA_COMPAT_VERSION_ANDROID. + s.env.METEOR_CORDOVA_COMPAT_VERSION_ANDROID = androidCompatibilityVersion; + + s.createApp("myapp", "standard-app"); + s.cd("myapp"); + + var platforms = s.read(".meteor/platforms"); + s.write(".meteor/platforms", platforms + "\nandroid\n"); + + run = s.run("run", "android", "--mobile-server", "example.com"); + run.waitSecs(30); + run.match("Started your app"); + + var result = JSON.parse(httpHelpers.getUrl( + "http://localhost:3000/__cordova/manifest.json")); + + // Check in the manifest if the overridden version was used. + selftest.expectEqual(result.cordovaCompatibilityVersions.android, androidCompatibilityVersion); + + run.stop(); + // Save the iOS compatibility version. + var iosCompatibilityVersion = result.cordovaCompatibilityVersions.ios; + + // Now exclude one of the plugins from compatibility version calculation. + s.env.METEOR_CORDOVA_COMPAT_VERSION_EXCLUDE = 'cordova-plugin-meteor-webapp,any-other-plugin'; + + run = s.run("run", "android", "--mobile-server", "example.com"); + run.waitSecs(30); + run.match("Started your app"); + + result = JSON.parse(httpHelpers.getUrl( + "http://localhost:3000/__cordova/manifest.json")); + + // Version should be different. There is no need to check if the particular plugin was not taken into account, + // if the version has changed it's proof enough. + selftest.expectFalse(result.cordovaCompatibilityVersions.ios === iosCompatibilityVersion); + + run.stop(); +}); \ No newline at end of file