Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail when returning null or undefined from an async options hook #4039

Merged
merged 1 commit into from Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;