Skip to content

Commit e4bc406

Browse files
committed
Fixed MaxListenersExceededWarning
1 parent 49e4c4f commit e4bc406

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
---
44

5+
## [4.0.3] 2024-02-09
6+
7+
### Fixed
8+
9+
- Fixed `MaxListenersExceededWarning` if npm or another package manager resolves many different versions of Utils on the filesystem
10+
11+
---
12+
513
## [4.0.2] 2024-02-06
614

715
### Changed

updater/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
let { getEventListeners } = require('events')
12
let chalk = require('chalk')
23
let { printer } = require('./lib')
34
let methods = require('./methods')
@@ -71,9 +72,18 @@ module.exports = function statusUpdater (name, args = {}) {
7172
}
7273
}
7374

74-
// For whatever reason signal-exit doesn't catch SIGINT, so do this
75-
process.on('SIGINT', () => {
76-
printer.restoreCursor()
77-
console.log('')
78-
process.exit()
79-
})
75+
// For whatever reason signal-exit doesn't catch SIGINT, so do this...
76+
// Also, if the resolved dep tree isn't totally flat on the filesystem, multiple installations of utils can attempt to attach SIGINT listeners, so we have to guard against that
77+
function restoreCursor () {
78+
let listeners = getEventListeners(process, 'SIGINT')
79+
let needsRestore = !listeners?.length ||
80+
!listeners.some(fn => fn.name === '_arcRestoreCursor')
81+
if (needsRestore) {
82+
process.on('SIGINT', function _arcRestoreCursor () {
83+
printer.restoreCursor()
84+
console.log('')
85+
process.exit()
86+
})
87+
}
88+
}
89+
restoreCursor()

0 commit comments

Comments
 (0)