Skip to content

Commit

Permalink
Fixed MaxListenersExceededWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Feb 9, 2024
1 parent 49e4c4f commit e4bc406
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

---

## [4.0.3] 2024-02-09

### Fixed

- Fixed `MaxListenersExceededWarning` if npm or another package manager resolves many different versions of Utils on the filesystem

---

## [4.0.2] 2024-02-06

### Changed
Expand Down
22 changes: 16 additions & 6 deletions updater/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
let { getEventListeners } = require('events')
let chalk = require('chalk')
let { printer } = require('./lib')
let methods = require('./methods')
Expand Down Expand Up @@ -71,9 +72,18 @@ module.exports = function statusUpdater (name, args = {}) {
}
}

// For whatever reason signal-exit doesn't catch SIGINT, so do this
process.on('SIGINT', () => {
printer.restoreCursor()
console.log('')
process.exit()
})
// For whatever reason signal-exit doesn't catch SIGINT, so do this...
// 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
function restoreCursor () {
let listeners = getEventListeners(process, 'SIGINT')
let needsRestore = !listeners?.length ||
!listeners.some(fn => fn.name === '_arcRestoreCursor')
if (needsRestore) {
process.on('SIGINT', function _arcRestoreCursor () {
printer.restoreCursor()
console.log('')
process.exit()
})
}
}
restoreCursor()

0 comments on commit e4bc406

Please sign in to comment.