aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/plugins')
-rw-r--r--server/lib/plugins/plugin-manager.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 444162a03..8127992b5 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -222,9 +222,8 @@ export class PluginManager implements ServerHook {
222 const pluginName = PluginModel.normalizePluginName(npmName) 222 const pluginName = PluginModel.normalizePluginName(npmName)
223 223
224 const packageJSON = await this.getPackageJSON(pluginName, pluginType) 224 const packageJSON = await this.getPackageJSON(pluginName, pluginType)
225 if (!isPackageJSONValid(packageJSON, pluginType)) { 225
226 throw new Error('PackageJSON is invalid.') 226 this.sanitizeAndCheckPackageJSONOrThrow(packageJSON, pluginType);
227 }
228 227
229 [ plugin ] = await PluginModel.upsert({ 228 [ plugin ] = await PluginModel.upsert({
230 name: pluginName, 229 name: pluginName,
@@ -301,9 +300,7 @@ export class PluginManager implements ServerHook {
301 const packageJSON = await this.getPackageJSON(plugin.name, plugin.type) 300 const packageJSON = await this.getPackageJSON(plugin.name, plugin.type)
302 const pluginPath = this.getPluginPath(plugin.name, plugin.type) 301 const pluginPath = this.getPluginPath(plugin.name, plugin.type)
303 302
304 if (!isPackageJSONValid(packageJSON, plugin.type)) { 303 this.sanitizeAndCheckPackageJSONOrThrow(packageJSON, plugin.type)
305 throw new Error('Package.JSON is invalid.')
306 }
307 304
308 let library: PluginLibrary 305 let library: PluginLibrary
309 if (plugin.type === PluginType.PLUGIN) { 306 if (plugin.type === PluginType.PLUGIN) {
@@ -598,6 +595,21 @@ export class PluginManager implements ServerHook {
598 } 595 }
599 } 596 }
600 597
598 private sanitizeAndCheckPackageJSONOrThrow (packageJSON: PluginPackageJson, pluginType: PluginType) {
599 if (!packageJSON.staticDirs) packageJSON.staticDirs = {}
600 if (!packageJSON.css) packageJSON.css = []
601 if (!packageJSON.clientScripts) packageJSON.clientScripts = []
602 if (!packageJSON.translations) packageJSON.translations = {}
603
604 const { result: packageJSONValid, badFields } = isPackageJSONValid(packageJSON, pluginType)
605 if (!packageJSONValid) {
606 const formattedFields = badFields.map(f => `"${f}"`)
607 .join(', ')
608
609 throw new Error(`PackageJSON is invalid (invalid fields: ${formattedFields}).`)
610 }
611 }
612
601 static get Instance () { 613 static get Instance () {
602 return this.instance || (this.instance = new this()) 614 return this.instance || (this.instance = new this())
603 } 615 }