mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -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',
|
console: 'inherit',
|
||||||
sandbox,
|
sandbox,
|
||||||
require: {
|
require: {
|
||||||
external: false,
|
external: false as boolean | { modules: string[] },
|
||||||
builtin: [] as string[],
|
builtin: [] as string[],
|
||||||
root: './',
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,6 +77,10 @@ export class FunctionItem implements INodeType {
|
||||||
options.require.builtin = process.env.NODE_FUNCTION_ALLOW_BUILTIN.split(',');
|
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);
|
const vm = new NodeVM(options);
|
||||||
|
|
||||||
// Get the code to execute
|
// Get the code to execute
|
||||||
|
@ -87,7 +90,7 @@ export class FunctionItem implements INodeType {
|
||||||
let jsonData: IDataObject;
|
let jsonData: IDataObject;
|
||||||
try {
|
try {
|
||||||
// Execute the function code
|
// Execute the function code
|
||||||
jsonData = await vm.run(`module.exports = async function() {${functionCode}}()`);
|
jsonData = await vm.run(`module.exports = async function() {${functionCode}}()`, './');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.reject(e);
|
return Promise.reject(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue