Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MaxListenersExceededWarning #230

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading