Last active
August 13, 2020 08:15
-
-
Save samolabams/eddc68648f1e96f47db7f28e523eeba2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadModule(filename, module, require) { | |
const wrappedSrc = ` | |
function(module, exports, require) { | |
${fs.readFileSync(filename, 'utf8')} | |
}(module, module.exports, require) | |
`; | |
eval(wrappedSrc); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function require(moduleName) { | |
const id = require.resolve(moduleName); | |
if (require.cache[id]) { | |
return require.cache[id].exports; | |
} | |
const module = { | |
exports: {}, | |
id | |
} | |
} | |
require.cache = {}; | |
require.resolve = (moduleName) => { | |
// resolve module based on name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment