Allow to use built-in modules in Function-Nodes if configured

This commit is contained in:
Jan Oberhauser
2019-12-13 11:23:30 -06:00
parent 8789e9be3c
commit 3da402a8d4
3 changed files with 36 additions and 4 deletions

View File

@@ -64,14 +64,21 @@ export class FunctionItem implements INodeType {
const dataProxy = this.getWorkflowDataProxy();
Object.assign(sandbox, dataProxy);
const vm = new NodeVM({
const options = {
console: 'inherit',
sandbox,
require: {
external: false,
builtin: [] as string[],
root: './',
}
});
};
if (process.env.NODE_FUNCTION_ALLOW_BUILTIN) {
options.require.builtin = process.env.NODE_FUNCTION_ALLOW_BUILTIN.split(',');
}
const vm = new NodeVM(options);
// Get the code to execute
const functionCode = this.getNodeParameter('functionCode') as string;