Skip to content

Commit

Permalink
throw exception if db plugins mismatch installed #8
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-steele committed Jun 25, 2024
1 parent 86aaf04 commit 8827337
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
9 changes: 8 additions & 1 deletion errors/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,12 @@
},
"description": "Plugin ${name}@${newVersion} already exists at a higher version (${existingVersion})",
"statusCode": 400
},
"CONTENTPLUGIN_VERSION_MISMATCH": {
"data": {
"registered": "Plugins that do not match their installed version"
},
"description": "The installed version of a plugin does not match the registered version",
"statusCode": 400
}
}
}
24 changes: 19 additions & 5 deletions lib/ContentPluginModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ class ContentPluginModule extends AbstractApiModule {
*/
this.framework = framework

const results = await Promise.allSettled([
this.initPlugins(),
this.processPluginSchemas()
])
results.forEach(r => r.result === 'rejected' && this.log('error', r.reason))
await this.initPlugins()

try {
await this.processPluginSchemas()
} catch (e) {
this.log('error', e)
}
}

/** @override */
Expand Down Expand Up @@ -147,6 +149,18 @@ class ContentPluginModule extends AbstractApiModule {
.filter(dbP => !installedPlugins.find(fwP => dbP.name === fwP.name))
.map(p => p.isLocalInstall ? path.join(this.getConfig('pluginDir'), p.name) : `${p.name}@${p.version}`)

const versionMismatches = dbPlugins
.filter(dbP => {
const fwP = installedPlugins.find(fwP => dbP.name === fwP.name)
return fwP._projectInfo.version !== dbP.version
})
.map(p => p.isLocalInstall ? path.join(this.getConfig('pluginDir'), p.name) : `${p.name}@${p.version}`)

if (versionMismatches.length) {
throw this.app.errors.CONTENTPLUGIN_VERSION_MISMATCH
.setData({registered: versionMismatches})
}

if (missingPlugins.length) { // use CLI directly, as plugins already exist in the DB
return AdaptCli.installPlugins({ ...this.cliArgs, plugins: missingPlugins })
}
Expand Down

0 comments on commit 8827337

Please sign in to comment.