Files
backstage/plugins/events-node
Johan Persson e70ff47db3 chore: migrate three packages to MSW v2
Migrates test files in config-loader, events-node and kubernetes-react
packages from MSW 1.x to MSW 2.x API to fix compatibility issues with
Jest 30 and JSDOM v26.

Changes:
- Updated msw dependency from ^1.0.0 to ^2.0.0
- Changed imports from `rest` to `http` and `HttpResponse`
- Converted handler syntax from `res(ctx.*)` to `HttpResponse.*`
- Changed `toStrictEqual` to `toEqual` for response assertions

Affected packages:
- @backstage/config-loader
- @backstage/plugin-events-node
- @backstage/plugin-kubernetes-react

Signed-off-by: Johan Persson <johanopersson@gmail.com>
2025-12-11 18:07:00 +01:00
..
2025-12-09 15:00:09 +00:00

@backstage/plugin-events-node

This package defined basic types for event-based interactions inside of Backstage.

Additionally, it provides the core event service eventsServiceRef of type EventsService with its default implementation that uses the DefaultEventsService implementation.

DefaultEventsService is a simple in-memory implementation that requires the co-deployment of producers and consumers of events.

Installation

Add @backstage/plugin-events-node as dependency to your plugin or plugin module package to which you want to add event support.

Use eventsServiceRef as a dependency at your plugin or plugin module.

Legacy Backend System

Create an EventsService instance and add it to the environment.

// packages/backend/src/plugins/events.ts
import { DefaultEventsService } from '@backstage/plugin-events-node';

// ...

function makeCreateEnv(config: Config) {
  // ...
  const eventsService = DefaultEventsService.create({ logger: root, config });
  // ...
  return (plugin: string): PluginEnvironment => {
    // ...
    return {
      // ...
      events: eventsService,
      // ...
    };
  };
}

Use the events from the PluginEnvironment as desired:

// packages/backend/src/plugins/events.ts
export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  // ...
  env.events; // ...
  // ...
}

Use Case

Exchange service implementation

Create your custom service factory implementation:

import { eventsServiceRef } from '@backstage/plugin-events-node';
// ...
export const customEventsServiceFactory = createServiceFactory({
  service: eventsServiceRef,
  deps: {
    // add needed dependencies here
  },
  async factory({ logger }) {
    // add your custom logic here
    return customEventsService;
  },
});

and your custom implementation:

// packages/backend/src/index.ts
+  backend.add(customEventsServiceFactory);