Skip to content

Commit

Permalink
Do not fail when returning null or undefined from an async options ho…
Browse files Browse the repository at this point in the history
…ok (#4039)
  • Loading branch information
lukastaegert committed Apr 10, 2021
1 parent 5a22c8a commit 6559f68
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rollup/rollup.ts
Expand Up @@ -122,13 +122,14 @@ function applyOptionHook(watchMode: boolean) {
inputOptions: Promise<GenericConfigObject>,
plugin: Plugin
): Promise<GenericConfigObject> => {
if (plugin.options)
if (plugin.options) {
return (
(plugin.options.call(
((await plugin.options.call(
{ meta: { rollupVersion, watchMode } },
await inputOptions
) as GenericConfigObject) || inputOptions
)) as GenericConfigObject) || inputOptions
);
}

return inputOptions;
};
Expand Down
25 changes: 25 additions & 0 deletions test/function/samples/aync-options/_config.js
@@ -0,0 +1,25 @@
const assert = require('assert');

module.exports = {
description: 'handles async plugin options',
options: {
preserveEntrySignatures: false,
plugins: [
{
options(options) {
assert.strictEqual(options.preserveEntrySignatures, false);
return Promise.resolve({ ...options, preserveEntrySignatures: 'strict' });
}
},
{
options(options) {
assert.strictEqual(options.preserveEntrySignatures, 'strict');
return Promise.resolve(null);
}
}
]
},
exports(exports) {
assert.strictEqual(exports.foo, 1);
}
};
1 change: 1 addition & 0 deletions test/function/samples/aync-options/main.js
@@ -0,0 +1 @@
export const foo = 1;

0 comments on commit 6559f68

Please sign in to comment.