From d850560a189c4f7a77bc27a4e2a6bbd03916c479 Mon Sep 17 00:00:00 2001 From: Farid Neshat Date: Fri, 8 Jan 2016 22:54:15 +0800 Subject: [PATCH] When config is overriden with null don't merge Fixes #146 and also fixes strongloop/loopback-component-explorer#51 --- lib/config-loader.js | 2 +- test/executor.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/config-loader.js b/lib/config-loader.js index e60c9df..c2baf32 100644 --- a/lib/config-loader.js +++ b/lib/config-loader.js @@ -266,7 +266,7 @@ function mergeSingleItemOrProperty(target, config, key, fullKey) { return mergeArrays(origValue, newValue, fullKey); } - if (typeof origValue === 'object') { + if (newValue !== null && typeof origValue === 'object') { return mergeObjects(origValue, newValue, fullKey); } diff --git a/test/executor.test.js b/test/executor.test.js index 52564af..a6f716b 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -756,6 +756,24 @@ describe('executor', function() { appdir.resolve('components/test-component/index.js')); }); + it('disable component if overrided by production configuration', function() { + appdir.writeConfigFileSync('component-config.json', { + './components/test-component': {} + }); + appdir.writeConfigFileSync('component-config.production.json', { + './components/test-component': null + }); + + appdir.writeFileSync('components/test-component/index.js', + 'module.exports = ' + + 'function(app, options) { app.componentOptions = options; }'); + + boot(app, { appRootDir: appdir.PATH, env: 'production' }); + + expect(Object.keys(require.cache)).to.not.include( + appdir.resolve('components/test-component/index.js')); + }); + it('configures middleware (that requires `this`)', function(done) { var passportPath = require.resolve('./fixtures/passport');