diff --git a/changelog.md b/changelog.md index e79ef3f..653899f 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/updater/index.js b/updater/index.js index dfd1889..28eaae2 100644 --- a/updater/index.js +++ b/updater/index.js @@ -1,3 +1,4 @@ +let { getEventListeners } = require('events') let chalk = require('chalk') let { printer } = require('./lib') let methods = require('./methods') @@ -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()