diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 26c18995a..7c8426cc3 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -1,15 +1,113 @@ 'use strict'; -const fs = require('fs').promises; const minify = require('../../utils/Minify'); -const path = require('path'); const plugins = require('../../../static/js/pluginfw/plugin_defs'); const settings = require('../../utils/Settings'); const CachingMiddleware = require('../../utils/caching_middleware'); const Yajsml = require('etherpad-yajsml'); -// Rewrite tar to include modules with no extensions and proper rooted paths. -const getTar = async () => { +const tar = (() => { + const associations = { + 'pad.js': [ + 'pad.js', + 'pad_utils.js', + '$js-cookie/dist/js.cookie.js', + 'security.js', + '$security.js', + 'vendors/browser.js', + 'pad_cookie.js', + 'pad_editor.js', + 'pad_editbar.js', + 'vendors/nice-select.js', + 'pad_modals.js', + 'pad_automatic_reconnect.js', + 'ace.js', + 'collab_client.js', + 'cssmanager.js', + 'pad_userlist.js', + 'pad_impexp.js', + 'pad_savedrevs.js', + 'pad_connectionstatus.js', + 'ChatMessage.js', + 'chat.js', + 'vendors/gritter.js', + '$js-cookie/dist/js.cookie.js', + '$tinycon/tinycon.js', + 'vendors/farbtastic.js', + 'skin_variants.js', + 'socketio.js', + 'colorutils.js', + ], + 'timeslider.js': [ + 'timeslider.js', + 'colorutils.js', + 'draggable.js', + 'pad_utils.js', + '$js-cookie/dist/js.cookie.js', + 'vendors/browser.js', + 'pad_cookie.js', + 'pad_editor.js', + 'pad_editbar.js', + 'vendors/nice-select.js', + 'pad_modals.js', + 'pad_automatic_reconnect.js', + 'pad_savedrevs.js', + 'pad_impexp.js', + 'AttributePool.js', + 'Changeset.js', + 'domline.js', + 'linestylefilter.js', + 'cssmanager.js', + 'broadcast.js', + 'broadcast_slider.js', + 'broadcast_revisions.js', + 'socketio.js', + 'AttributeManager.js', + 'AttributeMap.js', + 'attributes.js', + 'ChangesetUtils.js', + ], + 'ace2_inner.js': [ + 'ace2_inner.js', + 'vendors/browser.js', + 'AttributePool.js', + 'Changeset.js', + 'ChangesetUtils.js', + 'skiplist.js', + 'colorutils.js', + 'undomodule.js', + '$unorm/lib/unorm.js', + 'contentcollector.js', + 'changesettracker.js', + 'linestylefilter.js', + 'domline.js', + 'AttributeManager.js', + 'AttributeMap.js', + 'attributes.js', + 'scroll.js', + 'caretPosition.js', + 'pad_utils.js', + '$js-cookie/dist/js.cookie.js', + 'security.js', + '$security.js', + ], + 'ace2_common.js': [ + 'ace2_common.js', + 'vendors/browser.js', + 'vendors/jquery.js', + 'rjquery.js', + '$async.js', + 'underscore.js', + '$underscore.js', + '$underscore/underscore.js', + 'security.js', + '$security.js', + 'pluginfw/client_plugins.js', + 'pluginfw/plugin_defs.js', + 'pluginfw/shared.js', + 'pluginfw/hooks.js', + ], + }; const prefixLocalLibraryPath = (path) => { if (path.charAt(0) === '$') { return path.slice(1); @@ -17,16 +115,15 @@ const getTar = async () => { return `ep_etherpad-lite/static/js/${path}`; } }; - const tarJson = await fs.readFile(path.join(settings.root, 'src/node/utils/tar.json'), 'utf8'); const tar = {}; - for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson))) { + for (const [key, relativeFiles] of Object.entries(associations)) { const files = relativeFiles.map(prefixLocalLibraryPath); tar[prefixLocalLibraryPath(key)] = files .concat(files.map((p) => p.replace(/\.js$/, ''))) .concat(files.map((p) => `${p.replace(/\.js$/, '')}/index.js`)); } return tar; -}; +})(); exports.expressPreSession = async (hookName, {app}) => { // Cache both minified and static. @@ -49,7 +146,7 @@ exports.expressPreSession = async (hookName, {app}) => { }); const StaticAssociator = Yajsml.associators.StaticAssociator; - const associations = Yajsml.associators.associationsForSimpleMapping(await getTar()); + const associations = Yajsml.associators.associationsForSimpleMapping(tar); const associator = new StaticAssociator(associations); jsServer.setAssociator(associator); diff --git a/src/node/utils/tar.json b/src/node/utils/tar.json deleted file mode 100644 index 08ae93f6b..000000000 --- a/src/node/utils/tar.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "pad.js": [ - "pad.js" - , "pad_utils.js" - , "$js-cookie/dist/js.cookie.js" - , "security.js" - , "$security.js" - , "vendors/browser.js" - , "pad_cookie.js" - , "pad_editor.js" - , "pad_editbar.js" - , "vendors/nice-select.js" - , "pad_modals.js" - , "pad_automatic_reconnect.js" - , "ace.js" - , "collab_client.js" - , "cssmanager.js" - , "pad_userlist.js" - , "pad_impexp.js" - , "pad_savedrevs.js" - , "pad_connectionstatus.js" - , "ChatMessage.js" - , "chat.js" - , "vendors/gritter.js" - , "$js-cookie/dist/js.cookie.js" - , "$tinycon/tinycon.js" - , "vendors/farbtastic.js" - , "skin_variants.js" - , "socketio.js" - , "colorutils.js" - ] -, "timeslider.js": [ - "timeslider.js" - , "colorutils.js" - , "draggable.js" - , "pad_utils.js" - , "$js-cookie/dist/js.cookie.js" - , "vendors/browser.js" - , "pad_cookie.js" - , "pad_editor.js" - , "pad_editbar.js" - , "vendors/nice-select.js" - , "pad_modals.js" - , "pad_automatic_reconnect.js" - , "pad_savedrevs.js" - , "pad_impexp.js" - , "AttributePool.js" - , "Changeset.js" - , "domline.js" - , "linestylefilter.js" - , "cssmanager.js" - , "broadcast.js" - , "broadcast_slider.js" - , "broadcast_revisions.js" - , "socketio.js" - , "AttributeManager.js" - , "AttributeMap.js" - , "attributes.js" - , "ChangesetUtils.js" - ] -, "ace2_inner.js": [ - "ace2_inner.js" - , "vendors/browser.js" - , "AttributePool.js" - , "Changeset.js" - , "ChangesetUtils.js" - , "skiplist.js" - , "colorutils.js" - , "undomodule.js" - , "$unorm/lib/unorm.js" - , "contentcollector.js" - , "changesettracker.js" - , "linestylefilter.js" - , "domline.js" - , "AttributeManager.js" - , "AttributeMap.js" - , "attributes.js" - , "scroll.js" - , "caretPosition.js" - , "pad_utils.js" - , "$js-cookie/dist/js.cookie.js" - , "security.js" - , "$security.js" - ] -, "ace2_common.js": [ - "ace2_common.js" - , "vendors/browser.js" - , "vendors/jquery.js" - , "rjquery.js" - , "$async.js" - , "underscore.js" - , "$underscore.js" - , "$underscore/underscore.js" - , "security.js" - , "$security.js" - , "pluginfw/client_plugins.js" - , "pluginfw/plugin_defs.js" - , "pluginfw/shared.js" - , "pluginfw/hooks.js" - ] -} diff --git a/src/tests/backend/specs/caching_middleware.js b/src/tests/backend/specs/caching_middleware.js index ebfd65d9f..34e5585bd 100644 --- a/src/tests/backend/specs/caching_middleware.js +++ b/src/tests/backend/specs/caching_middleware.js @@ -1,9 +1,8 @@ 'use strict'; /** - * caching_middleware is responsible for serving everything under path `/javascripts/` - * That includes packages as defined in `src/node/utils/tar.json` and probably also plugin code - * + * caching_middleware is responsible for serving everything under path `/javascripts/`. That + * includes packages as defined in `src/node/hooks/express/static.js` and probably also plugin code. */ const common = require('../common');