Skip to content

Commit

Permalink
chore(mjmlTemplate): prevent possible Object.keys runtime error
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomascogez committed Oct 20, 2022
1 parent 2596ef9 commit 19f9a6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
- /usr/src/app/node_modules
links:
- maildev
depends_on:
- maildev
environment:
- MAILDEV_SMTP_PORT=25
- MAILDEV_SMTP_ENDPOINT=maildev
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/buildMjmlTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ export const buildMjmlTemplate = async (options: IPluginOptions, templateName: s
throw new Error(`[nodemailer-mjml] - Could not read mjml template at path: ${mjmlTemplatePath}`);
});

const shouldRunMustacheCompiler = !!templateData && Object.keys(templateData).length > 0;
const shouldRunMustacheCompiler = !!templateData && Object.keys(templateData ?? {}).length > 0;
const mustacheRenderedTemplate = shouldRunMustacheCompiler ? render(rawMjmlTemplate, templateData) : rawMjmlTemplate;

const mjmlOutput = mjml2html(mustacheRenderedTemplate, {
filePath: mjmlTemplatePath,
...renderOptions.mjmlOptions
});

checkMjmlError(mjmlOutput);

const finalHtmlOutput = renderOptions.minifyHtmlOutput ? minify(mjmlOutput.html, renderOptions.htmlMinifierOptions) : mjmlOutput.html;
Expand Down

0 comments on commit 19f9a6e

Please sign in to comment.