dop251 / goja_nodejs

Nodejs compatibility library for Goja
MIT License
329 stars 78 forks source link

Registry new option "WithHotReload" #28

Closed Simerax closed 2 years ago

Simerax commented 2 years ago

This new option causes require to always reload code from source. require.NewRegistry(require.WithHotReload())

I implemented this because we need this. It is fine if the project does not want this code then we just fork.

Performance for the regular registry stays the same (the only overhead are 2 if statements). When hot reload is enabled the performance obviously drops.

Hot reload can only be enabled per registry and not be disabled since we don't need this and it would just make the code more complex.

dop251 commented 2 years ago

I don't think this will work with circular dependencies.

Simerax commented 2 years ago

Yes you are right. I totally forgot that js allows this. You could probably fix it by creating a dependency graph and base your compilation on that but i think that would be overkill. If you don't have a simple solution in mind we can close this.

We will then probably just reinitialize the registry each time we run something