From 085bc8cbb3160b392c3f67c69c4851868818b6e2 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 10 Nov 2021 17:34:09 -0500 Subject: [PATCH] plugins: Don't create `.ep_initialized` files These files cause problems with Docker images and read-only directories/mounts, and they have dubious value (any install-time setup should instead be done at startup). --- .gitignore | 1 - CHANGELOG.md | 2 ++ doc/api/hooks_server-side.md | 9 +++++---- src/bin/plugins/lib/gitignore | 2 -- src/static/js/pluginfw/plugins.js | 15 +-------------- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 09618cc83..60638c50a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ var/dirty.db *.patch npm-debug.log *.DS_Store -.ep_initialized *.crt *.key credentials.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 450a2d8c1..5ce91f39d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ for an example fix. * The `clientReady` server-side hook is deprecated; use the new `userJoin` hook instead. + * The `init_` server-side hooks are now run every time Etherpad + starts up, not just the first time after the named plugin is installed. * The `userLeave` server-side hook's context properties have changed: * `auth`: Deprecated. * `author`: Deprecated; use the new `authorId` property instead. diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index c99ea58aa..5e8832fd4 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -50,12 +50,13 @@ Things in context: If this hook returns an error, the callback to the install function gets an error, too. This seems useful for adding in features when a particular plugin is installed. -## init_`` -Called from: src/static/js/pluginfw/plugins.js +## `init_` -Things in context: None +Called from: `src/static/js/pluginfw/plugins.js` -This function is called after a specific plugin is initialized. This would probably be more useful than the previous two functions if you only wanted to add in features to one specific plugin. +Run during startup after the named plugin is initialized. + +Context properties: None ## expressConfigure Called from: src/node/hooks/express.js diff --git a/src/bin/plugins/lib/gitignore b/src/bin/plugins/lib/gitignore index 0719a85c1..153216eb9 100755 --- a/src/bin/plugins/lib/gitignore +++ b/src/bin/plugins/lib/gitignore @@ -1,5 +1,3 @@ -.ep_initialized .DS_Store node_modules/ -node_modules npm-debug.log diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 74fbbafc8..a4a2df40d 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -72,19 +72,6 @@ exports.formatHooks = (hookSetName, html) => { return lines.join('\n'); }; -const callInit = async () => { - await Promise.all(Object.keys(defs.plugins).map(async (pluginName) => { - const plugin = defs.plugins[pluginName]; - const epInit = path.join(plugin.package.path, '.ep_initialized'); - try { - await fs.stat(epInit); - } catch (err) { - await fs.writeFile(epInit, 'done'); - await hooks.aCallAll(`init_${pluginName}`, {}); - } - })); -}; - exports.pathNormalization = (part, hookFnName, hookName) => { const tmp = hookFnName.split(':'); // hookFnName might be something like 'C:\\foo.js:myFunc'. // If there is a single colon assume it's 'filename:funcname' not 'C:\\filename'. @@ -111,7 +98,7 @@ exports.update = async () => { defs.parts = sortParts(parts); defs.hooks = pluginUtils.extractHooks(defs.parts, 'hooks', exports.pathNormalization); defs.loaded = true; - await callInit(); + await Promise.all(Object.keys(defs.plugins).map((p) => hooks.aCallAll(`init_${p}`, {}))); }; exports.getPackages = async () => {