From 76fe7dcb038e757e9f04d945ea7cf6fb33a58129 Mon Sep 17 00:00:00 2001 From: Gordon Smith Date: Thu, 19 Oct 2017 10:19:09 +0100 Subject: [PATCH] GH-67 Unexpected webpack require behaviour 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 GH-67 Signed-off-by: Gordon Smith --- lib/DojoAMDMainTemplate.runtime.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/DojoAMDMainTemplate.runtime.js b/lib/DojoAMDMainTemplate.runtime.js index 0bd1c8c..46d457d 100644 --- a/lib/DojoAMDMainTemplate.runtime.js +++ b/lib/DojoAMDMainTemplate.runtime.js @@ -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