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

Commit 31a6f88

Browse files
committed
Tweak .custom API, validate options hook - it cant be async
1 parent 54d3cee commit 31a6f88

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ function createBabelPluginFactory(customCallback = returnObject) {
3535
return pluginOptions => {
3636
let customOptions = null;
3737

38-
if (overrides.customOptions) {
39-
({ custom: customOptions = null, plugin: pluginOptions } = overrides.customOptions(pluginOptions));
38+
if (overrides.options) {
39+
const overridden = overrides.options(pluginOptions);
40+
41+
if (typeof overridden.then === 'function') {
42+
throw new Error(
43+
".options hook can't be asynchronous. It should return `{ customOptions, pluginsOptions }` synchronously.",
44+
);
45+
}
46+
({ customOptions = null, pluginOptions } = overridden);
4047
}
4148

4249
const {

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ describe('rollup-plugin-babel', function() {
291291
it('supports overriding the plugin options in custom loader', () => {
292292
const customBabelPlugin = babelPlugin.custom(() => {
293293
return {
294-
customOptions(options) {
294+
options(options) {
295295
// Ignore the js extension to test overriding the options
296-
return { plugin: Object.assign({}, options, { extensions: ['.x'] }) };
296+
return { pluginOptions: Object.assign({}, options, { extensions: ['.x'] }) };
297297
},
298298
config(cfg) {
299299
return Object.assign({}, cfg.options, {

0 commit comments

Comments
 (0)