From 9976dcee613e7fede9b6f528577b85ff783b06b3 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sun, 15 Jan 2017 18:26:24 +0000 Subject: [PATCH] feat(config): allow config to be a default export --- lib/config.js | 3 +++ test/unit/config.spec.js | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 089125bcf..3d2b26fa3 100644 --- a/lib/config.js +++ b/lib/config.js @@ -342,6 +342,9 @@ var parseConfig = function (configFilePath, cliOptions) { try { configModule = require(configFilePath) + if (typeof configModule === 'object' && typeof configModule.default !== 'undefined') { + configModule = configModule.default + } } catch (e) { if (e.code === 'MODULE_NOT_FOUND' && e.message.indexOf(configFilePath) !== -1) { log.error('File %s does not exist!', configFilePath) diff --git a/test/unit/config.spec.js b/test/unit/config.spec.js index 4bcd91497..2ce36129c 100644 --- a/test/unit/config.spec.js +++ b/test/unit/config.spec.js @@ -45,7 +45,8 @@ describe('config', () => { '/conf/exclude.js': wrapCfg({exclude: ['one.js', 'sub/two.js']}), '/conf/absolute.js': wrapCfg({files: ['http://some.com', 'https://more.org/file.js']}), '/conf/both.js': wrapCfg({files: ['one.js', 'two.js'], exclude: ['third.js']}), - '/conf/coffee.coffee': wrapCfg({files: ['one.js', 'two.js']}) + '/conf/coffee.coffee': wrapCfg({files: ['one.js', 'two.js']}), + '/conf/default-export.js': {default: wrapCfg({files: ['one.js', 'two.js']})} } // load file under test @@ -294,6 +295,11 @@ describe('config', () => { config = normalizeConfigWithDefaults({ protocol: 'unsupported:' }) expect(config.protocol).to.equal('http:') }) + + it('should allow the config to be set of the default export', () => { + var config = e.parseConfig('/conf/default-export.js', {}) + expect(config.autoWatch).to.equal(true) + }) }) describe('normalizeConfig', () => {