diff options
Diffstat (limited to 'server/lib/plugins/plugin-manager.ts')
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index ac31b06dc..9afda97ea 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -8,7 +8,7 @@ import { createReadStream, createWriteStream } from 'fs' | |||
8 | import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants' | 8 | import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants' |
9 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 9 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
10 | import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' | 10 | import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' |
11 | import { outputFile } from 'fs-extra' | 11 | import { outputFile, readJSON } from 'fs-extra' |
12 | import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' | 12 | import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' |
13 | import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' | 13 | import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' |
14 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' | 14 | import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' |
@@ -174,7 +174,7 @@ export class PluginManager implements ServerHook { | |||
174 | const pluginType = PluginModel.getTypeFromNpmName(npmName) | 174 | const pluginType = PluginModel.getTypeFromNpmName(npmName) |
175 | const pluginName = PluginModel.normalizePluginName(npmName) | 175 | const pluginName = PluginModel.normalizePluginName(npmName) |
176 | 176 | ||
177 | const packageJSON = this.getPackageJSON(pluginName, pluginType) | 177 | const packageJSON = await this.getPackageJSON(pluginName, pluginType) |
178 | if (!isPackageJSONValid(packageJSON, pluginType)) { | 178 | if (!isPackageJSONValid(packageJSON, pluginType)) { |
179 | throw new Error('PackageJSON is invalid.') | 179 | throw new Error('PackageJSON is invalid.') |
180 | } | 180 | } |
@@ -251,7 +251,7 @@ export class PluginManager implements ServerHook { | |||
251 | 251 | ||
252 | logger.info('Registering plugin or theme %s.', npmName) | 252 | logger.info('Registering plugin or theme %s.', npmName) |
253 | 253 | ||
254 | const packageJSON = this.getPackageJSON(plugin.name, plugin.type) | 254 | const packageJSON = await this.getPackageJSON(plugin.name, plugin.type) |
255 | const pluginPath = this.getPluginPath(plugin.name, plugin.type) | 255 | const pluginPath = this.getPluginPath(plugin.name, plugin.type) |
256 | 256 | ||
257 | if (!isPackageJSONValid(packageJSON, plugin.type)) { | 257 | if (!isPackageJSONValid(packageJSON, plugin.type)) { |
@@ -286,7 +286,10 @@ export class PluginManager implements ServerHook { | |||
286 | private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJson) { | 286 | private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJson) { |
287 | const npmName = PluginModel.buildNpmName(plugin.name, plugin.type) | 287 | const npmName = PluginModel.buildNpmName(plugin.name, plugin.type) |
288 | 288 | ||
289 | const library: PluginLibrary = require(join(pluginPath, packageJSON.library)) | 289 | // Delete cache if needed |
290 | const modulePath = join(pluginPath, packageJSON.library) | ||
291 | delete require.cache[modulePath] | ||
292 | const library: PluginLibrary = require(modulePath) | ||
290 | 293 | ||
291 | if (!isLibraryCodeValid(library)) { | 294 | if (!isLibraryCodeValid(library)) { |
292 | throw new Error('Library code is not valid (miss register or unregister function)') | 295 | throw new Error('Library code is not valid (miss register or unregister function)') |
@@ -350,7 +353,7 @@ export class PluginManager implements ServerHook { | |||
350 | private getPackageJSON (pluginName: string, pluginType: PluginType) { | 353 | private getPackageJSON (pluginName: string, pluginType: PluginType) { |
351 | const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json') | 354 | const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json') |
352 | 355 | ||
353 | return require(pluginPath) as PluginPackageJson | 356 | return readJSON(pluginPath) as Promise<PluginPackageJson> |
354 | } | 357 | } |
355 | 358 | ||
356 | private getPluginPath (pluginName: string, pluginType: PluginType) { | 359 | private getPluginPath (pluginName: string, pluginType: PluginType) { |