Skip to content

Commit

Permalink
fix conditionalResolutions conditions restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Sep 19, 2016
1 parent b56bcc9 commit e426c59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
21 changes: 10 additions & 11 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var writeOutputs = require('./output').writeOutputs;
var rollupTree = require('./rollup').rollupTree;

var traceExpression = require('./arithmetic').traceExpression;
var traceConditionalEnv = require('./arithmetic').traceConditionalEnv;

var Trace = require('./trace');

Expand All @@ -32,7 +31,7 @@ var getFormatHint = require('./utils').getFormatHint;
// new Builder({cfg})
// new Builder(baseURL, {cfg})
// new Builder(baseURL, 'cfg-file.js')
//
//
// baseURL is ignored in cfg when given
// cfg is saved and used by reset
function Builder(baseURL, cfg) {
Expand Down Expand Up @@ -86,7 +85,7 @@ Builder.prototype.invalidate = function(invalidationModuleName) {
if (invalidationWildcardIndex == -1)
return false;

return moduleName.substr(0, invalidationWildcardIndex) == wildcardLHS
return moduleName.substr(0, invalidationWildcardIndex) == wildcardLHS
&& moduleName.substr(moduleName.length - wildcardRHS.length) == wildcardRHS;
}

Expand Down Expand Up @@ -165,7 +164,7 @@ Builder.prototype.reset = function(baseLoader) {
loaderConfig.call(this, lCfg);
loader.configHash = generateConfigHash(loader);
};

this.getCanonicalName = getCanonicalName.bind(null, this.loader);
this.loader.getCanonicalName = this.loader.pluginLoader.getCanonicalName = this.getCanonicalName;

Expand Down Expand Up @@ -195,7 +194,7 @@ Builder.prototype.reset = function(baseLoader) {
loader.fetch = function(load) {
if (builder.fetch)
return Promise.resolve(builder.fetch.call(this, load, cachedFetch.bind(this)));
else
else
return cachedFetch.call(this, load);
};

Expand Down Expand Up @@ -287,7 +286,7 @@ function executeConfigFile(saveForReset, ignoreBaseURL, configPath, source) {

// make everything in global available to config file code
// only substitute local copy of System
// and prevent that code from adding anything to the real global
// and prevent that code from adding anything to the real global
var context = Object.create(global);
context.SystemJS = context.System = configLoader;
context.global = context;
Expand Down Expand Up @@ -454,7 +453,7 @@ function processCompileOpts(options, defaults) {
options = options || {};
if ('sfxFormat' in options) {
console.warn('SystemJS Builder "sfxFormat" is deprecated and has been renamed to "format".');
options.format = options.sfxFormat;
options.format = options.sfxFormat;
}
if ('sfxEncoding' in options) {
console.warn('SystemJS Builder "sfxEncoding" is deprecated and has been renamed to "encodeNames".');
Expand Down Expand Up @@ -492,7 +491,7 @@ function processCompileOpts(options, defaults) {
globalDeps: {},
globalName: null,
exportDefault: false,
// conditionalResolutions: {},
// conditionalResolutions: {},
// can add a special object here that matches condition predicates to direct module names to use for sfx

// set to true to build in "format amd" style sfx hints for SystemJS loading
Expand Down Expand Up @@ -585,7 +584,7 @@ Builder.prototype.compile = function(moduleNameOrLoad, outFile, opts) {
function processOutputOpts(options, defaults) {
var opts = {
outFile: undefined,

minify: false,
uglify: undefined,
mangle: true,
Expand Down Expand Up @@ -755,7 +754,7 @@ Builder.prototype.buildStatic = function(expressionOrTree, outFile, opts) {
// override the fetch function if given
if (opts && opts.fetch)
this.fetch = opts.fetch;

return Promise.resolve()
.then(function() {
return canonicalizeConditions(self.loader, traceOpts);
Expand Down Expand Up @@ -810,7 +809,7 @@ Builder.prototype.buildStatic = function(expressionOrTree, outFile, opts) {
output.assetList = compiled.assetList;
output.modules = compiled.modules;
output.tree = tree;
return output;
return output;
});
});
});
Expand Down
19 changes: 11 additions & 8 deletions lib/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Trace.prototype.traceModule = function(moduleName, traceOpts) {
return Promise.resolve(loader.normalize(moduleName))
.then(function(normalized) {
return traceCanonical(getCanonicalName(loader, normalized), traceOpts);
});
});
};

// given a module, return the conditional environment variation space
Expand Down Expand Up @@ -440,7 +440,7 @@ Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) {
.then(function(pluginNormalized) {
load.plugin = getCanonicalName(loader, pluginNormalized);

if (load.metadata.loaderModule &&
if (load.metadata.loaderModule &&
(load.metadata.loaderModule.build === false || Object.keys(load.metadata.loaderModule).length == 0))
load.runtimePlugin = true;

Expand All @@ -458,8 +458,8 @@ Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) {
return load;

curHook = 'fetch';


return loader
.fetch({ name: normalized, metadata: load.metadata, address: address })

Expand Down Expand Up @@ -488,7 +488,7 @@ Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) {
return source;
})
// dont let a missing source map fail the entire build
.catch(function() {
.catch(function() {
return source;
});
}
Expand Down Expand Up @@ -597,7 +597,7 @@ Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) {
* Returns the full trace tree of a module
*
* - conditionalEnv represents the conditional tracing environment module values to impose on the trace
* -
* -
*
* conditionalEnv provides canonical condition tracing rules of the form:
*
Expand Down Expand Up @@ -803,7 +803,7 @@ Trace.prototype.inlineConditions = function(tree, loader, traceOpts) {
name: '@system-env',
path: null,
metadata: {
format: 'json'
format: 'json'
},
deps: [],
depMap: {},
Expand Down Expand Up @@ -842,14 +842,17 @@ Trace.getConditionalResolutions = function(conditional, conditionalEnv, inlineCo
if (inlineConditionals[condition])
return inlineConditionals[condition][0] === value;

if (conditionalEnv[condition] && conditionalEnv[condition].indexOf(value) === -1)
return false;

conditionalEnvVariations[condition] = conditionalEnvVariations[condition] || [];
if (conditionalEnvVariations[condition].indexOf(value) === -1)
conditionalEnvVariations[condition].push(value);

if (conditionModules.indexOf(conditionModule) == -1)
conditionModules.push(conditionModule);

return conditionalEnv[condition] ? conditionalEnv[condition].indexOf(value) !== -1 : true;
return true;
}

// whether or not to include condition branch given our conditionalEnv
Expand Down

0 comments on commit e426c59

Please sign in to comment.