systemjs-builder
Advanced tools
Comparing version 0.15.30 to 0.15.31
@@ -13,2 +13,3 @@ var path = require('path'); | ||
compact: false, | ||
sourceType: 'script', | ||
filename: pathToUrl(load.path), | ||
@@ -15,0 +16,0 @@ filenameRelative: path.basename(load.path), |
@@ -223,32 +223,49 @@ var asp = require('bluebird').promisify; | ||
exports.traceExpression = function(builder, expression, traceOpts) { | ||
if (!expression) | ||
throw new Error('A module expression must be provided to trace.'); | ||
exports.traceExpression = function(builder, expression, traceOpts) { | ||
if (!expression) | ||
throw new Error('A module expression must be provided to trace.'); | ||
return Promise | ||
.resolve(expandAndCanonicalizeExpression(builder, expression)) | ||
.then(function processExpandedOperations(expandedOperations) { | ||
// chain the operations, applying them with the trace of the next module | ||
return expandedOperations.reduce(function(p, op) { | ||
return p.then(function(curTree) { | ||
// tree . module | ||
if (op.singleModule) | ||
return getTreeModuleOperation(builder, op.operator, traceOpts)(curTree, op.moduleName); | ||
if (expression instanceof Array) { | ||
var tree = {}; | ||
return Promise.all(expression.map(function(moduleName) { | ||
return builder.loader.normalize(moduleName) | ||
.then(function(normalized) { | ||
var canonical = builder.getCanonicalName(normalized); | ||
return builder.tracer.getLoadRecord(canonical, traceOpts) | ||
.then(function(load) { | ||
tree[canonical] = load; | ||
}); | ||
}); | ||
})) | ||
.then(function() { | ||
return tree; | ||
}); | ||
} | ||
if (op.operationsTree){ | ||
return processExpandedOperations(op.operationsTree).then(function(expandedTree){ | ||
return getTreeOperation(op.operator)(curTree, expandedTree); | ||
}); | ||
} | ||
// tree . tree | ||
return builder.tracer.traceCanonical(op.moduleName, traceOpts) | ||
.then(function(nextTrace) { | ||
return getTreeOperation(op.operator)(curTree, nextTrace.tree); | ||
return Promise | ||
.resolve(expandAndCanonicalizeExpression(builder, expression)) | ||
.then(function processExpandedOperations(expandedOperations) { | ||
// chain the operations, applying them with the trace of the next module | ||
return expandedOperations.reduce(function(p, op) { | ||
return p.then(function(curTree) { | ||
// tree . module | ||
if (op.singleModule) | ||
return getTreeModuleOperation(builder, op.operator, traceOpts)(curTree, op.moduleName); | ||
if (op.operationsTree){ | ||
return processExpandedOperations(op.operationsTree).then(function(expandedTree){ | ||
return getTreeOperation(op.operator)(curTree, expandedTree); | ||
}); | ||
} | ||
// tree . tree | ||
return builder.tracer.traceCanonical(op.moduleName, traceOpts) | ||
.then(function(nextTrace) { | ||
return getTreeOperation(op.operator)(curTree, nextTrace.tree); | ||
}); | ||
}, Promise.resolve({})); | ||
}); | ||
}; | ||
}); | ||
}, Promise.resolve({})); | ||
}); | ||
}; | ||
function expandAndCanonicalizeExpression(builder, expression){ | ||
function expandAndCanonicalizeExpression(builder, expression) { | ||
var operations = parseExpression(expression); | ||
@@ -361,3 +378,3 @@ var expandPromise = Promise.resolve(1); | ||
if (curNode && visitor(moduleName, parent) !== false) { | ||
var deps = getLoadDependencies(curNode, traceOpts.tracePackageConfig, false, traceOpts.traceAllConditionals, traceOpts.conditions, traceOpts.traceConditionsOnly); | ||
var deps = getLoadDependencies(curNode, traceOpts, traceOpts.conditions, traceOpts.inlineConditions); | ||
if (reversePost) | ||
@@ -364,0 +381,0 @@ deps = deps.reverse(); |
@@ -19,2 +19,3 @@ var Promise = require('bluebird'); | ||
var traceExpression = require('./arithmetic').traceExpression; | ||
var traceConditionalEnv = require('./arithmetic').traceConditionalEnv; | ||
@@ -349,3 +350,2 @@ var Trace = require('./trace'); | ||
dev: undefined, | ||
traceAllConditionals: true, | ||
conditions: { | ||
@@ -355,5 +355,4 @@ '@system-env|default': true, | ||
}, | ||
traceConditionModules: true, | ||
traceConditionsOnly: false, | ||
tracePackageConfig: true, | ||
inlineConditions: {}, | ||
traceRuntimePlugin: true, | ||
@@ -416,2 +415,9 @@ // package config tracing (used for bundles only) | ||
if (typeof opts.inlineConditions == 'object') | ||
extend(opts.conditions, opts.inlineConditions); | ||
else if (opts.inlineConditions === true) | ||
opts.inlineConditions = opts.conditions; | ||
else | ||
opts.inlineConditions = {}; | ||
return opts; | ||
@@ -424,9 +430,21 @@ } | ||
var traceOpts = processTraceOpts(opts); | ||
var self = this; | ||
return setExternals(this, opts && opts.externals) | ||
return setExternals(this, traceOpts.externals) | ||
.then(function() { | ||
return traceExpression(self, expression, processTraceOpts(opts)); | ||
return traceExpression(self, expression, traceOpts); | ||
}); | ||
}; | ||
Builder.prototype.traceConditionalEnv = function(expression, opts) { | ||
var traceOpts = processTraceOpts(opts); | ||
var self = this; | ||
return this.trace(expression, traceOpts) | ||
.then(function(tree) { | ||
return Trace.getConditionalEnv(self, tree, traceOpts); | ||
}); | ||
} | ||
function processCompileOpts(options, defaults) { | ||
@@ -465,4 +483,2 @@ // NB deprecate these warnings | ||
inlineConditions: false, | ||
sourceMaps: false, | ||
@@ -644,5 +660,2 @@ lowResSourceMaps: false, | ||
if (compileOpts.inlineConditions) | ||
traceOpts.traceConditionModules = false; | ||
// override the fetch function if given | ||
@@ -654,6 +667,3 @@ if (opts && opts.fetch) | ||
.then(function() { | ||
if (expressionOrTree instanceof Array) | ||
expressionOrTree = '[' + expressionOrTree.join('] + [') + ']'; | ||
if (typeof expressionOrTree != 'string') | ||
if (typeof expressionOrTree != 'string' && !(expressionOrTree instanceof Array)) | ||
return expressionOrTree; | ||
@@ -670,3 +680,3 @@ | ||
if (compileOpts.inlineConditions) | ||
return self.tracer.inlineConditions(tree, self.loader, traceOpts.conditions); | ||
return self.tracer.inlineConditions(tree, self.loader, traceOpts); | ||
return tree; | ||
@@ -733,6 +743,3 @@ }) | ||
.then(function() { | ||
if (expressionOrTree instanceof Array) | ||
expressionOrTree = '[' + expressionOrTree.join('] + [') + ']'; | ||
if (typeof expressionOrTree != 'string') | ||
if (typeof expressionOrTree != 'string' && !(expressionOrTree instanceof Array)) | ||
return expressionOrTree; | ||
@@ -747,3 +754,3 @@ | ||
// inline conditionals of the trace | ||
return self.tracer.inlineConditions(tree, self.loader, traceOpts.conditions) | ||
return self.tracer.inlineConditions(tree, self.loader, traceOpts) | ||
.then(function(inlinedTree) { | ||
@@ -750,0 +757,0 @@ if (!compileOpts.rollup) |
398
lib/trace.js
@@ -49,2 +49,35 @@ var getCanonicalName = require('./utils').getCanonicalName; | ||
// given a module, return the conditional environment variation space | ||
Trace.getConditionalEnv = function(builder, loads, traceOpts) { | ||
return toCanonicalConditionalEnv.call(builder, traceOpts.conditions) | ||
.then(function(canonicalConditionalEnv) { | ||
return toCanonicalConditionalEnv.call(builder, traceOpts.inlineConditions) | ||
.then(function(canonicalInlineConditionals) { | ||
var conditionalEnvVariations = {}; | ||
Object.keys(loads).forEach(function(canonical) { | ||
var load = loads[canonical]; | ||
if (!load.conditional) | ||
return; | ||
var envVariations = Trace.getConditionalResolutions(load.conditional, canonicalConditionalEnv, canonicalInlineConditionals).conditionalEnvVariations; | ||
Object.keys(envVariations).forEach(function(condition) { | ||
if (envVariations[condition] instanceof Array) { | ||
conditionalEnvVariations[condition] = conditionalEnvVariations[condition] || []; | ||
envVariations[condition].forEach(function(conditionValue) { | ||
if (conditionalEnvVariations[condition].indexOf(conditionValue) === -1) | ||
conditionalEnvVariations[condition].push(conditionValue); | ||
}); | ||
} | ||
else { | ||
conditionalEnvVariations[condition] = conditionalEnvVariations[condition] || envVariations[condition]; | ||
} | ||
}); | ||
}); | ||
return conditionalEnvVariations; | ||
}); | ||
}); | ||
}; | ||
Trace.prototype.traceCanonical = function(canonical, traceOpts) { | ||
@@ -55,6 +88,6 @@ var self = this; | ||
.then(function(canonicalConditionalEnv) { | ||
if (!traceOpts.traceConditionsOnly) | ||
return self.getAllLoadRecords(canonical, traceOpts, canonicalConditionalEnv, {}, []); | ||
else | ||
return self.getConditionLoadRecords(canonical, traceOpts, canonicalConditionalEnv, false, {}, []); | ||
return toCanonicalConditionalEnv.call(self, traceOpts.inlineConditions) | ||
.then(function(canonicalInlineConditionals) { | ||
return self.getAllLoadRecords(canonical, traceOpts, canonicalConditionalEnv, canonicalInlineConditionals, {}, []); | ||
}); | ||
}) | ||
@@ -115,3 +148,2 @@ .then(function(loads) { | ||
Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) { | ||
var loader = this.loader; | ||
@@ -572,6 +604,4 @@ var loads = this.loads; | ||
* | ||
* - traceAllConditionals indicates if conditional boundaries should be traversed during the trace. | ||
* - traceConditionModules indicates if conditional modules should be included in the trace. | ||
* - conditionalEnv represents the conditional tracing environment module values to impose on the trace | ||
* forcing traces for traceAllConditionals false, and skipping traces for traceAllConditionals true. | ||
* - | ||
* | ||
@@ -596,3 +626,3 @@ * conditionalEnv provides canonical condition tracing rules of the form: | ||
var systemModules = ['@empty', '@system-env', '@@amd-helpers', '@@global-helpers']; | ||
Trace.prototype.getAllLoadRecords = function(canonical, traceOpts, canonicalConditionalEnv, curLoads, parentStack) { | ||
Trace.prototype.getAllLoadRecords = function(canonical, traceOpts, canonicalConditionalEnv, canonicalInlineConditionals, curLoads, parentStack) { | ||
var loader = this.loader; | ||
@@ -616,4 +646,4 @@ | ||
parentStack = parentStack.concat([canonical]); | ||
return Promise.all(Trace.getLoadDependencies(load, traceOpts.tracePackageConfig, true, traceOpts.traceAllConditionals, traceOpts.traceConditionModules, canonicalConditionalEnv).map(function(dep) { | ||
return self.getAllLoadRecords(dep, traceOpts, canonicalConditionalEnv, curLoads, parentStack); | ||
return Promise.all(Trace.getLoadDependencies(load, traceOpts, canonicalConditionalEnv, canonicalInlineConditionals).map(function(dep) { | ||
return self.getAllLoadRecords(dep, traceOpts, canonicalConditionalEnv, canonicalInlineConditionals, curLoads, parentStack); | ||
})); | ||
@@ -627,35 +657,2 @@ } | ||
// helper function -> returns the "condition" build of a tree | ||
// that is the modules needed to determine the exact conditional solution of the tree | ||
Trace.prototype.getConditionLoadRecords = function(canonical, traceOpts, canonicalConditionalEnv, inConditionTree, curLoads, parentStack) { | ||
var loader = this.loader; | ||
if (canonical in curLoads) | ||
return curLoads; | ||
var self = this; | ||
return this.getLoadRecord(canonical, traceOpts, parentStack) | ||
.then(function(load) { | ||
if (inConditionTree && systemModules.indexOf(canonical) == -1) | ||
curLoads[canonical] = load; | ||
if (load) { | ||
parentStack = parentStack.concat([canonical]) | ||
// trace into the conditions themselves | ||
return Promise.all(Trace.getLoadDependencies(load, traceOpts.tracePackageConfig, true, true, traceOpts.traceConditionModules, canonicalConditionalEnv, true).map(function(dep) { | ||
return self.getConditionLoadRecords(dep, traceOpts, canonicalConditionalEnv, true, curLoads, parentStack); | ||
})) | ||
.then(function() { | ||
// trace non-conditions | ||
return Promise.all(Trace.getLoadDependencies(load, traceOpts.tracePackageConfig, true, true, traceOpts.traceConditionModules, canonicalConditionalEnv).map(function(dep) { | ||
return self.getConditionLoadRecords(dep, traceOpts, canonicalConditionalEnv, inConditionTree, curLoads, parentStack); | ||
})); | ||
}); | ||
} | ||
}) | ||
.then(function() { | ||
return curLoads; | ||
}); | ||
} | ||
function conditionalComplement(condition) { | ||
@@ -672,5 +669,37 @@ var conditionObj = parseCondition(condition); | ||
// convert boolean conditions of the form | ||
// @system-env|browser: [true, false] | ||
// @system-env|~browser: true | ||
// into just: | ||
// @system-env|browser: [true, false] | ||
// to be deprecated in due course | ||
Object.keys(conditionalEnv).map(function(m) { | ||
var conditionObj = parseCondition(m); | ||
if (!(conditionalEnv[m] instanceof Array)) { | ||
if (!conditionObj.negate) { | ||
conditionalEnv[m] = [conditionalEnv[m]]; | ||
} | ||
else { | ||
var complement = conditionalComplement(m); | ||
if (conditionalEnv[complement]) { | ||
if (conditionalEnv[complement] instanceof Array) { | ||
if (conditionalEnv[complement].indexOf(!conditionalEnv[m]) === -1) | ||
conditionalEnv[complement].push(!conditionalEnv[m]); | ||
} | ||
else { | ||
if (!conditionalEnv[m] !== conditionalEnv[complement]) | ||
conditionalEnv[conditionalComplement(m)] = [conditionalEnv[conditionalComplement(m)], !conditionalEnv[m]]; | ||
} | ||
} | ||
else { | ||
conditionalEnv[conditionalComplement(m)] = [!conditionalEnv[m]]; | ||
} | ||
delete conditionalEnv[m]; | ||
} | ||
} | ||
}); | ||
return Promise.all(Object.keys(conditionalEnv).map(function(m) { | ||
var conditionObj = parseCondition(m); | ||
return loader.normalize(conditionObj.module) | ||
@@ -694,135 +723,163 @@ .then(function(normalized) { | ||
*/ | ||
Trace.prototype.inlineConditions = function(tree, loader, conditionalEnv) { | ||
Trace.prototype.inlineConditions = function(tree, loader, traceOpts) { | ||
var self = this; | ||
return toCanonicalConditionalEnv.call(this, conditionalEnv) | ||
return toCanonicalConditionalEnv.call(self, traceOpts.conditions) | ||
.then(function(canonicalConditionalEnv) { | ||
var inconsistencyErrorMsg = 'For static condition inlining only an exact environment resolution can be built, pending https://github.com/systemjs/builder/issues/311.'; | ||
return toCanonicalConditionalEnv.call(self, traceOpts.inlineConditions) | ||
.then(function(canonicalInlineConditionals) { | ||
var inconsistencyErrorMsg = 'For static condition inlining only an exact environment resolution can be built, pending https://github.com/systemjs/builder/issues/311.'; | ||
// ensure we have no condition conflicts | ||
for (var c in conditionalEnv) { | ||
var val = conditionalEnv[c]; | ||
if (typeof val == 'string') | ||
continue; | ||
var complement = conditionalComplement(c); | ||
if (val instanceof Array || complement in conditionalEnv && conditionalEnv[complement] != !conditionalEnv[c]) | ||
throw new TypeError('Error building condition ' + c + '. ' + inconsistencyErrorMsg); | ||
} | ||
// ensure we have no condition conflicts | ||
for (var c in canonicalInlineConditionals) { | ||
if (canonicalInlineConditionals[c].length > 1) | ||
throw new TypeError('Error building condition ' + c + '. ' + inconsistencyErrorMsg); | ||
} | ||
var conditionalResolutions = {}; | ||
var importsSystemEnv = false; | ||
var conditionalResolutions = {}; | ||
var importsSystemEnv = false; | ||
// for each conditional in the tree, work out its substitution | ||
Object.keys(tree) | ||
.filter(function(m) { | ||
return tree[m] && tree[m].conditional; | ||
}) | ||
.forEach(function(c) { | ||
var branches = Trace.getConditionalResolutions(tree[c].conditional, false, canonicalConditionalEnv).branches; | ||
// get the list of all conditional dependencies in the tree | ||
var allConditionals = []; | ||
Object.keys(tree).forEach(function(m) { | ||
if (!tree[m] || tree[m].conditional) | ||
return; | ||
if (branches.length > 1) | ||
throw new TypeError('Error building condition ' + c + '. ' + inconsistencyErrorMsg); | ||
if (branches.length == 0) | ||
throw new TypeError('No exact resolution found at all for condition ' + c + '.'); | ||
Object.keys(tree[m].depMap).forEach(function(d) { | ||
var dep = tree[m].depMap[d]; | ||
conditionalResolutions[c] = branches[0]; | ||
}); | ||
if (dep.match(/#[\:\?\{]/)) { | ||
if (allConditionals.indexOf(dep) === -1) | ||
allConditionals.push(dep); | ||
} | ||
}); | ||
}); | ||
// resolve any chained conditionals | ||
Object.keys(conditionalResolutions).forEach(function(c) { | ||
var resolution = conditionalResolutions[c]; | ||
// determine the conditional resolutions | ||
return Promise.all(allConditionals.map(function(c) { | ||
return self.getLoadRecord(c, traceOpts) | ||
.then(function(load) { | ||
var branches = Trace.getConditionalResolutions(load.conditional, canonicalConditionalEnv, canonicalInlineConditionals).branches; | ||
var seen = []; | ||
while (conditionalResolutions[resolution] && seen.indexOf(resolution) == -1) { | ||
seen.push(resolution); | ||
resolution = conditionalResolutions[resolution]; | ||
conditionalResolutions[c] = resolution; | ||
} | ||
if (seen.indexOf(resolution) != -1) | ||
throw new Error('Circular conditional resolution ' + seen.join(' -> ') + ' -> ' + resolution); | ||
}); | ||
if (branches.length === 1) | ||
conditionalResolutions[c] = branches[0]; | ||
}); | ||
})) | ||
.then(function() { | ||
// resolve any chained conditionals | ||
Object.keys(conditionalResolutions).forEach(function(c) { | ||
var resolution = conditionalResolutions[c]; | ||
// finally we do a deep clone of the tree, applying the conditional resolutions as we go | ||
// if we have a dependency on a condition not in the tree, we throw as it would be an unresolved external | ||
var inlinedTree = {}; | ||
Object.keys(tree).forEach(function(m) { | ||
var load = tree[m]; | ||
var seen = []; | ||
while (conditionalResolutions[resolution] && seen.indexOf(resolution) == -1) { | ||
seen.push(resolution); | ||
resolution = conditionalResolutions[resolution]; | ||
conditionalResolutions[c] = resolution; | ||
} | ||
if (seen.indexOf(resolution) != -1) | ||
throw new Error('Circular conditional resolution ' + seen.join(' -> ') + ' -> ' + resolution); | ||
}); | ||
if (typeof load == 'boolean') { | ||
inlinedTree[m] = load; | ||
return; | ||
} | ||
// finally we do a deep clone of the tree, applying the conditional resolutions as we go | ||
// if we have a dependency on a condition not in the tree, we throw as it would be an unresolved external | ||
var inlinedTree = {}; | ||
Object.keys(tree).forEach(function(m) { | ||
var load = tree[m]; | ||
if (load.conditional) | ||
return; | ||
if (typeof load == 'boolean') { | ||
inlinedTree[m] = load; | ||
return; | ||
} | ||
var clonedLoad = extend({}, load); | ||
clonedLoad.depMap = {}; | ||
Object.keys(load.depMap).forEach(function(d) { | ||
var normalizedDep = load.depMap[d]; | ||
if (load.conditional) | ||
return; | ||
normalizedDep = conditionalResolutions[normalizedDep] || normalizedDep; | ||
var clonedLoad = extend({}, load); | ||
clonedLoad.depMap = {}; | ||
Object.keys(load.depMap).forEach(function(d) { | ||
var normalizedDep = load.depMap[d]; | ||
if (normalizedDep == '@system-env') | ||
importsSystemEnv = true; | ||
normalizedDep = conditionalResolutions[normalizedDep] || normalizedDep; | ||
if (normalizedDep.indexOf(/#[\:\?\{]/) != -1) | ||
throw new Error('Unable to inline conditional dependency ' + normalizedDep + '. Try including the ' + d + ' dependency of ' + load.name + ' in the build.'); | ||
if (normalizedDep == '@system-env') | ||
importsSystemEnv = true; | ||
clonedLoad.depMap[d] = normalizedDep; | ||
}); | ||
clonedLoad.depMap[d] = normalizedDep; | ||
}); | ||
inlinedTree[m] = clonedLoad; | ||
}); | ||
inlinedTree[m] = clonedLoad; | ||
}); | ||
// if we explicitly import from the system environment, then we need to build it into a static build | ||
// this is normally excluded as it is a system module in SystemJS but won't be available in static | ||
// builds which is exactly what this function acts on | ||
if (importsSystemEnv) { | ||
inlinedTree['@system-env'] = { | ||
name: '@system-env', | ||
path: null, | ||
metadata: { | ||
format: 'json' | ||
}, | ||
deps: [], | ||
depMap: {}, | ||
source: JSON.stringify({ | ||
production: conditionalEnv['@system-env|production'], | ||
browser: conditionalEnv['@system-env|browser'], | ||
node: conditionalEnv['@system-env|node'], | ||
dev: conditionalEnv['@system-env|dev'], | ||
default: true | ||
}), | ||
fresh: true, | ||
timestamp: null, | ||
configHash: loader.configHash, | ||
}; | ||
} | ||
// if we explicitly import from the system environment, then we need to build it into a static build | ||
// this is normally excluded as it is a system module in SystemJS but won't be available in static | ||
// builds which is exactly what this function acts on | ||
if (importsSystemEnv) { | ||
inlinedTree['@system-env'] = { | ||
name: '@system-env', | ||
path: null, | ||
metadata: { | ||
format: 'json' | ||
}, | ||
deps: [], | ||
depMap: {}, | ||
source: JSON.stringify({ | ||
production: canonicalInlineConditionals['@system-env|production'], | ||
browser: canonicalInlineConditionals['@system-env|browser'], | ||
node: canonicalInlineConditionals['@system-env|node'], | ||
dev: canonicalInlineConditionals['@system-env|dev'], | ||
default: true | ||
}), | ||
fresh: true, | ||
timestamp: null, | ||
configHash: loader.configHash, | ||
}; | ||
} | ||
return inlinedTree; | ||
return inlinedTree; | ||
}); | ||
}); | ||
}); | ||
}; | ||
Trace.getConditionalResolutions = function(conditional, traceAllConditionals, conditionalEnv) { | ||
if (traceAllConditionals !== false) | ||
traceAllConditionals = true; | ||
conditionalEnv = conditionalEnv || {}; | ||
/* | ||
* Given a conditional load record, a conditional environment, and an inline conditional environment | ||
* returns the list of possible conditional branch outcomes, the condition modules necessary | ||
* in runtime to determine non-inlined conditions and the conditionalEnvVariations | ||
* object representing the resultant condition space | ||
*/ | ||
Trace.getConditionalResolutions = function(conditional, conditionalEnv, inlineConditionals) { | ||
// flatten all conditions into a filtered array of condition, module branches | ||
var branches = []; | ||
var conditionModules = []; | ||
var conditionalEnvVariations = {}; | ||
// whether or not to include condition branch given our conditionalEnv | ||
function envTrace(condition) { | ||
var conditionModule = parseCondition(condition).module | ||
function traceCondition(condition, value) { | ||
var conditionModule = parseCondition(condition).module; | ||
if (inlineConditionals[condition]) | ||
return inlineConditionals[condition][0] === value; | ||
conditionalEnvVariations[condition] = conditionalEnvVariations[condition] || []; | ||
if (conditionalEnvVariations[condition].indexOf(value) === -1) | ||
conditionalEnvVariations[condition].push(value); | ||
if (conditionModules.indexOf(conditionModule) == -1) | ||
conditionModules.push(conditionModule); | ||
return condition in conditionalEnv ? conditionalEnv[condition] : traceAllConditionals; | ||
return conditionalEnv[condition] ? conditionalEnv[condition].indexOf(value) !== -1 : true; | ||
} | ||
// whether or not to include condition branch given our conditionalEnv | ||
function booleanEnvTrace(condition) { | ||
var conditionObj = parseCondition(condition); | ||
if (conditionObj.negate) | ||
return traceCondition(conditionalComplement(condition), false); | ||
else | ||
return traceCondition(condition, true); | ||
} | ||
// { condition, branch } boolean conditional | ||
if (conditional.branch) { | ||
branches.push(envTrace(conditional.condition) ? conditional.branch : '@empty'); | ||
conditionModules.push(parseCondition(conditional.condition).module); | ||
branches.push(booleanEnvTrace(conditional.condition) ? conditional.branch: '@empty'); | ||
} | ||
@@ -834,3 +891,3 @@ | ||
conditional.envs.forEach(function(env) { | ||
if (envTrace(env.condition)) | ||
if (doFallback && booleanEnvTrace(env.condition)) | ||
branches.push(env.branch); | ||
@@ -840,7 +897,7 @@ | ||
// then we stop the fallback branch from building | ||
if (!envTrace(conditionalComplement(env.condition))) | ||
if (!booleanEnvTrace(conditionalComplement(env.condition))) | ||
doFallback = false; | ||
}); | ||
if (doFallback && conditional.fallback) | ||
branches.push(conditional.fallback) | ||
branches.push(conditional.fallback); | ||
} | ||
@@ -850,11 +907,6 @@ | ||
else if (conditional.branches) { | ||
var et = envTrace(conditional.condition); | ||
if (et !== undefined && et !== false) { | ||
Object.keys(conditional.branches).forEach(function(branch) { | ||
if (et === true || et !== true && et.indexOf(branch) != -1) { | ||
envTrace(conditional.condition); | ||
branches.push(conditional.branches[branch]); | ||
} | ||
}); | ||
} | ||
Object.keys(conditional.branches).forEach(function(branch) { | ||
if (traceCondition(conditional.condition, branch)) | ||
branches.push(conditional.branches[branch]); | ||
}); | ||
} | ||
@@ -864,3 +916,4 @@ | ||
branches: branches, | ||
conditionModules: conditionModules | ||
conditionModules: conditionModules, | ||
conditionalEnvVariations: conditionalEnvVariations | ||
}; | ||
@@ -870,5 +923,3 @@ }; | ||
// Returns the ordered immediate dependency array from the trace of a module | ||
Trace.getLoadDependencies = function(load, tracePackageConfig, traceRuntimePlugin, traceAllConditionals, traceConditionModules, canonicalConditionalEnv, conditionsOnly) { | ||
if (traceAllConditionals !== false) | ||
traceAllConditionals = true; | ||
Trace.getLoadDependencies = function(load, traceOpts, canonicalConditionalEnv, canonicalInlineConditionals) { | ||
canonicalConditionalEnv = canonicalConditionalEnv || {}; | ||
@@ -878,30 +929,23 @@ | ||
if (!load.conditional && conditionsOnly) | ||
return deps; | ||
// conditional load records have their branches all included in the trace | ||
if (load.conditional) { | ||
var resolutions = Trace.getConditionalResolutions(load.conditional, traceAllConditionals, canonicalConditionalEnv); | ||
var resolutions = Trace.getConditionalResolutions(load.conditional, canonicalConditionalEnv, canonicalInlineConditionals); | ||
if (tracePackageConfig && load.packageConfig) | ||
if (traceOpts.tracePackageConfig && load.packageConfig) | ||
deps.push(load.packageConfig); | ||
if (traceConditionModules) | ||
resolutions.conditionModules.forEach(function(conditionModule) { | ||
if (deps.indexOf(conditionModule) == -1) | ||
deps.push(conditionModule); | ||
}); | ||
resolutions.conditionModules.forEach(function(conditionModule) { | ||
if (deps.indexOf(conditionModule) == -1) | ||
deps.push(conditionModule); | ||
}); | ||
if (conditionsOnly) | ||
return deps; | ||
else | ||
return deps.concat(resolutions.branches); | ||
return deps.concat(resolutions.branches); | ||
} | ||
// trace the plugin as a dependency | ||
if (traceRuntimePlugin && load.runtimePlugin) | ||
if (traceOpts.traceRuntimePlugin && load.runtimePlugin) | ||
deps.push(load.plugin); | ||
// plugins by syntax build in their config | ||
if (tracePackageConfig && load.pluginConfig) | ||
if (traceOpts.tracePackageConfig && load.pluginConfig) | ||
deps.push(load.pluginConfig); | ||
@@ -915,3 +959,3 @@ | ||
// trace the package config if necessary | ||
if (tracePackageConfig && load.packageConfig) | ||
if (traceOpts.tracePackageConfig && load.packageConfig) | ||
deps.push(load.packageConfig); | ||
@@ -918,0 +962,0 @@ |
{ | ||
"name": "systemjs-builder", | ||
"version": "0.15.30", | ||
"version": "0.15.31", | ||
"description": "SystemJS Build Tool", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"babel-core": "^6.9.0", | ||
"babel-plugin-transform-cjs-system-wrapper": "^0.2.0", | ||
"babel-plugin-transform-cjs-system-wrapper": "^0.2.1", | ||
"babel-plugin-transform-es2015-modules-systemjs": "^6.6.5", | ||
@@ -20,3 +20,3 @@ "babel-plugin-transform-global-system-wrapper": "0.0.1", | ||
"source-map": "^0.5.3", | ||
"systemjs": "^0.19.35", | ||
"systemjs": "^0.19.38", | ||
"traceur": "0.0.105", | ||
@@ -39,3 +39,4 @@ "uglify-js": "^2.6.1" | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
"test": "mocha", | ||
"update-expectations": "UPDATE_EXPECTATIONS=1 mocha" | ||
}, | ||
@@ -42,0 +43,0 @@ "author": "", |
@@ -35,15 +35,8 @@ var Builder = require('../index'); | ||
}) | ||
}) | ||
test('traceAllConditionals false', function() { | ||
return builder.trace('pkg/env-condition + interpolated-#{conditions.js|test}.js', { traceAllConditionals: false }) | ||
.then(function(tree) { | ||
assert.deepEqual(Object.keys(tree).sort(), ['interpolated-#{conditions.js|test}.js', 'pkg/#:./env-condition', 'conditions.js'].sort()); | ||
}); | ||
}); | ||
test('traceConditionModules false', function() { | ||
return builder.trace('pkg/env-condition + interpolated-#{conditions.js|test}.js', { traceConditionModules: false }) | ||
test('More conditions', function() { | ||
return builder.trace('pkg/env-condition + interpolated-#{conditions.js|test}.js') | ||
.then(function(tree) { | ||
assert.deepEqual(Object.keys(tree).sort(), ['interpolate-1-dep.js', 'interpolated-1.js', 'interpolated-2.js', 'pkg/env-condition-browser.js', 'pkg/env-condition.js', 'interpolated-#{conditions.js|test}.js', 'pkg/#:./env-condition'].sort()); | ||
assert.deepEqual(Object.keys(tree).sort(), ['conditions.js', 'interpolate-1-dep.js', 'interpolated-1.js', 'interpolated-2.js', 'pkg/env-condition-browser.js', 'pkg/env-condition.js', 'interpolated-#{conditions.js|test}.js', 'pkg/#:./env-condition'].sort()); | ||
}); | ||
@@ -67,5 +60,5 @@ }); | ||
test('Environment tracing', function() { | ||
return builder.trace('pkg/env-condition + interpolated-#{conditions.js|test}.js', { traceConditionsOnly: true }) | ||
.then(function(tree) { | ||
assert.deepEqual(Object.keys(tree), ['conditions.js']); | ||
return builder.traceConditionalEnv('pkg/env-condition + interpolated-#{conditions.js|test}.js') | ||
.then(function(conditions) { | ||
assert.deepEqual(conditions, { 'conditions.js|test': ['1', '2'], '@system-env|browser': [true, false] }); | ||
}); | ||
@@ -102,2 +95,3 @@ }); | ||
.then(function(output) { | ||
assert(output.source.indexOf('interpolated-#{') == -1); | ||
assert(output.source.indexOf('"interpolated-2.js"') != -1); | ||
@@ -107,2 +101,17 @@ assert(output.source); | ||
}); | ||
test('Selective conditional inlining', function() { | ||
return builder.bundle('custom-conditions.js + interpolated-#{conditions.js|test}.js', { | ||
inlineConditions: { | ||
'conditions.js|test': '2' | ||
} | ||
}) | ||
.then(function(output) { | ||
assert(output.modules.indexOf('conditions.js') == -1); | ||
assert(output.modules.indexOf('ENV.js') != -1); | ||
assert(output.source.indexOf('interpolated-#{') == -1); | ||
assert(output.source.indexOf('"interpolated-2.js"') != -1); | ||
assert(output.source); | ||
}); | ||
}); | ||
}); |
@@ -1,1 +0,1 @@ | ||
{"version":3,"sources":["test/fixtures/test-tree/third.js","test/fixtures/test-tree/cjs.js","test/fixtures/test-tree/second.js","test/fixtures/test-tree/jquery.js","test/fixtures/test-tree/global.js","test/fixtures/test-tree/text.txt","test/fixtures/test-tree/amd.js","test/fixtures/test-tree/unknown","test/fixtures/test-tree/file.json","test/fixtures/test-tree/first.js"],"names":[],"mappings":";OAAO,qBAAS,CAAC,aAAD,GAAiB,UAAS,SAAT,gBAAoB;AACnD,SAAO;AACL,aAAS,CAAC,YAAW,CAAE,CAAd,CADJ;AAEL,aAAS,YAAW;AAClB,gBAAU,MAAV,EAAkB,SAAlB;AACA,gBAAU,IAAV,EAAgB,GAAhB;AACA,gBAAU,MAAV,EAAkB,YAAlB;AACD;AANI,GAAP;AAQD;;;;;;;;UCTO,IAAI;;GAEX,UAAS,UAAT,EAAkB;AACjB,QAAI,OAAO,UAAP,IAAkB,WAAlB,IAAiC,KAAK,gBAAL,KAA0B,WAA/D,EACE,QAAQ,GAAR,GAAc,IAAd;;AAEF,QAAI,KAAJ,EACE,WAAQ,SAAS,YAAjB;AACH,KAAE;;UAEK;;;;;;MCRG,CAAC;;;;AAAD,OAAC,GAAG,CAAC;;;;;;;;;;QCFZ;QAAA,SAAS;0BAAT;;;;;;;;;;;;;;SCGC,SAAS,OAAO;;;;;;;;;;;;;;;;SCHd,UAAU;;;;;KCAZ,AAAC,CAAC,QAAO,CAAG,EAAC,aAAY,CAAE,wBAAsB,CAAE,8BAA4B,CAAC,CAAL,UAAS,CAAA,CAAG,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG;AAChG,OAAO;AAAE,KAAC,CAAG,MAAI;AAAG,OAAG,CAAG,EAAA;AAAA,EAAE,CAAC;CAD0E,CAEvG;;;;;;MCFE,AAAK,OAEE,AAAS;;;yBAFhB;AAAK,cAAG,AAAE;;AACT,YAAC,AAAa,gBAAG,YAAW,AAAC;AAAC;AAAC,AAAC,AAC1B;AAAS,kBAAG,6BAAK,AAAS,WAAC,AAAK,AAAG;;;;;;;;;;SCFvC,UAAU,EAAC,QAAO,MAAR;;;;;;eCON,CAAC,EAED,CAAC;;;oBAPH,CAAC;;uBAGF,IAAI;;;AAED,OAAC,GAAG,IAAI;;;;AAER,OAAC,GAAG,CAAC;;;;OACf,CAAC","file":"output.js"} | ||
{"version":3,"sources":["test/fixtures/test-tree/third.js","test/fixtures/test-tree/cjs.js","test/fixtures/test-tree/second.js","test/fixtures/test-tree/jquery.js","test/fixtures/test-tree/global.js","test/fixtures/test-tree/text.txt","test/fixtures/test-tree/amd.js","test/fixtures/test-tree/unknown","test/fixtures/test-tree/file.json","test/fixtures/test-tree/first.js"],"names":["register","$__export","setters","execute","__moduleName","log","__filename","eval","exports","cjs","env","jquery","myjquery","test"],"mappings":";OAAOA,qBAAS,CAAC,aAAD,GAAiB,UAASC,SAAT,gBAAoB;AACnD,SAAO;AACLC,aAAS,CAAC,YAAW,CAAE,CAAd,CADJ;AAELC,aAAS,YAAW;AAClBF,gBAAU,MAAV,EAAkB,SAAlB;AACAA,gBAAU,IAAV,EAAgB,GAAhB;AACAA,gBAAU,MAAV,EAAkBG,YAAlB;AACD;AANI,GAAP;AAQD;;;;;;;;UCTOC,IAAIC;;GAEX,sBAAkB;AACjB,QAAI,qBAAkB,WAAlB,IAAiCC,KAAK,gBAAL,KAA0B,WAA/D,EACEC,QAAQC,GAAR,GAAc,IAAd;;AAEF,QAAI,KAAJ,EACE,WAAQ,SAAS,YAAjB;AACH;;UAEOC;;;;;;MCRG,CAAC;;;;AAAD,OAAC,GAAG,CAAC;;;;;;;;;;QCFZC;QAAAA,SAAS;0BAATA;;;;;;;;;;;;;;SCGCC,SAASC,OAAO;;;;;;;;;;;;;;;;SCHdL,UAAU;;;;;KCAZ,AAAC,CAAC,QAAO,CAAG,EAAC,aAAY,CAAE,wBAAsB,CAAE,8BAA4B,CAAC,CAAL,UAAS,CAAA,CAAG,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG;AAChG,OAAO;AAAE,KAAC,CAAG,MAAI;AAAG,OAAG,CAAG,EAAA;AAAA,EAAE,CAAC;CAD0E,CAEvG;;;;;;MCFE,AAAK,OAEE,AAAS;;;yBAFhB;AAAK,cAAG,AAAE;;AACT,YAAC,AAAa,gBAAG,YAAW,AAAC;AAAC;AAAC,AAAC,AAC1B;AAAS,kBAAG,6BAAK,AAAS,WAAC,AAAK,AAAG;;;;;;;;;;SCFvCA,UAAU,EAAC,QAAO,MAAR;;;;;;eCON,CAAC,EAED,CAAC;;;oBAPH,CAAC;;uBAGF,IAAI;;;AAED,OAAC,GAAG,IAAI;;;;AAER,OAAC,GAAG,CAAC;;;;OACf,CAAC","file":"output.js"} |
@@ -1,1 +0,1 @@ | ||
{"version":3,"sources":["test/fixtures/test-tree/third.js","test/fixtures/test-tree/cjs.js","test/fixtures/test-tree/second.js","test/fixtures/test-tree/jquery.js","test/fixtures/test-tree/global.js","test/fixtures/test-tree/text.txt","test/fixtures/test-tree/amd.js","test/fixtures/test-tree/unknown","test/fixtures/test-tree/file.json","test/fixtures/test-tree/first.js"],"names":[],"mappings":";OAAO,qBAAS,CAAC,aAAD,GAAiB,UAAS,SAAT,gBAAoB;AACnD,SAAO;AACL,aAAS,CAAC,YAAW,CAAE,CAAd,CADJ;AAEL,aAAS,YAAW;AAClB,gBAAU,MAAV,EAAkB,SAAlB;AACA,gBAAU,IAAV,EAAgB,GAAhB;AACA,gBAAU,MAAV,EAAkB,YAAlB;AACD;AANI,GAAP;AAQD;;;;;;;;UCTO,IAAI;;GAEX,UAAS,UAAT,EAAkB;AACjB,QAAI,OAAO,UAAP,IAAkB,WAAlB,IAAiC,KAAK,gBAAL,KAA0B,WAA/D,EACE,QAAQ,GAAR,GAAc,IAAd;;AAEF,QAAI,KAAJ,EACE,WAAQ,SAAS,YAAjB;AACH,KAAE;;UAEK;;;KCVH,SAAS,AAAC,yCACc,UAAS,SAAQ;;;OADvC;AACD,UAAM,YADH,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG,GAAC,CACe;AACzB,UAAM;QAAG,EAAA;cAFP,AAAC,QAAqC,CAAA;IAEf;EAC3B,CAAA;AAAM,CAAC,CAAC;;;;;;QCHR;QAAA,SAAS;0BAAT;;;;;;;;;;;;;;SCGC,SAAS,OAAO;;;;;;;;;;;;;;;;SCHd,UAAU;;;;;KCAZ,AAAC,CAAC,QAAO,CAAG,EAAC,aAAY,CAAE,wBAAsB,CAAE,8BAA4B,CAAC,CAAL,UAAS,CAAA,CAAG,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG;AAChG,OAAO;AAAE,KAAC,CAAG,MAAI;AAAG,OAAG,CAAG,EAAA;AAAA,EAAE,CAAC;CAD0E,CAEvG;;;;;;MCFE,AAAK,OAEE,AAAS;;;yBAFhB;AAAK,cAAG,AAAE;;AACT,YAAC,AAAa,gBAAG,YAAW,AAAC;AAAC;AAAC,AAAC,AAC1B;AAAS,kBAAG,6BAAK,AAAS,WAAC,AAAK,AAAG;;;;;;;;;;SCFvC,UAAU,EAAC,QAAO,MAAR;;;KCAZ,SAAS,AAAC,4GACc,UAAS,SAAQ;;;;;;OADvC;AACD,UAAM,YADH,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG;QAAK,KAAG,EAAkB,CAAC;IAElC,WAFC,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG;WAAK,KAAG,KAAkB,CAAC;IAElC,CADuB;AACzB,UAAM;QAKG,KAAG;cAPV,AAAC,QAAqC,CAAA;QAS/B,EAAA;cATP,AAAC,QAAqC,CAAA;OAU7C;IAR8B;EAC3B,CAAA;AAAM,CAAC,CAAC;AAOX","file":"output.js"} | ||
{"version":3,"sources":["test/fixtures/test-tree/third.js","test/fixtures/test-tree/cjs.js","test/fixtures/test-tree/second.js","test/fixtures/test-tree/jquery.js","test/fixtures/test-tree/global.js","test/fixtures/test-tree/text.txt","test/fixtures/test-tree/amd.js","test/fixtures/test-tree/unknown","test/fixtures/test-tree/file.json","test/fixtures/test-tree/first.js"],"names":["register","$__export","setters","execute","__moduleName","log","__filename","eval","exports","cjs","env","jquery","myjquery","test"],"mappings":";OAAOA,qBAAS,CAAC,aAAD,GAAiB,UAASC,SAAT,gBAAoB;AACnD,SAAO;AACLC,aAAS,CAAC,YAAW,CAAE,CAAd,CADJ;AAELC,aAAS,YAAW;AAClBF,gBAAU,MAAV,EAAkB,SAAlB;AACAA,gBAAU,IAAV,EAAgB,GAAhB;AACAA,gBAAU,MAAV,EAAkBG,YAAlB;AACD;AANI,GAAP;AAQD;;;;;;;;UCTOC,IAAIC;;GAEX,sBAAkB;AACjB,QAAI,qBAAkB,WAAlB,IAAiCC,KAAK,gBAAL,KAA0B,WAA/D,EACEC,QAAQC,GAAR,GAAc,IAAd;;AAEF,QAAI,KAAJ,EACE,WAAQ,SAAS,YAAjB;AACH;;UAEOC;;;KCVH,SAAS,AAAC,yCACc,UAAS,SAAQ;;;OADvC;AACD,UAAM,YADH,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG,GAAC,CACe;AACzB,UAAM;QAAG,EAAA;cAFP,AAAC,QAAqC,CAAA;IAEf;EAC3B,CAAA;AAAM,CAAC,CAAC;;;;;;QCHRC;QAAAA,SAAS;0BAATA;;;;;;;;;;;;;;SCGCC,SAASC,OAAO;;;;;;;;;;;;;;;;SCHdL,UAAU;;;;;KCAZ,AAAC,CAAC,QAAO,CAAG,EAAC,aAAY,CAAE,wBAAsB,CAAE,8BAA4B,CAAC,CAAL,UAAS,CAAA,CAAG,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG;AAChG,OAAO;AAAE,KAAC,CAAG,MAAI;AAAG,OAAG,CAAG,EAAA;AAAA,EAAE,CAAC;CAD0E,CAEvG;;;;;;MCFE,AAAK,OAEE,AAAS;;;yBAFhB;AAAK,cAAG,AAAE;;AACT,YAAC,AAAa,gBAAG,YAAW,AAAC;AAAC;AAAC,AAAC,AAC1B;AAAS,kBAAG,6BAAK,AAAS,WAAC,AAAK,AAAG;;;;;;;;;;SCFvCA,UAAU,EAAC,QAAO,MAAR;;;KCAZ,SAAS,AAAC,4GACc,UAAS,SAAQ;;;;;;OADvC;AACD,UAAM,YADH,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG;QAAK,KAAG,EAAkB,CAAC;IAElC,WAFC,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG,GAAC,WAAP,IAAG,CAAG;WAAK,KAAG,KAAkB,CAAC;IAElC,CADuB;AACzB,UAAM;QAKG,KAAG;cAPV,AAAC,QAAqC,CAAA;QAS/B,EAAA;cATP,AAAC,QAAqC,CAAA;OAU7C;IAR8B;EAC3B,CAAA;AAAM,CAAC,CAAC;AAOX","file":"output.js"} |
@@ -6,5 +6,7 @@ (function() { | ||
function q() {} | ||
if (false) | ||
var window = 5; | ||
if (false) | ||
var window = 5; | ||
function q(preprocessedTokens, eval) { | ||
eval(); | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
299670
6718
29