1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3065 from node-red/funcExtMod-default

Enable functionExternalModules by default
This commit is contained in:
Nick O'Leary 2021-07-15 10:14:28 +01:00 committed by GitHub
commit 88ad2f4c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 8 deletions

View File

@ -329,7 +329,7 @@
function getLibsList() { function getLibsList() {
var _libs = []; var _libs = [];
if (RED.settings.functionExternalModules === true) { if (RED.settings.functionExternalModules !== false) {
var libs = $("#node-input-libs-container").editableList("items"); var libs = $("#node-input-libs-container").editableList("items");
libs.each(function(i) { libs.each(function(i) {
var item = $(this); var item = $(this);

View File

@ -100,7 +100,7 @@ module.exports = function(RED) {
node.fin = n.finalize ? n.finalize.trim() : ""; node.fin = n.finalize ? n.finalize.trim() : "";
node.libs = n.libs || []; 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")); throw new Error(RED._("function.error.externalModuleNotAllowed"));
} }
@ -500,7 +500,7 @@ module.exports = function(RED) {
RED.nodes.registerType("function",FunctionNode, { RED.nodes.registerType("function",FunctionNode, {
dynamicModuleList: "libs", dynamicModuleList: "libs",
settings: { settings: {
functionExternalModules: { value: false, exportable: true } functionExternalModules: { value: true, exportable: true }
} }
}); });
RED.library.register("functions"); RED.library.register("functions");

View File

@ -396,7 +396,7 @@ module.exports = {
//fileWorkingDirectory: "", //fileWorkingDirectory: "",
/** Allow the Function node to load additional npm modules directly */ /** 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. /** 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. * This allows extra node modules to be made available with in Function node.

View File

@ -1461,11 +1461,12 @@ describe('function node', function() {
afterEach(function() { afterEach(function() {
delete RED.settings.functionExternalModules; 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 = [ var flow = [
{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]}, {id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]},
{id:"n2", type:"helper"} {id:"n2", type:"helper"}
]; ];
RED.settings.functionExternalModules = false;
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
should.not.exist(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:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;"},
{id:"n2", type:"helper"} {id:"n2", type:"helper"}
]; ];
RED.settings.functionExternalModules = true;
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2"); 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:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"os", module:"os"}]},
{id:"n2", type:"helper"} {id:"n2", type:"helper"}
]; ];
RED.settings.functionExternalModules = true;
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2"); 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:"n1",type:"function",wires:[["n2"]],func:"msg.payload = os.type(); return msg;", "libs": [{var:"flow", module:"os"}]},
{id:"n2", type:"helper"} {id:"n2", type:"helper"}
]; ];
RED.settings.functionExternalModules = true;
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
should.not.exist(n1); should.not.exist(n1);