mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Handle subflow modules with their own npm dependencies
This commit is contained in:
@@ -94,20 +94,6 @@ function checkModulePath(folder) {
|
||||
version: moduleVersion
|
||||
};
|
||||
}
|
||||
|
||||
function checkExistingModule(module,version) {
|
||||
var info = registry.getModuleInfo(module);
|
||||
if (info) {
|
||||
if (!version || info.version === version) {
|
||||
var err = new Error("Module already loaded");
|
||||
err.code = "module_already_loaded";
|
||||
throw err;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function installModule(module,version,url) {
|
||||
if (Buffer.isBuffer(module)) {
|
||||
return installTarball(module)
|
||||
@@ -118,6 +104,7 @@ async function installModule(module,version,url) {
|
||||
var installName = module;
|
||||
let isRegistryPackage = true;
|
||||
var isUpgrade = false;
|
||||
var isExisting = false;
|
||||
if (url) {
|
||||
if (pkgurlRe.test(url) || localtgzRe.test(url)) {
|
||||
// Git remote url or Tarball url - check the valid package url
|
||||
@@ -158,7 +145,21 @@ async function installModule(module,version,url) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
isUpgrade = checkExistingModule(module,version);
|
||||
|
||||
var info = registry.getModuleInfo(module);
|
||||
if (info) {
|
||||
if (!info.user) {
|
||||
log.debug(`Installing existing module: ${module}`)
|
||||
isExisting = true;
|
||||
} else if (!version || info.version === version) {
|
||||
var err = new Error("Module already loaded");
|
||||
err.code = "module_already_loaded";
|
||||
throw err;
|
||||
}
|
||||
isUpgrade = true;
|
||||
} else {
|
||||
isUpgrade = false;
|
||||
}
|
||||
|
||||
if (!isUpgrade) {
|
||||
log.info(log._("server.install.installing",{name: module,version: version||"latest"}));
|
||||
@@ -172,7 +173,17 @@ async function installModule(module,version,url) {
|
||||
return exec.run(npmCommand,args,{
|
||||
cwd: installDir
|
||||
}, true).then(result => {
|
||||
if (!isUpgrade) {
|
||||
if (isExisting) {
|
||||
// This is a module we already have installed as a non-user module.
|
||||
// That means it was discovered when loading, but was not listed
|
||||
// in package.json and has been hidden from the editor.
|
||||
// The user has requested to install this module. Having run
|
||||
// the npm install above, it will now be listed in package.json.
|
||||
// Update the registry to mark it as a user module so it will
|
||||
// be available to the editor.
|
||||
log.info(log._("server.install.installed",{name:module}));
|
||||
return require("./registry").setUserInstalled(module,true).then(reportAddedModules);
|
||||
} else if (!isUpgrade) {
|
||||
log.info(log._("server.install.installed",{name:module}));
|
||||
return require("./index").addModule(module).then(reportAddedModules);
|
||||
} else {
|
||||
@@ -212,7 +223,6 @@ async function installModule(module,version,url) {
|
||||
}
|
||||
|
||||
function reportAddedModules(info) {
|
||||
//comms.publish("node/added",info.nodes,false);
|
||||
if (info.nodes.length > 0) {
|
||||
log.info(log._("server.added-types"));
|
||||
for (var i=0;i<info.nodes.length;i++) {
|
||||
|
Reference in New Issue
Block a user