From daaaeafc759120697f953caf4478277f405add5b Mon Sep 17 00:00:00 2001 From: Vladimir Smyshlyaev Date: Tue, 27 Sep 2016 13:25:22 +0300 Subject: [PATCH] Cut options validation into method --- src/rollup.js | 18 +++++++++++------- src/utils/validateKeys.js | 6 +----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rollup.js b/src/rollup.js index 0868960..0773d43 100644 --- a/src/rollup.js +++ b/src/rollup.js @@ -39,20 +39,24 @@ const ALLOWED_KEYS = [ 'useStrict' ]; -export function rollup ( options ) { +function checkOptions ( options ) { if ( !options || !options.entry ) { - return Promise.reject( new Error( 'You must supply options.entry to rollup' ) ); + return new Error( 'You must supply options.entry to rollup' ); } if ( options.transform || options.load || options.resolveId || options.resolveExternal ) { - 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' ) ); + return 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 ); + const error = validateKeys( keys(options), ALLOWED_KEYS ); + if ( error ) return error; - if ( error ) { - return Promise.reject( error ); - } + return null; +} + +export function rollup ( options ) { + const error = checkOptions ( options ); + if ( error ) return Promise.reject( error ); const bundle = new Bundle( options ); diff --git a/src/utils/validateKeys.js b/src/utils/validateKeys.js index 3ff51cd..d717b0a 100644 --- a/src/utils/validateKeys.js +++ b/src/utils/validateKeys.js @@ -1,8 +1,4 @@ -import { keys } from './object.js'; - -export default function validateKeys ( object, allowedKeys ) { - const actualKeys = keys( object ); - +export default function validateKeys ( actualKeys, allowedKeys ) { let i = actualKeys.length; while ( i-- ) {