Skip to content

Commit

Permalink
add mandatory plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Jun 15, 2023
1 parent 81f36d3 commit d979b06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions known-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"hmrc-frontend",
"jquery",
"notifications-node-client"
],
"mandatory": [
"govuk-prototype-kit",
"govuk-frontend"
]
}
}
7 changes: 4 additions & 3 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ function buildPluginData (data) {
name: packageName,
installed,
installedLocally,
latestVersion
latestVersion,
mandatory
} = pluginData
const { version: installedVersion } = installed ? pluginData.packageJson : {}
const { name } = plugins.preparePackageNameForDisplay(packageName)
Expand All @@ -477,9 +478,9 @@ function buildPluginData (data) {
name,
installLink: `${contextPath}/plugins/install?package=${encodeURIComponent(packageName)}`,
installCommand: `npm install ${packageName}`,
upgradeLink: installed && !installedLocally && latestVersion !== installedVersion ? `${contextPath}/plugins/uninstall?package=${encodeURIComponent(packageName)}` : undefined,
upgradeLink: installed && !installedLocally && latestVersion !== installedVersion ? `${contextPath}/plugins/upgrade?package=${encodeURIComponent(packageName)}` : undefined,
upgradeCommand: latestVersion && `npm install ${packageName}@${latestVersion}`,
uninstallLink: installed ? `${contextPath}/plugins/uninstall?package=${encodeURIComponent(packageName)}` : undefined,
uninstallLink: installed && !mandatory ? `${contextPath}/plugins/uninstall?package=${encodeURIComponent(packageName)}` : undefined,
uninstallCommand: `npm uninstall ${packageName}`,
installedVersion
}
Expand Down
25 changes: 13 additions & 12 deletions lib/utils/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ const { packageDir, projectDir } = require('../utils/paths')
const { requestHttpsJson } = require('../utils/requestHttps')
const { verboseLog } = require('./verboseLogger')
const knownPlugins = require(path.join(packageDir, 'known-plugins.json'))
const projectPackage = require(path.join(projectDir, 'package.json'))
const config = require('../config')

let packageTrackerInterval

const pkgPath = path.join(projectDir, 'package.json')

const packagesInfo = {}

// This allows npm modules to act as if they are plugins by providing the plugin config for them
Expand All @@ -33,13 +32,9 @@ function startPackageTracker () {
}

async function updatePackagesInfo () {
const packages = await fse.readJson(pkgPath)
const availablePlugins = knownPlugins?.plugins?.available || []
const packagesRequired = [...availablePlugins, ...Object.keys(packages.dependencies)]
packagesRequired.map(async (packageName) => {
const installedVersion = packages.dependencies[packageName]
refreshPackageInfo(packageName, installedVersion)
})
const packagesRequired = [...availablePlugins, ...Object.keys(projectPackage.dependencies)]
packagesRequired.map(async (packageName) => refreshPackageInfo(packageName))
}

async function readJson (filename) {
Expand All @@ -61,10 +56,14 @@ async function requestRegistryInfo (packageName) {
}
}

async function refreshPackageInfo (packageName, installedVersion) {
async function refreshPackageInfo (packageName) {
const packageDir = path.join(projectDir, 'node_modules', packageName)
const pluginConfigFile = path.join(packageDir, 'govuk-prototype-kit.config.json')

const mandatoryPlugins = knownPlugins?.plugins?.mandatory || []

const mandatory = (!(packageName === 'govuk-frontend' && config.getConfig().allowGovukFrontendUninstall)) && mandatoryPlugins.includes(packageName)

let [
packageJson,
pluginConfig,
Expand All @@ -77,7 +76,10 @@ async function refreshPackageInfo (packageName, installedVersion) {

const latestVersion = registryInfo ? registryInfo['dist-tags']?.latest : undefined

const installed = !!packageJson
const installedVersion = projectPackage.dependencies[packageName]
const installed = !!installedVersion
const installedLocally = installedVersion?.startsWith('file:')

if (!installed) {
// Retrieve the packageJson and pluginConfig from the registry if possible
if (registryInfo) {
Expand All @@ -92,15 +94,14 @@ async function refreshPackageInfo (packageName, installedVersion) {
pluginConfig = proxyPluginConfig[packageName]
}

const installedLocally = installedVersion?.startsWith('file:')

packagesInfo[packageName] = {
...registryInfo,
name: packageName,
installed,
installedVersion,
installedLocally,
available,
mandatory,
latestVersion,
packageJson,
pluginConfig
Expand Down

0 comments on commit d979b06

Please sign in to comment.