Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Tweak .custom API, validate options hook - it cant be async
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Dec 29, 2018
1 parent 54d3cee commit 31a6f88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ function createBabelPluginFactory(customCallback = returnObject) {
return pluginOptions => {
let customOptions = null;

if (overrides.customOptions) {
({ custom: customOptions = null, plugin: pluginOptions } = overrides.customOptions(pluginOptions));
if (overrides.options) {
const overridden = overrides.options(pluginOptions);

if (typeof overridden.then === 'function') {
throw new Error(
".options hook can't be asynchronous. It should return `{ customOptions, pluginsOptions }` synchronously.",
);
}
({ customOptions = null, pluginOptions } = overridden);
}

const {
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ describe('rollup-plugin-babel', function() {
it('supports overriding the plugin options in custom loader', () => {
const customBabelPlugin = babelPlugin.custom(() => {
return {
customOptions(options) {
options(options) {
// Ignore the js extension to test overriding the options
return { plugin: Object.assign({}, options, { extensions: ['.x'] }) };
return { pluginOptions: Object.assign({}, options, { extensions: ['.x'] }) };
},
config(cfg) {
return Object.assign({}, cfg.options, {
Expand Down

0 comments on commit 31a6f88

Please sign in to comment.