From 8a867c17e507c7d8076951fba377e7fc3996042f Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 14 Feb 2016 09:50:35 -0500 Subject: [PATCH] warn on missing options in config file --- bin/handleError.js | 4 ++++ bin/runRollup.js | 3 +++ test/cli/config-missing-export/_config.js | 9 +++++++++ test/cli/config-missing-export/rollup.config.js | 0 test/test.js | 5 ++++- 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/cli/config-missing-export/_config.js create mode 100644 test/cli/config-missing-export/rollup.config.js 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 );