Created
September 9, 2017 21:04
-
-
Save trivektor/2aec44e2c44c5f3f7ffe928c5eacb0dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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