From 33cdba16bb15112dfbe8dddce65309bbbf36e7b9 Mon Sep 17 00:00:00 2001 From: guybedford Date: Tue, 10 May 2016 14:31:28 +0200 Subject: [PATCH] conditional config defaults --- lib/builder.js | 10 +++++++--- test/conditional-builds.js | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index 950d7ad..13af8d9 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -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); }; @@ -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; @@ -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') diff --git a/test/conditional-builds.js b/test/conditional-builds.js index d325426..f1d13d8 100644 --- a/test/conditional-builds.js +++ b/test/conditional-builds.js @@ -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()); }); @@ -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()); }); });