Skip to content

Commit

Permalink
Merge pull request #1834 from alphagov/fix-update-bug-on-test-plugins
Browse files Browse the repository at this point in the history
Fix upgrade bug on test plugins
  • Loading branch information
BenSurgisonGDS authored Dec 6, 2022
2 parents f02b939 + 832867b commit cf7e0c9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/routes/prototype-admin-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const appViews = extensions.getAppViews([
path.join(projectDir, 'app/views/')
])

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

const currentKitVersion = require(path.join(packageDir, 'package.json')).version
const knownPlugins = require(path.join(packageDir, 'known-plugins.json'))

Expand Down Expand Up @@ -312,13 +314,19 @@ router.get('/templates/post-install', (req, res) => {
const removeDuplicates = (val, index, arr) => !arr.includes(val, index + 1)

async function getPluginDetails () {
const pkg = fse.readJsonSync(pkgPath)
const installed = extensions.listInstalledExtensions()
const all = await Promise.all(installed.concat(knownPlugins.plugins.available)
.filter(removeDuplicates)
.map(async (packageName) => ({
packageName,
latestVersion: await lookupLatestPackageVersion(packageName)
}))
.map(async (packageName) => {
// Only those plugins not referenced locally can be looked up
const reference = pkg.dependencies[packageName] || ''
const canLookUp = !reference.startsWith('file:')
return {
packageName,
latestVersion: canLookUp && await lookupLatestPackageVersion(packageName)
}
})
.map(async (packageDetails) => {
const pack = await packageDetails
Object.assign(pack, extensions.preparePackageNameForDisplay(pack.packageName), {
Expand All @@ -334,7 +342,7 @@ async function getPluginDetails () {
}
} else {
}
if (pack.installedVersion && pack.installedVersion !== pack.latestVersion) {
if (pack.latestVersion && pack.installedVersion && pack.installedVersion !== pack.latestVersion) {
pack.upgradeLink = `${contextPath}/plugins/install?package=${encodeURIComponent(pack.packageName)}&mode=upgrade`
}
return pack
Expand Down

0 comments on commit cf7e0c9

Please sign in to comment.