Add functionality to send console.log messages to editor-UI (#1816)

*  Send console.log messages to editor-UI

*  Send message only to session which started workflow

*  Made it also work in own process

*  Add support for console.log UI forward also to FunctionItem Node

* 👕 Fix lint issue

* 👕 Fix linting issue

*  Improve code

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Jan
2021-05-29 13:41:25 -05:00
committed by GitHub
parent 8e793e27b3
commit 4946bfcd3e
11 changed files with 84 additions and 11 deletions

View File

@@ -60,8 +60,10 @@ export class Function implements INodeType {
// By default use data from first item
Object.assign(sandbox, sandbox.$item(0));
const mode = this.getMode();
const options = {
console: 'inherit',
console: (mode === 'manual') ? 'redirect' : 'inherit',
sandbox,
require: {
external: false as boolean | { modules: string[] },
@@ -77,9 +79,12 @@ export class Function implements INodeType {
options.require.external = { modules: process.env.NODE_FUNCTION_ALLOW_EXTERNAL.split(',') };
}
const vm = new NodeVM(options);
if (mode === 'manual') {
vm.on('console.log', this.sendMessageToUI);
}
// Get the code to execute
const functionCode = this.getNodeParameter('functionCode', 0) as string;