nest-modules / mailer

πŸ“¨ A mailer module for Nest framework (node.js)
https://nest-modules.github.io/mailer/
MIT License
837 stars 176 forks source link

Fix for partial not found error on windows due to glob.sync #906

Closed damdafayton closed 9 months ago

damdafayton commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @nestjs-modules/mailer@1.8.1 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@nestjs-modules/mailer/dist/adapters/handlebars.adapter.js b/node_modules/@nestjs-modules/mailer/dist/adapters/handlebars.adapter.js
index b42eee5..76a76c1 100644
--- a/node_modules/@nestjs-modules/mailer/dist/adapters/handlebars.adapter.js
+++ b/node_modules/@nestjs-modules/mailer/dist/adapters/handlebars.adapter.js
@@ -29,6 +29,7 @@ class HandlebarsAdapter {
                 ? path.dirname(template)
                 : path.join((0, lodash_1.get)(options, 'dir', ''), path.dirname(template));
             const templatePath = path.join(templateDir, templateName + templateExt);
+            
             if (!this.precompiledTemplates[templateName]) {
                 try {
                     const template = fs.readFileSync(templatePath, 'utf-8');
@@ -51,7 +52,9 @@ class HandlebarsAdapter {
             data: {},
         });
         if (runtimeOptions.partials) {
-            const files = glob.sync(path.join(runtimeOptions.partials.dir, '**', '*.hbs'));
+            const partialPath=path.join(runtimeOptions.partials.dir, '**', '*.hbs').replace(/\\/g,'/');
+            
+            const files = glob.sync(partialPath);
             files.forEach((file) => {
                 const { templateName, templatePath } = precompile(file, () => { }, runtimeOptions.partials);
                 const templateDir = path.relative(runtimeOptions.partials.dir, path.dirname(templatePath));

This issue body was partially generated by patch-package.

KybalionX commented 1 year ago

That's amazing! I've been trying to solve this issue in a different ways, but this is the only one that work for me (Windows user)

adamrehill commented 1 year ago

Thanks for this! saved me a ton of time digging! Created a PR here: https://github.com/nest-modules/mailer/pull/951

Prooksius commented 1 year ago

Thanks for the tip. Everything works fine now. But unfortunately when installing the package from npm, it is old, without this fix. Pls update.

francobasilico commented 1 year ago

WHen is this going to be deployed?

fendermany commented 1 year ago

Fixed by ^1.9.1