[Pkg-javascript-commits] [dojo] 119/149: fixes #18129, allow mapping to work with multiple versions of Dojo

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:54 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository dojo.

commit 3c4337021dba9f60c6ffc2beb7a9696f87c2c4f8
Author: Benjamin Santalucia <ben at dojotoolkit-fr.org>
Date:   Wed Dec 30 06:41:28 2015 -0700

    fixes #18129, allow mapping to work with multiple versions of Dojo
---
 dojo.js                                            | 24 ++++---
 tests/functional/_base/loader.js                   | 82 ++++++++++++++++++++++
 .../_base/loader/mapping-multi-layer/App1/thing.js | 14 ++++
 .../_base/loader/mapping-multi-layer/App2/thing.js | 21 ++++++
 .../loader/mapping-multi-layer/Common1/another.js  |  4 ++
 .../loader/mapping-multi-layer/Common2/another.js  |  4 ++
 .../mapping-multi-layer/Common2/anotherone.js      |  4 ++
 .../mapping-multi-layer/MappedModule/mappedA.js    |  4 ++
 .../mapping-multi-layer/MappedModule/mappedB.js    |  4 ++
 .../mapping-multi-layer/MappedModule/mappedC.js    |  4 ++
 .../loader/mapping-multi-layer/Router/demoA.js     |  4 ++
 .../loader/mapping-multi-layer/Router/demoB.js     |  4 ++
 .../loader/mapping-multi-layer/Router/demoC.js     |  4 ++
 .../_base/loader/mapping-multi-layer/main.js       | 70 ++++++++++++++++++
 .../functional/_base/loader/mappingMultiLayer.html | 63 +++++++++++++++++
 15 files changed, 300 insertions(+), 10 deletions(-)

