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

Fix up loading of freshly installed modules in Function node

This commit is contained in:
Nick O'Leary 2021-02-12 22:40:30 +00:00
parent 9c09ee3b71
commit a94c19a6cf
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 6 additions and 7 deletions

View File

@ -89,15 +89,13 @@ module.exports = function(RED) {
} }
function FunctionNode(n) { function FunctionNode(n) {
var libs = n.libs || [];
n.modules = libs.map(x => x.spec).filter(x => (x && (x !== "")));
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
node.name = n.name; node.name = n.name;
node.func = n.func; node.func = n.func;
node.ini = n.initialize ? n.initialize.trim() : ""; node.ini = n.initialize ? n.initialize.trim() : "";
node.fin = n.finalize ? n.finalize.trim() : ""; node.fin = n.finalize ? n.finalize.trim() : "";
node.libs = libs || []; node.libs = n.libs || [];
if (RED.settings.functionExternalModules === false && node.libs.length > 0) { if (RED.settings.functionExternalModules === false && node.libs.length > 0) {
throw new Error("Function node not allowed to load external modules"); throw new Error("Function node not allowed to load external modules");
@ -298,9 +296,9 @@ module.exports = function(RED) {
if (vname && (vname !== "")) { if (vname && (vname !== "")) {
sandbox[vname] = null; sandbox[vname] = null;
try { try {
var spec = module.spec; var spec = module.module;
if (spec && (spec !== "")) { if (spec && (spec !== "")) {
var lib = RED.require(module.spec); var lib = RED.require(module.module);
sandbox[vname] = lib; sandbox[vname] = lib;
} }
} }

View File

@ -137,7 +137,7 @@ async function checkFlowDependencies(flowConfig) {
} }
}) })
return Promise.all(promises).then(() => { return Promise.all(promises).then(refreshExternalModules).then(() => {
if (errors.length > 0) { if (errors.length > 0) {
throw errors; throw errors;
} }
@ -154,7 +154,8 @@ async function ensureModuleDir() {
const pkgFile = path.join(installDir,"package.json"); const pkgFile = path.join(installDir,"package.json");
if (!fs.existsSync(pkgFile)) { if (!fs.existsSync(pkgFile)) {
await fs.writeFile(path.join(installDir,"package.json"),`{ 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", "version": "1.0.0",
"private": true, "private": true,
"dependencies": {} "dependencies": {}