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

@@ -59,14 +59,21 @@ export class Function implements INodeType {
// By default use data from first item
Object.assign(sandbox, sandbox.$item(0));
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', 0) as string;