Change node port proxy by overriding require directly in Module.
@@ -43,19 +43,16 @@ const addon = (() => {
return addon;
})();
-/* Monkey patch require for simplifying load */
-Module.prototype.require = new Proxy(Module.prototype.require, {
- apply(target, module, args) {
-
- const node_require = () => {
- return Reflect.apply(target, module, args);
- };
+const node_require = Module.require;
const metacall_require = (tag, name) => {
// TODO: Inspect the current handle and append it to an object mocking the function calls with metacall
return addon.metacall_load_from_file(tag, [ name ]);
};
+/* Monkey patch require for simplifying load */
+Module.prototype.require = (id) => {
+
const tags = {
mock: 'mock',
py: 'py',
@@ -64,24 +61,22 @@ Module.prototype.require = new Proxy(Module.prototype.require, {
/*dll: 'cs',*/
};
- const name = args[0];
- const index = name.lastIndexOf('.');
+ const index = id.lastIndexOf('.');
if (index === -1) {
- return node_require();
+ return node_require(id);
} else {
// Load the module
- const ext = name.substr(index + 1);
- const tag = tags[ext];
+ const extension = id.substr(index + 1);
+ const tag = tags[extension];
if (tag) {
- return metacall_require(tag, name);
+ return metacall_require(tag, id);
} else {
- return node_require();
- }
+ return node_require(id);
}
}
-});
+};
/* Export the API */
module.exports = {
