Improve getModuleListForNodes + fix typo

This commit is contained in:
GogoVega 2024-10-27 13:26:47 +01:00
parent 5e9195ab99
commit 44b4c7da24
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -3009,19 +3009,25 @@ RED.nodes = (function() {
*/
function getModuleListForNodes(nodes) {
const modules = {}
nodes.forEach(n => {
const typeSet = new Set()
nodes.forEach((n) => {
if (!typeSet.has(n.type)) {
typeSet.add(n.type)
const nodeSet = RED.nodes.registry.getNodeSetForType(n.type)
if (nodeSet) {
modules[nodeSet.module] = nodeSet.version
nodeSet.types.forEach((t) => typeSet.add(t))
}
}
})
return modules
}
function updateGlobalConfigModuleList(nodes) {
const modules = getModuleListForNodes(nodes)
delete modules['node-red']
const hasModules = (Object.keys(modules).length > 0)
let globalConfigNode = nodes.find(n => n.type === 'global-config')
let globalConfigNode = nodes.find((n) => n.type === 'global-config')
if (!globalConfigNode && hasModules) {
globalConfigNode = {
id: RED.nodes.id(),
@ -3030,7 +3036,7 @@ RED.nodes = (function() {
modules
}
nodes.push(globalConfigNode)
} else if (globalConfigNode) {
} else if (hasModules) {
globalConfigNode.modules = modules
}
}