defunctzombie / node-process

process information for node.js and browsers
MIT License
122 stars 62 forks source link

Feature detect if browser or node.js #85

Open mushishi78 opened 5 years ago

mushishi78 commented 5 years ago

Taken from https://github.com/visionmedia/debug/blob/master/src/index.js

calvinmetcalf commented 5 years ago

this is the thing that's supposed to be adding the global.process, I'm not sure you can check against it for this module.

mushishi78 commented 5 years ago

This is not adding the process object to the global process variable, it's adding it to the export for this package. The purpose is so that if you want to be agnostic about whether you're in browser, you can rely on the import of this library being there but you can't rely on the global variable being there.

The reason I needed this is because I'm trying out a bundler that doesn't respect the "browser" field in the package.json. I saw that the linked debug library had used this fix in later versions to support this use case so I figured it was fair to give PR to do the same here.

Could also probably just do this if you prefer:

module.exports = global.process || require('./browser.js');