-import decache from 'decache'
-import * as express from 'express'
+import express from 'express'
import { createReadStream, createWriteStream } from 'fs'
import { ensureDir, outputFile, readJSON } from 'fs-extra'
import { basename, join } from 'path'
+import { decachePlugin } from '@server/helpers/decache'
import { MOAuthTokenUser, MUser } from '@server/types/models'
import { getCompleteLocale } from '@shared/core-utils'
import { ClientScript, PluginPackageJson, PluginTranslation, PluginTranslationPaths, RegisterServerHookOptions } from '@shared/models'
uninstalled: false,
peertubeEngine: packageJSON.engine.peertube
}, { returning: true })
- } catch (err) {
- logger.error('Cannot install plugin %s, removing it...', toInstall, { err })
+
+ logger.info('Successful installation of plugin %s.', toInstall)
+
+ await this.registerPluginOrTheme(plugin)
+ } catch (rootErr) {
+ logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr })
try {
- await removeNpmPlugin(npmName)
+ await this.uninstall(npmName)
} catch (err) {
- logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err })
+ logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err })
+
+ try {
+ await removeNpmPlugin(npmName)
+ } catch (err) {
+ logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err })
+ }
}
- throw err
+ throw rootErr
}
- logger.info('Successful installation of plugin %s.', toInstall)
-
- await this.registerPluginOrTheme(plugin)
-
return plugin
}
// Delete cache if needed
const modulePath = join(pluginPath, packageJSON.library)
- decache(modulePath)
+ decachePlugin(pluginPath, modulePath)
const library: PluginLibrary = require(modulePath)
if (!isLibraryCodeValid(library)) {
await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath())
- library.register(registerOptions)
- .catch(err => logger.error('Cannot register plugin %s.', npmName, { err }))
+ await library.register(registerOptions)
logger.info('Add plugin %s CSS to global file.', npmName)