felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

Added the cache option #62

Closed kzar closed 7 years ago

kzar commented 7 years ago

Hi,

Thanks for creating this library, very useful. Anyway I'm porting some unit tests to use it and found that I needed to make this small change. I needed to be able to share the module cache between SandBoxedModule instances. Any chance you could merge?

Thanks, Dave.

(CC @palant)

kzar commented 7 years ago

We no longer need this feature since @palant realised there's an easier way to achieve the same thing. If you create a sandbox for a module which exports its require function you can then use that to require any other modules you need inside the sandbox. For example:

example.js

exports.require = require;

A different file

let SandboxedModule = require("sandboxed-module");
let requireInSandbox = SandboxedModule.require("example").require;
requireInSandbox("foo");