aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/plugins/plugin-index.ts2
-rw-r--r--server/lib/plugins/plugin-manager.ts13
-rw-r--r--server/lib/plugins/yarn.ts6
3 files changed, 13 insertions, 8 deletions
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts
index 6b7810618..25b4f3c61 100644
--- a/server/lib/plugins/plugin-index.ts
+++ b/server/lib/plugins/plugin-index.ts
@@ -21,7 +21,7 @@ async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList)
21 sort, 21 sort,
22 pluginType, 22 pluginType,
23 search, 23 search,
24 currentPeerTubeEngine: PEERTUBE_VERSION 24 currentPeerTubeEngine: options.currentPeerTubeEngine || PEERTUBE_VERSION
25 } 25 }
26 26
27 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins' 27 const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins'
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'
8import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants' 8import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants'
9import { PluginType } from '../../../shared/models/plugins/plugin.type' 9import { PluginType } from '../../../shared/models/plugins/plugin.type'
10import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' 10import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn'
11import { outputFile } from 'fs-extra' 11import { outputFile, readJSON } from 'fs-extra'
12import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model' 12import { RegisterSettingOptions } from '../../../shared/models/plugins/register-setting.model'
13import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model' 13import { RegisterHookOptions } from '../../../shared/models/plugins/register-hook.model'
14import { PluginSettingsManager } from '../../../shared/models/plugins/plugin-settings-manager.model' 14import { 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) {
diff --git a/server/lib/plugins/yarn.ts b/server/lib/plugins/yarn.ts
index 74c67653c..e40351b6e 100644
--- a/server/lib/plugins/yarn.ts
+++ b/server/lib/plugins/yarn.ts
@@ -13,7 +13,9 @@ async function installNpmPlugin (npmName: string, version?: string) {
13 let toInstall = npmName 13 let toInstall = npmName
14 if (version) toInstall += `@${version}` 14 if (version) toInstall += `@${version}`
15 15
16 await execYarn('add ' + toInstall) 16 const { stdout } = await execYarn('add ' + toInstall)
17
18 logger.debug('Added a yarn package.', { yarnStdout: stdout })
17} 19}
18 20
19async function installNpmPluginFromDisk (path: string) { 21async function installNpmPluginFromDisk (path: string) {
@@ -46,7 +48,7 @@ async function execYarn (command: string) {
46 await outputJSON(pluginPackageJSON, {}) 48 await outputJSON(pluginPackageJSON, {})
47 } 49 }
48 50
49 await execShell(`yarn ${command}`, { cwd: pluginDirectory }) 51 return execShell(`yarn ${command}`, { cwd: pluginDirectory })
50 } catch (result) { 52 } catch (result) {
51 logger.error('Cannot exec yarn.', { command, err: result.err, stderr: result.stderr }) 53 logger.error('Cannot exec yarn.', { command, err: result.err, stderr: result.stderr })
52 54