mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
chore: deprecation notices for plugins using plugin old hook methods
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
@@ -26,10 +27,21 @@ Plugins.data = require('./data');
|
|||||||
Plugins.hooks = require('./hooks');
|
Plugins.hooks = require('./hooks');
|
||||||
|
|
||||||
// Backwards compatibility for hooks, remove in v1.18.0
|
// Backwards compatibility for hooks, remove in v1.18.0
|
||||||
Plugins.registerHook = Plugins.hooks.register;
|
const _deprecate = async function () {
|
||||||
Plugins.unregisterHook = Plugins.hooks.unregister;
|
const args = Array.from(arguments);
|
||||||
Plugins.fireHook = Plugins.hooks.fire;
|
const oldMethod = args.shift();
|
||||||
Plugins.hasListeners = Plugins.hooks.hasListeners;
|
const newMethod = args.shift();
|
||||||
|
const method = args.shift();
|
||||||
|
const stack = new Error().stack.toString().split(os.EOL);
|
||||||
|
const context = stack[stack.findIndex(line => line.startsWith(' at Object.wrapperCallback')) + 1];
|
||||||
|
winston.warn(`[plugins/hooks] ${oldMethod} has been deprecated, call ${newMethod} instead.`);
|
||||||
|
winston.warn(`[plugins/hooks] ${context}`);
|
||||||
|
return method.apply(Plugins.hooks, args);
|
||||||
|
};
|
||||||
|
Plugins.registerHook = _deprecate.bind(null, 'Plugins.registerHook', 'Plugins.hooks.register', Plugins.hooks.register);
|
||||||
|
Plugins.unregisterHook = _deprecate.bind(null, 'Plugins.unregisterHook', 'Plugins.hooks.unregister', Plugins.hooks.unregister);
|
||||||
|
Plugins.fireHook = _deprecate.bind(null, 'Plugins.fireHook', 'Plugins.hooks.fire', Plugins.hooks.fire);
|
||||||
|
Plugins.hasListeners = _deprecate.bind(null, 'Plugins.hasListeners', 'Plugins.hooks.hasListeners', Plugins.hooks.hasListeners);
|
||||||
// end
|
// end
|
||||||
|
|
||||||
Plugins.getPluginPaths = Plugins.data.getPluginPaths;
|
Plugins.getPluginPaths = Plugins.data.getPluginPaths;
|
||||||
|
|||||||
Reference in New Issue
Block a user