diff --git a/Readme.md b/Readme.md index f1e88cc..888f941 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,8 @@ # 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. @@ -8,7 +10,7 @@ modules. ## Installation ``` bash -npm install sandboxed-module +npm install @log4js-node/sandboxed-module ``` ## Usage @@ -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]) diff --git a/lib/builtin_modules.json b/lib/builtin_modules.json index ed048ba..ed1a44a 100644 --- a/lib/builtin_modules.json +++ b/lib/builtin_modules.json @@ -1,5 +1,4 @@ [ - "_debug_agent", "_debugger", "_linklist", "assert", @@ -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", @@ -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" ] \ No newline at end of file diff --git a/lib/sandboxed_module.js b/lib/sandboxed_module.js index 6bf483c..7a7095e 100644 --- a/lib/sandboxed_module.js +++ b/lib/sandboxed_module.js @@ -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; diff --git a/package.json b/package.json index 767cf90..055cb74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "author": "Felix Geisendörfer (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", @@ -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/" diff --git a/test/integration/test-inject-missing.js b/test/integration/test-inject-missing.js new file mode 100644 index 0000000..357d174 --- /dev/null +++ b/test/integration/test-inject-missing.js @@ -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');