Browse Source

Prevent invalid keys from being passed in options.

gh-384
Brian Donovan 9 years ago
parent
commit
934d1e1133
  1. 24
      src/rollup.js
  2. 11
      src/utils/validateKeys.js

24
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,8 @@ 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' ) );
}
validateKeys( options, ALLOWED_KEYS );
const bundle = new Bundle( options );
return bundle.build().then( () => {

11
src/utils/validateKeys.js

@ -0,0 +1,11 @@
import { keys } from './object.js';
export default function validateKeys ( object, allowedKeys ) {
const actualKeys = keys( object );
actualKeys.forEach( key => {
if ( allowedKeys.indexOf( key ) < 0 ) {
throw new Error( `Unexpected key '${ key }' found, expected one of: ${ allowedKeys.join( ', ' ) }` );
}
});
}
Loading…
Cancel
Save