Skip to content

Commit

Permalink
fix(html): types for plugin (#1264)
Browse files Browse the repository at this point in the history
* fix(html): Correct types for the template function

 - Make templateoptions non-optional
 - Allow template to return a Promise

Also adds type annotations to the implementation to ensure the types are
more consistent.

* chore: correct types after bad conflict resolve

---------

Co-authored-by: Andrew Powell <[email protected]>
Co-authored-by: shellscape <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent 92daef0 commit 3165a25
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 3165a25

Please sign in to comment.