Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 6, 2022
1 parent 3e7147e commit b703d1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
18 changes: 7 additions & 11 deletions src/rollup/rollup.ts
Expand Up @@ -129,17 +129,13 @@ function applyOptionHook(watchMode: boolean) {
inputOptions: Promise<GenericConfigObject>,
plugin: Plugin
): Promise<GenericConfigObject> => {
if (plugin.options) {
const handler = 'handler' in plugin.options ? plugin.options.handler : plugin.options;
return (
((await handler.call(
{ meta: { rollupVersion, watchMode } },
await inputOptions
)) as GenericConfigObject) || inputOptions
);
}

return inputOptions;
const handler = 'handler' in plugin.options! ? plugin.options.handler : plugin.options!;
return (
((await handler.call(
{ meta: { rollupVersion, watchMode } },
await inputOptions
)) as GenericConfigObject) || inputOptions
);
};
}

Expand Down
40 changes: 18 additions & 22 deletions src/utils/PluginDriver.ts
Expand Up @@ -170,13 +170,11 @@ export class PluginDriver {
args: Parameters<FunctionPluginHooks[H]>,
replaceContext?: ReplaceContext
): Promise<void> {
const promises: Promise<void>[] = [];
for (const plugin of this.getSortedPlugins(hookName)) {
const hookPromise = this.runHook(hookName, args, plugin, replaceContext);
if (!hookPromise) continue;
promises.push(hookPromise);
}
return Promise.all(promises).then(() => {});
return Promise.all(
this.getSortedPlugins(hookName).map(plugin =>
this.runHook(hookName, args, plugin, replaceContext)
)
).then(() => {});
}

// chains, reduces returned value, handling the reduced value as the first hook argument
Expand All @@ -192,14 +190,14 @@ export class PluginDriver {
): Promise<Arg0<H>> {
let promise = Promise.resolve(arg0);
for (const plugin of this.getSortedPlugins(hookName)) {
promise = promise.then(arg0 => {
const args = [arg0, ...rest] as Parameters<FunctionPluginHooks[H]>;
const hookPromise = this.runHook(hookName, args, plugin, replaceContext);
if (!hookPromise) return arg0;
return hookPromise.then(result =>
reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin)
);
});
promise = promise.then(arg0 =>
this.runHook(
hookName,
[arg0, ...rest] as Parameters<FunctionPluginHooks[H]>,
plugin,
replaceContext
).then(result => reduce.call(this.pluginContexts.get(plugin), arg0, result, plugin))
);
}
return promise;
}
Expand Down Expand Up @@ -239,13 +237,11 @@ export class PluginDriver {
}
}
)) {
promise = promise.then(value => {
const hookPromise = this.runHook(hookName, args, plugin);
if (!hookPromise) return value;
return hookPromise.then(result =>
promise = promise.then(value =>
this.runHook(hookName, args, plugin).then(result =>
reduce.call(this.pluginContexts.get(plugin), value, result, plugin)
);
});
)
);
}
return promise;
}
Expand Down Expand Up @@ -314,7 +310,7 @@ export class PluginDriver {
args: unknown[],
plugin: Plugin,
replaceContext?: ReplaceContext | null
): Promise<unknown> | undefined {
): Promise<unknown> {
// We always filter for plugins that support the hook before running it
const hook = plugin[hookName]!;
const handler = typeof hook === 'object' ? hook.handler : hook;
Expand Down

0 comments on commit b703d1b

Please sign in to comment.