Skip to content

Commit

Permalink
fix(html): Correct types for the template function
Browse files Browse the repository at this point in the history
 - Make templateoptions non-optional
 - Allow template to return a Promise

Also adds type annotations to the implementation to ensure the types are
more consistent.
  • Loading branch information
SquidDev committed Sep 14, 2022
1 parent 2483b40 commit c7286ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const defaultTemplate = async ({

const supportedFormats = ['es', 'esm', 'iife', 'umd'];

const defaults = {
const defaults: Required<RollupHtmlOptions> = {
attributes: {
link: null,
html: { lang: 'en' },
Expand All @@ -89,11 +89,14 @@ const defaults = {
};

export default function html(opts: RollupHtmlOptions = {}): Plugin {
const { attributes, fileName, meta, publicPath, template, title } = Object.assign(
{},
defaults,
opts
);
const {
attributes,
fileName,
meta,
publicPath,
template,
title
}: Required<RollupHtmlOptions> = Object.assign({}, defaults, opts);

return {
name: 'html',
Expand Down
2 changes: 1 addition & 1 deletion packages/html/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface RollupHtmlOptions {
fileName?: string;
meta?: Record<string, any>[];
publicPath?: string;
template?: (templateoptions?: RollupHtmlTemplateOptions) => string;
template?: (templateoptions: RollupHtmlTemplateOptions) => string | Promise<string>;
}

export function makeHtmlAttributes(attributes: Record<string, string>): string;
Expand Down

0 comments on commit c7286ec

Please sign in to comment.