Skip to content

Commit

Permalink
Fixes #1577, plugin normalize called too many times
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Feb 19, 2017
1 parent 3e55417 commit a838655
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
7 changes: 5 additions & 2 deletions require.js
Expand Up @@ -440,7 +440,9 @@ var requirejs, require, define;
//Account for relative paths if there is a base name.
if (name) {
if (prefix) {
if (pluginModule && pluginModule.normalize) {
if (isNormalized) {
normalizedName = name;
} else if (pluginModule && pluginModule.normalize) {
//Plugin is loaded, use its normalize method.
normalizedName = pluginModule.normalize(name, function (name) {
return normalize(name, parentName, applyMap);
Expand Down Expand Up @@ -972,7 +974,8 @@ var requirejs, require, define;
//prefix and name should already be normalized, no need
//for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name,
this.map.parentMap);
this.map.parentMap,
true);
on(normalizedMap,
'defined', bind(this, function (value) {
this.map.normalizedMap = normalizedMap;
Expand Down
2 changes: 2 additions & 0 deletions tests/all.js
Expand Up @@ -140,6 +140,8 @@ doh.registerUrl("pluginsSync", "../plugins/sync.html");
doh.registerUrl("pluginsOnError", "../plugins/onerror/onerror.html");
doh.registerUrl("doublePluginCall", "../plugins/double.html");
doh.registerUrl("pluginsNameOnly", "../plugins/nameOnly.html");
doh.registerUrl("pluginNormalize", "../pluginNormalize/pluginNormalize.html");
doh.registerUrl("pluginNormalizeLoad", "../pluginNormalizeLoad/pluginNormalizeLoad.html");
doh.registerUrl("pluginsDelegated", "../plugins/delegated/delegated.html");
doh.registerUrl("pluginsFromText", "../plugins/fromText/fromText.html");
doh.registerUrl("pluginsFromTextEvalError", "../plugins/fromTextEvalError/fromTextEvalError.html");
Expand Down
47 changes: 47 additions & 0 deletions tests/pluginNormalize/pluginNormalize.html
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Remote URL Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">

define("Plugin", function() {
return {
load: function(name, parentRequire, onload, config) {
onload(name);
},
normalize: function(name, normalize) {
return name + '.xyz';
}
}
});

require({
baseUrl: "./"
},
["Plugin!hello", "Plugin!world"],
function(hello, world) {
doh.register(
"pluginNormalize",
[
function pluginNormalize(t){
t.is("hello.xyz", hello);
t.is("world.xyz", world);
}
]
);

doh.run();
}
);


</script>
</head>
<body>
<h1>require.js: Plugin Normalize Test</h1>
<p>Check console for messages</p>
</body>
</html>
10 changes: 10 additions & 0 deletions tests/pluginNormalizeLoad/Plugin.js
@@ -0,0 +1,10 @@
define(function() {
return {
load: function(name, parentRequire, onload, config) {
onload(name);
},
normalize: function(name, normalize) {
return name + '.xyz';
}
}
});
35 changes: 35 additions & 0 deletions tests/pluginNormalizeLoad/pluginNormalizeLoad.html
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Remote URL Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">
require({
baseUrl: "./"
},
["Plugin!hello", "Plugin!world"],
function(hello, world) {
doh.register(
"pluginNormalizeLoad",
[
function pluginNormalizeLoad(t){
t.is("hello.xyz", hello);
t.is("world.xyz", world);
}
]
);

doh.run();
}
);


</script>
</head>
<body>
<h1>require.js: Plugin Normalize Test</h1>
<p>Check console for messages</p>
</body>
</html>

0 comments on commit a838655

Please sign in to comment.