import { ensureDir, outputFile, readJSON } from 'fs-extra'
import { basename, join } from 'path'
import { decachePlugin } from '@server/helpers/decache'
+import { ApplicationModel } from '@server/models/application/application'
import { MOAuthTokenUser, MUser } from '@server/types/models'
import { getCompleteLocale } from '@shared/core-utils'
-import { ClientScriptJSON, PluginPackageJSON, PluginTranslation, PluginTranslationPathsJSON, RegisterServerHookOptions } from '@shared/models'
+import {
+ ClientScriptJSON,
+ PluginPackageJSON,
+ PluginTranslation,
+ PluginTranslationPathsJSON,
+ RegisterServerHookOptions
+} from '@shared/models'
import { getHookType, internalRunHook } from '../../../shared/core-utils/plugins/hooks'
import { PluginType } from '../../../shared/models/plugins/plugin.type'
import { ServerHook, ServerHookName } from '../../../shared/models/plugins/server/server-hook.model'
import { PluginLibrary, RegisterServerAuthExternalOptions, RegisterServerAuthPassOptions, RegisterServerOptions } from '../../types/plugins'
import { ClientHtml } from '../client-html'
import { RegisterHelpers } from './register-helpers'
-import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn'
+import { installNpmPlugin, installNpmPluginFromDisk, rebuildNativePlugins, removeNpmPlugin } from './yarn'
export interface RegisteredPlugin {
npmName: string
for (const hook of this.hooks[hookName]) {
logger.debug('Running hook %s of plugin %s.', hookName, hook.npmName)
- result = await internalRunHook(hook.handler, hookType, result, params, err => {
- logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err })
+ result = await internalRunHook({
+ handler: hook.handler,
+ hookType,
+ result,
+ params,
+ onError: err => { logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err }) }
})
}
logger.info('Regenerating registered plugin CSS to global file.')
await this.regeneratePluginGlobalCSS()
}
+
+ ClientHtml.invalidCache()
}
// ###################### Installation ######################
logger.info('Plugin %s uninstalled.', npmName)
}
+ async rebuildNativePluginsIfNeeded () {
+ if (!await ApplicationModel.nodeABIChanged()) return
+
+ return rebuildNativePlugins()
+ }
+
// ###################### Private register ######################
private async registerPluginOrTheme (plugin: PluginModel) {
}
await this.addTranslations(plugin, npmName, packageJSON.translations)
+
+ ClientHtml.invalidCache()
}
private async registerPlugin (plugin: PluginModel, pluginPath: string, packageJSON: PluginPackageJSON) {
// ###################### CSS ######################
private resetCSSGlobalFile () {
- ClientHtml.invalidCache()
-
return outputFile(PLUGIN_GLOBAL_CSS_PATH, '')
}
for (const cssPath of cssRelativePaths) {
await this.concatFiles(join(pluginPath, cssPath), PLUGIN_GLOBAL_CSS_PATH)
}
-
- ClientHtml.invalidCache()
}
private concatFiles (input: string, output: string) {
if (!this.hooks[options.target]) this.hooks[options.target] = []
this.hooks[options.target].push({
- npmName: npmName,
+ npmName,
pluginName: plugin.name,
handler: options.handler,
priority: options.priority || 0