From e5132e3f792de889af1f59aef38b05a7d2a2d41e Mon Sep 17 00:00:00 2001 From: guybedford Date: Thu, 15 Sep 2016 17:37:43 +0200 Subject: [PATCH] allow conditions to directly imply interpolation variations --- lib/trace.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/trace.js b/lib/trace.js index a6c8665..233d4a2 100644 --- a/lib/trace.js +++ b/lib/trace.js @@ -330,6 +330,24 @@ Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) { if (condition.indexOf('|') == -1) condition += '|default'; + // if the condition values have been provided via traceOpts.conditions + // then we dont need to work out variations from the file system and can just take what is given + if (traceOpts.conditions[condition]) { + var branches = {}; + traceOpts.conditions[condition].forEach(function(c) { + var branchCanonical = canonical.substr(0, interpolationMatch.index) + c + canonical.substr(interpolationMatch[0].length + interpolationMatch.index); + branches[c] = branchCanonical; + }); + return { + name: canonical, + fresh: false, + conditional: { + condition: condition, + branches: branches + } + }; + } + var metadata = {}; return Promise.resolve(loader.locate({ name: normalized.replace(interpolationRegEx, '*'), metadata: metadata })) .then(function(address) {