diff --git a/bin/handleError.js b/bin/handleError.js index 23a8e86..b7cd224 100644 --- a/bin/handleError.js +++ b/bin/handleError.js @@ -1,6 +1,10 @@ var chalk = require( 'chalk' ); var handlers = { + MISSING_CONFIG: function () { + console.error( chalk.red( 'Config file must export an options object. See https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file' ) ); + }, + MISSING_INPUT_OPTION: function () { console.error( chalk.red( 'You must specify an --input (-i) option' ) ); }, diff --git a/bin/runRollup.js b/bin/runRollup.js index 5b665ed..08696a5 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -59,6 +59,9 @@ module.exports = function ( command ) { try { var options = require( path.resolve( config ) ); + if ( Object.keys( options ).length === 0 ) { + handleError({ code: 'MISSING_CONFIG' }); + } } catch ( err ) { handleError( err ); } diff --git a/test/cli/config-missing-export/_config.js b/test/cli/config-missing-export/_config.js new file mode 100644 index 0000000..051f155 --- /dev/null +++ b/test/cli/config-missing-export/_config.js @@ -0,0 +1,9 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'throws error if config does not export an object', + command: 'rollup -c', + error: function ( err ) { + assert.ok( /Config file must export an options object/.test( err.message ) ); + } +}; diff --git a/test/cli/config-missing-export/rollup.config.js b/test/cli/config-missing-export/rollup.config.js new file mode 100644 index 0000000..e69de29 diff --git a/test/test.js b/test/test.js index bf6e5a2..2ccc21c 100644 --- a/test/test.js +++ b/test/test.js @@ -342,7 +342,10 @@ describe( 'rollup', function () { PATH: path.resolve( __dirname, '../bin' ) + path.delimiter + process.env.PATH } }, function ( err, code, stderr ) { - if ( err ) return done( err ); + if ( err || config.error ) { + config.error( err ); + return done(); + } if ( stderr ) console.error( stderr );