Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update filtersRegistry.js #1129

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading