|
22 | 22 |
|
23 | 23 | const mod = require('module'); |
24 | 24 | const path = require('path'); |
| 25 | +const { URL } = require('url'); |
25 | 26 |
|
26 | 27 | const addon = (() => { |
27 | 28 | try { |
@@ -103,6 +104,8 @@ const metacall_load_from_memory = (tag, code) => { |
103 | 104 | } |
104 | 105 |
|
105 | 106 | return addon.metacall_load_from_memory(tag, code); |
| 107 | + |
| 108 | + // TODO: Implement here the inspect of the memory module by handle |
106 | 109 | }; |
107 | 110 |
|
108 | 111 | const metacall_inspect = () => { |
@@ -140,11 +143,13 @@ const metacall_require = (tag, name) => { |
140 | 143 | // TODO: Inspect only the handle instead of the whole metacall namespace |
141 | 144 | /* return */ addon.metacall_load_from_file(tag, [ name ]); |
142 | 145 |
|
| 146 | + /* TODO: Replace metacall_inspect by retrieving the handle and metacall_export */ |
143 | 147 | const inspect = metacall_inspect(); |
144 | 148 | const script = inspect[tag].find(s => s.name === path.basename(name)); |
145 | 149 |
|
146 | 150 | const obj = {}; |
147 | 151 |
|
| 152 | + /* TODO: Support async functions */ |
148 | 153 | for (const func of script.scope.funcs) { |
149 | 154 | obj[func.name] = (...args) => addon.metacall(func.name, ...args); |
150 | 155 | } |
@@ -199,6 +204,16 @@ mod.prototype.require = function (name) { |
199 | 204 | /* Probably in the future we can differenciate between them, but it is not trivial */ |
200 | 205 | }; |
201 | 206 |
|
| 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 | + |
202 | 217 | /* Try to load it with NodeJS first */ |
203 | 218 | try { |
204 | 219 | return node_require.apply(this, [ name ]); |
|
0 commit comments