Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions runtime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const path = require('path')

// runtime cache
const cache = {}

Expand All @@ -15,10 +17,23 @@ function checkProcessArgv (moduleName) {
let preloadModules
function checkPreloadModules (moduleName) {
/* c8 ignore start */
// nullish needed for non Node.js runtime
// coverage - nullish needed for non Node.js runtime
preloadModules ??= (process._preload_modules ?? [])

// coverage - TS specific
if (preloadModules.includes(moduleName)) {
return true
}

const modulePath = path.join(process.cwd(), 'node_modules', moduleName)
if (Object.keys(require.cache).some(k => k.startsWith(modulePath))) {
preloadModules.push(moduleName)
Copy link

@zetaraku zetaraku Aug 1, 2024

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


return true
}
/* c8 ignore stop */
return preloadModules.includes(moduleName)

return false
}

let preloadModulesString
Expand Down