-
Notifications
You must be signed in to change notification settings - Fork 122
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
support registering hook in worker threads #295
base: master
Are you sure you want to change the base?
Conversation
1d4ef3c
to
7335fed
Compare
Hi @bjornstar! Could this get a review please? |
I'd like to see a test so we can validate it's working. |
lib/wrap.js
Outdated
if (isMainThread) { | ||
// When using worker threads, each thread inherits execArgv and re-evaulates | ||
// --require scripts. Worker threads do not inherit argv, so we copy argv[1] | ||
// to the environment for those processes to use. | ||
process.env.NODE_DEV_SCRIPT = process.argv[1]; | ||
} | ||
|
||
const script = process.argv[1]; | ||
const script = process.env.NODE_DEV_SCRIPT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The standard use case does not involve an environment variable called NODE_DEV_SCRIPT
We should not be populating an environment variable on every run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you suggest we do this instead? worker threads do not inherit argv, and I think polluting the worker data sounds worse that adding an env variable. There is also already a precedent of setting NODE_DEV_PRELOAD
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just discovered and refactored this to use getEnvironmentData
/setEnvironmentData
which feels like it might be more in line with what you're looking for. I also have #284 which gets rid of the other existing env var as well!
7335fed
to
dfcf8e1
Compare
After adding a test case, I realized that it wasn't actually working as I expected - worker threads don't seem to inherit IPC handles, so I had to adapt the ipc.js helper to set up a new |
31a259a
to
d2b1d45
Compare
This provides a better implementation for #285 by setting and reading the main script from process.env. This allows modules
require
d from threads to trigger reloads.I considered some alternative solutions where we monkeypatch into the
Worker
constructor, but ultimately I think an env variable solves this well