@@ -7,7 +7,7 @@ import CodeInjector from './modules/codeInjector.js';
77import ExpressServer from './servers/express.js' ;
88import OpenApiRegistry from './servers/openapi.js' ;
99// import FastifyServer from './servers/fastify.js';
10- import { ADMINFORTH_VERSION , listify , suggestIfTypo , RateLimiter , RAMLock , getClientIp , isProbablyUUIDColumn , convertPeriodToSeconds , hookResponseError } from './modules/utils.js' ;
10+ import { ADMINFORTH_VERSION , listify , suggestIfTypo , RateLimiter , RAMLock , getClientIp , isProbablyUUIDColumn , convertPeriodToSeconds , hookResponseError , formatHugePluginError } from './modules/utils.js' ;
1111import {
1212 type AdminForthConfig ,
1313 type IAdminForth ,
@@ -237,13 +237,18 @@ class AdminForth implements IAdminForth {
237237 activatePlugins ( ) {
238238 afLogger . trace ( '🔌🔌🔌 Activating plugins' ) ;
239239 const allPluginInstances = [ ] ;
240+ const globalPlugins = this . config . globalPlugins || [ ] ;
240241 for ( let resource of this . config . resources ) {
241242 afLogger . trace ( `🔌 Checking plugins for resource: ${ resource . resourceId } ` ) ;
242243 for ( let pluginInstance of resource . plugins || [ ] ) {
243244 afLogger . trace ( `🔌 Found plugin: ${ pluginInstance . constructor . name } for resource ${ resource . resourceId } ` ) ;
245+ if ( pluginInstance . pluginsScope === 'global' ) {
246+ throw new Error ( formatHugePluginError ( `Move plugin ${ pluginInstance . constructor . name } to index.ts config.globalPlugins array` ) ) ;
247+ }
244248 allPluginInstances . push ( { pi : pluginInstance , resource} ) ;
245249 }
246250 }
251+ allPluginInstances . push ( ...globalPlugins . map ( ( pluginInstance ) => ( { pi : pluginInstance , resource : null } ) ) ) ;
247252 afLogger . trace ( `🔌 Total plugins to activate: ${ allPluginInstances . length } ` ) ;
248253
249254 let activationLoopCounter = 0 ;
@@ -272,8 +277,12 @@ class AdminForth implements IAdminForth {
272277 unactivatedPlugins . forEach (
273278 ( { pi : pluginInstance , resource} , index ) => {
274279 afLogger . trace ( `Activating plugin: ${ pluginInstance . constructor . name } ` ) ;
275- afLogger . trace ( `🔌 Activating plugin ${ index + 1 } /${ unactivatedPlugins . length } : ${ pluginInstance . constructor . name } for resource ${ resource . resourceId } ` ) ;
276- pluginInstance . modifyResourceConfig ( this , resource , allPluginInstances ) ;
280+ afLogger . trace ( `🔌 Activating plugin ${ index + 1 } /${ unactivatedPlugins . length } : ${ pluginInstance . constructor . name } for resource ${ resource ? resource . resourceId : 'global' } ` ) ;
281+ if ( pluginInstance . pluginsScope === 'global' ) {
282+ pluginInstance . modifyGlobalConfig ( this ) ;
283+ } else {
284+ pluginInstance . modifyResourceConfig ( this , resource , allPluginInstances ) ;
285+ }
277286 afLogger . trace ( `🔌 Plugin ${ pluginInstance . constructor . name } modifyResourceConfig completed` ) ;
278287
279288 const plugin = this . activatedPlugins . find ( ( p ) => p . pluginInstanceId === pluginInstance . pluginInstanceId ) ;
0 commit comments