Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# sandboxed-module

[![Build Status](https://secure.travis-ci.org/felixge/node-sandboxed-module.png)](http://travis-ci.org/felixge/node-sandboxed-module)
[![Build Status](https://secure.travis-ci.org/log4js-node/node-sandboxed-module.png)](http://travis-ci.org/log4js-node/node-sandboxed-module)

NOTE: this is a fork of [felixge's original](https://github.com/felixge/node-sandboxed-module), that doesn't seem to be maintained at the moment. If felixge's starts to be maintained again, this module will be deprecated.

A sandboxed node.js module loader that lets you inject dependencies into your
modules.

## Installation

``` bash
npm install sandboxed-module
npm install @log4js-node/sandboxed-module
```

## Usage
Expand Down Expand Up @@ -52,6 +54,8 @@ using the same options that were used for the original sandboxed module.
* `sourceTransformersSingleOnly:` If false, the source transformers will not be run against
modules required by the sandboxed module. By default it will take the same value as
`singleOnly`.
* `ignoreMissing:` If true, injected modules will not be required to have a corresponding file
on the file system. By default this is false.

### SandboxedModule.require(moduleId, [options])

Expand Down
13 changes: 0 additions & 13 deletions lib/builtin_modules.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[
"_debug_agent",
"_debugger",
"_linklist",
"assert",
Expand All @@ -16,18 +15,11 @@
"freelist",
"fs",
"http",
"_http_agent",
"_http_client",
"_http_common",
"_http_incoming",
"_http_outgoing",
"_http_server",
"https",
"module",
"net",
"os",
"path",
"process",
"punycode",
"querystring",
"readline",
Expand All @@ -38,18 +30,13 @@
"_stream_duplex",
"_stream_transform",
"_stream_passthrough",
"_stream_wrap",
"string_decoder",
"sys",
"timers",
"tls",
"_tls_common",
"_tls_legacy",
"_tls_wrap",
"tty",
"url",
"util",
"v8",
"vm",
"zlib"
]
8 changes: 7 additions & 1 deletion lib/sandboxed_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ SandboxedModule.prototype._createRecursiveRequireProxy = function() {
var cache = Object.create(null);
var required = this._getRequires();
for (var key in required) {
var injectedFilename = requireLike(this.filename).resolve(key);
var injectedFilename;
try {
injectedFilename = requireLike(this.filename).resolve(key);
} catch(missing) {
if(!this._options.ignoreMissing) {throw missing;}
injectedFilename = key;
}
cache[injectedFilename] = required[key];
}
cache[this.filename] = this.exports;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
"name": "sandboxed-module",
"name": "@log4js-node/sandboxed-module",
"description": "A sandboxed Node.js module loader that lets you inject dependencies into your modules.",
"keywords": [
"require",
Expand All @@ -11,8 +11,8 @@
"testing"
],
"license": "MIT",
"version": "2.0.3",
"repository": "felixge/node-sandboxed-module",
"version": "2.1.0",
"repository": "log4js-node/node-sandboxed-module",
"main": "./lib/sandboxed_module",
"files": [
"lib/"
Expand Down
9 changes: 9 additions & 0 deletions test/integration/test-inject-missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var assert = require('assert');
var SandboxedModule = require('../..');

var foo = SandboxedModule.require('../fixture/foo', {
"requires": {"doesNotExist": {}},
"ignoreMissing": true
});
assert.strictEqual(foo.foo, 'foo');
assert.strictEqual(foo.bar, 'bar');