Skip to content

Comments

chore: Replace events npm package with native ESM EventEmitter implementation#3657

Closed
marshallswain wants to merge 2 commits intov6from
v6-events
Closed

chore: Replace events npm package with native ESM EventEmitter implementation#3657
marshallswain wants to merge 2 commits intov6from
v6-events

Conversation

@marshallswain
Copy link
Member

Replaces the events npm package (a CJS browserify polyfill) with a lightweight, pure ESM EventEmitter written in TypeScript. This fixes compatibility issues with Node 24's stricter ESM/CJS interop.

Problem:
The [email protected] npm package is CommonJS. In Node 24, the tightened CJS named export detection causes import { EventEmitter } from 'events' to fail when it resolves to the npm polyfill instead of the Node built-in.

Solution:

  • Added a native ESM EventEmitter implementation directly in events.ts
  • Prototype methods are assigned as enumerable properties so Object.assign mixin pattern continues to work
  • Lazy __events initialization supports both class inheritance and mixin usage
  • Removed the events npm dependency from package.json
  • Channel interface now extends EventEmitter for proper typing

API surface implemented: on, addListener, once, off, removeListener, removeAllListeners, emit, listenerCount, listeners

Files changed (8):

  • packages/feathers/src/events.ts — EventEmitter implementation + existing event hooks
  • packages/feathers/src/events.test.ts — 18 new EventEmitter unit tests merged with existing service event tests
  • packages/feathers/src/application.ts — import update
  • packages/feathers/src/channel/base.ts — import update
  • packages/feathers/src/declarations.ts — import update, Channel interface extends EventEmitter
  • packages/feathers/src/service.ts — inlined emitter method names in protectedMethods
  • packages/feathers/src/index.ts — exports EventEmitter
  • packages/feathers/package.json — removed events dependency

Tests: 371 passed, 1 skipped (pre-existing). TypeScript clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant