Skip to content

Commit bdf7aaa

Browse files
committed
Fixes requirejs#291 allow stubModules per layer.
1 parent a402e2b commit bdf7aaa

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ build/tests/lib/removeCombined/baseUrl-built
5959
build/tests/lib/requireHoist/perLayer/built
6060
build/tests/lib/rhino-186/built
6161
build/tests/lib/stubModules/main-built.js
62+
build/tests/lib/stubModules/perModule/built
6263
build/tests/lib/transportBeforeMinify/www-built
6364
build/tests/lib/urlToEmpty/main-built.js
6465
build/tests/lib/wrap/outBothArray.js

build/jslib/build.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,11 @@ define(function (require) {
10521052
include: config.include,
10531053
exclude: config.exclude,
10541054
excludeShallow: config.excludeShallow,
1055-
insertRequire: config.insertRequire
1055+
insertRequire: config.insertRequire,
1056+
stubModules: config.stubModules
10561057
}
10571058
];
1059+
delete config.stubModules;
10581060
} else if (config.modules && config.out) {
10591061
throw new Error('If the "modules" option is used, then there ' +
10601062
'should be a "dir" option set and "out" should ' +
@@ -1079,12 +1081,22 @@ define(function (require) {
10791081
}
10801082
}
10811083

1082-
//Create a hash lookup for the stubModules config to make lookup
1083-
//cheaper later.
1084-
if (config.stubModules) {
1085-
config.stubModules._byName = {};
1086-
config.stubModules.forEach(function (id) {
1087-
config.stubModules._byName[id] = true;
1084+
//Cycle through modules and combine any local stubModules with
1085+
//global values.
1086+
if (config.modules && config.modules.length) {
1087+
config.modules.forEach(function (mod) {
1088+
if (config.stubModules) {
1089+
mod.stubModules = config.stubModules.concat(mod.stubModules || []);
1090+
}
1091+
1092+
//Create a hash lookup for the stubModules config to make lookup
1093+
//cheaper later.
1094+
if (mod.stubModules) {
1095+
mod.stubModules._byName = {};
1096+
mod.stubModules.forEach(function (id) {
1097+
mod.stubModules._byName[id] = true;
1098+
});
1099+
}
10881100
});
10891101
}
10901102

@@ -1360,7 +1372,7 @@ define(function (require) {
13601372

13611373
namespace = config.namespace || '';
13621374
namespaceWithDot = namespace ? namespace + '.' : '';
1363-
stubModulesByName = (config.stubModules && config.stubModules._byName) || {};
1375+
stubModulesByName = (module.stubModules && module.stubModules._byName) || {};
13641376

13651377
//Start build output for the module.
13661378
buildFileContents += "\n" +

build/tests/builds.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,27 @@ define(['build', 'env!env/file'], function (build, file) {
12921292
);
12931293
doh.run();
12941294

1295+
1296+
//Tests https://github.com/jrburke/r.js/issues/291 per layer stub modules
1297+
doh.register("stubModulesPerModule",
1298+
[
1299+
function stubModulesPerModule(t) {
1300+
file.deleteFile("lib/stubModules/perModule/built");
1301+
1302+
build(["lib/stubModules/perModule/build.js"]);
1303+
1304+
t.is(noSlashRn(nol(c("lib/stubModules/perModule/expected-first.js"))),
1305+
noSlashRn(nol(c("lib/stubModules/perModule/built/first.js"))));
1306+
t.is(noSlashRn(nol(c("lib/stubModules/perModule/expected-second.js"))),
1307+
noSlashRn(nol(c("lib/stubModules/perModule/built/second.js"))));
1308+
1309+
require._buildReset();
1310+
}
1311+
1312+
]
1313+
);
1314+
doh.run();
1315+
12951316
//Tests https://github.com/jrburke/r.js/issues/155 no copy of paths
12961317
doh.register("pathsNoCopy",
12971318
[

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy