Last active
September 13, 2025 01:50
-
-
Save forivall/021f5642a370af4ce30364b7bd6419fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// manually loading a module with only public apis | |
type ModuleBody = ( | |
exports: object, | |
require: NodeRequire, | |
module: Module, | |
filename: string, | |
dirname: string, | |
) => void; | |
const moduleSource = wrap(fs.readFileSync(filename, 'utf8')); | |
const moduleBody: ModuleBody = runInThisContext(moduleSource, { filename }); | |
const require = createRequire(filename); | |
moduleBody.call( | |
m.exports, | |
m.exports, | |
require, | |
m, | |
filename, | |
path.dirname(filename), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment