diff --git a/src/rollup.js b/src/rollup.js index f7a6674..11f1c68 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -2,11 +2,33 @@ import Promise from 'es6-promise/lib/es6-promise/promise.js'; import { basename } from './utils/path.js'; import { writeFile } from './utils/fs.js'; import { keys } from './utils/object.js'; +import validateKeys from './utils/validateKeys.js'; import SOURCEMAPPING_URL from './utils/sourceMappingURL.js'; import Bundle from './Bundle.js'; export const VERSION = '<@VERSION@>'; +const ALLOWED_KEYS = [ + 'entry', + 'dest', + 'plugins', + 'external', + 'onwarn', + 'indent', + 'format', + 'moduleName', + 'sourceMap', + 'intro', + 'outro', + 'banner', + 'footer', + 'globals', + 'transform', + 'load', + 'resolveId', + 'resolveExternal' +]; + export function rollup ( options ) { if ( !options || !options.entry ) { return Promise.reject( new Error( 'You must supply options.entry to rollup' ) ); @@ -16,6 +38,12 @@ export function rollup ( options ) { return Promise.reject( new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' ) ); } + const error = validateKeys( options, ALLOWED_KEYS ); + + if ( error ) { + return Promise.reject( error ); + } + const bundle = new Bundle( options ); return bundle.build().then( () => { diff --git a/src/utils/validateKeys.js b/src/utils/validateKeys.js new file mode 100644 index 0000000..3ff51cd --- /dev/null +++ b/src/utils/validateKeys.js @@ -0,0 +1,17 @@ +import { keys } from './object.js'; + +export default function validateKeys ( object, allowedKeys ) { + const actualKeys = keys( object ); + + let i = actualKeys.length; + + while ( i-- ) { + const key = actualKeys[i]; + + if ( allowedKeys.indexOf( key ) === -1 ) { + return new Error( + `Unexpected key '${ key }' found, expected one of: ${ allowedKeys.join( ', ' ) }` + ); + } + } +} diff --git a/test/test.js b/test/test.js index bd76009..5ee72ba 100644 --- a/test/test.js +++ b/test/test.js @@ -69,6 +69,14 @@ describe( 'rollup', function () { assert.equal( 'You must supply options.entry to rollup', err.message ); }); }); + + it( 'fails with invalid keys', function () { + return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () { + throw new Error( 'Missing expected error' ); + }, function ( err ) { + assert.equal( 'Unexpected key \'plUgins\' found, expected one of: entry, dest, plugins, external, onwarn, indent, format, moduleName, sourceMap, intro, outro, banner, footer, globals, transform, load, resolveId, resolveExternal', err.message ); + }); + }); }); describe( 'bundle.write()', function () {