Skip to content

Commit

Permalink
fix(adapters): resolving correct templateDir
Browse files Browse the repository at this point in the history
The conditional expression which decides if the passed template name is a path or not resolved the template dir in the wrong order. This fix will change the order. As a result if the template name is a path, the templateDir will be resolved from the template name. Elsewhere it will use the default template dir provided by the Module.forRoot
  • Loading branch information
jembach committed Jun 15, 2021
1 parent 1df3315 commit 9bee48b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/adapters/ejs.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class EjsAdapter implements TemplateAdapter {
);
const templateDir =
mail.data.template.startsWith('./')
? get(mailerOptions, 'template.dir', '')
: path.dirname(mail.data.template);
? path.dirname(mail.data.template)
: get(mailerOptions, 'template.dir', '')
const templatePath = path.join(templateDir, templateName + templateExt);

if (!this.precompiledTemplates[templateName]) {
Expand Down
7 changes: 3 additions & 4 deletions lib/adapters/handlebars.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ export class HandlebarsAdapter implements TemplateAdapter {
const precompile = (template: any, callback: any, options: any) => {
const templateExt = path.extname(template) || '.hbs';
const templateName = path.basename(template, path.extname(template));
const templateDir =
template.startsWith('./')
? get(options, 'dir', '')
: path.dirname(template);
const templateDir = template.startsWith('./')
? path.dirname(template)
: get(options, 'dir', '');
const templatePath = path.join(templateDir, templateName + templateExt);

if (!this.precompiledTemplates[templateName]) {
Expand Down
7 changes: 3 additions & 4 deletions lib/adapters/pug.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export class PugAdapter implements TemplateAdapter {
mail.data.template,
path.extname(mail.data.template),
);
const templateDir =
mail.data.template.startsWith('./')
? get(mailerOptions, 'template.dir', '')
: path.dirname(mail.data.template);
const templateDir = mail.data.template.startsWith('./')
? path.dirname(mail.data.template)
: get(mailerOptions, 'template.dir', '');
const templatePath = path.join(templateDir, templateName + templateExt);

const options = {
Expand Down

0 comments on commit 9bee48b

Please sign in to comment.