sandboxed-module-loader

1.0.6 • Public • Published

sandboxed-module-loader

Sandbox loading of modules. Useful in unit testing to give each test an unique copy of each dependency.

Install

$ npm install sandboxed-module-loader

Usage

const loader = require('sandboxed-module-loader');
 
loader(/\/main-file.js$/, {
  verbose: 1,
  sandboxExternal: false
});

API

The sandboxed-module-loader is initialized with a main file. All dependencies of this file will be sandboxed. This means that they will not share any modules. If the same module is required, each sandbox will have a separate instance of the module.

loader(path, options)

path

Regex specifying a main file. All dependencies of this file will be sandboxed.

options.verbose

Number specifying verbosity level. Used for debugging.

  • 0: Silent
  • 1: Info
  • 2: Verbose

options.sandboxExternal

Boolean, specifying if only local files should be sandboxed. If set to false, external modules are shared between sandboxes.

loader.reset()

Reset the module loader to the original.

License

MIT © Johan Blumenberg

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.61latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.61
1.0.51
1.0.41
1.0.11
1.0.01

Package Sidebar

Install

npm i sandboxed-module-loader

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

18.3 kB

Total Files

16

Last publish

Collaborators

  • johanblumenberg