Improved translation.js module installation.

This commit is contained in:
Ylian Saint-Hilaire 2023-10-20 23:59:14 -07:00
parent cdde9b5d67
commit aadfbafc33
4 changed files with 3144 additions and 3025 deletions

View File

@ -4038,7 +4038,7 @@ function mainStart() {
else if (config.settings.xmongodb != null) { modules.push('mongojs@3.1.0'); } // Add MongoJS, old driver. else if (config.settings.xmongodb != null) { modules.push('mongojs@3.1.0'); } // Add MongoJS, old driver.
if (nodemailer || ((config.smtp != null) && (config.smtp.name != 'console')) || (config.sendmail != null)) { modules.push('nodemailer@6.9.6'); } // Add SMTP support if (nodemailer || ((config.smtp != null) && (config.smtp.name != 'console')) || (config.sendmail != null)) { modules.push('nodemailer@6.9.6'); } // Add SMTP support
if (sendgrid || (config.sendgrid != null)) { modules.push('@sendgrid/mail'); } // Add SendGrid support if (sendgrid || (config.sendgrid != null)) { modules.push('@sendgrid/mail'); } // Add SendGrid support
if (args.translate) { modules.push('jsdom'); modules.push('esprima'); modules.push('minify-js'); modules.push('html-minifier'); } // Translation support if (args.translate) { modules.push('jsdom@22.1.0'); modules.push('esprima@4.0.1'); modules.push('minify-js@0.0.4'); modules.push('html-minifier@4.0.0'); } // Translation support
if (typeof config.settings.crowdsec == 'object') { modules.push('@crowdsec/express-bouncer@0.1.0'); } // Add CrowdSec bounser module (https://www.npmjs.com/package/@crowdsec/express-bouncer) if (typeof config.settings.crowdsec == 'object') { modules.push('@crowdsec/express-bouncer@0.1.0'); } // Add CrowdSec bounser module (https://www.npmjs.com/package/@crowdsec/express-bouncer)
if (typeof config.settings.autobackup == 'object') { if (typeof config.settings.autobackup == 'object') {

File diff suppressed because one or more lines are too long

View File

@ -158,9 +158,9 @@ if (directRun && (NodeJSVer >= 12)) {
if (directRun) { setup(); } if (directRun) { setup(); }
function setup() { function setup() {
var libs = ['jsdom', 'esprima', 'minify-js']; var libs = ['jsdom@22.1.0', 'esprima@4.0.1', 'minify-js@0.0.4'];
if (minifyLib == 1) { libs.push('minify-js'); } if (minifyLib == 1) { libs.push('minify-js@0.0.4'); }
if (minifyLib == 2) { libs.push('html-minifier'); } if (minifyLib == 2) { libs.push('html-minifier@4.0.0'); }
InstallModules(libs, start); InstallModules(libs, start);
} }
@ -1079,25 +1079,24 @@ function format(format) { var args = Array.prototype.slice.call(arguments, 1); r
// Check if a list of modules are present and install any missing ones // Check if a list of modules are present and install any missing ones
var InstallModuleChildProcess = null; var InstallModuleChildProcess = null;
var previouslyInstalledModules = {};
function InstallModules(modules, func) { function InstallModules(modules, func) {
var missingModules = []; var missingModules = [];
if (previouslyInstalledModules == null) { previouslyInstalledModules = {}; }
if (modules.length > 0) { if (modules.length > 0) {
for (var i in modules) { for (var i in modules) {
try { try {
var xxmodule = require(modules[i]); var xxmodule = require(modules[i]);
} catch (e) { } catch (e) {
if (previouslyInstalledModules[modules[i]] !== true) { missingModules.push(modules[i]); } missingModules.push(modules[i]);
} }
} }
if (missingModules.length > 0) { InstallModule(missingModules.shift(), InstallModules, modules, func); } else { func(); } if (missingModules.length > 0) { InstallModuleEx(modules, func); } else { func(); }
} }
} }
// Check if a module is present and install it if missing // Check if a module is present and install it if missing
function InstallModule(modulename, func, tag1, tag2) { function InstallModuleEx(modulenames, func) {
log('Installing ' + modulename + '...'); log('Installing modules...');
var names = modulenames.join(' ');
var child_process = require('child_process'); var child_process = require('child_process');
var parentpath = __dirname; var parentpath = __dirname;
@ -1105,15 +1104,14 @@ function InstallModule(modulename, func, tag1, tag2) {
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, '../..'); }
// Looks like we need to keep a global reference to the child process object for this to work correctly. // Looks like we need to keep a global reference to the child process object for this to work correctly.
InstallModuleChildProcess = child_process.exec('npm install --no-optional ' + modulename, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) { InstallModuleChildProcess = child_process.exec(`npm install --no-audit --no-package-lock --no-optional --omit=optional --no-save ${names}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
InstallModuleChildProcess = null; InstallModuleChildProcess = null;
if ((error != null) && (error != '')) { if ((error != null) && (error != '')) {
log('ERROR: Unable to install required module "' + modulename + '". 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'); log('ERROR: Unable to install required modules. May not have access to npm, or npm may not have suffisent rights to load the new modules. Try "npm install ' + names + '" to manualy install the modules.\r\n');
process.exit(); process.exit();
return; return;
} }
previouslyInstalledModules[modulename] = true; func();
func(tag1, tag2);
return; return;
}); });
} }

File diff suppressed because it is too large Load Diff