You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/17 17:59:32 UTC
[1/2] js commit: [all] Turns on modulemapper.
[all] Turns on modulemapper.
- Adds the ability to load all modules that match a given pattern.
- Uses this in bootstrap to load all symbol modules.
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/d989ba1f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/d989ba1f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/d989ba1f
Branch: refs/heads/symbolmapping
Commit: d989ba1fb954f8c69bcc76cfa9536ecea6987e21
Parents: 403d931
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jan 17 11:55:39 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jan 17 11:55:39 2013 -0500
----------------------------------------------------------------------
lib/common/modulemapper.js | 11 ++++++++++-
lib/scripts/bootstrap.js | 4 ++++
test/test.modulemapper.js | 24 ++++++++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d989ba1f/lib/common/modulemapper.js
----------------------------------------------------------------------
diff --git a/lib/common/modulemapper.js b/lib/common/modulemapper.js
index 9714618..18f2e5c 100644
--- a/lib/common/modulemapper.js
+++ b/lib/common/modulemapper.js
@@ -19,6 +19,7 @@
*/
var builder = require('cordova/builder'),
+ moduleMap = define.moduleMap,
symbolList,
deprecationMap;
@@ -28,7 +29,7 @@ exports.reset = function() {
};
function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
- if (!(moduleName in define.moduleMap)) {
+ if (!(moduleName in moduleMap)) {
throw new Error('Module ' + moduleName + ' does not exist.');
}
symbolList.push(strategy, moduleName, symbolPath);
@@ -84,5 +85,13 @@ exports.getOriginalSymbol = function(context, symbolPath) {
return origSymbols && origSymbols[symbolPath];
};
+exports.loadMatchingModules = function(matchingRegExp) {
+ for (var k in moduleMap) {
+ if (matchingRegExp.exec(k)) {
+ require(k);
+ }
+ }
+};
+
exports.reset();
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d989ba1f/lib/scripts/bootstrap.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap.js b/lib/scripts/bootstrap.js
index 62f3e69..9fa92d8 100644
--- a/lib/scripts/bootstrap.js
+++ b/lib/scripts/bootstrap.js
@@ -37,6 +37,7 @@
channel.join(function() {
var builder = require('cordova/builder'),
base = require('cordova/common'),
+ modulemapper = require('cordova/modulemapper'),
platform = require('cordova/platform');
// Drop the common globals into the window object, but be nice and don't overwrite anything.
@@ -48,6 +49,9 @@
builder.buildIntoAndClobber(platform.clobbers, context);
builder.buildIntoAndMerge(platform.merges, context);
+ modulemapper.loadMatchingModules(/cordova.*\/symbols$/);
+ modulemapper.mapModules(context);
+
// Call the platform-specific initialization
platform.initialize();
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d989ba1f/test/test.modulemapper.js
----------------------------------------------------------------------
diff --git a/test/test.modulemapper.js b/test/test.modulemapper.js
index 826fab2..8ae27d3 100644
--- a/test/test.modulemapper.js
+++ b/test/test.modulemapper.js
@@ -145,4 +145,28 @@ describe('modulemapper', function() {
modulemapper.mapModules(context);
expect(modulemapper.getOriginalSymbol(context, 'obj')).toBe(orig);
});
+ it('should load modules with loadMatchingModules', function() {
+ var spyModules = {};
+ this.after(function() {
+ Object.keys(spyModules).forEach(define.remove);
+ });
+ function addModule(name) {
+ spyModules[name] = jasmine.createSpy(name);
+ define(name, spyModules[name]);
+ }
+ function expectCalled(names) {
+ for (var k in spyModules) {
+ expect(spyModules[k].wasCalled).toBe(names.indexOf(k) != -1, 'for module:' + k);
+ }
+ }
+ addModule('foo/a');
+ addModule('foo/b');
+ addModule('foo/symbols1');
+ addModule('foo/symbols');
+ addModule('foo/bar/symbols');
+ addModule('baz/symbols');
+ modulemapper.loadMatchingModules(/^foo.*\/symbols$/);
+ expectCalled(['foo/symbols', 'foo/bar/symbols']);
+ });
});
+