CB-10845 Invalidate manifest cache in prepare
Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/16a02435 Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/16a02435 Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/16a02435 Branch: refs/heads/4.3.x Commit: 16a024355d57029813f259972e87f2ca81470046 Parents: d1ab042 Author: Vladimir Kotikov <kotikov.vladi...@gmail.com> Authored: Thu Mar 24 16:04:13 2016 +0300 Committer: Vladimir Kotikov <kotikov.vladi...@gmail.com> Committed: Thu Mar 31 10:43:03 2016 +0300 ---------------------------------------------------------------------- spec/unit/AppxManifest.spec.js | 36 +++++++++++++++++++++++++++++++ template/cordova/lib/AppxManifest.js | 19 ++++++++++++++++ template/cordova/lib/prepare.js | 5 +++++ 3 files changed, 60 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/16a02435/spec/unit/AppxManifest.spec.js ---------------------------------------------------------------------- diff --git a/spec/unit/AppxManifest.spec.js b/spec/unit/AppxManifest.spec.js index 48fb514..691252a 100644 --- a/spec/unit/AppxManifest.spec.js +++ b/spec/unit/AppxManifest.spec.js @@ -65,6 +65,42 @@ describe('AppxManifest', function () { }); }); + describe('purgeCache method', function () { + beforeEach(function () { + AppxManifest.__set__('manifestCache', { a: 'foo/a', b: 'foo/b', c: 'foo/c' }); + }); + + it('should remove all entries when no parameter is specified', function () { + AppxManifest.purgeCache(); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(0); + }); + + it('should remove an entry when parameter is a string key', function () { + AppxManifest.purgeCache('a'); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(2); + expect(cache.a).not.toBeDefined(); + }); + + it('should remove multiple entries when parameter is an array of keys', function () { + AppxManifest.purgeCache(['a', 'b']); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(1); + expect(cache.a).not.toBeDefined(); + expect(cache.b).not.toBeDefined(); + }); + + it('should not remove anything if there is no such key', function () { + AppxManifest.purgeCache(['bar']); + var cache = AppxManifest.__get__('manifestCache'); + expect(Object.keys(cache).length).toBe(3); + expect(cache.a).toBeDefined(); + expect(cache.b).toBeDefined(); + expect(cache.c).toBeDefined(); + }); + }); + describe('static get() method', function () { it('should return an AppxManifest instance', function () { http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/16a02435/template/cordova/lib/AppxManifest.js ---------------------------------------------------------------------- diff --git a/template/cordova/lib/AppxManifest.js b/template/cordova/lib/AppxManifest.js index 8c934e6..ee1e727 100644 --- a/template/cordova/lib/AppxManifest.js +++ b/template/cordova/lib/AppxManifest.js @@ -112,6 +112,25 @@ AppxManifest.get = function (fileName, ignoreCache) { return result; }; +/** + * Removes manifests from cache to prevent using stale entries + * + * @param {String|String[]} [cacheKeys] The keys to delete from cache. If not + * specified, the whole cache will be purged + */ +AppxManifest.purgeCache = function (cacheKeys) { + if (!cacheKeys) { + // if no arguments passed, remove all entries + manifestCache = {}; + return; + } + + var keys = Array.isArray(cacheKeys) ? cacheKeys : [cacheKeys]; + keys.forEach(function (key) { + delete manifestCache[key]; + }); +}; + AppxManifest.prototype.getPhoneIdentity = function () { var phoneIdentity = this.doc.getroot().find('./mp:PhoneIdentity'); if (!phoneIdentity) http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/16a02435/template/cordova/lib/prepare.js ---------------------------------------------------------------------- diff --git a/template/cordova/lib/prepare.js b/template/cordova/lib/prepare.js index 699e379..aefe12c 100644 --- a/template/cordova/lib/prepare.js +++ b/template/cordova/lib/prepare.js @@ -410,6 +410,11 @@ module.exports.prepare = function (cordovaProject) { this._config = updateConfigFilesFrom(cordovaProject.projectConfig, this._munger, this.locations); + // CB-10845 avoid using cached appxmanifests since they could be + // previously modififed outside of AppxManifest class + // TODO: invalidate only entries that were affected by config munge + AppxManifest.purgeCache(); + // Update own www dir with project's www assets and plugins' assets and js-files return Q.when(updateWwwFrom(cordovaProject, this.locations)) .then(function () { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org