mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
and also fix deprecated hooks with no alternative
This commit is contained in:
@@ -35,12 +35,15 @@ module.exports = function (Plugins) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Plugins.deprecatedHooks[data.hook]) {
|
||||
winston.warn('[plugins/' + id + '] Hook `' + data.hook + '` is deprecated, ' +
|
||||
(Plugins.deprecatedHooks[data.hook] ?
|
||||
'please use `' + Plugins.deprecatedHooks[data.hook] + '` instead.' :
|
||||
'there is no alternative.'
|
||||
));
|
||||
// `hasOwnProperty` needed for hooks with no alternative (set to null)
|
||||
if (Plugins.deprecatedHooks.hasOwnProperty(data.hook)) {
|
||||
const deprecated = Plugins.deprecatedHooks[data.hook];
|
||||
|
||||
if (deprecated) {
|
||||
winston.warn(`[plugins/${id}] Hook "${data.hook}" is deprecated, please use "${deprecated}" instead.`);
|
||||
} else {
|
||||
winston.warn(`[plugins/${id}] Hook "${data.hook}" is deprecated, there is no alternative.`);
|
||||
}
|
||||
}
|
||||
|
||||
data.id = id;
|
||||
|
||||
@@ -41,8 +41,28 @@ Plugins.loadedPlugins = [];
|
||||
|
||||
Plugins.initialized = false;
|
||||
|
||||
Plugins.requireLibrary = function (pluginID, libraryPath) {
|
||||
Plugins.libraries[pluginID] = require(libraryPath);
|
||||
Plugins.requireLibrary = function (pluginData) {
|
||||
let libraryPath;
|
||||
// attempt to load a plugin directly with `require("nodebb-plugin-*")`
|
||||
// Plugins should define their entry point in the standard `main` property of `package.json`
|
||||
try {
|
||||
libraryPath = pluginData.path;
|
||||
Plugins.libraries[pluginData.id] = require(libraryPath);
|
||||
} catch (e) {
|
||||
// DEPRECATED: @1.15.0, remove in version >=1.17
|
||||
// for backwards compatibility
|
||||
// if that fails, fall back to `pluginData.library`
|
||||
if (pluginData.library) {
|
||||
winston.warn(` [plugins/${pluginData.id}] The plugin.json field "library" is deprecated. Please use the package.json field "main" instead.`);
|
||||
winston.verbose(`[plugins/${pluginData.id}] See https://github.com/NodeBB/NodeBB/issues/8686`);
|
||||
|
||||
libraryPath = path.join(pluginData.path, pluginData.library);
|
||||
Plugins.libraries[pluginData.id] = require(libraryPath);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Plugins.libraryPaths.push(libraryPath);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const semver = require('semver');
|
||||
const async = require('async');
|
||||
const winston = require('winston');
|
||||
@@ -156,22 +155,16 @@ module.exports = function (Plugins) {
|
||||
}
|
||||
|
||||
function registerHooks(pluginData) {
|
||||
if (!pluginData.library) {
|
||||
return;
|
||||
}
|
||||
|
||||
const libraryPath = path.join(pluginData.path, pluginData.library);
|
||||
|
||||
try {
|
||||
if (!Plugins.libraries[pluginData.id]) {
|
||||
Plugins.requireLibrary(pluginData.id, libraryPath);
|
||||
Plugins.requireLibrary(pluginData);
|
||||
}
|
||||
|
||||
if (Array.isArray(pluginData.hooks)) {
|
||||
pluginData.hooks.forEach(hook => Plugins.registerHook(pluginData.id, hook));
|
||||
}
|
||||
} catch (err) {
|
||||
winston.warn('[plugins] Unable to parse library for: ' + pluginData.id);
|
||||
winston.warn('[plugins] Unable to load library for: ' + pluginData.id);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user