mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
⚡ Enable external module imports in FunctionItem-Node
This commit is contained in:
parent
7b8f88f39e
commit
1846e4ab30
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue