diff --git a/CHANGELOG.md b/CHANGELOG.md index fc3a00cc78..c24cd35868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ - [#2150: Prevent CSURF deprecated warning](https://github.com/alphagov/govuk-prototype-kit/pull/2150) - [#2130: Create our own file store functionality in place of the session-file-store package](https://github.com/alphagov/govuk-prototype-kit/pull/2130) +- +- [#2172: Hiding govuk-frontend uninstall until we deal with dependent plugins](https://github.com/alphagov/govuk-prototype-kit/pull/2172) ## 13.6.2 diff --git a/cypress/e2e/plugins/2-prototype-kit-plugin-tests/remove-govuk-frontend.cypress.js b/cypress/e2e/plugins/2-prototype-kit-plugin-tests/remove-govuk-frontend.cypress.js index d76b62f060..812aa9162a 100644 --- a/cypress/e2e/plugins/2-prototype-kit-plugin-tests/remove-govuk-frontend.cypress.js +++ b/cypress/e2e/plugins/2-prototype-kit-plugin-tests/remove-govuk-frontend.cypress.js @@ -1,11 +1,20 @@ const { managePluginsPagePath, performPluginAction } = require('../plugin-utils') const { uninstallPlugin, installPlugin } = require('../../utils') +const path = require('path') const plugin = 'govuk-frontend' const pluginName = 'GOV.UK Frontend' const dependentPlugin = '@govuk-prototype-kit/common-templates' +const appConfigPath = path.join('app', 'config.json') describe('Manage prototype pages without govuk-frontend', () => { + before(() => { + cy.task('copyFromStarterFiles', { filename: appConfigPath }) + cy.task('addToConfigJson', { allowGovukFrontendUninstall: true }) + }) + after(() => { + cy.task('copyFromStarterFiles', { filename: appConfigPath }) + }) it('Uninstall govuk-frontend', () => { uninstallPlugin(dependentPlugin) diff --git a/cypress/events/index.js b/cypress/events/index.js index c4b106c590..4af13a6197 100644 --- a/cypress/events/index.js +++ b/cypress/events/index.js @@ -13,6 +13,7 @@ // core dependencies const fs = require('fs') const fsp = fs.promises +const fse = require('fs-extra') const path = require('path') // npm dependencies @@ -283,6 +284,15 @@ module.exports = function setupNodeEvents (on, config) { .then(makeSureCypressCanInterpretTheResult) }, + addToConfigJson: (additionalConfig) => { + log(`Adding config JSON => ${downloadsFolder}`) + const appConfigPath = path.join(config.env.projectFolder, 'app', 'config.json') + return fse.readJson(appConfigPath) + .then(existingConfig => Object.assign({}, existingConfig, additionalConfig)) + .then(newConfig => fse.writeJson(appConfigPath, newConfig)) + .then(makeSureCypressCanInterpretTheResult) + }, + log: (message) => { log(message) return makeSureCypressCanInterpretTheResult() diff --git a/lib/config.js b/lib/config.js index 6995e05b5f..5f7a1169f1 100644 --- a/lib/config.js +++ b/lib/config.js @@ -95,6 +95,7 @@ function getConfig (config, swallowError = true) { overrideOrDefault('logPerformanceSummary', 'LOG_PERFORMANCE_SUMMARY', asNumber, undefined) overrideOrDefault('verbose', 'VERBOSE', asBoolean, false) overrideOrDefault('showPrereleases', 'SHOW_PRERELEASES', asBoolean, false) + overrideOrDefault('allowGovukFrontendUninstall', 'ALLOW_GOVUK_FRONTEND_UNINSTALL', asBoolean, false) if (config.serviceName === undefined) { config.serviceName = 'GOV.UK Prototype Kit' diff --git a/lib/config.test.js b/lib/config.test.js index eb9385572e..d7f13e8099 100644 --- a/lib/config.test.js +++ b/lib/config.test.js @@ -33,6 +33,7 @@ describe('config', () => { useNjkExtensions: false, logPerformance: false, showPrereleases: false, + allowGovukFrontendUninstall: false, verbose: false }) diff --git a/lib/manage-prototype-handlers.js b/lib/manage-prototype-handlers.js index b47a5d8b87..2c27dcd23c 100644 --- a/lib/manage-prototype-handlers.js +++ b/lib/manage-prototype-handlers.js @@ -450,7 +450,11 @@ async function getPluginDetails () { const pluginPkgPath = path.join(projectDir, 'node_modules', pack.packageName, 'package.json') const pluginPkg = await fse.pathExists(pluginPkgPath) ? await fse.readJson(pluginPkgPath) : {} pack.installedVersion = pluginPkg.version - if (!['govuk-prototype-kit'].includes(pack.packageName)) { + const mandatoryPlugins = ['govuk-prototype-kit'] + if (!config.getConfig().allowGovukFrontendUninstall) { + mandatoryPlugins.push('govuk-frontend') + } + if (!mandatoryPlugins.includes(pack.packageName)) { pack.uninstallLink = `${contextPath}/plugins/uninstall?package=${encodeURIComponent(pack.packageName)}` } }