plugin.module.ts 903 B

1234567891011121314151617181920212223
  1. import { Module } from '@nestjs/common';
  2. import { notNullOrUndefined } from '../../../shared/shared-utils';
  3. import { getConfig } from '../config/config-helpers';
  4. import { ConfigModule } from '../config/config.module';
  5. import { EventBusModule } from '../event-bus/event-bus.module';
  6. import { ServiceModule } from '../service/service.module';
  7. const pluginProviders = getConfig()
  8. .plugins.map(p => (p.defineProviders ? p.defineProviders() : undefined))
  9. .filter(notNullOrUndefined)
  10. .reduce((flattened, providers) => flattened.concat(providers), []);
  11. /**
  12. * This module collects and re-exports all providers defined in plugins so that they can be used in other
  13. * modules (e.g. providing customer resolvers to the ApiModule)
  14. */
  15. @Module({
  16. imports: [ServiceModule, EventBusModule, ConfigModule],
  17. providers: pluginProviders,
  18. exports: pluginProviders,
  19. })
  20. export class PluginModule {}