fix(Code Node): Consistent redirection of stdout for JS and Python sandboxes (#6818)

Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-08-01 17:47:43 +02:00
committed by GitHub
parent 34df8b6238
commit f718c2291f
5 changed files with 28 additions and 31 deletions

View File

@@ -92,8 +92,9 @@ export class Code implements INodeType {
const nodeMode = this.getNodeParameter('mode', 0) as CodeExecutionMode;
const workflowMode = this.getMode();
const node = this.getNode();
const language: CodeNodeEditorLanguage =
this.getNode()?.typeVersion === 2
node.typeVersion === 2
? (this.getNodeParameter('language', 0) as CodeNodeEditorLanguage)
: 'javaScript';
const codeParameterName = language === 'python' ? 'pythonCode' : 'jsCode';
@@ -107,16 +108,16 @@ export class Code implements INodeType {
context.item = context.$input.item;
}
if (language === 'python') {
context.printOverwrite = workflowMode === 'manual' ? this.sendMessageToUI : null;
return new PythonSandbox(context, code, index, this.helpers);
} else {
const sandbox = new JavaScriptSandbox(context, code, index, workflowMode, this.helpers);
if (workflowMode === 'manual') {
sandbox.vm.on('console.log', this.sendMessageToUI);
}
return sandbox;
}
const Sandbox = language === 'python' ? PythonSandbox : JavaScriptSandbox;
const sandbox = new Sandbox(context, code, index, this.helpers);
sandbox.on(
'output',
workflowMode === 'manual'
? this.sendMessageToUI
: (...args) =>
console.log(`[Workflow "${this.getWorkflow().id}"][Node "${node.name}"]`, ...args),
);
return sandbox;
};
// ----------------------------------