Skip to content
Open
Changes from all 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
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* global globalThis */

const path = require('path')
const Module = require('module')
Expand Down Expand Up @@ -122,6 +123,7 @@ function Hook (modules, options, onrequire) {

this._unhooked = false
this._origRequire = Module.prototype.require
this._sync = resolve.sync

const self = this
const patching = new Set()
Expand Down Expand Up @@ -233,7 +235,7 @@ function Hook (modules, options, onrequire) {
// figure out if this is the main module file, or a file inside the module
let res
try {
res = resolve.sync(moduleName, { basedir })
res = self._sync(moduleName, { basedir })
} catch (e) {
debug('could not resolve module: %s', moduleName)
self._cache.set(filename, exports, core)
Expand Down Expand Up @@ -265,6 +267,9 @@ function Hook (modules, options, onrequire) {
debug('returning module: %s', moduleName)
return patchedExports
}
if (globalThis) {
globalThis.__ritm_hooks__ = [...(globalThis.__ritm_hooks__ || []), this]
}
}

Hook.prototype.unhook = function () {
Expand Down