-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
fix: check require.cache to find preloaded modules #406
base: master
Are you sure you want to change the base?
fix: check require.cache to find preloaded modules #406
Conversation
runtime.js
Outdated
@@ -14,11 +16,16 @@ function checkProcessArgv (moduleName) { | |||
|
|||
let preloadModules | |||
function checkPreloadModules (moduleName) { | |||
const modulePath = path.join(process.cwd(), 'node_modules/', moduleName) |
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.
Not sure about this path join.
I just want to do a startsWith
instead of includes
.
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.
Can process.cwd()
guarantee to be the project root if the program is executed from other path?
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.
What would you do?
|
||
const modulePath = path.join(process.cwd(), 'node_modules', moduleName) | ||
if (Object.keys(require.cache).some(k => k.startsWith(modulePath))) { | ||
preloadModules.push(moduleName) |
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 still discourage mutating preloadModules
, as you may mutate the process._preload_modules
that may be used by others.
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.
Nevermind, double checked it is not affected.
Thanks for opening a PR! Can you please add a unit test? |
Will try to make one later. |
Fixes #404
I tested on the reproduction repo and it does work well: https://github.com/zetaraku/fastify-app