Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readFile(filename, 'utf8', (err, str) => {
if (err) return this.config.logger.error(err);
const options = { cache: true, filename };
if (pug.cache[filename])
return this.config.logger.warn(
`${filename} was already cached in pug.cache`
);
//
setImmediate(() => {
const template = pug.compile(str, options);
if (this.config.cache) {
debug(`caching ${filename}`);
try {
pug.cache[filename] = template;
} catch (err) {
this.config.logger.error(err);
}
} else {
debug(
`not caching ${filename} since \`cache\` option was set to \`false\``
const clearTemplateCache = () => {
for (const prop of Object.keys(pug.cache)) {
delete pug.cache[prop];
}
};
if (stat.isDirectory()) {
setImmediate(() => {
this.cacheDirectory(filename);
});
return;
}
debug(`checking ${filename}`);
if (path.extname(filename) !== '.pug') {
debug(`${filename} did not have ".pug" extension`);
return;
}
if (pug.cache[filename]) {
debug(`${filename} was already cached in pug.cache`);
return;
}
setImmediate(() => {
this.writeCache(filename);
});
});
}
const clearTemplateCache = () => {
for (const prop of Object.keys(pug.cache)) {
delete pug.cache[prop];
}
};