Skip to content

Commit 4bd1cec

Browse files
committed
fix(spawnify) when error.code === EACESS, close and exit events do not emitted
1 parent bafc6c8 commit 4bd1cec

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/spawnify.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,30 @@
9191
};
9292

9393
Spawnify.prototype._emit = function emit(event, data) {
94-
var count;
94+
var self = this,
95+
count = function(event) {
96+
var listeners = self.listeners(event);
97+
98+
return listeners.length;
99+
};
95100

96101
assert(event, 'event could not be empty!');
97102

98-
count = this.listeners(event).length;
99-
100-
if (count || event === 'error')
103+
if (count(event) || event === 'error') {
101104
this.emit(event, data);
105+
106+
/*
107+
* when code is EACESS
108+
* close and exit events
109+
* whould not be emitted
110+
*/
111+
if (event === 'error' && data.code === 'EACCES')
112+
if (count('close'))
113+
this.emit('close');
114+
115+
if (count('exit'))
116+
this.emit('exit');
117+
}
102118
};
103119

104120
Spawnify.prototype._set = function set(type, command, options) {

0 commit comments

Comments
 (0)