mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Move externalModules back into the user dir
This commit is contained in:
parent
b01c5a05e7
commit
e6a845e606
@ -12,7 +12,6 @@ const log = require("@node-red/util").log;
|
|||||||
const hooks = require("@node-red/util").hooks;
|
const hooks = require("@node-red/util").hooks;
|
||||||
|
|
||||||
const BUILTIN_MODULES = require('module').builtinModules;
|
const BUILTIN_MODULES = require('module').builtinModules;
|
||||||
const EXTERNAL_MODULES_DIR = "externalModules";
|
|
||||||
|
|
||||||
// TODO: outsource running npm to a plugin
|
// TODO: outsource running npm to a plugin
|
||||||
const NPM_COMMAND = (process.platform === "win32") ? "npm.cmd" : "npm";
|
const NPM_COMMAND = (process.platform === "win32") ? "npm.cmd" : "npm";
|
||||||
@ -28,15 +27,30 @@ let installAllowList = ['*'];
|
|||||||
let installDenyList = [];
|
let installDenyList = [];
|
||||||
|
|
||||||
function getInstallDir() {
|
function getInstallDir() {
|
||||||
return path.resolve(path.join(settings.userDir || process.env.NODE_RED_HOME || ".", "externalModules"));
|
return path.resolve(settings.userDir || process.env.NODE_RED_HOME || ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let loggedLegacyWarning = false;
|
||||||
async function refreshExternalModules() {
|
async function refreshExternalModules() {
|
||||||
const externalModuleDir = path.resolve(path.join(settings.userDir || process.env.NODE_RED_HOME || ".", EXTERNAL_MODULES_DIR));
|
|
||||||
|
if (!loggedLegacyWarning) {
|
||||||
|
loggedLegacyWarning = true;
|
||||||
|
const oldExternalModulesDir = path.join(path.resolve(settings.userDir || process.env.NODE_RED_HOME || "."),"externalModules");
|
||||||
|
if (fs.existsSync(oldExternalModulesDir)) {
|
||||||
|
try {
|
||||||
|
log.warn(log._("server.install.old-ext-mod-dir-warning",{oldDir:oldExternalModulesDir, newDir:getInstallDir()}))
|
||||||
|
} catch(err) {console.log(err)}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const externalModuleDir = getInstallDir();
|
||||||
try {
|
try {
|
||||||
const pkgFile = JSON.parse(await fs.readFile(path.join(externalModuleDir,"package.json"),"utf-8"));
|
const pkgFile = JSON.parse(await fs.readFile(path.join(externalModuleDir,"package.json"),"utf-8"));
|
||||||
knownExternalModules = pkgFile.dependencies;
|
knownExternalModules = pkgFile.dependencies;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
knownExternalModules = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +58,7 @@ function init(_settings) {
|
|||||||
settings = _settings;
|
settings = _settings;
|
||||||
knownExternalModules = {};
|
knownExternalModules = {};
|
||||||
installEnabled = true;
|
installEnabled = true;
|
||||||
|
|
||||||
if (settings.externalModules && settings.externalModules.modules) {
|
if (settings.externalModules && settings.externalModules.modules) {
|
||||||
if (settings.externalModules.modules.allowList || settings.externalModules.modules.denyList) {
|
if (settings.externalModules.modules.allowList || settings.externalModules.modules.denyList) {
|
||||||
installAllowList = settings.externalModules.modules.allowList;
|
installAllowList = settings.externalModules.modules.allowList;
|
||||||
@ -82,7 +97,7 @@ function requireModule(module) {
|
|||||||
e.code = "module_not_allowed";
|
e.code = "module_not_allowed";
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
const externalModuleDir = path.resolve(path.join(settings.userDir || process.env.NODE_RED_HOME || ".", EXTERNAL_MODULES_DIR));
|
const externalModuleDir = getInstallDir();
|
||||||
const moduleDir = path.join(externalModuleDir,"node_modules",module);
|
const moduleDir = path.join(externalModuleDir,"node_modules",module);
|
||||||
return require(moduleDir);
|
return require(moduleDir);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
"uninstalling": "Uninstalling module: __name__",
|
"uninstalling": "Uninstalling module: __name__",
|
||||||
"uninstall-failed": "Uninstall failed",
|
"uninstall-failed": "Uninstall failed",
|
||||||
"uninstall-failed-long": "Uninstall of module __name__ failed:",
|
"uninstall-failed-long": "Uninstall of module __name__ failed:",
|
||||||
"uninstalled": "Uninstalled module: __name__"
|
"uninstalled": "Uninstalled module: __name__",
|
||||||
|
"old-ext-mod-dir-warning": "\n\n---------------------------------------------------------------------\nNode-RED 1.3 external modules directory detected:\n __oldDir__\nThis directory is no longer used. External Modules will be\nreinstalled in your Node-RED user directory:\n __newDir__\nDelete the old externalModules directory to stop this message.\n---------------------------------------------------------------------\n"
|
||||||
},
|
},
|
||||||
"deprecatedOption": "Use of __old__ is DEPRECATED. Use __new__ instead",
|
"deprecatedOption": "Use of __old__ is DEPRECATED. Use __new__ instead",
|
||||||
"unable-to-listen": "Unable to listen on __listenpath__",
|
"unable-to-listen": "Unable to listen on __listenpath__",
|
||||||
|
Loading…
Reference in New Issue
Block a user