esm: protect against removal of `"beforeExit"` event handler
tbh I'm not sure if that's a good idea, it's still quite brittle because hooks authors could still remove the removeListener
listener (e.g. by calling process.removeAllListeners())
, and at some point there's no way around it – or at least, I didn't find a way. I'm opening this in case someone has a better solution they'd want to share.