Skip to content

Commit 0c9c3e2

Browse files
committed
Use instance methods on process to check for listeners
1 parent 74c2ac1 commit 0c9c3e2

File tree

4 files changed

+22
-71
lines changed

4 files changed

+22
-71
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
* Drop support for Node.js 0.6
55
* Replace interal `eval` usage with `Function` constructor
6+
* Use instance methods on `process` to check for listeners
67

78
1.1.2 / 2018-01-11
89
==================

index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* Module dependencies.
99
*/
1010

11-
var eventListenerCount = require('./lib/compat').eventListenerCount
1211
var relative = require('path').relative
1312

1413
/**
@@ -127,6 +126,26 @@ function depd (namespace) {
127126
return deprecate
128127
}
129128

129+
/**
130+
* Determine if event emitter has listeners of a given type.
131+
*
132+
* The way to do this check is done three different ways in Node.js >= 0.8
133+
* so this consolidates them into a minimal set using instance methods.
134+
*
135+
* @param {EventEmitter} emitter
136+
* @param {string} type
137+
* @returns {boolean}
138+
* @private
139+
*/
140+
141+
function eehaslisteners (emitter, type) {
142+
var count = typeof emitter.listenerCount !== 'function'
143+
? emitter.listeners(type).length
144+
: emitter.listenerCount(type)
145+
146+
return count > 0
147+
}
148+
130149
/**
131150
* Determine if namespace is ignored.
132151
*/
@@ -166,7 +185,7 @@ function istraced (namespace) {
166185
*/
167186

168187
function log (message, site) {
169-
var haslisteners = eventListenerCount(process, 'deprecation') !== 0
188+
var haslisteners = eehaslisteners(process, 'deprecation')
170189

171190
// abort early if no destination
172191
if (!haslisteners && this._ignored) {

lib/compat/event-listener-count.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/compat/index.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)