Skip to content

Commit

Permalink
Fixes #432, write out module for module.create layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed May 9, 2013
1 parent bacda23 commit ca5c312
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ build/tests/lib/removeCombined/baseUrl-built
build/tests/lib/requireHoist/perLayer/built
build/tests/lib/rhino-186/built
build/tests/lib/shimFakeDefine/main-built.js
build/tests/lib/stubModules/create/foobar-built.js
build/tests/lib/stubModules/main-built.js
build/tests/lib/stubModules/perModule/built
build/tests/lib/transportBeforeMinify/www-built
Expand Down
8 changes: 8 additions & 0 deletions build/jslib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,14 @@ define(function (require) {
});
}

if (module.create) {
//The ID is for a created layer. Write out
//a module definition for it in case the
//built file is used with enforceDefine
//(#432)
fileContents += '\n' + namespaceWithDot + 'define("' + module.name + '", function(){});\n';
}

//Add a require at the end to kick start module execution, if that
//was desired. Usually this is only specified when using small shim
//loaders like almond.
Expand Down
20 changes: 20 additions & 0 deletions build/tests/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,26 @@ define(['build', 'env!env/file'], function (build, file) {
);
doh.run();


//Tests https://github.com/jrburke/r.js/issues/432 insert stub module
//for module.create layers.
doh.register("stubModulesCreate",
[
function stubModulesCreate(t) {
file.deleteFile("lib/stubModules/create/foobar-built.js");

build(["lib/stubModules/create/build.js"]);

t.is(noSlashRn(nol(c("lib/stubModules/create/expected.js"))),
noSlashRn(nol(c("lib/stubModules/create/foobar-built.js"))));

require._buildReset();
}

]
);
doh.run();

//Tests https://github.com/jrburke/r.js/issues/155 no copy of paths
doh.register("pathsNoCopy",
[
Expand Down
3 changes: 3 additions & 0 deletions build/tests/lib/stubModules/create/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define({
name: 'a'
});
8 changes: 8 additions & 0 deletions build/tests/lib/stubModules/create/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
baseUrl: '.',
optimize: 'none',
name: 'foobar',
include: ['a'],
create: true,
out: 'foobar-built.js'
}
6 changes: 6 additions & 0 deletions build/tests/lib/stubModules/create/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

define('a',{
name: 'a'
});

define("foobar", function(){});

0 comments on commit ca5c312

Please sign in to comment.