Move wrapRequire to its own module

This commit is contained in:
Jonathan Clem
2021-04-21 16:37:24 -04:00
parent e853490b13
commit 75e3a5b35d
3 changed files with 116 additions and 112 deletions

16
src/wrap-require.ts Normal file
View File

@@ -0,0 +1,16 @@
import * as path from 'path'
declare const __non_webpack_require__: NodeRequire
export const wrapRequire = new Proxy(__non_webpack_require__, {
apply: (target, thisArg, [moduleID]) => {
if (moduleID.startsWith('.')) {
moduleID = path.join(process.cwd(), moduleID)
}
return target.apply(thisArg, [moduleID])
},
get: (target, prop, receiver) => {
Reflect.get(target, prop, receiver)
}
})