Fix plugin unregister: unload all modules.

This commit is contained in:
John Livingston
2021-04-08 03:47:55 +02:00
parent 490d6f18c3
commit 0bad31dddb
3 changed files with 26 additions and 0 deletions

View File

@ -1,5 +1,9 @@
import { initSettings } from './lib/settings'
import { initRouters } from './lib/routers'
import type { Logger } from 'winston'
const decache = require('decache')
let logger: Logger | undefined
async function register ({
registerSetting,
@ -7,6 +11,8 @@ async function register ({
getRouter,
peertubeHelpers
}: RegisterServerOptions): Promise<any> {
logger = peertubeHelpers.logger
await initSettings({ registerSetting })
await initRouters({
settingsManager,
@ -16,6 +22,10 @@ async function register ({
}
async function unregister (): Promise<any> {
const module = __filename
logger?.info(`Unloading module ${module}...`)
decache(module)
logger?.info(`Successfully unloaded the module ${module}`)
}
module.exports = {