feat: Don't load native module if WS_NO_BUFFER_UTIL is set
This PR ensures that bufferutil.node is not loaded if the environment variable WS_NO_BUFFER_UTIL is set.
I'm in a somewhat weird situation: I want to build an app that needs to rebuild bufferutil in node_modules. At the same time, some of my devDependencies use webSockets, so they end up loading bufferutil.node - which creates a file lock on Windows, and then an EPERM error when I end up calling node-gyp rebuild. With this change, I can ensure that my various dependencies don't load bufferutil even if it's present - and even if I can't directly control which exact version of webSockets they use.
No thanks, WS_NO_BUFFER_UTIL is not a bufferutil specific environment variable. Also, if bufferutil is still required (albeit with fallback code), it means that WS_NO_BUFFER_UTIL is not honored.
No worries! I wish there was a way to control bufferutil's native behavior though. In practice, not being able to control bufferutil directly means that I can't use it or WebSockets in any of my Electron apps if any of my dev dependencies (like webpack) also use it.
Obviously, WS_NO_BUFFER_UTIL would be the right solution at the WebSockets level - but many dependencies are still on older versions of WebSockets and API changes mean that I can't easily upgrade them. I could do that with bufferutil.
I get that that's a pretty specific use case though, for now we're just removing WebSockets from our apps and replacing them with MessagePorts.