Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
watchItem.watcher = fs.watch(fName, async (eventType) => {
const relPath = path.relative(process.cwd(), fName);
broker.logger.info(chalk.magenta.bold(`The '${relPath}' file is changed. (Event: ${eventType})`));
// Clear from require cache
clearRequireCache(fName);
if (watchItem.others.length > 0) {
watchItem.others.forEach(f => clearRequireCache(f));
}
if (watchItem.brokerRestart) {
// TODO: it is not working properly. The ServiceBroker doesn't reload the config from the moleculer.config.js
// file because it is loaded by Moleculer Runner (with merged environment files)
broker.logger.info(chalk.bgMagenta.white.bold("Action: Stop all file watcher & restart broker..."));
stopAllFileWatcher(projectFiles);
// Clear the whole require cache
require.cache.length = 0;
broker.restart();
} else if (watchItem.allServices) {
// Reload all services
broker.services.forEach(svc => {
watchItem.others.forEach(f => clearRequireCache(f));
}