determine root global node.js package location in runtime instead of hardcoding it
This commit is contained in:
parent
d85683178b
commit
38989fa884
@ -26,7 +26,7 @@
|
|||||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||||
<content_rating type="oars-1.1" />
|
<content_rating type="oars-1.1" />
|
||||||
<releases>
|
<releases>
|
||||||
<release version="4.0.4" date="2021-12-16"/>
|
<release version="4.0.4" date="2021-12-20"/>
|
||||||
</releases>
|
</releases>
|
||||||
<content_rating type="oars-1.0">
|
<content_rating type="oars-1.0">
|
||||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "core/filterutils.h"
|
#include "core/filterutils.h"
|
||||||
|
|
||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
|
#include "miscellaneous/iofactory.h"
|
||||||
#include "miscellaneous/textfactory.h"
|
#include "miscellaneous/textfactory.h"
|
||||||
|
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
@ -87,19 +88,5 @@ QDateTime FilterUtils::parseDateTime(const QString& dat) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString FilterUtils::runExecutableGetOutput(const QString& executable, const QStringList& arguments) const {
|
QString FilterUtils::runExecutableGetOutput(const QString& executable, const QStringList& arguments) const {
|
||||||
QProcess proc;
|
return IOFactory::startProcessGetOutput(executable, arguments);
|
||||||
|
|
||||||
proc.setProgram(executable);
|
|
||||||
proc.setArguments(arguments);
|
|
||||||
|
|
||||||
proc.start();
|
|
||||||
|
|
||||||
if (proc.waitForFinished() &&
|
|
||||||
proc.exitStatus() == QProcess::ExitStatus::NormalExit &&
|
|
||||||
proc.exitCode() == EXIT_SUCCESS) {
|
|
||||||
return proc.readAllStandardOutput();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return proc.readAllStandardError().simplified();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,27 @@ bool IOFactory::startProcessDetached(const QString& program, const QStringList&
|
|||||||
return process.startDetached(nullptr);
|
return process.startDetached(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString IOFactory::startProcessGetOutput(const QString& executable, const QStringList& arguments) {
|
||||||
|
QProcess proc;
|
||||||
|
|
||||||
|
proc.setProgram(executable);
|
||||||
|
proc.setArguments(arguments);
|
||||||
|
proc.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
|
||||||
|
|
||||||
|
proc.start();
|
||||||
|
|
||||||
|
if (proc.waitForFinished() &&
|
||||||
|
proc.exitStatus() == QProcess::ExitStatus::NormalExit &&
|
||||||
|
proc.exitCode() == EXIT_SUCCESS) {
|
||||||
|
return proc.readAllStandardOutput();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QString err = proc.readAllStandardError().simplified();
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray IOFactory::readFile(const QString& file_path) {
|
QByteArray IOFactory::readFile(const QString& file_path) {
|
||||||
QFile input_file(file_path);
|
QFile input_file(file_path);
|
||||||
QByteArray input_data;
|
QByteArray input_data;
|
||||||
|
@ -31,6 +31,7 @@ class IOFactory {
|
|||||||
const QStringList& arguments,
|
const QStringList& arguments,
|
||||||
const QString& native_arguments = {},
|
const QString& native_arguments = {},
|
||||||
const QString& working_directory = {});
|
const QString& working_directory = {});
|
||||||
|
static QString startProcessGetOutput(const QString& executable, const QStringList& arguments = {});
|
||||||
|
|
||||||
// Returns contents of a file.
|
// Returns contents of a file.
|
||||||
// Throws exception when no such file exists.
|
// Throws exception when no such file exists.
|
||||||
|
@ -296,19 +296,20 @@ QProcess* AdBlockManager::startServer(int port) {
|
|||||||
proc->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
|
proc->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
|
||||||
|
|
||||||
auto pe = proc->processEnvironment();
|
auto pe = proc->processEnvironment();
|
||||||
QString default_node_path =
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
pe.value(QSL("APPDATA")) + QDir::separator() + QSL("npm") + QDir::separator() + QSL("node_modules");
|
|
||||||
#elif defined(Q_OS_LINUX)
|
|
||||||
QSL("/usr/lib/node_modules");
|
|
||||||
#elif defined(Q_OS_MACOS)
|
|
||||||
QSL("/usr/local/lib/node_modules");
|
|
||||||
#else
|
|
||||||
QSL("");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!pe.contains(QSL("NODE_PATH")) && !default_node_path.isEmpty()) {
|
if (!pe.contains(QSL("NODE_PATH"))) {
|
||||||
pe.insert(QSL("NODE_PATH"), default_node_path);
|
const QString system_node_prefix = IOFactory::startProcessGetOutput(
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
QSL("npm.cmd")
|
||||||
|
#else
|
||||||
|
QSL("npm")
|
||||||
|
#endif
|
||||||
|
, { QSL("root"), QSL("--quiet"), QSL("-g") }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!system_node_prefix.isEmpty()) {
|
||||||
|
pe.insert(QSL("NODE_PATH"), system_node_prefix.simplified());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc->setProcessEnvironment(pe);
|
proc->setProcessEnvironment(pe);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user