Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: throw exception if db plugins mismatch installed (fixes #8) #10

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading