From 2f7f53ed96aa953a597b50e037883d6e24d2a667 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 4 Sep 2018 11:26:05 +0100 Subject: [PATCH 1/2] Filter global modules installed locally If a module is found both locally and globally installed, the local copy will take precedence. This will allow a user to upgrade a node module that they may not otherwise be able to touch --- red/runtime/nodes/registry/localfilesystem.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/red/runtime/nodes/registry/localfilesystem.js b/red/runtime/nodes/registry/localfilesystem.js index 527ccce71..a23a68781 100644 --- a/red/runtime/nodes/registry/localfilesystem.js +++ b/red/runtime/nodes/registry/localfilesystem.js @@ -290,6 +290,33 @@ function getNodeFiles(disableNodePathScan) { if (!disableNodePathScan) { var moduleFiles = scanTreeForNodesModules(); + + // Filter the module list to ignore global modules + // that have also been installed locally - allowing the user to + // update a module they may not otherwise be able to touch + + moduleFiles.sort(function(A,B) { + if (A.local && !B.local) { + return -1 + } else if (!A.local && B.local) { + return 1 + } + return 0; + }) + var knownModules = {}; + moduleFiles = moduleFiles.filter(function(mod) { + var result; + if (!knownModules[mod.package.name]) { + knownModules[mod.package.name] = true; + result = true; + } else { + result = false; + } + log.debug("Module: "+mod.package.name+" "+mod.package.version+(result?"":" *ignored due to local copy*")); + log.debug(" "+mod.dir); + return result; + }); + moduleFiles.forEach(function(moduleFile) { var nodeModuleFiles = getModuleNodeFiles(moduleFile); nodeList[moduleFile.package.name] = { From f29d7c9252262b252c528e6d27e66b253b9f75a2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 4 Sep 2018 11:37:04 +0100 Subject: [PATCH 2/2] Fixup localfilesystem registry test --- test/red/runtime/nodes/registry/localfilesystem_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/red/runtime/nodes/registry/localfilesystem_spec.js b/test/red/runtime/nodes/registry/localfilesystem_spec.js index 2ffc220f4..2e6093567 100644 --- a/test/red/runtime/nodes/registry/localfilesystem_spec.js +++ b/test/red/runtime/nodes/registry/localfilesystem_spec.js @@ -128,7 +128,7 @@ describe("red/nodes/registry/localfilesystem",function() { } return _join.apply(null,arguments); })); - localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}}); + localfilesystem.init({log:{debug:function(){}},i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}}); var nodeList = localfilesystem.getNodeFiles(); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red'];