From d6bb3a558f6da935e05488cb1708562b0b242ebb Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Sat, 3 Sep 2022 21:23:38 +0100 Subject: [PATCH 01/35] fix loading node package in nodesDir on linux fixes #3861 --- .../@node-red/registry/lib/loader.js | 39 ++++++++++--------- .../@node-red/registry/lib/localfilesystem.js | 10 +++++ .../@node-red/registry/lib/registry.js | 11 +++++- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/packages/node_modules/@node-red/registry/lib/loader.js b/packages/node_modules/@node-red/registry/lib/loader.js index 61f28ab86..3f0487750 100644 --- a/packages/node_modules/@node-red/registry/lib/loader.js +++ b/packages/node_modules/@node-red/registry/lib/loader.js @@ -43,37 +43,40 @@ function load(disableNodePathScan) { return loadModuleFiles(modules); } +function splitPath(p) { + return path.posix.normalize((p || '').replace(/\\/g, path.sep)).split(path.sep) +} function loadModuleTypeFiles(module, type) { const things = module[type]; - var first = true; - var promises = []; - for (var thingName in things) { + let first = true; + const promises = []; + for (let thingName in things) { /* istanbul ignore else */ if (things.hasOwnProperty(thingName)) { if (module.name != "node-red" && first) { // Check the module directory exists first = false; - var fn = things[thingName].file; - var parts = fn.split("/"); - var i = parts.length-1; - for (;i>=0;i--) { - if (parts[i] == "node_modules") { - break; - } + let moduleFn = module.path + const fn = things[thingName].file + const parts = splitPath(fn) + const nmi = parts.indexOf('node_modules') + if(nmi > -1) { + moduleFn = parts.slice(0,nmi+2).join(path.sep); + } + if (!moduleFn) { + // shortcut - skip calling statSync on empty string + break; // Module not found, don't attempt to load its nodes } - var moduleFn = parts.slice(0,i+2).join("/"); - try { - var stat = fs.statSync(moduleFn); + const stat = fs.statSync(moduleFn); } catch(err) { - // Module not found, don't attempt to load its nodes - break; + break; // Module not found, don't attempt to load its nodes } } try { - var promise; + let promise; if (type === "nodes") { promise = loadNodeConfig(things[thingName]); } else if (type === "plugins") { @@ -82,8 +85,7 @@ function loadModuleTypeFiles(module, type) { promises.push( promise.then( (function() { - var m = module.name; - var n = thingName; + const n = thingName; return function(nodeSet) { things[n] = nodeSet; return nodeSet; @@ -93,7 +95,6 @@ function loadModuleTypeFiles(module, type) { ); } catch(err) { console.log(err) - // } } } diff --git a/packages/node_modules/@node-red/registry/lib/localfilesystem.js b/packages/node_modules/@node-red/registry/lib/localfilesystem.js index da4006ecc..edb805572 100644 --- a/packages/node_modules/@node-red/registry/lib/localfilesystem.js +++ b/packages/node_modules/@node-red/registry/lib/localfilesystem.js @@ -156,6 +156,16 @@ function scanDirForNodesModules(dir,moduleName,package) { } } } + + // if we have found a package.json, this IS a node_module, lets see if it is a node-red node + if (!isNodeRedModule && files.indexOf('package.json') > -1) { + package = getPackageDetails(dir) // get package details + if(package && package.isNodeRedModule) { + isNodeRedModule = true + files = ['package.json'] // shortcut the file scan + } + } + for (let i=0;i Date: Sat, 3 Sep 2022 21:37:27 +0100 Subject: [PATCH 02/35] add test for specific arrangement of node package --- .../registry/lib/localfilesystem_spec.js | 21 ++++++++++++++- .../@lower-case2/lower-case2/lower-case.html | 26 +++++++++++++++++++ .../@lower-case2/lower-case2/lower-case.js | 11 ++++++++ .../nodesDir2/@lower-case2/package.json | 9 +++++++ .../lower-case/lower-case/lower-case.html | 26 +++++++++++++++++++ .../lower-case/lower-case/lower-case.js | 11 ++++++++ .../nodesDir2/lower-case/package.json | 9 +++++++ 7 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.html create mode 100644 test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.js create mode 100644 test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/package.json create mode 100644 test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.html create mode 100644 test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.js create mode 100644 test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/package.json diff --git a/test/unit/@node-red/registry/lib/localfilesystem_spec.js b/test/unit/@node-red/registry/lib/localfilesystem_spec.js index 3b1bb63f3..3ce74c158 100644 --- a/test/unit/@node-red/registry/lib/localfilesystem_spec.js +++ b/test/unit/@node-red/registry/lib/localfilesystem_spec.js @@ -329,17 +329,36 @@ describe("red/nodes/registry/localfilesystem",function() { localfilesystem.init({nodesDir:[nodesDir2]}); const nodeModule = localfilesystem.getModuleFiles(); const loaded = Object.keys(nodeModule) - loaded.should.have.a.property("length", 3) loaded.indexOf('@test/testnode').should.greaterThan(-1, "Should load @test/testnode") + loaded.indexOf('lower-case').should.greaterThan(-1, "Should load lower-case") + loaded.indexOf('@lowercase/lower-case2').should.greaterThan(-1, "Should load @lowercase/lower-case2") loaded.indexOf('testnode2').should.greaterThan(-1, "Should load testnode2") loaded.indexOf('test-theme2').should.greaterThan(-1, "Should load test-theme2") + loaded.should.have.a.property("length", 5) + // scoped module with nodes in same dir as package.json nodeModule['@test/testnode'].should.have.a.property('name','@test/testnode'); nodeModule['@test/testnode'].should.have.a.property('version','1.0.0'); nodeModule['@test/testnode'].should.have.a.property('nodes'); nodeModule['@test/testnode'].should.have.a.property('path'); nodeModule['@test/testnode'].should.have.a.property('user', false); + // node-red module with nodes in sub dir + nodeModule['@lowercase/lower-case2'].should.have.a.property('name','@lowercase/lower-case2'); + nodeModule['@lowercase/lower-case2'].should.have.a.property('version','2.0.0'); + nodeModule['@lowercase/lower-case2'].should.have.a.property('nodes'); + nodeModule['@lowercase/lower-case2'].nodes.should.have.a.property('lower-case'); + nodeModule['@lowercase/lower-case2'].should.have.a.property('path'); + nodeModule['@lowercase/lower-case2'].should.have.a.property('user', false); + + // scoped module with nodes in sub dir + nodeModule['lower-case'].should.have.a.property('name', 'lower-case'); + nodeModule['lower-case'].should.have.a.property('version','1.0.0'); + nodeModule['lower-case'].should.have.a.property('nodes'); + nodeModule['lower-case'].nodes.should.have.a.property('lower-case'); + nodeModule['lower-case'].should.have.a.property('path'); + nodeModule['lower-case'].should.have.a.property('user', false); + nodeModule['testnode2'].should.have.a.property('name','testnode2'); nodeModule['testnode2'].should.have.a.property('version','1.0.0'); nodeModule['testnode2'].should.have.a.property('nodes'); diff --git a/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.html b/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.html new file mode 100644 index 000000000..617f48491 --- /dev/null +++ b/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.html @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.js b/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.js new file mode 100644 index 000000000..73579ba04 --- /dev/null +++ b/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/lower-case2/lower-case.js @@ -0,0 +1,11 @@ +module.exports = function(RED) { +function LowerCaseNode(config) { + RED.nodes.createNode(this,config); + var node = this; + node.on('input', function(msg) { + msg.payload = msg.payload.toLowerCase(); + node.send(msg); + }); + } + RED.nodes.registerType("lower-case2",LowerCaseNode); +} \ No newline at end of file diff --git a/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/package.json b/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/package.json new file mode 100644 index 000000000..6b6ce9aa9 --- /dev/null +++ b/test/unit/@node-red/registry/lib/resources/nodesDir2/@lower-case2/package.json @@ -0,0 +1,9 @@ +{ + "name" : "@lowercase/lower-case2", + "node-red" : { + "nodes": { + "lower-case": "lower-case2/lower-case.js" + } + }, + "version": "2.0.0" +} \ No newline at end of file diff --git a/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.html b/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.html new file mode 100644 index 000000000..e57d51131 --- /dev/null +++ b/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.html @@ -0,0 +1,26 @@ + + + + + diff --git a/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.js b/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.js new file mode 100644 index 000000000..006b35eb6 --- /dev/null +++ b/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/lower-case/lower-case.js @@ -0,0 +1,11 @@ +module.exports = function(RED) { + function LowerCaseNode(config) { + RED.nodes.createNode(this,config); + var node = this; + node.on('input', function(msg) { + msg.payload = msg.payload.toLowerCase(); + node.send(msg); + }); + } + RED.nodes.registerType("lower-case",LowerCaseNode); +} diff --git a/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/package.json b/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/package.json new file mode 100644 index 000000000..a632eaddd --- /dev/null +++ b/test/unit/@node-red/registry/lib/resources/nodesDir2/lower-case/package.json @@ -0,0 +1,9 @@ +{ + "name" : "lower-case", + "node-red" : { + "nodes": { + "lower-case": "lower-case/lower-case.js" + } + }, + "version": "1.0.0" +} From 7507a7b459fdebf22287dda7b9dc4ac939402a4a Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Fri, 16 Sep 2022 02:10:14 +0900 Subject: [PATCH 03/35] Limit number of ports in function node --- .../@node-red/nodes/core/function/10-function.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 fc57895a2..a647bed49 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 @@ -451,7 +451,8 @@ tabs.activateTab("func-tab-body"); $( "#node-input-outputs" ).spinner({ - min:0, + min: 0, + max: 10, change: function(event, ui) { var value = this.value; if (!value.match(/^\d+$/)) { value = 1; } From 9fd4989142243d63f914fe523542fc8f03a1abbe Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 15 Sep 2022 21:22:55 +0100 Subject: [PATCH 04/35] Fix autocomplete entry for responseUrl Fixes #3883 --- .../@node-red/editor-client/src/js/ui/common/typedInput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js index ef1be05bc..7440b464e 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js @@ -146,7 +146,7 @@ { value: "reset", source: ["delay","trigger","join","rbe"] }, { value: "responseCookies", source: ["http request"] }, { value: "responseTopic", source: ["mqtt"] }, - { value: "responseURL", source: ["http request"] }, + { value: "responseUrl", source: ["http request"] }, { value: "restartTimeout", source: ["join"] }, { value: "retain", source: ["mqtt"] }, { value: "schema", source: ["json"] }, From 199caccbc3244fe73ac131bf5bd772c09fe2d112 Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Sat, 17 Sep 2022 00:25:46 +0900 Subject: [PATCH 05/35] Change the maximum number of ports to 500 --- .../node_modules/@node-red/nodes/core/function/10-function.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a647bed49..345a77aab 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 @@ -452,7 +452,7 @@ $( "#node-input-outputs" ).spinner({ min: 0, - max: 10, + max: 500, change: function(event, ui) { var value = this.value; if (!value.match(/^\d+$/)) { value = 1; } From ce31edc80327d4141d5a46b6f07ef33c5113c1ec Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Sun, 18 Sep 2022 02:22:52 +0900 Subject: [PATCH 06/35] Fix handling of max and min values in function outputs --- .../@node-red/nodes/core/function/10-function.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 345a77aab..43f8c7b39 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 @@ -454,9 +454,10 @@ min: 0, max: 500, change: function(event, ui) { - var value = this.value; - if (!value.match(/^\d+$/)) { value = 1; } - else if (value < this.min) { value = this.min; } + var value = parseInt(this.value); + value = isNaN(value) ? 1 : value; + value = Math.max(value, parseInt($(this).attr("aria-valuemin"))); + value = Math.min(value, parseInt($(this).attr("aria-valuemax"))); if (value !== this.value) { $(this).spinner("value", value); } } }); From efc0f1ab9144f6444544095fe7fbdfcd4732f2f0 Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Sun, 18 Sep 2022 16:24:25 +0900 Subject: [PATCH 07/35] Fix default values for MQTT retain settings --- .../node_modules/@node-red/nodes/core/network/10-mqtt.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html index 03ef4b2e3..cf443f48b 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html @@ -499,17 +499,17 @@ cleansession: {value: true}, birthTopic: {value:"", validate:validateMQTTPublishTopic}, birthQos: {value:"0"}, - birthRetain: {value:false}, + birthRetain: {value:"false"}, birthPayload: {value:""}, birthMsg: { value: {}}, closeTopic: {value:"", validate:validateMQTTPublishTopic}, closeQos: {value:"0"}, - closeRetain: {value:false}, + closeRetain: {value:"false"}, closePayload: {value:""}, closeMsg: { value: {}}, willTopic: {value:"", validate:validateMQTTPublishTopic}, willQos: {value:"0"}, - willRetain: {value:false}, + willRetain: {value:"false"}, willPayload: {value:""}, willMsg: { value: {}}, userProps: { value: ""}, From a81b1aa0cb769b3cc90a562f14c6eb79cbaa00ff Mon Sep 17 00:00:00 2001 From: Kazuhito Yokoi Date: Sun, 18 Sep 2022 17:10:19 +0900 Subject: [PATCH 08/35] Support i18n in MQTT node property --- .../@node-red/nodes/core/network/10-mqtt.html | 8 ++++++-- .../@node-red/nodes/locales/en-US/messages.json | 4 +++- .../node_modules/@node-red/nodes/locales/ja/messages.json | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html index cf443f48b..6492060e2 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.html @@ -421,7 +421,11 @@