Skip to content

Commit 84f4adb

Browse files
committed
Fixes #919, do not copy main named modules file if in rawText
1 parent 465c0e4 commit 84f4adb

File tree

10 files changed

+98
-1
lines changed

10 files changed

+98
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ build/tests/lib/pristineSrc/built
8181
build/tests/lib/rawText/built.js
8282
build/tests/lib/rawTextLongId/built.js
8383
build/tests/lib/rawTextNameTarget/a-built.js
84+
build/tests/lib/rawTextNameWholeProject/www-built
8485
build/tests/lib/removeCombined/app-built
8586
build/tests/lib/removeCombined/baseUrl-built
8687
build/tests/lib/removeCombinedPaths/testcase/project/build/build_output

build/jslib/build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ define(function (require) {
442442
'. Stopping, config is malformed.');
443443
}
444444

445-
if (!module.create) {
445+
// Copy the file, but only if it is not provided in rawText.
446+
if (!module.create && (!config.rawText || !lang.hasProp(config.rawText, module.name))) {
446447
file.copyFile(module._sourcePath, module._buildPath);
447448
}
448449
}

build/tests/builds.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,30 @@ define(['build', 'env!env/file', 'env', 'lang'], function (build, file, env, lan
23272327
);
23282328
doh.run();
23292329

2330+
//Allow whole project config where a module entry's name is provided
2331+
// via rawText instead of being on disk.
2332+
// https://github.com/requirejs/r.js/issues/919
2333+
doh.register("rawTextNameWholeProject",
2334+
[
2335+
function rawTextNameWholeProject(t) {
2336+
2337+
file.deleteFile("lib/rawTextNameWholeProject/built");
2338+
2339+
build(["lib/rawTextNameWholeProject/www/app.build.js"]);
2340+
2341+
t.is(nol(c("lib/rawTextNameWholeProject/expected-main.js")),
2342+
nol(c("lib/rawTextNameWholeProject/www-built/js/main.js")));
2343+
t.is(nol(c("lib/rawTextNameWholeProject/expected-b.js")),
2344+
nol(c("lib/rawTextNameWholeProject/www-built/js/b.js")));
2345+
2346+
require._buildReset();
2347+
2348+
}
2349+
2350+
]
2351+
);
2352+
doh.run();
2353+
23302354
//Allow skipping semicolon insertion
23312355
//https://github.com/requirejs/r.js/issues/506
23322356
doh.register("semicolonInsert",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define('b',['./util/helper'], function(helper) {
2+
return {
3+
name: 'b',
4+
helper: helper
5+
};
6+
});
7+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
define('util/helper',[],function () {
2+
return function () {
3+
return 'helper is ready';
4+
};
5+
});
6+
7+
define('a',['./util/helper'], function(helper) {
8+
return {
9+
name: 'a',
10+
helper: helper
11+
};
12+
});
13+
14+
require(['a'], function(a) { console.log(a); require(['b'], function(b) { console.log(b); });});
15+
define("main", function(){});
16+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
({
2+
appDir: '.',
3+
baseUrl: 'js',
4+
dir: '../www-built',
5+
optimize: 'none',
6+
7+
rawText: {
8+
'main':
9+
'require([\'a\'], function(a) {' +
10+
' console.log(a);' +
11+
' require([\'b\'], function(b) {' +
12+
' console.log(b);' +
13+
' });' +
14+
'});'
15+
},
16+
17+
modules: [{
18+
name: 'main',
19+
}, {
20+
name: 'b',
21+
exclude: ['main']
22+
}]
23+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../../../../../require.js" data-main="js/main"></script>
5+
</head>
6+
<body>
7+
</body>
8+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
define(['./util/helper'], function(helper) {
2+
return {
3+
name: 'a',
4+
helper: helper
5+
};
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
define(['./util/helper'], function(helper) {
2+
return {
3+
name: 'b',
4+
helper: helper
5+
};
6+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
define(function () {
2+
return function () {
3+
return 'helper is ready';
4+
};
5+
});

0 commit comments

Comments
 (0)