Skip to content

Commit

Permalink
Update filtersRegistry.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Durgesh4993 authored Feb 29, 2024
1 parent 3c70ccc commit 4865826
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/filtersRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,28 @@ function registerLocalFilters(nunjucks, templateDir, filtersDir) {
followLinks: false
});

walker.on('file', async (root, stats, next) => {
try {
walker.on('file', async (root, stats, next) => {
try {
// Construct the absolute path to the file
const filePath = path.resolve(templateDir, path.resolve(root, stats.name));
// If it's a module constructor, inject dependencies to ensure consistent usage in remote templates in other projects or plain directories.

// Clear the module cache to ensure consistent usage of modules
delete require.cache[require.resolve(filePath)];

// Require the module at the specified file path
const mod = require(filePath);


// Add filters from the module to Nunjucks
addFilters(nunjucks, mod);

// Move to the next file
next();
} catch (e) {
} catch (e) {
// If an error occurs, reject the promise
reject(e);
}
});
}
}).on('error', reject);


walker.on('errors', (root, nodeStatsArray) => {
reject(nodeStatsArray);
Expand Down

0 comments on commit 4865826

Please sign in to comment.