Browse Source

warn on missing options in config file

gh-669
Rich-Harris 9 years ago
parent
commit
8a867c17e5
  1. 4
      bin/handleError.js
  2. 3
      bin/runRollup.js
  3. 9
      test/cli/config-missing-export/_config.js
  4. 0
      test/cli/config-missing-export/rollup.config.js
  5. 5
      test/test.js

4
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' ) );
},

3
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 );
}

9
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 ) );
}
};

0
test/cli/config-missing-export/rollup.config.js

5
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 );

Loading…
Cancel
Save