-
Notifications
You must be signed in to change notification settings - Fork 361
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
using top level context to determine node vs browser environment #350
Conversation
Pull Request Test Coverage Report for Build 495
💛 - Coveralls |
So, this environment detection function is kind of hard to test. It's by definition very tightly coupled with the environment in runs on. It's written to avoid being mocked (so that a node environment with a mocked window global, like with jsdom, doesn't trigger a false positive browser detection). I'm open to an argument as to how/why to test this function. |
This looks reasonable to me, but it occurred to me that I didn't know whether it would work properly in the weird environment that the devtools run in. So, I think someone else ought to review it, like maybe @codehag |
This looks good to me 👍 |
Another option here would be to use a replacement file for browser builds, e.g. in
then the alternate file would be used when the library is bundled with Webpack and such, and it would be up to the consumers of the package to choose the build target. |
@loganfsmyth - this seems like a much cleaner approach. I haven't done too much with npm publishing, so I'm unfamiliar with this environment specific configuration. Is there a good example/best practice of how webpack projects that target these sorts alternative builds? |
Webpack has its I think it'd be a good approach to handle to existing way that this code works. That said, I do want to clarify that I have reservations in general about how this all works, since I think it is a little scary for a library to behave in two very different ways depending on how it is used, since a you have to pass the worker URL in one case but not the other. It might be nicer in the long run for the node build to use |
Possible solution for:
#349
Ran into this issue because of my node environment's fetch polyfill. To get around this, I used a solution inspired by the solution proposed in this stack overflow question to fix this for myself.