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) {
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;
}
}

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) {
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": {}