diff --git a/dojo.js b/dojo.js
index ada9bbb..5c4bdd9 100644
--- a/dojo.js
+++ b/dojo.js
@@ -482,7 +482,8 @@
 			= 0;
 
 	if(has("dojo-config-api")){
-		var consumePendingCacheInsert = function(referenceModule){
+		var consumePendingCacheInsert = function(referenceModule, clear){
+				clear = clear !== false;
 				var p, item, match, now, m;
 				for(p in pendingCacheInsert){
 					item = pendingCacheInsert[p];
@@ -499,7 +500,9 @@
 				if(now){
 					now(createRequire(referenceModule));
 				}
-				pendingCacheInsert = {};
+				if(clear){
+					pendingCacheInsert = {};
+				}
 			},
 
 			escapeString = function(s){
@@ -654,9 +657,8 @@
 				if(config.cache){
 					consumePendingCacheInsert();
 					pendingCacheInsert = config.cache;
-					if(config.cache["*noref"]){
-						consumePendingCacheInsert();
-					}
+					//inject now all depencies so cache is available for mapped module
+					consumePendingCacheInsert(0, !!config.cache["*noref"]);
 				}
 
 				signal("config", [config, req.rawConfig]);
@@ -958,7 +960,7 @@
 			}
 		},
 
-		getModuleInfo_ = function(mid, referenceModule, packs, modules, baseUrl, mapProgs, pathsMapProg, aliases, alwaysCreate){
+		getModuleInfo_ = function(mid, referenceModule, packs, modules, baseUrl, mapProgs, pathsMapProg, aliases, alwaysCreate, fromPendingCache){
 			// arguments are passed instead of using lexical variables so that this function my be used independent of the loader (e.g., the builder)
 			// alwaysCreate is useful in this case so that getModuleInfo never returns references to real modules owned by the loader
 			var pid, pack, midInPackage, mapItem, url, result, isRelative, requestedMid;
@@ -979,11 +981,13 @@
 				// at this point, mid is an absolute mid
 
 				// map the mid
-				if(referenceModule){
+				if(!fromPendingCache && !isRelative && mapProgs.star){
+					mapItem = runMapProg(mid, mapProgs.star[1]);
+				}
+				if(!mapItem && referenceModule){
 					mapItem = runMapProg(referenceModule.mid, mapProgs);
+					mapItem = mapItem && runMapProg(mid, mapItem[1]);
 				}
-				mapItem = mapItem || mapProgs.star;
-				mapItem = mapItem && runMapProg(mid, mapItem[1]);
 
 				if(mapItem){
 					mid = mapItem[1] + mid.substring(mapItem[3]);
@@ -1038,7 +1042,7 @@
 		},
 
 		getModuleInfo = function(mid, referenceModule, fromPendingCache){
-			return getModuleInfo_(mid, referenceModule, packs, modules, req.baseUrl, fromPendingCache ? [] : mapProgs, fromPendingCache ? [] : pathsMapProg, fromPendingCache ? [] : aliases);
+			return getModuleInfo_(mid, referenceModule, packs, modules, req.baseUrl, mapProgs, pathsMapProg, aliases, undefined, fromPendingCache);
 		},
 
 		resolvePluginResourceId = function(plugin, prid, referenceModule){
diff --git a/tests/functional/_base/loader.js b/tests/functional/_base/loader.js
index 2cfa603..1484ebc 100644
--- a/tests/functional/_base/loader.js
+++ b/tests/functional/_base/loader.js
@@ -648,6 +648,88 @@ define([
 				});
 			}
 		),
+		mappingMultiLayer: loaderTest(
+			require.toUrl('./loader/index.html'),
+			{
+				async: true,
+				baseUrl: '.',
+				packages: [
+					{ name: 'dojo', location: 'node_modules/dojo' },
+					{
+						name: 'test',
+						location: './mapping-multi-layer'
+					},
+					{
+						name: 'app1',
+						location: './mapping-multi-layer/App1'
+					},
+					{
+						name: 'app2',
+						location: './mapping-multi-layer/App2'
+					},
+					{
+						name: 'common1',
+						location: './mapping-multi-layer/Common1'
+					},
+					{
+						name: 'common2',
+						location: './mapping-multi-layer/Common2'
+					},
+					{
+						name: 'router',
+						location: './mapping-multi-layer/Router'
+					},
+					{
+						name: 'mappedModule',
+						location: './mapping-multi-layer/MappedModule'
+					}
+				],
+				map: {
+					'app1': {
+						'common': 'common1'
+					},
+					'app2': {
+						'common': 'common2'
+					},
+					'my/replacement/A': {
+						'my/A': 'my/A'
+					},
+					'*': {
+						'starmap/demo1': 'router/demoA',
+						'starmap/demo2': 'router/demoB',
+						'starmapModule': 'mappedModule',
+						'my/A': 'my/replacement/A'
+					}
+				}
+			},
+			function (callback) {
+				// consume pending cache, the following are added at the end of a built dojo.js in a closure
+				require({ cache: {} });
+				!require.async && require([ 'dojo' ]);
+				require.boot && require.apply(null, require.boot);
+
+				// begin test:
+				// moving modules from the pending cache to the module cache should ignore
+				// any mapping, pathing, or alias rules
+				var handle = require.on('error', function () {
+					handle.remove();
+					callback({ error: true });
+				});
+				require([ 'test/main' ], function () {
+					handle.remove();
+					callback({ error: false, results: results });
+				});
+			},
+			function (data) {
+				if (data.error) {
+					assert.fail("require error");
+				}
+				else {
+					var expected = ["Common1/another:cache", "Router/demoB:nocache", "App1/thing:cache", "Router/demoC:cache", "Router/demoA:cache", "MappedModule/mappedC:cache", "mappedModule/mappedA:cache", "my/B:cache", "my/A:cache", "my/replacement/A:cache", "mainRequire1:loaded", "Common2/anotherone:cache", "Common2/another:cache", "mappedModule/mappedB:cache", "App2/thing:cache", "mainRequire2:loaded"];
+					assert.strictEqual(data.results.join(), expected.join());
+				}
+			}
+		),
 
 		mapping: loaderTest(
 			require.toUrl('./loader/index.html'),
diff --git a/tests/functional/_base/loader/mapping-multi-layer/App1/thing.js b/tests/functional/_base/loader/mapping-multi-layer/App1/thing.js
new file mode 100644
index 0000000..b8dd2e5
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/App1/thing.js
@@ -0,0 +1,14 @@
+require({cache:
+	{
+		'common/another':function(){
+			define([], function () {
+				console.log('this is Common1/another in layer');
+				results.push('Common1/another:cache');
+			});
+		}
+	}
+});
+define(['common/another', 'starmap/demo2'], function() {
+	console.log('this is App1/thing in layer');
+	results.push('App1/thing:cache');
+});
diff --git a/tests/functional/_base/loader/mapping-multi-layer/App2/thing.js b/tests/functional/_base/loader/mapping-multi-layer/App2/thing.js
new file mode 100644
index 0000000..f2e28a1
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/App2/thing.js
@@ -0,0 +1,21 @@
+require({cache:
+	{
+		'common/another':function(){
+			define(['./anotherone'], function () {
+				console.log('this is Common2/another in layer');
+				results.push('Common2/another:cache');
+			});
+		},
+		'common/anotherone':function(){
+			define([], function () {
+				console.log('this is Common2/anotherone in layer');
+				results.push('Common2/anotherone:cache');
+			});
+		}
+
+	}
+});
+define(['common/another', 'starmapModule/mappedB'], function() {
+	console.log('this is App2/thing in layer');
+	results.push('App2/thing:cache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/Common1/another.js b/tests/functional/_base/loader/mapping-multi-layer/Common1/another.js
new file mode 100644
index 0000000..6f833ae
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/Common1/another.js
@@ -0,0 +1,4 @@
+define([], function () {
+	console.log('this is Common1/another no layer');
+	results.push('Common1/another:nocache');
+});
diff --git a/tests/functional/_base/loader/mapping-multi-layer/Common2/another.js b/tests/functional/_base/loader/mapping-multi-layer/Common2/another.js
new file mode 100644
index 0000000..2871a5b
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/Common2/another.js
@@ -0,0 +1,4 @@
+define(['./anotherone'], function () {
+	console.log('this is Common2/another no layer');
+	results.push('Common2/another:nocache');
+});
diff --git a/tests/functional/_base/loader/mapping-multi-layer/Common2/anotherone.js b/tests/functional/_base/loader/mapping-multi-layer/Common2/anotherone.js
new file mode 100644
index 0000000..8d24677
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/Common2/anotherone.js
@@ -0,0 +1,4 @@
+define([], function () {
+	console.log('this is Common2/anotherone no layer');
+	results.push('Common2/anotherone:nocache');
+});
diff --git a/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedA.js b/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedA.js
new file mode 100644
index 0000000..ed3c37a
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedA.js
@@ -0,0 +1,4 @@
+define(['./mappedC'], function () {
+	console.log('this is MappedModule/mappedA no layer');
+	results.push('MappedModule/mappedA:nocache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedB.js b/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedB.js
new file mode 100644
index 0000000..d852303
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedB.js
@@ -0,0 +1,4 @@
+define([], function () {
+	console.log('this is MappedModule/mappedB no layer');
+	results.push('MappedModule/mappedB:nocache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedC.js b/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedC.js
new file mode 100644
index 0000000..affe328
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/MappedModule/mappedC.js
@@ -0,0 +1,4 @@
+define([], function () {
+	console.log('this is MappedModule/mappedC no layer');
+	results.push('MappedModule/mappedC:nocache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/Router/demoA.js b/tests/functional/_base/loader/mapping-multi-layer/Router/demoA.js
new file mode 100644
index 0000000..eeae92c
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/Router/demoA.js
@@ -0,0 +1,4 @@
+define(['./demoC'], function () {
+	console.log('this is Router/demoA no layer');
+	results.push('Router/demoA:nocache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/Router/demoB.js b/tests/functional/_base/loader/mapping-multi-layer/Router/demoB.js
new file mode 100644
index 0000000..2fed1e4
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/Router/demoB.js
@@ -0,0 +1,4 @@
+define([], function () {
+	console.log('this is Router/demoB no layer');
+	results.push('Router/demoB:nocache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/Router/demoC.js b/tests/functional/_base/loader/mapping-multi-layer/Router/demoC.js
new file mode 100644
index 0000000..5dcad90
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/Router/demoC.js
@@ -0,0 +1,4 @@
+define([], function () {
+	console.log('this is Router/demoC no layer');
+	results.push('Router/demoC:nocache');
+});
\ No newline at end of file
diff --git a/tests/functional/_base/loader/mapping-multi-layer/main.js b/tests/functional/_base/loader/mapping-multi-layer/main.js
new file mode 100644
index 0000000..de912bf
--- /dev/null
+++ b/tests/functional/_base/loader/mapping-multi-layer/main.js
@@ -0,0 +1,70 @@
+results = [];
+require({cache:
+	{
+		'router/demoA':function(){
+			define(['./demoC'], function () {
+				console.log('this is Router/demoA in layer');
+				results.push('Router/demoA:cache');
+			});
+		},
+		'router/demoC':function(){
+			define([], function () {
+				console.log('this is Router/demoC in layer');
+				results.push('Router/demoC:cache');
+			});
+		},
+		'mappedModule/mappedA': function() {
+			define(['./mappedC'], function () {
+				console.log('this is MappedModule/mappedA in layer');
+				results.push('mappedModule/mappedA:cache');
+			});
+		},
+		'mappedModule/mappedB': function() {
+			define([], function () {
+				console.log('this is MappedModule/mappedB in layer');
+				results.push('mappedModule/mappedB:cache');
+			});
+		},
+		'mappedModule/mappedC': function() {
+			define([], function () {
+				console.log('this is MappedModule/mappedC in layer');
+				results.push('MappedModule/mappedC:cache');
+			});
+		},
+		'my/replacement/A': function () {
+			define([ '../A' ], function (A) {
+				console.log('this is my/replacement/A in layer');
+				results.push('my/replacement/A:cache');
+			});
+		},
+		'my/replacement/B': function () {
+			define([], function () {
+				console.log('this is my/replacement/B in layer : SHOULD NEVER BE CALLED');
+				results.push('my/replacement/B:cache');
+			});
+		},
+		'my/A': function () {
+			define([ './B' ], function (B) {
+				console.log('this is my/A in layer');
+				results.push('my/A:cache');
+			});
+		},
+		'my/B': function () {
+			define([], function () {
+				console.log('this is my/B in layer');
+				results.push('my/B:cache');
+			});
+		}
+	}
+});
+
+require(['app1/thing', 'starmap/demo1', 'starmapModule/mappedA', 'my/A'], function() {
+	console.log('main/app1/thing is loaded');
+	results.push('mainRequire1:loaded');
+	
+	require(['app2/thing'], function() {
+		console.log('main/app2/thing is loaded');
+		results.push('mainRequire2:loaded');
+	});
+
+});
diff --git a/tests/functional/_base/loader/mappingMultiLayer.html b/tests/functional/_base/loader/mappingMultiLayer.html
new file mode 100644
index 0000000..4d7b543
--- /dev/null
+++ b/tests/functional/_base/loader/mappingMultiLayer.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="utf-8">
+	<title>Dojo loader mapping after build test</title>
+</head>
+<body>
+	<script>
+		var dojoConfig = {
+			async: true,
+			packages: [
+				{ name: 'dojo', location: 'node_modules/dojo' }
+				{
+					name: 'test',
+					location: './tests/_base/loader/mapping-multi-layer'
+				},
+				{
+					name: 'app1',
+					location: './tests/_base/loader/mapping-multi-layer/App1'
+				},
+				{
+					name: 'app2',
+					location: './tests/_base/loader/mapping-multi-layer/App2'
+				},
+				{
+					name: 'common1',
+					location: './tests/_base/loader/mapping-multi-layer/Common1'
+				},
+				{
+					name: 'common2',
+					location: './tests/_base/loader/mapping-multi-layer/Common2'
+				},
+				{
+					name: 'router',
+					location: './tests/_base/loader/mapping-multi-layer/Router'
+				},
+				{
+					name: 'mappedModule',
+					location: './tests/_base/loader/mapping-multi-layer/MappedModule'
+				}
+			],
+			map: {
+				'app1': {
+					'common': 'common1'
+				},
+				'app2': {
+					'common': 'common2'
+				},
+				'my/replacement/A': {
+					'my/A': 'my/A'
+				},
+				'*': {
+					'starmap/demo1': 'router/demoA',
+					'starmap/demo2': 'router/demoB',
+					'starmapModule': 'mappedModule',
+					'my/A': 'my/replacement/A'
+				}
+			}
+		};
+	</script>
+	<script src="../../../../dojo.js"></script>
+</body>
+</html>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list