Skip to content

Commit

Permalink
Closes requirejs#142, './mod' not resolved to 'mod' when at top level
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Nov 19, 2011
1 parent 129dbdd commit a71b5af
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions require.js
Expand Up @@ -268,6 +268,10 @@ var requirejs, require, define;
if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
name = pkgName;
}
} else if (name.indexOf("./") === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
}
}
return name;
Expand Down
1 change: 1 addition & 0 deletions tests/all-server.js
Expand Up @@ -41,6 +41,7 @@ load('doh/_' + env + 'Runner.js');
load("simple-tests.js");
load("circular-tests.js");
load("relative/relative-tests.js");
load("relative/relativeBaseUrl-tests.js");
load("exports/exports-tests.js");
load("exports/moduleAndExports-tests.js");
load("anon/anon-tests.js");
Expand Down
24 changes: 24 additions & 0 deletions tests/relative/relativeBaseUrl-tests.js
@@ -0,0 +1,24 @@
//Use a property on require so if the test runs in node, it is visible.
//Remove it when done with the test.
require.relativeBaseUrlCounter = 0;

require({
baseUrl: require.isBrowser ? "./" : "./relative/"
},
["./top", "top"],
function(top1, top2) {
doh.register(
"relativeBaseUrl",
[
function relativeBaseUrl(t){
t.is(top1.id, top2.id);
t.is(1, require.relativeBaseUrlCounter);

delete require.relativeBaseUrlCounter;
}
]
);

doh.run();
}
);
14 changes: 14 additions & 0 deletions tests/relative/relativeBaseUrl.html
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Relative Module Names at baseUrl 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" src="relativeBaseUrl-tests.js"></script>
</head>
<body>
<h1>require.js: Relative Module Names at baseUrl Test</h1>
<p>Check console for messages</p>
</body>
</html>
7 changes: 7 additions & 0 deletions tests/relative/top.js
@@ -0,0 +1,7 @@

define(function () {
require.relativeBaseUrlCounter += 1;
return {
id: require.relativeBaseUrlCounter
};
});

0 comments on commit a71b5af

Please sign in to comment.