Skip to content

Commit

Permalink
OpenNTFGH-67 Unexpected webpack require behaviour
Browse files Browse the repository at this point in the history
In WebPack calling require([x, y, z]), callback); where "y" does not exist, throws an exception.

In Dojo the same call would still callback with a valid x + z.

Fixes OpenNTFGH-67

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Oct 19, 2017
1 parent 19f842c commit 76fe7dc
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/DojoAMDMainTemplate.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,33 @@ module.exports = function() {

// dojo require function");
function req(config, dependencies, callback) {
return contextRequire(config, dependencies, callback, 0, req);
if (typeof config === "string") {
return contextRequire(config, dependencies, callback, 0, req);
}

var depsLength = config.length;
var deps = [];
deps.length = depsLength;
for (var i = 0; i < config.length; ++i) {
singleRequire(i);
}

function singleRequire(idx) {
try {
contextRequire([config[idx]], function (dep) {
deps[idx] = dep;
checkFinished();
}, callback, 0, req);
} catch (e) {
checkFinished();
}
}

function checkFinished() {
if (dependencies && --depsLength === 0) {
dependencies.apply(this, deps);
}
}
}

function createContextRequire(moduleId) { // eslint-disable-line no-unused-vars
Expand Down

0 comments on commit 76fe7dc

Please sign in to comment.