Enable external module imports in FunctionItem-Node

This commit is contained in:
Jan Oberhauser 2020-01-01 15:37:10 -06:00
parent 7b8f88f39e
commit 1846e4ab30

View file

@ -68,9 +68,8 @@ export class FunctionItem implements INodeType {
console: 'inherit',
sandbox,
require: {
external: false,
external: false as boolean | { modules: string[] },
builtin: [] as string[],
root: './',
}
};
@ -78,6 +77,10 @@ export class FunctionItem implements INodeType {
options.require.builtin = process.env.NODE_FUNCTION_ALLOW_BUILTIN.split(',');
}
if (process.env.NODE_FUNCTION_ALLOW_EXTERNAL) {
options.require.external = { modules: process.env.NODE_FUNCTION_ALLOW_EXTERNAL.split(',') };
}
const vm = new NodeVM(options);
// Get the code to execute
@ -87,7 +90,7 @@ export class FunctionItem implements INodeType {
let jsonData: IDataObject;
try {
// Execute the function code
jsonData = await vm.run(`module.exports = async function() {${functionCode}}()`);
jsonData = await vm.run(`module.exports = async function() {${functionCode}}()`, './');
} catch (e) {
return Promise.reject(e);
}