Skip to content

Commit

Permalink
Remove error check/log
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks authored and craftamap committed Apr 21, 2022
1 parent 55a7dc9 commit af412bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
13 changes: 4 additions & 9 deletions lib/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,12 @@ const htmlPlugin = (configuration = { files: [], }) => {
});
}
}
async function renderTemplate({ htmlTemplate, define }, log) {
const templateContext = { define };
async function renderTemplate({ htmlTemplate, define }) {
const template = (htmlTemplate && fs_1.default.existsSync(htmlTemplate)
? await fs_1.default.promises.readFile(htmlTemplate)
: htmlTemplate || '').toString();
const isValid = template.startsWith('<!DOCTYPE html>');
if (log && htmlTemplate && !isValid) {
console.warn(`Warning: The htmlTemplate prop "${htmlTemplate}" does not reference a valid file`);
}
const compiledTemplateFn = (0, lodash_template_1.default)(isValid ? template : defaultHtmlTemplate);
return compiledTemplateFn(templateContext);
const compiledTemplateFn = (0, lodash_template_1.default)(template || defaultHtmlTemplate);
return compiledTemplateFn({ define });
}
// use the same joinWithPublicPath function as esbuild:
// https://github.com/evanw/esbuild/blob/a1ff9d144cdb8d50ea2fa79a1d11f43d5bd5e2d8/internal/bundler/bundler.go#L533
Expand Down Expand Up @@ -208,7 +203,7 @@ const htmlPlugin = (configuration = { files: [], }) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const outdir = build.initialOptions.outdir;
const publicPath = build.initialOptions.publicPath;
const templatingResult = await renderTemplate(htmlFileConfiguration, Boolean(build.initialOptions.logLevel));
const templatingResult = await renderTemplate(htmlFileConfiguration);
// Next, we insert the found files into the htmlTemplate - if no htmlTemplate was specified, we default to a basic one.
const dom = new jsdom_1.JSDOM(templatingResult);
const document = dom.window.document;
Expand Down
14 changes: 4 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,12 @@ export const htmlPlugin = (configuration: Configuration = { files: [], }): esbui
}
}

async function renderTemplate({ htmlTemplate, define }: HtmlFileConfiguration, log: boolean) {
const templateContext = { define }
async function renderTemplate({ htmlTemplate, define }: HtmlFileConfiguration) {
const template = (htmlTemplate && fs.existsSync(htmlTemplate)
? await fs.promises.readFile(htmlTemplate)
: htmlTemplate || '').toString()
const isValid = template.startsWith('<!DOCTYPE html>')

if (log && htmlTemplate && !isValid) {
console.warn(`Warning: The htmlTemplate prop "${htmlTemplate}" does not reference a valid file`)
}
const compiledTemplateFn = lodashTemplate(isValid ? template : defaultHtmlTemplate)
return compiledTemplateFn(templateContext)
const compiledTemplateFn = lodashTemplate(template || defaultHtmlTemplate)
return compiledTemplateFn({ define })
}

// use the same joinWithPublicPath function as esbuild:
Expand Down Expand Up @@ -243,7 +237,7 @@ export const htmlPlugin = (configuration: Configuration = { files: [], }): esbui

const publicPath = build.initialOptions.publicPath

const templatingResult = await renderTemplate(htmlFileConfiguration, Boolean(build.initialOptions.logLevel))
const templatingResult = await renderTemplate(htmlFileConfiguration)

// Next, we insert the found files into the htmlTemplate - if no htmlTemplate was specified, we default to a basic one.
const dom = new JSDOM(templatingResult)
Expand Down

0 comments on commit af412bc

Please sign in to comment.