From a94c19a6cfa6ce3df360d27086b133f118a55a29 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 12 Feb 2021 22:40:30 +0000 Subject: [PATCH] Fix up loading of freshly installed modules in Function node --- .../@node-red/nodes/core/function/10-function.js | 8 +++----- .../@node-red/registry/lib/externalModules.js | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) 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 10ffc1189..b9fae8626 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 @@ -89,15 +89,13 @@ module.exports = function(RED) { } function FunctionNode(n) { - var libs = n.libs || []; - n.modules = libs.map(x => x.spec).filter(x => (x && (x !== ""))); RED.nodes.createNode(this,n); var node = this; node.name = n.name; node.func = n.func; node.ini = n.initialize ? n.initialize.trim() : ""; node.fin = n.finalize ? n.finalize.trim() : ""; - node.libs = libs || []; + node.libs = n.libs || []; if (RED.settings.functionExternalModules === false && node.libs.length > 0) { throw new Error("Function node not allowed to load external modules"); @@ -298,9 +296,9 @@ module.exports = function(RED) { if (vname && (vname !== "")) { sandbox[vname] = null; try { - var spec = module.spec; + var spec = module.module; if (spec && (spec !== "")) { - var lib = RED.require(module.spec); + var lib = RED.require(module.module); sandbox[vname] = lib; } } diff --git a/packages/node_modules/@node-red/registry/lib/externalModules.js b/packages/node_modules/@node-red/registry/lib/externalModules.js index 6486ce8b3..f794f1fc6 100644 --- a/packages/node_modules/@node-red/registry/lib/externalModules.js +++ b/packages/node_modules/@node-red/registry/lib/externalModules.js @@ -137,7 +137,7 @@ async function checkFlowDependencies(flowConfig) { } }) - return Promise.all(promises).then(() => { + return Promise.all(promises).then(refreshExternalModules).then(() => { if (errors.length > 0) { throw errors; } @@ -154,7 +154,8 @@ async function ensureModuleDir() { const pkgFile = path.join(installDir,"package.json"); if (!fs.existsSync(pkgFile)) { await fs.writeFile(path.join(installDir,"package.json"),`{ - "name": "Node-RED External Modules", + "name": "Node-RED-External-Modules", + "description": "These modules are automatically installed by Node-RED to use in Function nodes.", "version": "1.0.0", "private": true, "dependencies": {}