From 2cc1973f625033d3f788988b01f3d2c342ff6d5b Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 15 Jul 2021 10:07:52 +0100 Subject: [PATCH 1/2] Enable functionExternalModules by default --- .../@node-red/nodes/core/function/10-function.html | 2 +- .../node_modules/@node-red/nodes/core/function/10-function.js | 4 ++-- packages/node_modules/node-red/settings.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.html b/packages/node_modules/@node-red/nodes/core/function/10-function.html index 4305f055b..ff343a0bd 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.html +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.html @@ -329,7 +329,7 @@ function getLibsList() { var _libs = []; - if (RED.settings.functionExternalModules === true) { + if (RED.settings.functionExternalModules !== false) { var libs = $("#node-input-libs-container").editableList("items"); libs.each(function(i) { var item = $(this); diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js index d58b057c7..b229c0767 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js @@ -100,7 +100,7 @@ module.exports = function(RED) { node.fin = n.finalize ? n.finalize.trim() : ""; node.libs = n.libs || []; - if (RED.settings.functionExternalModules !== true && node.libs.length > 0) { + if (RED.settings.functionExternalModules === false && node.libs.length > 0) { throw new Error(RED._("function.error.externalModuleNotAllowed")); } @@ -500,7 +500,7 @@ module.exports = function(RED) { RED.nodes.registerType("function",FunctionNode, { dynamicModuleList: "libs", settings: { - functionExternalModules: { value: false, exportable: true } + functionExternalModules: { value: true, exportable: true } } }); RED.library.register("functions"); diff --git a/packages/node_modules/node-red/settings.js b/packages/node_modules/node-red/settings.js index b5c19e8fb..b8fd4c31d 100644 --- a/packages/node_modules/node-red/settings.js +++ b/packages/node_modules/node-red/settings.js @@ -396,7 +396,7 @@ module.exports = { //fileWorkingDirectory: "", /** Allow the Function node to load additional npm modules directly */ - functionExternalModules: false, + functionExternalModules: true, /** The following property can be used to set predefined values in Global Context. * This allows extra node modules to be made available with in Function node. From be9f9e7b0ccd65ffa9fed393979b6ccfad52f760 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 15 Jul 2021 10:13:21 +0100 Subject: [PATCH 2/2] Change default functionExternalModules test --- test/nodes/core/function/10-function_spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/nodes/core/function/10-function_spec.js b/test/nodes/core/function/10-function_spec.js index 4c6f3bab2..4f7f0b806 100644 --- a/test/nodes/core/function/10-function_spec.js +++ b/test/nodes/core/function/10-function_spec.js @@ -1461,11 +1461,12 @@ describe('function node', function() { afterEach(function() { delete RED.settings.functionExternalModules; }) - it('should fail if using OS module without functionExternalModules set to true', function(done) { + it('should fail if using OS module with functionExternalModules set to false', function(done) { var flow = [ {id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]}, {id:"n2", type:"helper"} ]; + RED.settings.functionExternalModules = false; helper.load(functionNode, flow, function() { var n1 = helper.getNode("n1"); should.not.exist(n1); @@ -1478,7 +1479,6 @@ describe('function node', function() { {id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;"}, {id:"n2", type:"helper"} ]; - RED.settings.functionExternalModules = true; helper.load(functionNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -1502,7 +1502,6 @@ describe('function node', function() { {id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]}, {id:"n2", type:"helper"} ]; - RED.settings.functionExternalModules = true; helper.load(functionNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -1523,7 +1522,6 @@ describe('function node', function() { {id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"flow", module:"os"}]}, {id:"n2", type:"helper"} ]; - RED.settings.functionExternalModules = true; helper.load(functionNode, flow, function() { var n1 = helper.getNode("n1"); should.not.exist(n1);