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

fix loading node package in nodesDir on linux

fixes #3861
This commit is contained in:
Steve-Mcl 2022-09-03 21:23:38 +01:00
parent 5365786386
commit d6bb3a558f
3 changed files with 40 additions and 20 deletions

View File

@ -43,37 +43,40 @@ function load(disableNodePathScan) {
return loadModuleFiles(modules);
}
function splitPath(p) {
return path.posix.normalize((p || '').replace(/\\/g, path.sep)).split(path.sep)
}
function loadModuleTypeFiles(module, type) {
const things = module[type];
var first = true;
var promises = [];
for (var thingName in things) {
let first = true;
const promises = [];
for (let thingName in things) {
/* istanbul ignore else */
if (things.hasOwnProperty(thingName)) {
if (module.name != "node-red" && first) {
// Check the module directory exists
first = false;
var fn = things[thingName].file;
var parts = fn.split("/");
var i = parts.length-1;
for (;i>=0;i--) {
if (parts[i] == "node_modules") {
break;
let moduleFn = module.path
const fn = things[thingName].file
const parts = splitPath(fn)
const nmi = parts.indexOf('node_modules')
if(nmi > -1) {
moduleFn = parts.slice(0,nmi+2).join(path.sep);
}
if (!moduleFn) {
// shortcut - skip calling statSync on empty string
break; // Module not found, don't attempt to load its nodes
}
var moduleFn = parts.slice(0,i+2).join("/");
try {
var stat = fs.statSync(moduleFn);
const stat = fs.statSync(moduleFn);
} catch(err) {
// Module not found, don't attempt to load its nodes
break;
break; // Module not found, don't attempt to load its nodes
}
}
try {
var promise;
let promise;
if (type === "nodes") {
promise = loadNodeConfig(things[thingName]);
} else if (type === "plugins") {
@ -82,8 +85,7 @@ function loadModuleTypeFiles(module, type) {
promises.push(
promise.then(
(function() {
var m = module.name;
var n = thingName;
const n = thingName;
return function(nodeSet) {
things[n] = nodeSet;
return nodeSet;
@ -93,7 +95,6 @@ function loadModuleTypeFiles(module, type) {
);
} catch(err) {
console.log(err)
//
}
}
}

View File

@ -156,6 +156,16 @@ function scanDirForNodesModules(dir,moduleName,package) {
}
}
}
// if we have found a package.json, this IS a node_module, lets see if it is a node-red node
if (!isNodeRedModule && files.indexOf('package.json') > -1) {
package = getPackageDetails(dir) // get package details
if(package && package.isNodeRedModule) {
isNodeRedModule = true
files = ['package.json'] // shortcut the file scan
}
}
for (let i=0;i<files.length;i++) {
let fn = files[i];
if (!isNodeRedModule && /^@/.test(fn)) {

View File

@ -185,10 +185,19 @@ function loadNodeConfigs() {
function addModule(module) {
moduleNodes[module.name] = [];
moduleConfigs[module.name] = module;
// console.log("registry.js.addModule",module.name,"user?",module.user,"usedBy",module.usedBy,"dependencies",module.dependencies)
for (var setName in module.nodes) {
if (module.nodes.hasOwnProperty(setName)) {
var set = module.nodes[setName];
if (!set.types) {
const err = new Error("Node has no types")
err.code = "has_no_types"
err.details = {
setName: set.name,
set: { ...set }
}
console.warn(err)
set.err = err
}
moduleNodes[module.name].push(set.name);
nodeList.push(set.id);
if (!set.err) {