Skip to content

Commit

Permalink
feat(config): allow config to be a default export
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed Jan 15, 2017
1 parent 99d647b commit 9976dce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion test/unit/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 9976dce

Please sign in to comment.