mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-25 22:55:52 -05:00
Merge pull request #871 from TotallyNotElite/mc-dyndepends
Improve the way dynamic dependencies work
This commit is contained in:
commit
db66f4f38a
@ -2168,20 +2168,27 @@ function getConfig(createSampleConfig) {
|
|||||||
function InstallModules(modules, func) {
|
function InstallModules(modules, func) {
|
||||||
var missingModules = [];
|
var missingModules = [];
|
||||||
if (modules.length > 0) {
|
if (modules.length > 0) {
|
||||||
|
var dependencies = require("./package.json").dependencies;
|
||||||
for (var i in modules) {
|
for (var i in modules) {
|
||||||
// Modules may contain a version tag (foobar@1.0.0), remove it so the module can be found using require
|
// Modules may contain a version tag (foobar@1.0.0), remove it so the module can be found using require
|
||||||
var moduleName = modules[i].split("@", 1)[0];
|
var moduleInfo = modules[i].split("@", 2);
|
||||||
|
var moduleName = moduleInfo[0];
|
||||||
|
var moduleVersion = moduleInfo[1];
|
||||||
try {
|
try {
|
||||||
if (moduleName == 'greenlock') {
|
// Does the module need a specific version?
|
||||||
// Check if we have GreenLock v3
|
if (moduleVersion) {
|
||||||
delete require.cache[require.resolve('greenlock')]; // Clear the require cache
|
if (require(`${moduleName}/package.json`).version != moduleVersion)
|
||||||
if (typeof require('greenlock').challengeType == 'string') { missingModules.push(modules[i]); }
|
throw new Error();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// For all other modules, do the check here.
|
// For all other modules, do the check here.
|
||||||
|
// Is the module in package.json? Install exact version.
|
||||||
|
if (typeof dependencies[moduleName] != undefined)
|
||||||
|
moduleVersion = dependencies[moduleName];
|
||||||
require(moduleName);
|
require(moduleName);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (previouslyInstalledModules[modules[i]] !== true) { missingModules.push(modules[i]); }
|
if (previouslyInstalledModules[modules[i]] !== true) { missingModules.push(`${moduleName}${moduleVersion ? `@${moduleVersion}` : ""}`); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (missingModules.length > 0) { InstallModule(missingModules.shift(), InstallModules, modules, func); } else { func(); }
|
if (missingModules.length > 0) { InstallModule(missingModules.shift(), InstallModules, modules, func); } else { func(); }
|
||||||
@ -2197,7 +2204,7 @@ function InstallModule(modulename, func, tag1, tag2) {
|
|||||||
// Get the working directory
|
// Get the working directory
|
||||||
if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); }
|
if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); }
|
||||||
|
|
||||||
child_process.exec(`npm install --no-optional ${modulename}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
|
child_process.exec(`npm install --no-save --no-optional ${modulename}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
|
||||||
if ((error != null) && (error != '')) {
|
if ((error != null) && (error != '')) {
|
||||||
console.log('ERROR: Unable to install required module "' + modulename + '". MeshCentral may not have access to npm, or npm may not have suffisent rights to load the new module. Try "npm install ' + modulename + '" to manualy install this module.\r\n');
|
console.log('ERROR: Unable to install required module "' + modulename + '". MeshCentral may not have access to npm, or npm may not have suffisent rights to load the new module. Try "npm install ' + modulename + '" to manualy install this module.\r\n');
|
||||||
process.exit();
|
process.exit();
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
"multiparty": "^4.2.1",
|
"multiparty": "^4.2.1",
|
||||||
"nedb": "^1.8.0",
|
"nedb": "^1.8.0",
|
||||||
"node-forge": "^0.8.4",
|
"node-forge": "^0.8.4",
|
||||||
|
"otplib": "^12.0.1",
|
||||||
"ws": "^6.2.1",
|
"ws": "^6.2.1",
|
||||||
"xmldom": "^0.1.27",
|
"xmldom": "^0.1.27",
|
||||||
"yauzl": "^2.10.0"
|
"yauzl": "^2.10.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user