Skip to content

Commit

Permalink
fix!: remove CustomEvent export from @libp2p/interface (#2656)
Browse files Browse the repository at this point in the history
`CustomEvent` is global in Node.js as of `v18.7.0`. We support LTS
and Current which means `v20+`, and Electron has upgraded to node
20 so the polyfill isn't necessary any more.

BREAKING CHANGE: `@libp2p/interface` no longer exports a `CustomEvent` polyfill
  • Loading branch information
achingbrain committed Sep 6, 2024
1 parent 301bfc3 commit fab6fc9
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint max-nested-callbacks: ["error", 8] */
import { CustomEvent, TypedEventEmitter } from '@libp2p/interface'
import { TypedEventEmitter } from '@libp2p/interface'
import { expect } from 'aegir/chai'
import drain from 'it-drain'
import { pipe } from 'it-pipe'
Expand Down
2 changes: 0 additions & 2 deletions packages/interface/src/event-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,3 @@ export class TypedEventEmitter<EventMap extends Record<string, any>> extends Eve
return this.dispatchEvent(new CustomEvent<Detail>(type as string, detail))
}
}

export const CustomEvent = globalThis.CustomEvent
2 changes: 1 addition & 1 deletion packages/kad-dht/src/kad-dht.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError, CustomEvent, TypedEventEmitter, contentRoutingSymbol, peerDiscoverySymbol, peerRoutingSymbol, serviceCapabilities, serviceDependencies, start, stop } from '@libp2p/interface'
import { CodeError, TypedEventEmitter, contentRoutingSymbol, peerDiscoverySymbol, peerRoutingSymbol, serviceCapabilities, serviceDependencies, start, stop } from '@libp2p/interface'
import drain from 'it-drain'
import pDefer from 'p-defer'
import { PROTOCOL } from './constants.js'
Expand Down
1 change: 0 additions & 1 deletion packages/kad-dht/src/query/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CustomEvent } from '@libp2p/interface'
import type { MessageType, SendQueryEvent, PeerResponseEvent, DialPeerEvent, AddPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '../index.js'
import type { PeerId, PeerInfo } from '@libp2p/interface'
import type { Libp2pRecord } from '@libp2p/record'
Expand Down
2 changes: 1 addition & 1 deletion packages/kad-dht/src/topology-listener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CustomEvent, TypedEventEmitter } from '@libp2p/interface'
import { TypedEventEmitter } from '@libp2p/interface'
import type { KadDHTComponents } from '.'
import type { Logger, PeerId, Startable } from '@libp2p/interface'

Expand Down
1 change: 0 additions & 1 deletion packages/kad-dht/test/query-self.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-env mocha */

import { CustomEvent } from '@libp2p/interface'
import { defaultLogger } from '@libp2p/logger'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
Expand Down
2 changes: 1 addition & 1 deletion packages/kad-dht/test/routing-table.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env mocha */

import { TypedEventEmitter, CustomEvent, stop, start } from '@libp2p/interface'
import { TypedEventEmitter, stop, start } from '@libp2p/interface'
import { mockConnectionManager } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { PeerSet } from '@libp2p/peer-collections'
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/src/libp2p.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys'
import { contentRoutingSymbol, CodeError, TypedEventEmitter, CustomEvent, setMaxListeners, peerDiscoverySymbol, peerRoutingSymbol } from '@libp2p/interface'
import { contentRoutingSymbol, CodeError, TypedEventEmitter, setMaxListeners, peerDiscoverySymbol, peerRoutingSymbol } from '@libp2p/interface'
import { defaultLogger } from '@libp2p/logger'
import { PeerSet } from '@libp2p/peer-collections'
import { peerIdFromString } from '@libp2p/peer-id'
Expand Down
2 changes: 1 addition & 1 deletion packages/peer-discovery-mdns/src/mdns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CustomEvent, TypedEventEmitter, peerDiscoverySymbol, serviceCapabilities } from '@libp2p/interface'
import { TypedEventEmitter, peerDiscoverySymbol, serviceCapabilities } from '@libp2p/interface'
import multicastDNS from 'multicast-dns'
import * as query from './query.js'
import { stringGen } from './utils.js'
Expand Down
1 change: 0 additions & 1 deletion packages/peer-discovery-mdns/test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-env mocha */

import { CustomEvent } from '@libp2p/interface'
import tests from '@libp2p/interface-compliance-tests/peer-discovery'
import { defaultLogger } from '@libp2p/logger'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
Expand Down
2 changes: 1 addition & 1 deletion packages/pubsub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* ```
*/

import { CodeError, TypedEventEmitter, CustomEvent, TopicValidatorResult } from '@libp2p/interface'
import { CodeError, TypedEventEmitter, TopicValidatorResult } from '@libp2p/interface'
import { PeerMap, PeerSet } from '@libp2p/peer-collections'
import { pipe } from 'it-pipe'
import Queue from 'p-queue'
Expand Down
2 changes: 1 addition & 1 deletion packages/pubsub/src/peer-streams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypedEventEmitter, CustomEvent } from '@libp2p/interface'
import { TypedEventEmitter } from '@libp2p/interface'
import { closeSource } from '@libp2p/utils/close-source'
import * as lp from 'it-length-prefixed'
import { pipe } from 'it-pipe'
Expand Down

0 comments on commit fab6fc9

Please sign in to comment.