Skip to content

Commit 67d5e45

Browse files
committed
Add base to support URLs in Node Port.
1 parent b91973c commit 67d5e45

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

source/ports/node_port/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
const mod = require('module');
2424
const path = require('path');
25+
const { URL } = require('url');
2526

2627
const addon = (() => {
2728
try {
@@ -103,6 +104,8 @@ const metacall_load_from_memory = (tag, code) => {
103104
}
104105

105106
return addon.metacall_load_from_memory(tag, code);
107+
108+
// TODO: Implement here the inspect of the memory module by handle
106109
};
107110

108111
const metacall_inspect = () => {
@@ -140,11 +143,13 @@ const metacall_require = (tag, name) => {
140143
// TODO: Inspect only the handle instead of the whole metacall namespace
141144
/* return */ addon.metacall_load_from_file(tag, [ name ]);
142145

146+
/* TODO: Replace metacall_inspect by retrieving the handle and metacall_export */
143147
const inspect = metacall_inspect();
144148
const script = inspect[tag].find(s => s.name === path.basename(name));
145149

146150
const obj = {};
147151

152+
/* TODO: Support async functions */
148153
for (const func of script.scope.funcs) {
149154
obj[func.name] = (...args) => addon.metacall(func.name, ...args);
150155
}
@@ -199,6 +204,16 @@ mod.prototype.require = function (name) {
199204
/* Probably in the future we can differenciate between them, but it is not trivial */
200205
};
201206

207+
// TODO:
208+
// /* Check if the module is an URL */
209+
// try {
210+
// const { origin, pathname } = new URL(name);
211+
212+
// return metacall_load_from_memory('rpc', origin + pathname); // TODO: Load from memory with RPC loader and get the exports from the handle
213+
// } catch (e) {
214+
// /* Continue loading */
215+
// }
216+
202217
/* Try to load it with NodeJS first */
203218
try {
204219
return node_require.apply(this, [ name ]);

0 commit comments

Comments
 (0)