diff --git a/lib/manage-prototype-handlers.js b/lib/manage-prototype-handlers.js index 0aa7d2b7fa..154aca3ef7 100644 --- a/lib/manage-prototype-handlers.js +++ b/lib/manage-prototype-handlers.js @@ -119,7 +119,7 @@ function postPasswordHandler (req, res) { } } -function managePluginsMiddleware (req, res, next) { +function managePrototypeMiddleware (req, res, next) { const { scripts: frontEndScripts } = getScriptsAndAssetsConfig(getInternalGovukFrontendDir()) const { scripts: kitScripts } = getScriptsAndAssetsConfig(packageDir) res.locals.managePlugins = { @@ -744,7 +744,7 @@ async function postPluginsModeHandler (req, res) { module.exports = { contextPath, - managePluginsMiddleware, + managePrototypeMiddleware, setKitRestarted, csrfProtection: [doubleCsrfProtection, csrfErrorHandler], getPageLoadedHandler, diff --git a/lib/manage-prototype-routes.js b/lib/manage-prototype-routes.js index 24d2ecc2d1..ff4b52ad39 100644 --- a/lib/manage-prototype-routes.js +++ b/lib/manage-prototype-routes.js @@ -6,7 +6,7 @@ const express = require('express') const { contextPath, - managePluginsMiddleware, + managePrototypeMiddleware, setKitRestarted, csrfProtection, getPageLoadedHandler, @@ -36,7 +36,7 @@ const { govukFrontendPaths } = require('./govukFrontendPaths') const router = require('../index').requests.setupRouter(contextPath) -router.use(managePluginsMiddleware) +router.use(managePrototypeMiddleware) function getAssetUrls (pluginDir) { const { scripts, assets } = getScriptsAndAssetsConfig(pluginDir) diff --git a/lib/utils/index.js b/lib/utils/index.js index ca3f4f6456..77239d9530 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -253,7 +253,12 @@ async function searchAndReplaceFiles (dir, searchText, replaceText, extensions) return modifiedFiles.flat().filter(Boolean) } +const managePrototypeCache = {} + function getScriptsAndAssetsConfig (pluginDir) { + if (managePrototypeCache[pluginDir]) { + return managePrototypeCache[pluginDir] + } let { assets = [], scripts = [] @@ -267,7 +272,8 @@ function getScriptsAndAssetsConfig (pluginDir) { scripts = [scripts] } - return { assets, scripts } + managePrototypeCache[pluginDir] = { assets, scripts } + return managePrototypeCache[pluginDir] } function sortByObjectKey (key) {