3 var Module = require('module');
4 var path = require('path');
6 module.exports = function requireFromString(code, filename, opts) {
7 if (typeof filename === 'object') {
13 filename = filename || '';
15 opts.appendPaths = opts.appendPaths || [];
16 opts.prependPaths = opts.prependPaths || [];
18 if (typeof code !== 'string') {
19 throw new Error('code must be a string, not ' + typeof code);
22 var paths = Module._nodeModulePaths(path.dirname(filename));
24 var m = new Module(filename, module.parent);
25 m.filename = filename;
26 m.paths = [].concat(opts.prependPaths).concat(paths).concat(opts.appendPaths);
27 m._compile(code, filename);