Browse Source

Always fail `rollup` with a rejected promise, not a thrown error.

gh-384
Brian Donovan 9 years ago
parent
commit
dfd921e54f
  1. 6
      src/rollup.js
  2. 8
      src/utils/validateKeys.js
  3. 8
      test/test.js

6
src/rollup.js

@ -38,7 +38,11 @@ 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 error = validateKeys( options, ALLOWED_KEYS );
if ( error ) {
return Promise.reject( error );
}
const bundle = new Bundle( options );

8
src/utils/validateKeys.js

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

8
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 () {

Loading…
Cancel
Save