You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2016/03/29 08:33:05 UTC
cordova-windows git commit: CB-10845 Invalidate manifest cache in
prepare
Repository: cordova-windows
Updated Branches:
refs/heads/master b796bd75c -> a4c673e30
CB-10845 Invalidate manifest cache in prepare
This closes #164
Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/a4c673e3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/a4c673e3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/a4c673e3
Branch: refs/heads/master
Commit: a4c673e3028f8b2cb28e2a9cc395ebb9620c2fce
Parents: b796bd7
Author: Vladimir Kotikov <ko...@gmail.com>
Authored: Thu Mar 24 16:04:13 2016 +0300
Committer: Vladimir Kotikov <ko...@gmail.com>
Committed: Tue Mar 29 09:29:14 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/a4c673e3/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/a4c673e3/template/cordova/lib/AppxManifest.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/AppxManifest.js b/template/cordova/lib/AppxManifest.js
index 465f698..5688ce1 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/a4c673e3/template/cordova/lib/prepare.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/prepare.js b/template/cordova/lib/prepare.js
index ca90fab..e8e04fc 100644
--- a/template/cordova/lib/prepare.js
+++ b/template/cordova/lib/prepare.js
@@ -420,6 +420,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-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org