benjamn/reify

async module.import.

Closed this issue · 3 comments

The basic idea for async module.import is

Module.prototype.import = function (path) {
  return Promise.resolve().then(() => {
    const ns = Object.create(null);
    module.importSync(path, {
      "*": (value, name) => {
        ns[name] = value;
      }
    });
    return ns;
  });
};

Except that the file needs to retrievable from remote, so http and https, and that the promise won't resolve until all of the module's deps and deps of deps are loaded too. That means keeping queue of requests that need to complete.

Update:
Turns out remote module loading with http and https won't likely be supported by Node out of the box so our mockup is pretty close.

Update:
Ok, I got clarification, so we don't have to wait for deps of deps to be loaded either so the mockup is reeaaally close.

This is fixed now, right?

Yep! 🎉