mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
pluginfw: Always include the function name in hook_fn_name
Plugin authors are allowed to omit the function name in the `ep.json` parts definition. For example: ``` { "parts": [ { "name": "ep_example", "hooks": { "authenticate": "ep_example", "authFailure": "ep_example" } } ] } ``` If omitted, the function name is assumed to be the same as the hook name. Before this change, `hook_fn_name` for the example hooks would both be `/opt/etherpad-lite/node_modules/ep_example`. Now they are suffixed with `:authenticate` and `:authFailure`. This improves logging, and it makes it possible to use `hook_fn_name` to uniquely identify a particular hook function.
This commit is contained in:
parent
6f3e7d14f6
commit
442fe1e86f
2 changed files with 7 additions and 3 deletions
|
@ -72,8 +72,12 @@ exports.callInit = function () {
|
|||
return Promise.all(p);
|
||||
}
|
||||
|
||||
exports.pathNormalization = function (part, hook_fn_name) {
|
||||
return path.normalize(path.join(path.dirname(exports.plugins[part.plugin].package.path), hook_fn_name));
|
||||
exports.pathNormalization = function (part, hook_fn_name, hook_name) {
|
||||
const parts = hook_fn_name.split(':');
|
||||
const functionName = (parts.length > 1) ? parts.pop() : hook_name;
|
||||
const packageDir = path.dirname(exports.plugins[part.plugin].package.path);
|
||||
const fileName = path.normalize(path.join(packageDir, parts.join(':')));
|
||||
return fileName + ((functionName == null) ? '' : (':' + functionName));
|
||||
}
|
||||
|
||||
exports.update = async function () {
|
||||
|
|
|
@ -39,7 +39,7 @@ function extractHooks(parts, hook_set_name, normalizer) {
|
|||
* a dependency of another plugin! Bah, pesky little details of
|
||||
* npm... */
|
||||
if (normalizer) {
|
||||
hook_fn_name = normalizer(part, hook_fn_name);
|
||||
hook_fn_name = normalizer(part, hook_fn_name, hook_name);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue