-
-
Notifications
You must be signed in to change notification settings - Fork 75
fix: check require.cache to find preloaded modules #406
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
cd9a6c0
28dc49f
d5a6502
77a701d
cef560e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
// runtime cache | ||
const cache = {} | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this path join. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you do? |
||
|
||
/* c8 ignore start */ | ||
// nullish needed for non Node.js runtime | ||
// coverage - nullish needed for non Node.js runtime | ||
preloadModules ??= (process._preload_modules ?? []) | ||
jean-michelet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// coverage - TS specific | ||
return preloadModules.includes(moduleName) || | ||
Object.keys(require.cache).some(k => k.startsWith(modulePath) && preloadModules.push(modulePath)) | ||
jean-michelet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* c8 ignore stop */ | ||
return preloadModules.includes(moduleName) | ||
} | ||
|
||
let preloadModulesString | ||
|
Uh oh!
There was an error while loading. Please reload this page.