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 Jun 5, 2024
1 parent 8550c4b commit cd00ee0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions packages/html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const defaultTemplate = async ({

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

const defaults = {
const defaults: Required<RollupHtmlOptions> = {
attributes: {
link: null,
html: { lang: 'en' },
Expand All @@ -84,11 +84,8 @@ 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 cd00ee0

Please sign in to comment.