diff --git a/lib/compiler.js b/lib/compiler.js index 0a3ef7d..4c184cd 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -480,18 +480,20 @@ function resolveMiddlewareParams(rootDir, params) { } function buildComponentInstructions(rootDir, componentConfig) { - return Object.keys(componentConfig).map(function(name) { - var sourceFile; - if (name.indexOf('./') === 0 || name.indexOf('../') === 0) { - // Relative path - sourceFile = path.resolve(rootDir, name); - } else { - sourceFile = require.resolve(name); - } + return Object.keys(componentConfig) + .filter(function(name) { return !!componentConfig[name]; }) + .map(function(name) { + var sourceFile; + if (name.indexOf('./') === 0 || name.indexOf('../') === 0) { + // Relative path + sourceFile = path.resolve(rootDir, name); + } else { + sourceFile = require.resolve(name); + } - return { - sourceFile: sourceFile, - config: componentConfig[name] - }; - }); + return { + sourceFile: sourceFile, + config: componentConfig[name] + }; + }); } diff --git a/test/executor.test.js b/test/executor.test.js index 789e00b..4ae0a81 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -468,9 +468,27 @@ describe('executor', function() { boot(app, appdir.PATH); + expect(Object.keys(require.cache)).to.include( + appdir.resolve('components/test-component/index.js')); + expect(app.componentOptions).to.eql({ option: 'value' }); }); + it('disables component when configuration is not set', function() { + appdir.writeConfigFileSync('component-config.json', { + './components/test-component': false + }); + + appdir.writeFileSync('components/test-component/index.js', + 'module.exports = ' + + 'function(app, options) { app.componentOptions = options; }'); + + boot(app, appdir.PATH); + + 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');