moleculerjs / moleculer

:rocket: Progressive microservices framework for Node.js
https://moleculer.services/
MIT License
6.07k stars 575 forks source link

Hot reload circular dependency in monorepos #1220

Open ishfx opened 1 year ago

ishfx commented 1 year ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Current Behavior

In a monorepo, with 2 projects: a moleculer project and a helper project. The moleculer project imports the helper project. When the hot reload middleware is enabled, any file changes in the moleculer project causes high cpu usage because the hot relaod is stuck in circular dependency.

Expected Behavior

No circular dependency and normal hot reload.

Failure Information

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Create monorepo
  2. Create project B
  3. Create project A that imports moleculer and project B
  4. Launch project A with hot reload
  5. Change a file in project A and save.

Reproduce code snippet

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Solution

Add option to hot reload middleware to ignore build directory of other monorepo projects (dist, build, out, etc)

Here is the line : https://github.com/moleculerjs/moleculer/blob/v0.14.29/src/middlewares/hot-reload.js#L241

Example with hardcoded value :

if (fName.indexOf("node_modules") !== -1 || fName.indexOf("dist") !== -1) {
  if (cache.get(fName)) return;
  cache.set(fName, mod);
}
icebob commented 1 year ago

Please create a repro repo.

grinat commented 10 months ago

I have similar problem.

Time if ignore /dist disabled: ✔ ServiceBroker with 43 service(s) started successfully in 6s Time if ignore /dist enabled: ✔ ServiceBroker with 43 service(s) started successfully in 3s

We need option like that: https://webpack.js.org/configuration/watch/#watchoptionsignored