eval-as-module
Advanced tools
Comparing version 0.1.0 to 0.1.1
10
index.js
var dirname = require('path').dirname | ||
var Module = require('module') | ||
var json = JSON.stringify | ||
@@ -14,6 +15,7 @@ /** | ||
function run(js, path) { | ||
var m = new Module(path, module); | ||
m.paths = Module._nodeModulePaths(dirname(path)); | ||
m.filename = path; | ||
m._compile(js, path); | ||
var m = new Module(path, module) | ||
m.paths = Module._nodeModulePaths(dirname(path)) | ||
m.filename = path | ||
js = 'module.return=eval(' + json(js) + ')' | ||
m._compile(js, path) | ||
return m | ||
@@ -20,0 +22,0 @@ } |
{ | ||
"name": "eval-as-module", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Eval a JS string as if it was a file being required", | ||
@@ -5,0 +5,0 @@ "keywords": ["eval","module"], |
@@ -26,3 +26,9 @@ | ||
```js | ||
run('module.exports = require("./")', __filename).exports // => run | ||
run('module.exports = require("eval-as-module")', __filename).exports // => run | ||
``` | ||
And like `eval` it also gives you access to the value of the last statement executed in the script. | ||
```js | ||
run('1;2;3').return // => 3 | ||
``` |
1582
19
34