Skip to content

Commit

Permalink
Fixes requirejs#1472, allow plugin use in data-main
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Mar 15, 2016
1 parent 34a77f2 commit c5f7735
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions require.js
Original file line number Diff line number Diff line change
Expand Up @@ -2025,8 +2025,10 @@ var requirejs, require, define;
//Preserve dataMain in case it is a path (i.e. contains '?')
mainScript = dataMain;

//Set final baseUrl if there is not already an explicit one.
if (!cfg.baseUrl) {
//Set final baseUrl if there is not already an explicit one,
//but only do so if the data-main value is not a loader plugin
//module ID.
if (!cfg.baseUrl && mainScript.indexOf('!') === -1) {
//Pull off the directory of data-main for use as the
//baseUrl.
src = mainScript.split('/');
Expand Down
1 change: 1 addition & 0 deletions tests/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ doh.registerUrl("dataMain", "../dataMain/dataMain.html");
doh.registerUrl("skipDataMain", "../dataMain/skipDataMain/skipDataMain.html");
doh.registerUrl("dataMainIndex", "../dataMain/dataMainIndex/dataMainIndex.html");
doh.registerUrl("dataMainBaseUrl", "../dataMain/baseUrl/dataMainBaseUrl.html");
doh.registerUrl("dataMainPlugin", "../dataMain/dataMainPlugin/dataMainPlugin.html");

doh.registerUrl("moduleExports", "../moduleExports/moduleExports.html");

Expand Down
17 changes: 17 additions & 0 deletions tests/dataMain/dataMainPlugin/dataMainPlugin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: data-main plugin Test</title>
<script type="text/javascript" src="../../doh/runner.js"></script>
<script type="text/javascript" src="../../doh/_browserRunner.js"></script>
<script type="text/javascript" data-main="my/plugin!sub/test" src="../../../require.js"></script>
</head>
<body>
<h1>require.js: data-main plugin Test</h1>

<p>Confirm that a data-main="som/plugin!some/value" works. More info:
<a href="https://github.com/requirejs/requirejs/issues/1472">1472</a>.

<p>Check console for messages</p>
</body>
</html>
3 changes: 3 additions & 0 deletions tests/dataMain/dataMainPlugin/modules/sub/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define({
name: 'a'
});
11 changes: 11 additions & 0 deletions tests/dataMain/dataMainPlugin/modules/sub/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define(['./a'], function (a) {
doh.register(
"dataMainPlugin",
[
function dataMainPlugin(t){
t.is("a", a.name);
}
]
);
doh.run();
});
6 changes: 6 additions & 0 deletions tests/dataMain/dataMainPlugin/my/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
define({
load: function( name, req, onload, config ) {
requirejs.config({ baseUrl: './modules' });
req([name], onload);
}
});

0 comments on commit c5f7735

Please sign in to comment.