1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-04 09:00:05 +02:00
copilot/ui/docs/webpack/embed-markdown-loader/src/eval.js
Sérgio Ramos 557cd5a291 wip rm css
2016-12-12 10:28:47 +00:00

30 lines
620 B
JavaScript

const Module = require('module');
const vm = require('vm');
const path = require('path');
module.exports = ({
source,
entrypoint
}) => {
const script = vm.createScript(source, entrypoint);
const dirname = path.basename(entrypoint);
const rootName = path.join(dirname, '@root');
const _module = new Module(rootName);
_module.filename = rootName;
_module.paths = Module._nodeModulePaths(dirname);
script.runInNewContext({
nmodule: _module,
nrequire: _module.require,
__filename: entrypoint,
__dirname: dirname,
process,
console,
Buffer
});
return _module.exports;
};