Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
conditional config defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 10, 2016
1 parent 8c16e95 commit 33cdba1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/builder.js
Expand Up @@ -152,8 +152,10 @@ Builder.prototype.reset = function(baseLoader) {

var loaderConfig = loader.config;
loader.config = function(cfg) {
loaderConfig.call(this, cfg);
loader.pluginLoader.config(cfg);
var lCfg = extend({}, cfg);
lCfg.browserConfig = lCfg.nodeConfig = lCfg.productionConfig = undefined;
loaderConfig.call(this, lCfg);
loader.configHash = generateConfigHash(loader);
};

Expand Down Expand Up @@ -355,7 +357,6 @@ function processTraceOpts(options, defaults) {

// conditional tracing defaults
if (typeof opts.browser == 'boolean' || typeof opts.node == 'boolean') {

// browser true/false -> node is opposite
if (typeof opts.browser == 'boolean' && typeof opts.node != 'boolean')
opts.node = !opts.browser;
Expand All @@ -371,7 +372,10 @@ function processTraceOpts(options, defaults) {
opts.conditions['~@system-env|browser'] = opts.browser === true ? opts.node : !opts.browser;
opts.conditions['@system-env|node'] = opts.node;
opts.conditions['~@system-env|node'] = opts.node === true ? opts.browser : !opts.node;

}

if (typeof opts.production == 'boolean' || typeof opts.development == 'boolean') {
// by default we always do a production bundle
if (typeof opts.production != 'boolean')
opts.production = !opts.development;
if (typeof opts.development != 'boolean')
Expand Down
4 changes: 2 additions & 2 deletions test/conditional-builds.js
Expand Up @@ -6,7 +6,7 @@ builder.loadConfigSync('test/fixtures/conditional-tree.config.js');

suite('Conditional Builds', function() {
test('Package environment traces all conditional variations', function() {
return builder.trace('pkg/env-condition')
return builder.trace('pkg/env-condition', { browser: true, node: true })
.then(function(tree) {
assert.deepEqual(Object.keys(tree).sort(), ['pkg/#:./env-condition', 'pkg/env-condition-browser.js', 'pkg/env-condition.js'].sort());
});
Expand Down Expand Up @@ -36,7 +36,7 @@ suite('Conditional Builds', function() {
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());
assert.deepEqual(Object.keys(tree).sort(), ['interpolated-#{conditions.js|test}.js', 'pkg/#:./env-condition', 'conditions.js', 'pkg/env-condition-browser.js'].sort());
});
});

Expand Down

0 comments on commit 33cdba1

Please sign in to comment.