Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@trivektor
Created September 9, 2017 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trivektor/2aec44e2c44c5f3f7ffe928c5eacb0dc to your computer and use it in GitHub Desktop.
Save trivektor/2aec44e2c44c5f3f7ffe928c5eacb0dc to your computer and use it in GitHub Desktop.
if (!_isEmpty(executedCode)) {
// https://nodejs.org/api/vm.html
const vm = require('vm');
const babel = require('babel-standalone');
const sandbox = {
project,
projectId,
require: require,
};
const generatedCode = babel.transform(
executedCode, {
ast: false,
presets: ['es2015'],
plugins: [
['module-alias', [
{ src: 'crete' }
]]
]
}
).code;
const script = new vm.Script(generatedCode);
const context = new vm.createContext(sandbox);
script.runInContext(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment