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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plugins.deprecatedHooks[data.hook]) {
|
// `hasOwnProperty` needed for hooks with no alternative (set to null)
|
||||||
winston.warn('[plugins/' + id + '] Hook `' + data.hook + '` is deprecated, ' +
|
if (Plugins.deprecatedHooks.hasOwnProperty(data.hook)) {
|
||||||
(Plugins.deprecatedHooks[data.hook] ?
|
const deprecated = Plugins.deprecatedHooks[data.hook];
|
||||||
'please use `' + Plugins.deprecatedHooks[data.hook] + '` instead.' :
|
|
||||||
'there is no alternative.'
|
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;
|
data.id = id;
|
||||||
|
|||||||
@@ -41,8 +41,28 @@ Plugins.loadedPlugins = [];
|
|||||||
|
|
||||||
Plugins.initialized = false;
|
Plugins.initialized = false;
|
||||||
|
|
||||||
Plugins.requireLibrary = function (pluginID, libraryPath) {
|
Plugins.requireLibrary = function (pluginData) {
|
||||||
Plugins.libraries[pluginID] = require(libraryPath);
|
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);
|
Plugins.libraryPaths.push(libraryPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
@@ -156,22 +155,16 @@ module.exports = function (Plugins) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerHooks(pluginData) {
|
function registerHooks(pluginData) {
|
||||||
if (!pluginData.library) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const libraryPath = path.join(pluginData.path, pluginData.library);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!Plugins.libraries[pluginData.id]) {
|
if (!Plugins.libraries[pluginData.id]) {
|
||||||
Plugins.requireLibrary(pluginData.id, libraryPath);
|
Plugins.requireLibrary(pluginData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(pluginData.hooks)) {
|
if (Array.isArray(pluginData.hooks)) {
|
||||||
pluginData.hooks.forEach(hook => Plugins.registerHook(pluginData.id, hook));
|
pluginData.hooks.forEach(hook => Plugins.registerHook(pluginData.id, hook));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
winston.warn('[plugins] Unable to parse library for: ' + pluginData.id);
|
winston.warn('[plugins] Unable to load library for: ' + pluginData.id);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user