Uncached modules

Isiah Meadows isiahmeadows at gmail.com
Thu Sep 6 00:08:14 UTC 2018

I'd like to have the ability to define a module that is cached
per-module rather than globally on import. Maybe something like this,
defined only for modules:

// Creates a new constant read-only proxy to parent `import.meta`,
// limits caching to just this one parent module.
import from parent;

As for use cases, here's a few:

- proxyquire, which currently does an uncached `require` in CommonJS
to gain reliable access to the parent module. If top-level await is
added, they could instead do a single default export returning the
namespace for the method.
- My invoke-parallel does similar, to allow for implicit parallelism
of exported methods, and I currently can't support ESM without a
similar facility.

This proposal is about as simple as I can think of while still
providing the minimum required functionality.


Isiah Meadows
contact at isiahmeadows.com

More information about the es-discuss mailing list